ESPHome  2024.4.0
as3935_spi.cpp
Go to the documentation of this file.
1 #include "as3935_spi.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace as3935_spi {
6 
7 static const char *const TAG = "as3935_spi";
8 
10  ESP_LOGI(TAG, "SPIAS3935Component setup started!");
11  this->spi_setup();
12  ESP_LOGI(TAG, "SPI setup finished!");
14 }
15 
17  AS3935Component::dump_config();
18  LOG_PIN(" CS Pin: ", this->cs_);
19 }
20 
21 void SPIAS3935Component::write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_pos) {
22  uint8_t write_reg = this->read_register(reg);
23 
24  write_reg &= (~mask);
25  write_reg |= (bits << start_pos);
26 
27  this->enable();
28  this->write_byte(reg);
29  this->write_byte(write_reg);
30  this->disable();
31 }
32 
33 uint8_t SPIAS3935Component::read_register(uint8_t reg) {
34  uint8_t value = 0;
35  this->enable();
36  this->write_byte(reg | SPI_READ_M);
37  value = this->read_byte();
38  // According to datsheet, the chip select must be written HIGH, LOW, HIGH
39  // to correctly end the READ command.
40  this->cs_->digital_write(true);
41  this->cs_->digital_write(false);
42  this->disable();
43  ESP_LOGV(TAG, "read_register_: %d", value);
44  return value;
45 }
46 
47 } // namespace as3935_spi
48 } // namespace esphome
void setup()
virtual void digital_write(bool value)=0
GPIOPin * cs_
Definition: spi.h:395
uint8_t read_register(uint8_t reg) override
Definition: as3935_spi.cpp:33
void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position) override
Definition: as3935_spi.cpp:21
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7