ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
as3935_spi.cpp
Go to the documentation of this file.
1#include "as3935_spi.h"
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "as3935_spi";
7
9 this->spi_setup();
10 AS3935Component::setup();
11}
12
14 AS3935Component::dump_config();
15 LOG_PIN(" CS Pin: ", this->cs_);
16}
17
18void SPIAS3935Component::write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_pos) {
19 uint8_t write_reg = this->read_register(reg);
20
21 write_reg &= (~mask);
22 write_reg |= (bits << start_pos);
23
24 this->enable();
25 this->write_byte(reg);
26 this->write_byte(write_reg);
27 this->disable();
28}
29
31 uint8_t value = 0;
32 this->enable();
33 this->write_byte(reg | SPI_READ_M);
34 value = this->read_byte();
35 // According to datsheet, the chip select must be written HIGH, LOW, HIGH
36 // to correctly end the READ command.
37 this->cs_->digital_write(true);
38 this->cs_->digital_write(false);
39 this->disable();
40 ESP_LOGV(TAG, "read_register_: %d", value);
41 return value;
42}
43
44} // namespace esphome::as3935_spi
virtual void digital_write(bool value)=0
uint8_t read_register(uint8_t reg) override
void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position) override