ESPHome 2026.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
5
6static const char *const TAG = "bmp3xx_spi.sensor";
7
8uint8_t set_bit(uint8_t num, int position) {
9 int mask = 1 << position;
10 return num | mask;
11}
12
13uint8_t clear_bit(uint8_t num, int position) {
14 int mask = 1 << position;
15 return num & ~mask;
16}
17
18void BMP3XXSPIComponent::setup() {
19 this->spi_setup();
20 BMP3XXComponent::setup();
21}
22
23bool BMP3XXSPIComponent::read_byte(uint8_t a_register, uint8_t *data) {
24 this->enable();
25 this->transfer_byte(set_bit(a_register, 7));
26 *data = this->transfer_byte(0);
27 this->disable();
28 return true;
29}
30
31bool BMP3XXSPIComponent::write_byte(uint8_t a_register, uint8_t data) {
32 this->enable();
33 this->transfer_byte(clear_bit(a_register, 7));
34 this->transfer_byte(data);
35 this->disable();
36 return true;
37}
38
39bool BMP3XXSPIComponent::read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
40 this->enable();
41 this->transfer_byte(set_bit(a_register, 7));
42 this->read_array(data, len);
43 this->disable();
44 return true;
45}
46
47bool BMP3XXSPIComponent::write_bytes(uint8_t a_register, uint8_t *data, size_t len) {
48 this->enable();
49 this->transfer_byte(clear_bit(a_register, 7));
50 this->transfer_array(data, len);
51 this->disable();
52 return true;
53}
54
55} // namespace esphome::bmp3xx_spi
float position
Definition cover.h:0
uint8_t set_bit(uint8_t num, int position)
Definition bmp3xx_spi.cpp:8
uint8_t clear_bit(uint8_t num, int position)
std::string size_t len