9static const char *
const TAG =
"mcp4728";
12 auto err = this->
write(
nullptr, 0);
20 ESP_LOGCONFIG(TAG,
"MCP4728:");
23 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
29 this->update_ =
false;
30 if (this->store_in_eeprom_) {
57 ESP_LOGV(TAG,
"Setting MCP4728 channel %c to %d!", cn, value);
58 reg_[channel].
data = value;
64 for (uint8_t i = 0; i < 4; ++i) {
67 wd[1] = ((uint8_t) reg_[i].
vref << 7) | ((uint8_t) reg_[i].pd << 5) | ((uint8_t) reg_[i].
gain << 4) |
69 wd[2] = reg_[i].
data & 0xFF;
70 err[i] = this->
write(wd,
sizeof(wd));
85 for (uint8_t i = 0; i < 4; i++) {
86 wd[i * 2 + 1] = ((uint8_t) reg_[i].
vref << 7) | ((uint8_t) reg_[i].pd << 5) | ((uint8_t) reg_[i].
gain << 4) |
88 wd[i * 2 + 2] = reg_[i].
data & 0xFF;
90 auto err = this->
write(wd,
sizeof(wd));
95 reg_[channel].
vref = vref;
101 reg_[channel].
pd = pd;
103 this->update_ =
true;
109 this->update_ =
true;
virtual void mark_failed()
Mark this component as failed.
void status_clear_error()
void status_set_error(const char *message=nullptr)
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
void set_channel_value_(MCP4728ChannelIdx channel, uint16_t value)
void select_vref_(MCP4728ChannelIdx channel, MCP4728Vref vref)
void select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain)
void dump_config() override
void select_power_down_(MCP4728ChannelIdx channel, MCP4728PwrDown pd)
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
Providing packet encoding functions for exchanging data with a remote host.