ESPHome
2026.11.0b6
Loading...
Searching...
No Matches
esphome
components
cs5460a
cs5460a.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/components/sensor/sensor.h
"
5
#include "
esphome/components/spi/spi.h
"
6
7
#include <cinttypes>
8
9
namespace
esphome::cs5460a
{
10
11
enum
CS5460ACommand
{
12
CMD_SYNC0
= 0xfe,
13
CMD_SYNC1
= 0xff,
14
CMD_START_SINGLE
= 0xe0,
15
CMD_START_CONT
= 0xe8,
16
CMD_POWER_UP
= 0xa0,
17
CMD_POWER_STANDBY
= 0x88,
18
CMD_POWER_SLEEP
= 0x90,
19
CMD_CALIBRATION
= 0xc0,
20
CMD_READ
= 0x00,
21
CMD_WRITE
= 0x40,
22
};
23
24
enum
CS5460ARegister
{
25
REG_CONFIG
= 0x00,
26
REG_IDCOFF
= 0x01,
27
REG_IGN
= 0x02,
28
REG_VDCOFF
= 0x03,
29
REG_VGN
= 0x04,
30
REG_CYCLE_COUNT
= 0x05,
31
REG_PULSE_RATE
= 0x06,
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,
44
REG_CONTROL
= 0x1c,
45
};
46
49
enum
CS5460APGAGain
{
50
CS5460A_PGA_GAIN_10X
= 0b0,
51
CS5460A_PGA_GAIN_50X
= 0b1,
52
};
53
54
class
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
:
81
uint32_t
samples_
;
82
int8_t
phase_offset_
;
83
CS5460APGAGain
pga_gain_
;
84
float
current_gain_
;
85
float
voltage_gain_
;
86
bool
current_hpf_
;
87
bool
voltage_hpf_
;
88
float
pulse_energy_wh_
;
89
90
void
write_register_
(
enum
CS5460ARegister
addr,
uint32_t
value
);
91
uint32_t
read_register_
(uint8_t addr);
92
bool
softreset_
();
93
void
hw_init_
();
94
void
restart_
();
95
void
started_
();
96
void
schedule_next_check_
();
97
bool
check_status_
();
98
99
float
current_multiplier_
;
100
float
voltage_multiplier_
;
101
float
power_multiplier_
;
102
float
pulse_freq_
;
103
uint32_t
expect_data_ts_
;
104
uint32_t
prev_raw_current_
{0};
105
uint32_t
prev_raw_energy_
{0};
106
};
107
108
}
// namespace esphome::cs5460a
esphome::Component
Definition
component.h:147
esphome::cs5460a::CS5460AComponent
Definition
cs5460a.h:56
esphome::cs5460a::CS5460AComponent::current_multiplier_
float current_multiplier_
Definition
cs5460a.h:99
esphome::cs5460a::CS5460AComponent::power_multiplier_
float power_multiplier_
Definition
cs5460a.h:101
esphome::cs5460a::CS5460AComponent::pga_gain_
CS5460APGAGain pga_gain_
Definition
cs5460a.h:83
esphome::cs5460a::CS5460AComponent::voltage_gain_
float voltage_gain_
Definition
cs5460a.h:85
esphome::cs5460a::CS5460AComponent::restart_
void restart_()
Definition
cs5460a.cpp:104
esphome::cs5460a::CS5460AComponent::prev_raw_energy_
uint32_t prev_raw_energy_
Definition
cs5460a.h:105
esphome::cs5460a::CS5460AComponent::phase_offset_
int8_t phase_offset_
Definition
cs5460a.h:82
esphome::cs5460a::CS5460AComponent::softreset_
bool softreset_()
Definition
cs5460a.cpp:29
esphome::cs5460a::CS5460AComponent::write_register_
void write_register_(enum CS5460ARegister addr, uint32_t value)
Definition
cs5460a.cpp:11
esphome::cs5460a::CS5460AComponent::expect_data_ts_
uint32_t expect_data_ts_
Definition
cs5460a.h:103
esphome::cs5460a::CS5460AComponent::pulse_freq_
float pulse_freq_
Definition
cs5460a.h:102
esphome::cs5460a::CS5460AComponent::current_gain_
float current_gain_
Definition
cs5460a.h:84
esphome::cs5460a::CS5460AComponent::pulse_energy_wh_
float pulse_energy_wh_
Definition
cs5460a.h:88
esphome::cs5460a::CS5460AComponent::current_hpf_
bool current_hpf_
Definition
cs5460a.h:86
esphome::cs5460a::CS5460AComponent::read_register_
uint32_t read_register_(uint8_t addr)
Definition
cs5460a.cpp:18
esphome::cs5460a::CS5460AComponent::samples_
uint32_t samples_
Definition
cs5460a.h:81
esphome::cs5460a::CS5460AComponent::schedule_next_check_
void schedule_next_check_()
Definition
cs5460a.cpp:132
esphome::cs5460a::CS5460AComponent::voltage_multiplier_
float voltage_multiplier_
Definition
cs5460a.h:100
esphome::cs5460a::CS5460AComponent::check_status_
bool check_status_()
Definition
cs5460a.cpp:167
esphome::cs5460a::CS5460AComponent::started_
void started_()
Definition
cs5460a.cpp:115
esphome::cs5460a::CS5460AComponent::voltage_hpf_
bool voltage_hpf_
Definition
cs5460a.h:87
esphome::cs5460a::CS5460AComponent::prev_raw_current_
uint32_t prev_raw_current_
Definition
cs5460a.h:104
esphome::cs5460a::CS5460AComponent::hw_init_
void hw_init_()
Definition
cs5460a.cpp:77
esphome::spi::SPIDevice
The SPIDevice is what components using the SPI will create.
Definition
spi.h:456
component.h
esphome::cs5460a
Definition
cs5460a.cpp:5
esphome::cs5460a::CS5460APGAGain
CS5460APGAGain
Enum listing the current channel aplifiergain settings for the CS5460A.
Definition
cs5460a.h:49
esphome::cs5460a::CS5460A_PGA_GAIN_10X
@ CS5460A_PGA_GAIN_10X
Definition
cs5460a.h:50
esphome::cs5460a::CS5460A_PGA_GAIN_50X
@ CS5460A_PGA_GAIN_50X
Definition
cs5460a.h:51
esphome::cs5460a::CS5460ARegister
CS5460ARegister
Definition
cs5460a.h:24
esphome::cs5460a::REG_IACOFF
@ REG_IACOFF
Definition
cs5460a.h:41
esphome::cs5460a::REG_IGN
@ REG_IGN
Definition
cs5460a.h:27
esphome::cs5460a::REG_CONFIG
@ REG_CONFIG
Definition
cs5460a.h:25
esphome::cs5460a::REG_VACOFF
@ REG_VACOFF
Definition
cs5460a.h:42
esphome::cs5460a::REG_P
@ REG_P
Definition
cs5460a.h:34
esphome::cs5460a::REG_E
@ REG_E
Definition
cs5460a.h:35
esphome::cs5460a::REG_TBC
@ REG_TBC
Definition
cs5460a.h:38
esphome::cs5460a::REG_IRMS
@ REG_IRMS
Definition
cs5460a.h:36
esphome::cs5460a::REG_CYCLE_COUNT
@ REG_CYCLE_COUNT
Definition
cs5460a.h:30
esphome::cs5460a::REG_V
@ REG_V
Definition
cs5460a.h:33
esphome::cs5460a::REG_VRMS
@ REG_VRMS
Definition
cs5460a.h:37
esphome::cs5460a::REG_IDCOFF
@ REG_IDCOFF
Definition
cs5460a.h:26
esphome::cs5460a::REG_I
@ REG_I
Definition
cs5460a.h:32
esphome::cs5460a::REG_VGN
@ REG_VGN
Definition
cs5460a.h:29
esphome::cs5460a::REG_PULSE_RATE
@ REG_PULSE_RATE
Definition
cs5460a.h:31
esphome::cs5460a::REG_VDCOFF
@ REG_VDCOFF
Definition
cs5460a.h:28
esphome::cs5460a::REG_CONTROL
@ REG_CONTROL
Definition
cs5460a.h:44
esphome::cs5460a::REG_STATUS
@ REG_STATUS
Definition
cs5460a.h:40
esphome::cs5460a::REG_POFF
@ REG_POFF
Definition
cs5460a.h:39
esphome::cs5460a::REG_MASK
@ REG_MASK
Definition
cs5460a.h:43
esphome::cs5460a::CS5460ACommand
CS5460ACommand
Definition
cs5460a.h:11
esphome::cs5460a::CMD_START_SINGLE
@ CMD_START_SINGLE
Definition
cs5460a.h:14
esphome::cs5460a::CMD_WRITE
@ CMD_WRITE
Definition
cs5460a.h:21
esphome::cs5460a::CMD_SYNC0
@ CMD_SYNC0
Definition
cs5460a.h:12
esphome::cs5460a::CMD_READ
@ CMD_READ
Definition
cs5460a.h:20
esphome::cs5460a::CMD_START_CONT
@ CMD_START_CONT
Definition
cs5460a.h:15
esphome::cs5460a::CMD_POWER_SLEEP
@ CMD_POWER_SLEEP
Definition
cs5460a.h:18
esphome::cs5460a::CMD_POWER_UP
@ CMD_POWER_UP
Definition
cs5460a.h:16
esphome::cs5460a::CMD_POWER_STANDBY
@ CMD_POWER_STANDBY
Definition
cs5460a.h:17
esphome::cs5460a::CMD_CALIBRATION
@ CMD_CALIBRATION
Definition
cs5460a.h:19
esphome::cs5460a::CMD_SYNC1
@ CMD_SYNC1
Definition
cs5460a.h:13
esphome::value
uint32_t value
Definition
hal.cpp:41
uint32_t
static void uint32_t
Definition
crash_handler.cpp:153
sensor.h
spi.h
Generated by
1.12.0