ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
spa06_spi.cpp
Go to the documentation of this file.
1#include <cstdint>
2#include <cstddef>
3
4#include "spa06_spi.h"
7
8// OR (|) register with SPA06_SPI_READ for read.
9inline constexpr uint8_t SPA06_SPI_READ = 0x80;
10
11// AND (&) register with SPA06_SPI_WRITE for write.
12inline constexpr uint8_t SPA06_SPI_WRITE = 0x7F;
13
15
16ESPHOME_LOG_TAG(TAG, "spa06_spi");
17
18void SPA06SPIComponent::dump_config() {
19 SPA06Component::dump_config();
20 LOG_SPI_DEVICE(this)
21}
22
23void SPA06SPIComponent::setup() {
24 this->spi_setup();
25 SPA06Component::setup();
26}
27
29 // Forces the device into SPI mode using a dummy read
30 uint8_t dummy_read = 0;
31 this->spa_read_byte(spa06_base::SPA06_ID, &dummy_read);
32}
33
34// In SPI mode, only 7 bits of the register addresses are used; the MSB of register address
35// is not used and replaced by a read/write bit (RW = ‘0’ for write and RW = ‘1’ for read).
36// Example: address 0xF7 is accessed by using SPI register address 0x77. For write access,
37// the byte 0x77 is transferred, for read access, the byte 0xF7 is transferred.
38// The expressions SPA06_SPI_READ (| with register) and SPA06_SPI_WRITE (& with register)
39// are defined for readability.
40
41bool SPA06SPIComponent::spa_read_byte(uint8_t a_register, uint8_t *data) {
42 *data = this->read_register(a_register | SPA06_SPI_READ);
43 return true;
44}
45
46bool SPA06SPIComponent::spa_write_byte(uint8_t a_register, uint8_t data) {
47 this->write_register(a_register & SPA06_SPI_WRITE, data);
48 return true;
49}
50
51bool SPA06SPIComponent::spa_read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
52 this->read_registers(a_register | SPA06_SPI_READ, data, len);
53 return true;
54}
55
56bool SPA06SPIComponent::spa_write_bytes(uint8_t a_register, uint8_t *data, size_t len) {
57 this->write_registers(a_register & SPA06_SPI_WRITE, data, len);
58 return true;
59}
60} // namespace esphome::spa06_spi
ESPHOME_LOG_TAG(TAG, "spa06_spi")
const void size_t len
Definition hal.h:68
constexpr uint8_t SPA06_SPI_WRITE
Definition spa06_spi.cpp:12
constexpr uint8_t SPA06_SPI_READ
Definition spa06_spi.cpp:9