ESPHome  2022.12.8
pcf8574.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace pcf8574 {
9 
10 class PCF8574Component : public Component, public i2c::I2CDevice {
11  public:
12  PCF8574Component() = default;
13 
14  void set_pcf8575(bool pcf8575) { pcf8575_ = pcf8575; }
15 
17  void setup() 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 
27  void dump_config() override;
28 
29  protected:
30  bool read_gpio_();
31 
32  bool write_gpio_();
33 
35  uint16_t mode_mask_{0x00};
37  uint16_t output_mask_{0x00};
39  uint16_t input_mask_{0x00};
40  bool pcf8575_;
41 };
42 
44 class PCF8574GPIOPin : public GPIOPin {
45  public:
46  void setup() override;
47  void pin_mode(gpio::Flags flags) override;
48  bool digital_read() override;
49  void digital_write(bool value) override;
50  std::string dump_summary() const override;
51 
52  void set_parent(PCF8574Component *parent) { parent_ = parent; }
53  void set_pin(uint8_t pin) { pin_ = pin; }
54  void set_inverted(bool inverted) { inverted_ = inverted; }
55  void set_flags(gpio::Flags flags) { flags_ = flags; }
56 
57  protected:
59  uint8_t pin_;
60  bool inverted_;
62 };
63 
64 } // namespace pcf8574
65 } // namespace esphome
uint16_t mode_mask_
Mask for the pin mode - 1 means output, 0 means input.
Definition: pcf8574.h:35
void set_pin(uint8_t pin)
Definition: pcf8574.h:53
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition: pcf8574.cpp:41
uint16_t input_mask_
The state read in read_gpio_ - 1 means HIGH, 0 means LOW.
Definition: pcf8574.h:39
void set_inverted(bool inverted)
Definition: pcf8574.h:54
bool digital_read(uint8_t pin)
Helper function to read the value of a pin.
Definition: pcf8574.cpp:28
Helper class to expose a PCF8574 pin as an internal input GPIO pin.
Definition: pcf8574.h:44
PCF8574Component * parent_
Definition: pcf8574.h:58
uint16_t output_mask_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition: pcf8574.h:37
float get_setup_priority() const override
Definition: pcf8574.cpp:93
const uint32_t flags
Definition: stm32flash.h:85
bool pcf8575_
TRUE->16-channel PCF8575, FALSE->8-channel PCF8574.
Definition: pcf8574.h:40
void setup() override
Check i2c availability and setup masks.
Definition: pcf8574.cpp:9
Definition: a4988.cpp:4
void set_parent(PCF8574Component *parent)
Definition: pcf8574.h:52
void set_pcf8575(bool pcf8575)
Definition: pcf8574.h:14
void digital_write(uint8_t pin, bool value)
Helper function to write the value of a pin.
Definition: pcf8574.cpp:32
void set_flags(gpio::Flags flags)
Definition: pcf8574.h:55