ESPHome
2025.9.0-dev
Loading...
Searching...
No Matches
esphome
components
as3935_spi
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
9
void
SPIAS3935Component::setup
() {
10
this->
spi_setup
();
11
AS3935Component::setup();
12
}
13
14
void
SPIAS3935Component::dump_config
() {
15
AS3935Component::dump_config();
16
LOG_PIN(
" CS Pin: "
, this->
cs_
);
17
}
18
19
void
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
31
uint8_t
SPIAS3935Component::read_register
(uint8_t reg) {
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
as3935_spi.h
esphome::GPIOPin::digital_write
virtual void digital_write(bool value)=0
esphome::as3935_spi::SPIAS3935Component::read_register
uint8_t read_register(uint8_t reg) override
Definition
as3935_spi.cpp:31
esphome::as3935_spi::SPIAS3935Component::write_register
void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position) override
Definition
as3935_spi.cpp:19
esphome::as3935_spi::SPIAS3935Component::setup
void setup() override
Definition
as3935_spi.cpp:9
esphome::as3935_spi::SPIAS3935Component::dump_config
void dump_config() override
Definition
as3935_spi.cpp:14
esphome::spi::SPIClient::cs_
GPIOPin * cs_
Definition
spi.h:412
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ >::enable
void enable()
Definition
spi.h:499
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ >::spi_setup
void spi_setup() override
Definition
spi.h:436
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ >::read_byte
uint8_t read_byte()
Definition
spi.h:450
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ >::write_byte
void write_byte(uint8_t data)
Definition
spi.h:476
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ >::disable
void disable()
Definition
spi.h:501
log.h
esphome::as3935_spi::SPI_READ_M
@ SPI_READ_M
Definition
as3935_spi.h:10
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
Generated by
1.12.0