ESPHome 2025.5.0
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 ESP_LOGI(TAG, "SPIAS3935Component setup started!");
11 this->spi_setup();
12 ESP_LOGI(TAG, "SPI setup finished!");
13 AS3935Component::setup();
14}
15
17 AS3935Component::dump_config();
18 LOG_PIN(" CS Pin: ", this->cs_);
19}
20
21void 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
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
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