ESPHome  2024.10.3
ch422g.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace ch422g {
9 
10 class CH422GComponent : public Component, public i2c::I2CDevice {
11  public:
12  CH422GComponent() = default;
13 
15  void setup() override;
17  void loop() override;
19  bool digital_read(uint8_t pin);
21  void digital_write(uint8_t pin, bool value);
23  void pin_mode(uint8_t pin, gpio::Flags flags);
24 
25  float get_setup_priority() const override;
26  float get_loop_priority() const override;
27  void dump_config() override;
28 
29  protected:
30  bool write_reg_(uint8_t reg, uint8_t value);
31  uint8_t read_reg_(uint8_t reg);
32  bool set_mode_(uint8_t mode);
33  bool read_inputs_();
34  bool write_outputs_();
35 
37  uint16_t output_bits_{0x00};
39  uint8_t pin_read_flags_ = {0x00};
41  uint8_t input_bits_ = {0x00};
43  uint8_t mode_value_{};
44 };
45 
47 class CH422GGPIOPin : public GPIOPin {
48  public:
49  void setup() override{};
50  void pin_mode(gpio::Flags flags) override;
51  bool digital_read() override;
52  void digital_write(bool value) override;
53  std::string dump_summary() const override;
54 
55  void set_parent(CH422GComponent *parent) { parent_ = parent; }
56  void set_pin(uint8_t pin) { pin_ = pin; }
57  void set_inverted(bool inverted) { inverted_ = inverted; }
58  void set_flags(gpio::Flags flags);
59 
60  protected:
61  CH422GComponent *parent_{};
62  uint8_t pin_{};
63  bool inverted_{};
64  gpio::Flags flags_{};
65 };
66 
67 } // namespace ch422g
68 } // namespace esphome
float get_loop_priority() const override
Definition: ch422g.cpp:126
void setup() override
Check i2c availability and setup masks.
Definition: ch422g.cpp:16
void loop() override
Poll for input changes periodically.
Definition: ch422g.cpp:31
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition: i2c.h:149
void digital_write(uint8_t pin, bool value)
Helper function to write the value of a pin.
Definition: ch422g.cpp:66
uint16_t output_bits_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition: ch422g.h:37
bool write_reg_(uint8_t reg, uint8_t value)
Definition: ch422g.cpp:94
uint8_t mode_value_
Copy of the mode value.
Definition: ch422g.h:43
void set_parent(CH422GComponent *parent)
Definition: ch422g.h:55
uint8_t pin_read_flags_
Flags to check if read previously during this loop.
Definition: ch422g.h:39
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:183
bool digital_read(uint8_t pin)
Helper function to read the value of a pin.
Definition: ch422g.cpp:56
void dump_config() override
Definition: ch422g.cpp:36
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition: ch422g.cpp:44
const uint32_t flags
Definition: stm32flash.h:85
float get_setup_priority() const override
Definition: ch422g.cpp:122
void setup() override
Definition: ch422g.h:49
void set_pin(uint8_t pin)
Definition: ch422g.h:56
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_inverted(bool inverted)
Definition: ch422g.h:57
uint8_t input_bits_
Copy of last read values.
Definition: ch422g.h:41
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
uint8_t read_reg_(uint8_t reg)
Definition: ch422g.cpp:104
Helper class to expose a CH422G pin as a GPIO pin.
Definition: ch422g.h:47
bool set_mode_(uint8_t mode)
Definition: ch422g.cpp:115