ESPHome  2022.6.3
sn74hc595.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
5 
6 namespace esphome {
7 namespace sn74hc595 {
8 
9 class SN74HC595Component : public Component {
10  public:
11  SN74HC595Component() = default;
12 
13  void setup() override;
14  float get_setup_priority() const override;
15  void dump_config() override;
16 
17  void set_data_pin(GPIOPin *pin) { data_pin_ = pin; }
18  void set_clock_pin(GPIOPin *pin) { clock_pin_ = pin; }
19  void set_latch_pin(GPIOPin *pin) { latch_pin_ = pin; }
20  void set_oe_pin(GPIOPin *pin) {
21  oe_pin_ = pin;
22  have_oe_pin_ = true;
23  }
24  void set_sr_count(uint8_t count) { sr_count_ = count; }
25 
26  protected:
27  friend class SN74HC595GPIOPin;
28  bool digital_read_(uint8_t pin);
29  void digital_write_(uint8_t pin, bool value);
30  bool write_gpio_();
31 
36  uint8_t sr_count_;
37  bool have_oe_pin_{false};
38  uint32_t output_bits_{0x00};
39 };
40 
42 class SN74HC595GPIOPin : public GPIOPin {
43  public:
44  void setup() override {}
45  void pin_mode(gpio::Flags flags) override {}
46  bool digital_read() override { return false; }
47  void digital_write(bool value) override;
48  std::string dump_summary() const override;
49 
50  void set_parent(SN74HC595Component *parent) { parent_ = parent; }
51  void set_pin(uint8_t pin) { pin_ = pin; }
52  void set_inverted(bool inverted) { inverted_ = inverted; }
53 
54  protected:
56  uint8_t pin_;
57  bool inverted_;
58 };
59 
60 } // namespace sn74hc595
61 } // namespace esphome
SN74HC595Component * parent_
Definition: sn74hc595.h:55
Helper class to expose a SC74HC595 pin as an internal output GPIO pin.
Definition: sn74hc595.h:42
void pin_mode(gpio::Flags flags) override
Definition: sn74hc595.h:45
float get_setup_priority() const override
Definition: sn74hc595.cpp:63
uint8_t flags
Definition: bedjet_base.h:134
void set_parent(SN74HC595Component *parent)
Definition: sn74hc595.h:50
void digital_write_(uint8_t pin, bool value)
Definition: sn74hc595.cpp:33
void set_inverted(bool inverted)
Definition: sn74hc595.h:52
Definition: a4988.cpp:4
void set_sr_count(uint8_t count)
Definition: sn74hc595.h:24