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