ESPHome 2025.5.0
Loading...
Searching...
No Matches
bmp3xx_spi.cpp
Go to the documentation of this file.
1#include "bmp3xx_spi.h"
2#include <cinttypes>
3
4namespace esphome {
5namespace bmp3xx_spi {
6
7static const char *const TAG = "bmp3xx_spi.sensor";
8
9uint8_t set_bit(uint8_t num, int position) {
10 int mask = 1 << position;
11 return num | mask;
12}
13
14uint8_t clear_bit(uint8_t num, int position) {
15 int mask = 1 << position;
16 return num & ~mask;
17}
18
19void BMP3XXSPIComponent::setup() {
20 this->spi_setup();
21 BMP3XXComponent::setup();
22}
23
24bool BMP3XXSPIComponent::read_byte(uint8_t a_register, uint8_t *data) {
25 this->enable();
26 this->transfer_byte(set_bit(a_register, 7));
27 *data = this->transfer_byte(0);
28 this->disable();
29 return true;
30}
31
32bool BMP3XXSPIComponent::write_byte(uint8_t a_register, uint8_t data) {
33 this->enable();
34 this->transfer_byte(clear_bit(a_register, 7));
35 this->transfer_byte(data);
36 this->disable();
37 return true;
38}
39
40bool BMP3XXSPIComponent::read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
41 this->enable();
42 this->transfer_byte(set_bit(a_register, 7));
43 this->read_array(data, len);
44 this->disable();
45 return true;
46}
47
48bool BMP3XXSPIComponent::write_bytes(uint8_t a_register, uint8_t *data, size_t len) {
49 this->enable();
50 this->transfer_byte(clear_bit(a_register, 7));
51 this->transfer_array(data, len);
52 this->disable();
53 return true;
54}
55
56} // namespace bmp3xx_spi
57} // namespace esphome
float position
Definition cover.h:0
uint8_t set_bit(uint8_t num, int position)
Definition bmp3xx_spi.cpp:9
uint8_t clear_bit(uint8_t num, int position)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:301