ESPHome 2026.11.0b6
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 SUB_SENSOR(current)
58 SUB_SENSOR(voltage)
59 SUB_SENSOR(power)
60
61 public:
62 void set_samples(uint32_t samples) { samples_ = samples; }
63 void set_phase_offset(int8_t phase_offset) { phase_offset_ = phase_offset; }
64 void set_pga_gain(CS5460APGAGain pga_gain) { pga_gain_ = pga_gain; }
65 void set_gains(float current_gain, float voltage_gain) {
66 current_gain_ = current_gain;
67 voltage_gain_ = voltage_gain;
68 }
69 void set_hpf_enable(bool current_hpf, bool voltage_hpf) {
70 current_hpf_ = current_hpf;
71 voltage_hpf_ = voltage_hpf;
72 }
73 void set_pulse_energy_wh(float pulse_energy_wh) { pulse_energy_wh_ = pulse_energy_wh; }
74
75 void restart() { restart_(); }
76
77 void setup() override;
78 void dump_config() override;
79
80 protected:
89
91 uint32_t read_register_(uint8_t addr);
92 bool softreset_();
93 void hw_init_();
94 void restart_();
95 void started_();
97 bool check_status_();
98
106};
107
108} // namespace esphome::cs5460a
void write_register_(enum CS5460ARegister addr, uint32_t value)
Definition cs5460a.cpp:11
uint32_t read_register_(uint8_t addr)
Definition cs5460a.cpp:18
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
uint32_t value
Definition hal.cpp:41
static void uint32_t