ESPHome 2025.9.0-dev
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
4namespace esphome {
5namespace as3935_spi {
6
7static const char *const TAG = "as3935_spi";
8
10 this->spi_setup();
11 AS3935Component::setup();
12}
13
15 AS3935Component::dump_config();
16 LOG_PIN(" CS Pin: ", this->cs_);
17}
18
19void SPIAS3935Component::write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_pos) {
20 uint8_t write_reg = this->read_register(reg);
21
22 write_reg &= (~mask);
23 write_reg |= (bits << start_pos);
24
25 this->enable();
26 this->write_byte(reg);
27 this->write_byte(write_reg);
28 this->disable();
29}
30
32 uint8_t value = 0;
33 this->enable();
34 this->write_byte(reg | SPI_READ_M);
35 value = this->read_byte();
36 // According to datsheet, the chip select must be written HIGH, LOW, HIGH
37 // to correctly end the READ command.
38 this->cs_->digital_write(true);
39 this->cs_->digital_write(false);
40 this->disable();
41 ESP_LOGV(TAG, "read_register_: %d", value);
42 return value;
43}
44
45} // namespace as3935_spi
46} // namespace esphome
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
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7