ESPHome  2024.11.0
bmp3xx_spi.cpp
Go to the documentation of this file.
1 #include "bmp3xx_spi.h"
2 #include <cinttypes>
3 
4 namespace esphome {
5 namespace bmp3xx_spi {
6 
7 static const char *const TAG = "bmp3xx_spi.sensor";
8 
9 uint8_t set_bit(uint8_t num, int position) {
10  int mask = 1 << position;
11  return num | mask;
12 }
13 
14 uint8_t clear_bit(uint8_t num, int position) {
15  int mask = 1 << position;
16  return num & ~mask;
17 }
18 
19 void BMP3XXSPIComponent::setup() {
20  this->spi_setup();
22 }
23 
24 bool 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 
32 bool 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 
40 bool 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 
48 bool 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
void setup()
void transfer_array(uint8_t *data, size_t length)
Write the array data, replace with received data.
Definition: spi.h:447
uint8_t set_bit(uint8_t num, int position)
Definition: bmp3xx_spi.cpp:9
uint8_t clear_bit(uint8_t num, int position)
Definition: bmp3xx_spi.cpp:14
std::string size_t len
Definition: helpers.h:293
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
float position
Definition: cover.h:14