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;
108 reg_[channel].
gain = gain;
110 this->update_ =
true;
114 const uint16_t max_duty = 4095;
115 const float duty_rounded = roundf(state * max_duty);
116 auto duty =
static_cast<uint16_t
>(duty_rounded);
117 this->parent_->set_channel_value_(this->channel_, duty);
void set_channel_value_(MCP4728ChannelIdx channel, uint16_t value)
void select_power_down_(MCP4728ChannelIdx channel, MCP4728PwrDown pd)
void select_vref_(MCP4728ChannelIdx channel, MCP4728Vref vref)
void select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain)
ErrorCode write(const uint8_t *data, uint8_t len, bool stop=true)
void write_state(float state) override
void status_clear_error()
virtual void mark_failed()
Mark this component as failed.
void dump_config() override
Implementation of SPI Controller mode.