ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ade7953_base.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7#include <vector>
8
9namespace esphome::ade7953_base {
10
11static constexpr uint8_t PGA_V_8 =
12 0x007; // PGA_V, (R/W) Default: 0x00, Unsigned, Voltage channel gain configuration (Bits[2:0])
13static constexpr uint8_t PGA_IA_8 =
14 0x008; // PGA_IA, (R/W) Default: 0x00, Unsigned, Current Channel A gain configuration (Bits[2:0])
15static constexpr uint8_t PGA_IB_8 =
16 0x009; // PGA_IB, (R/W) Default: 0x00, Unsigned, Current Channel B gain configuration (Bits[2:0])
17
18static constexpr uint16_t CONFIG_16 = 0x102; // CONFIG, (R/W) Default: 0x8004, Unsigned, Configuration register
19
20static constexpr uint16_t AIGAIN_32 =
21 0x380; // AIGAIN, (R/W) Default: 0x400000, Unsigned,Current channel gain (Current Channel A)(32 bit)
22static constexpr uint16_t AVGAIN_32 =
23 0x381; // AVGAIN, (R/W) Default: 0x400000, Unsigned,Voltage channel gain(32 bit)
24static constexpr uint16_t AWGAIN_32 =
25 0x382; // AWGAIN, (R/W) Default: 0x400000, Unsigned,Active power gain (Current Channel A)(32 bit)
26static constexpr uint16_t AVARGAIN_32 =
27 0x383; // AVARGAIN, (R/W) Default: 0x400000, Unsigned, Reactive power gain (Current Channel A)(32 bit)
28static constexpr uint16_t AVAGAIN_32 =
29 0x384; // AVAGAIN, (R/W) Default: 0x400000, Unsigned,Apparent power gain (Current Channel A)(32 bit)
30
31static constexpr uint16_t BIGAIN_32 =
32 0x38C; // BIGAIN, (R/W) Default: 0x400000, Unsigned,Current channel gain (Current Channel B)(32 bit)
33static constexpr uint16_t BVGAIN_32 =
34 0x38D; // BVGAIN, (R/W) Default: 0x400000, Unsigned,Voltage channel gain(32 bit)
35static constexpr uint16_t BWGAIN_32 =
36 0x38E; // BWGAIN, (R/W) Default: 0x400000, Unsigned,Active power gain (Current Channel B)(32 bit)
37static constexpr uint16_t BVARGAIN_32 =
38 0x38F; // BVARGAIN, (R/W) Default: 0x400000, Unsigned, Reactive power gain (Current Channel B)(32 bit)
39static constexpr uint16_t BVAGAIN_32 =
40 0x390; // BVAGAIN, (R/W) Default: 0x400000, Unsigned,Apparent power gain (Current Channel B)(32 bit)
41
42class ADE7953 : public PollingComponent, public sensor::Sensor {
43 public:
44 void set_irq_pin(InternalGPIOPin *irq_pin) { irq_pin_ = irq_pin; }
45
46 // Set PGA input gains: 0 1x, 1 2x, 0b10 4x
47 void set_pga_v(uint8_t pga_v) { pga_v_ = pga_v; }
48 void set_pga_ia(uint8_t pga_ia) { pga_ia_ = pga_ia; }
49 void set_pga_ib(uint8_t pga_ib) { pga_ib_ = pga_ib; }
50
51 // Set input gains
52 void set_vgain(uint32_t vgain) {
53 // Datasheet says: "to avoid discrepancies in other registers,
54 // if AVGAIN is set then BVGAIN should be set to the same value."
55 avgain_ = vgain;
56 bvgain_ = vgain;
57 }
58 void set_aigain(uint32_t aigain) { aigain_ = aigain; }
59 void set_bigain(uint32_t bigain) { bigain_ = bigain; }
60 void set_awgain(uint32_t awgain) { awgain_ = awgain; }
61 void set_bwgain(uint32_t bwgain) { bwgain_ = bwgain; }
62
63 void set_use_acc_energy_regs(bool use_acc_energy_regs) { use_acc_energy_regs_ = use_acc_energy_regs; }
64
65 SUB_SENSOR(voltage)
67
68 SUB_SENSOR(power_factor_a)
69 SUB_SENSOR(power_factor_b)
70
71 SUB_SENSOR(current_a)
72 SUB_SENSOR(current_b)
73
74 SUB_SENSOR(apparent_power_a)
75 SUB_SENSOR(apparent_power_b)
76
77 SUB_SENSOR(active_power_a)
78 SUB_SENSOR(active_power_b)
79
80 SUB_SENSOR(reactive_power_a)
81 SUB_SENSOR(reactive_power_b)
82
83 void setup() override;
84
85 void dump_config() override;
86
87 void update() override;
88
89 protected:
91 bool is_setup_{false};
92 uint8_t pga_v_;
93 uint8_t pga_ia_;
94 uint8_t pga_ib_;
103
104 virtual bool ade_write_8(uint16_t reg, uint8_t value) = 0;
105
106 virtual bool ade_write_16(uint16_t reg, uint16_t value) = 0;
107
108 virtual bool ade_write_32(uint16_t reg, uint32_t value) = 0;
109
110 virtual bool ade_read_8(uint16_t reg, uint8_t *value) = 0;
111
112 virtual bool ade_read_16(uint16_t reg, uint16_t *value) = 0;
113
114 virtual bool ade_read_32(uint16_t reg, uint32_t *value) = 0;
115};
116
117} // namespace esphome::ade7953_base
uint16_le_t frequency
Definition bl0942.h:6
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:84
This class simplifies creating components that periodically check a state.
Definition component.h:532
virtual bool ade_write_32(uint16_t reg, uint32_t value)=0
void set_pga_ib(uint8_t pga_ib)
virtual bool ade_read_16(uint16_t reg, uint16_t *value)=0
void set_pga_v(uint8_t pga_v)
void set_use_acc_energy_regs(bool use_acc_energy_regs)
void set_bwgain(uint32_t bwgain)
void set_awgain(uint32_t awgain)
virtual bool ade_read_8(uint16_t reg, uint8_t *value)=0
virtual bool ade_read_32(uint16_t reg, uint32_t *value)=0
void set_pga_ia(uint8_t pga_ia)
void set_aigain(uint32_t aigain)
virtual bool ade_write_16(uint16_t reg, uint16_t value)=0
SUB_SENSOR(voltage) SUB_SENSOR(frequency) SUB_SENSOR(power_factor_a) SUB_SENSOR(power_factor_b) SUB_SENSOR(current_a) SUB_SENSOR(current_b) SUB_SENSOR(apparent_power_a) SUB_SENSOR(apparent_power_b) SUB_SENSOR(active_power_a) SUB_SENSOR(active_power_b) SUB_SENSOR(reactive_power_a) SUB_SENSOR(reactive_power_b) void setup() override
void set_irq_pin(InternalGPIOPin *irq_pin)
void set_vgain(uint32_t vgain)
virtual bool ade_write_8(uint16_t reg, uint8_t value)=0
void set_bigain(uint32_t bigain)
Base-class for all sensors.
Definition sensor.h:48
uint32_t value
Definition hal.cpp:41
static void uint32_t