ESPHome 2025.5.0
Loading...
Searching...
No Matches
pcf8574.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7namespace esphome {
8namespace pcf8574 {
9
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
44class 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 gpio::Flags get_flags() const override { return this->flags_; }
58
59 protected:
61 uint8_t pin_;
64};
65
66} // namespace pcf8574
67} // namespace esphome
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
uint16_t input_mask_
The state read in read_gpio_ - 1 means HIGH, 0 means LOW.
Definition pcf8574.h:39
void setup() override
Check i2c availability and setup masks.
Definition pcf8574.cpp:9
uint16_t mode_mask_
Mask for the pin mode - 1 means output, 0 means input.
Definition pcf8574.h:35
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
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition pcf8574.cpp:41
void set_pcf8575(bool pcf8575)
Definition pcf8574.h:14
bool digital_read(uint8_t pin)
Helper function to read the value of a pin.
Definition pcf8574.cpp:28
void digital_write(uint8_t pin, bool value)
Helper function to write the value of a pin.
Definition pcf8574.cpp:32
bool pcf8575_
TRUE->16-channel PCF8575, FALSE->8-channel PCF8574.
Definition pcf8574.h:40
Helper class to expose a PCF8574 pin as an internal input GPIO pin.
Definition pcf8574.h:44
void digital_write(bool value) override
Definition pcf8574.cpp:98
void set_inverted(bool inverted)
Definition pcf8574.h:54
void set_pin(uint8_t pin)
Definition pcf8574.h:53
void set_flags(gpio::Flags flags)
Definition pcf8574.h:55
void pin_mode(gpio::Flags flags) override
Definition pcf8574.cpp:96
std::string dump_summary() const override
Definition pcf8574.cpp:99
gpio::Flags get_flags() const override
Definition pcf8574.h:57
PCF8574Component * parent_
Definition pcf8574.h:60
void set_parent(PCF8574Component *parent)
Definition pcf8574.h:52
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7