9 static const char *
const TAG =
"mcp4728";
12 ESP_LOGCONFIG(TAG,
"Setting up MCP4728 (0x%02X)...", this->
address_);
13 auto err = this->
write(
nullptr, 0);
21 ESP_LOGCONFIG(TAG,
"MCP4728:");
24 ESP_LOGE(TAG,
"Communication with MCP4728 failed!");
30 this->update_ =
false;
31 if (this->store_in_eeprom_) {
58 ESP_LOGV(TAG,
"Setting MCP4728 channel %c to %d!", cn, value);
59 reg_[channel].
data = value;
65 for (uint8_t i = 0; i < 4; ++i) {
68 wd[1] = ((uint8_t) reg_[i].vref << 7) | ((uint8_t) reg_[i].pd << 5) | ((uint8_t) reg_[i].
gain << 4) |
70 wd[2] = reg_[i].
data & 0xFF;
71 err[i] = this->
write(wd,
sizeof(wd));
86 for (uint8_t i = 0; i < 4; i++) {
87 wd[i * 2 + 1] = ((uint8_t) reg_[i].vref << 7) | ((uint8_t) reg_[i].pd << 5) | ((uint8_t) reg_[i].
gain << 4) |
89 wd[i * 2 + 2] = reg_[i].
data & 0xFF;
91 auto err = this->
write(wd,
sizeof(wd));
96 reg_[channel].
vref = vref;
102 reg_[channel].
pd = pd;
104 this->update_ =
true;
110 this->update_ =
true;
void set_channel_value_(MCP4728ChannelIdx channel, uint16_t value)
void select_power_down_(MCP4728ChannelIdx channel, MCP4728PwrDown pd)
void select_vref_(MCP4728ChannelIdx channel, MCP4728Vref vref)
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
void status_set_error(const char *message="unspecified")
No error found during execution of method.
void select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain)
uint8_t address_
store the address of the device on the bus
void status_clear_error()
virtual void mark_failed()
Mark this component as failed.
void dump_config() override
Implementation of SPI Controller mode.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.