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