ESPHome 2026.4.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
16static const char *const 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 this->enable();
43 this->transfer_byte(a_register | SPA06_SPI_READ);
44 *data = this->transfer_byte(0);
45 this->disable();
46 return true;
47}
48
49bool SPA06SPIComponent::spa_write_byte(uint8_t a_register, uint8_t data) {
50 this->enable();
51 this->transfer_byte(a_register & SPA06_SPI_WRITE);
52 this->transfer_byte(data);
53 this->disable();
54 return true;
55}
56
57bool SPA06SPIComponent::spa_read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
58 this->enable();
59 this->transfer_byte(a_register | SPA06_SPI_READ);
60 this->read_array(data, len);
61 this->disable();
62 return true;
63}
64
65bool SPA06SPIComponent::spa_write_bytes(uint8_t a_register, uint8_t *data, size_t len) {
66 this->enable();
67 this->transfer_byte(a_register & SPA06_SPI_WRITE);
68 this->write_array(data, len);
69 this->disable();
70 return true;
71}
72} // namespace esphome::spa06_spi
std::string size_t len
Definition helpers.h:1045
constexpr uint8_t SPA06_SPI_WRITE
Definition spa06_spi.cpp:12
constexpr uint8_t SPA06_SPI_READ
Definition spa06_spi.cpp:9