ESPHome  2022.6.3
mcp4728_output.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace mcp4728 {
9 
10 enum class CMD {
11  FAST_WRITE = 0x00,
12  MULTI_WRITE = 0x40,
13  SINGLE_WRITE = 0x58,
14  SEQ_WRITE = 0x50,
15  SELECT_VREF = 0x80,
16  SELECT_GAIN = 0xC0,
17  SELECT_POWER_DOWN = 0xA0
18 };
19 
21 
27 };
28 
30 
32 
33 struct DACInputData {
37  uint16_t data;
38 };
39 
40 class MCP4728Channel;
41 
43 class MCP4728Component : public Component, public i2c::I2CDevice {
44  public:
45  MCP4728Component(bool store_in_eeprom) : store_in_eeprom_(store_in_eeprom) {}
46 
47  void setup() override;
48  void dump_config() override;
49  float get_setup_priority() const override { return setup_priority::HARDWARE; }
50  void loop() override;
51 
52  protected:
54  void set_channel_value_(MCP4728ChannelIdx channel, uint16_t value);
55  bool multi_write_();
56  bool seq_write_();
57  void select_vref_(MCP4728ChannelIdx channel, MCP4728Vref vref);
58  void select_power_down_(MCP4728ChannelIdx channel, MCP4728PwrDown pd);
59  void select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain);
60 
61  private:
62  DACInputData reg_[4];
63  bool store_in_eeprom_ = false;
64  bool update_ = false;
65 };
66 
68  public:
70  MCP4728PwrDown pwrdown)
71  : parent_(parent), channel_(channel), vref_(vref), gain_(gain), pwrdown_(pwrdown) {
72  // update VREF
73  parent->select_vref_(channel, vref_);
74  // update PD
75  parent->select_power_down_(channel, pwrdown_);
76  // update GAIN
77  parent->select_gain_(channel, gain_);
78  }
79 
80  protected:
81  void write_state(float state) override;
82 
88 };
89 
90 } // namespace mcp4728
91 } // namespace esphome
void setup()
void loop()
void select_power_down_(MCP4728ChannelIdx channel, MCP4728PwrDown pd)
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
MCP4728 float output component.
MCP4728Component(bool store_in_eeprom)
void select_vref_(MCP4728ChannelIdx channel, MCP4728Vref vref)
MCP4728Channel(MCP4728Component *parent, MCP4728ChannelIdx channel, MCP4728Vref vref, MCP4728Gain gain, MCP4728PwrDown pwrdown)
void select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain)
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:17
float get_setup_priority() const override
Definition: a4988.cpp:4
bool state
Definition: fan.h:34