ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
cs5460a.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <cinttypes>
9
10namespace esphome::cs5460a {
11
24
26 REG_CONFIG = 0x00,
27 REG_IDCOFF = 0x01,
28 REG_IGN = 0x02,
29 REG_VDCOFF = 0x03,
30 REG_VGN = 0x04,
33 REG_I = 0x07,
34 REG_V = 0x08,
35 REG_P = 0x09,
36 REG_E = 0x0a,
37 REG_IRMS = 0x0b,
38 REG_VRMS = 0x0c,
39 REG_TBC = 0x0d,
40 REG_POFF = 0x0e,
41 REG_STATUS = 0x0f,
42 REG_IACOFF = 0x10,
43 REG_VACOFF = 0x11,
44 REG_MASK = 0x1a,
46};
47
54
56 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
57 spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ> {
58 public:
59 void set_samples(uint32_t samples) { samples_ = samples; }
60 void set_phase_offset(int8_t phase_offset) { phase_offset_ = phase_offset; }
61 void set_pga_gain(CS5460APGAGain pga_gain) { pga_gain_ = pga_gain; }
62 void set_gains(float current_gain, float voltage_gain) {
63 current_gain_ = current_gain;
64 voltage_gain_ = voltage_gain;
65 }
66 void set_hpf_enable(bool current_hpf, bool voltage_hpf) {
67 current_hpf_ = current_hpf;
68 voltage_hpf_ = voltage_hpf;
69 }
70 void set_pulse_energy_wh(float pulse_energy_wh) { pulse_energy_wh_ = pulse_energy_wh; }
71 void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; }
72 void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
73 void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
74
75 void restart() { restart_(); }
76
77 void setup() override;
78 void dump_config() override;
79
80 protected:
92
93 void write_register_(enum CS5460ARegister addr, uint32_t value);
94 uint32_t read_register_(uint8_t addr);
95 bool softreset_();
96 void hw_init_();
97 void restart_();
98 void started_();
100 bool check_status_();
101
109};
110
111template<typename... Ts> class CS5460ARestartAction : public Action<Ts...> {
112 public:
114
115 void play(const Ts &...x) override { cs5460a_->restart(); }
116
117 protected:
119};
120
121} // namespace esphome::cs5460a
void set_gains(float current_gain, float voltage_gain)
Definition cs5460a.h:62
void set_power_sensor(sensor::Sensor *power_sensor)
Definition cs5460a.h:73
void write_register_(enum CS5460ARegister addr, uint32_t value)
Definition cs5460a.cpp:8
void set_current_sensor(sensor::Sensor *current_sensor)
Definition cs5460a.h:71
sensor::Sensor * voltage_sensor_
Definition cs5460a.h:90
void set_phase_offset(int8_t phase_offset)
Definition cs5460a.h:60
void set_pulse_energy_wh(float pulse_energy_wh)
Definition cs5460a.h:70
uint32_t read_register_(uint8_t addr)
Definition cs5460a.cpp:15
void set_samples(uint32_t samples)
Definition cs5460a.h:59
sensor::Sensor * power_sensor_
Definition cs5460a.h:91
void set_voltage_sensor(sensor::Sensor *voltage_sensor)
Definition cs5460a.h:72
void set_hpf_enable(bool current_hpf, bool voltage_hpf)
Definition cs5460a.h:66
sensor::Sensor * current_sensor_
Definition cs5460a.h:89
void set_pga_gain(CS5460APGAGain pga_gain)
Definition cs5460a.h:61
void play(const Ts &...x) override
Definition cs5460a.h:115
CS5460ARestartAction(CS5460AComponent *cs5460a)
Definition cs5460a.h:113
Base-class for all sensors.
Definition sensor.h:47
The SPIDevice is what components using the SPI will create.
Definition spi.h:429
CS5460APGAGain
Enum listing the current channel aplifiergain settings for the CS5460A.
Definition cs5460a.h:50
static void uint32_t
uint16_t x
Definition tt21100.cpp:5