ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
ade7953_spi.cpp
Go to the documentation of this file.
1#include "ade7953_spi.h"
3#include "esphome/core/log.h"
4
5namespace esphome {
6namespace ade7953_spi {
7
8static const char *const TAG = "ade7953";
9
10// Datasheet requires at least 1.2µs after clearing CONFIG LOCK_BIT before raising CS
11constexpr uint8_t CONFIG_LOCK_SETTLE_US = 2;
12
17
19 ESP_LOGCONFIG(TAG, "ADE7953_spi:");
20 LOG_PIN(" CS Pin: ", this->cs_);
22}
23
24bool AdE7953Spi::ade_write_8(uint16_t reg, uint8_t value) {
25 this->enable();
26 this->write_byte16(reg);
27 this->transfer_byte(0);
28 this->transfer_byte(value);
29 this->disable();
30 return false;
31}
32
33bool AdE7953Spi::ade_write_16(uint16_t reg, uint16_t value) {
34 this->enable();
35 this->write_byte16(reg);
36 this->transfer_byte(0);
37 this->write_byte16(value);
38 if (reg == ade7953_base::CONFIG_16) {
40 }
41 this->disable();
42 return false;
43}
44
45bool AdE7953Spi::ade_write_32(uint16_t reg, uint32_t value) {
46 this->enable();
47 this->write_byte16(reg);
48 this->transfer_byte(0);
49 this->write_byte16(value >> 16);
50 this->write_byte16(value & 0xFFFF);
51 this->disable();
52 return false;
53}
54
55bool AdE7953Spi::ade_read_8(uint16_t reg, uint8_t *value) {
56 this->enable();
57 this->write_byte16(reg);
58 this->transfer_byte(0x80);
59 *value = this->read_byte();
60 this->disable();
61 return false;
62}
63
64bool AdE7953Spi::ade_read_16(uint16_t reg, uint16_t *value) {
65 this->enable();
66 this->write_byte16(reg);
67 this->transfer_byte(0x80);
68 uint8_t recv[2];
69 this->read_array(recv, 2);
70 *value = encode_uint16(recv[0], recv[1]);
71 this->disable();
72 return false;
73}
74
75bool AdE7953Spi::ade_read_32(uint16_t reg, uint32_t *value) {
76 this->enable();
77 this->write_byte16(reg);
78 this->transfer_byte(0x80);
79 uint8_t recv[4];
80 this->read_array(recv, 4);
81 *value = encode_uint32(recv[0], recv[1], recv[2], recv[3]);
82 this->disable();
83 return false;
84}
85
86} // namespace ade7953_spi
87} // namespace esphome
bool ade_write_8(uint16_t reg, uint8_t value) override
bool ade_read_8(uint16_t reg, uint8_t *value) override
bool ade_read_32(uint16_t reg, uint32_t *value) override
bool ade_write_32(uint16_t reg, uint32_t value) override
bool ade_read_16(uint16_t reg, uint16_t *value) override
bool ade_write_16(uint16_t reg, uint16_t value) override
constexpr uint8_t CONFIG_LOCK_SETTLE_US
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:30
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
Definition helpers.h:889
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Definition helpers.h:881
static void uint32_t