ESPHome  2024.5.3
mcp4728.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace mcp4728 {
8 
9 enum class CMD {
10  FAST_WRITE = 0x00,
11  MULTI_WRITE = 0x40,
12  SINGLE_WRITE = 0x58,
13  SEQ_WRITE = 0x50,
14  SELECT_VREF = 0x80,
15  SELECT_GAIN = 0xC0,
16  SELECT_POWER_DOWN = 0xA0
17 };
18 
20 
26 };
27 
29 
31 
32 struct DACInputData {
36  uint16_t data;
37 };
38 
39 class MCP4728Channel;
40 
42 class MCP4728Component : public Component, public i2c::I2CDevice {
43  public:
44  MCP4728Component(bool store_in_eeprom) : store_in_eeprom_(store_in_eeprom) {}
45 
46  void setup() override;
47  void dump_config() override;
48  float get_setup_priority() const override { return setup_priority::HARDWARE; }
49  void loop() override;
50 
51  protected:
53  void set_channel_value_(MCP4728ChannelIdx channel, uint16_t value);
54  bool multi_write_();
55  bool seq_write_();
56  void select_vref_(MCP4728ChannelIdx channel, MCP4728Vref vref);
57  void select_power_down_(MCP4728ChannelIdx channel, MCP4728PwrDown pd);
58  void select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain);
59 
60  private:
61  DACInputData reg_[4];
62  bool store_in_eeprom_ = false;
63  bool update_ = false;
64 };
65 
66 } // namespace mcp4728
67 } // namespace esphome
void setup()
void loop()
MCP4728 float output component.
Definition: mcp4728.h:42
MCP4728Component(bool store_in_eeprom)
Definition: mcp4728.h:44
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
float get_setup_priority() const override
Definition: mcp4728.h:48
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133