7static const char *
const TAG =
"sy6970";
13 ESP_LOGW(TAG,
"Failed to read registers 0x00-0x14");
22 ESP_LOGW(TAG,
"Failed to write register 0x%02X",
reg);
31 ESP_LOGW(TAG,
"Failed to read register 0x%02X for update",
reg);
34 reg_value = (reg_value & ~mask) | (value & mask);
39 ESP_LOGV(TAG,
"Setting up SY6970...");
43 if (!this->
read_byte(SY6970_REG_DEVICE_ID, ®_value)) {
44 ESP_LOGE(TAG,
"Failed to communicate with SY6970");
49 uint8_t chip_id = reg_value & 0x03;
50 if (chip_id != 0x00) {
51 ESP_LOGW(TAG,
"Unexpected chip ID: 0x%02X (expected 0x00)", chip_id);
55 ESP_LOGV(TAG,
"Setting LED enabled to %s", ONOFF(this->
led_enabled_));
61 ESP_LOGV(TAG,
"Setting charge voltage to %u mV", this->
charge_voltage_);
64 ESP_LOGV(TAG,
"Setting charge current to %u mA", this->
charge_current_);
70 ESP_LOGV(TAG,
"Setting charge enabled to %s", ONOFF(this->
charge_enabled_));
73 ESP_LOGV(TAG,
"Setting ADC measurements to %s", ONOFF(this->
enable_adc_));
76 ESP_LOGV(TAG,
"SY6970 initialized successfully");
83 " Input Current Limit: %u mA\n"
84 " Charge Voltage: %u mV\n"
85 " Charge Current: %u mA\n"
86 " Precharge Current: %u mA\n"
87 " Charge Enabled: %s\n"
92 LOG_UPDATE_INTERVAL(
this);
94 ESP_LOGE(TAG,
"Communication with SY6970 failed!");
105 ESP_LOGW(TAG,
"Failed to read registers during update");
114 listener->on_data(this->
data_);
122 if (milliamps < INPUT_CURRENT_MIN) {
123 milliamps = INPUT_CURRENT_MIN;
126 uint8_t
val = (milliamps - INPUT_CURRENT_MIN) / INPUT_CURRENT_STEP;
138 if (millivolts < CHG_VOLTAGE_BASE) {
139 millivolts = CHG_VOLTAGE_BASE;
142 uint8_t
val = (millivolts - CHG_VOLTAGE_BASE) / CHG_VOLTAGE_STEP;
154 if (milliamps < PRE_CHG_BASE_MA) {
155 milliamps = PRE_CHG_BASE_MA;
158 uint8_t
val = (milliamps - PRE_CHG_BASE_MA) / PRE_CHG_STEP_MA;
170 uint8_t
val = milliamps / 64;
182 this->
update_register_(SY6970_REG_SYS_CONTROL, 0x10, enabled ? 0x10 : 0x00);
190 this->
update_register_(SY6970_REG_TIMER_CONTROL, 0x40, enabled ? 0x00 : 0x40);
198 this->
update_register_(SY6970_REG_ADC_CONTROL, 0xC0, enabled ? 0xC0 : 0x00);
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
void set_charge_target_voltage(uint16_t millivolts)
void set_enable_adc_measure(bool enabled=true)
void set_input_current_limit(uint16_t milliamps)
void set_charge_enabled(bool enabled)
uint16_t input_current_limit_
void set_precharge_current(uint16_t milliamps)
bool write_register_(uint8_t reg, uint8_t value)
uint16_t precharge_current_
void set_led_enabled(bool enabled)
void set_charge_current(uint16_t milliamps)
bool read_all_registers_()
std::vector< SY6970Listener * > listeners_
bool update_register_(uint8_t reg, uint8_t mask, uint8_t value)
void dump_config() override