ESPHome  2024.11.0
sn74hc165.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 sn74hc165 {
11 
12 class SN74HC165Component : public Component {
13  public:
14  SN74HC165Component() = default;
15 
16  void setup() override;
17  void loop() override;
18  float get_setup_priority() const override;
19  void dump_config() override;
20 
21  void set_data_pin(GPIOPin *pin) { this->data_pin_ = pin; }
22  void set_clock_pin(GPIOPin *pin) { this->clock_pin_ = pin; }
23  void set_load_pin(GPIOPin *pin) { this->load_pin_ = pin; }
24  void set_clock_inhibit_pin(GPIOPin *pin) { this->clock_inhibit_pin_ = pin; }
25  void set_sr_count(uint8_t count) {
26  this->sr_count_ = count;
27  this->input_bits_.resize(count * 8);
28  }
29 
30  protected:
31  friend class SN74HC165GPIOPin;
32  bool digital_read_(uint16_t pin);
33  void read_gpio_();
34 
39  uint8_t sr_count_;
40  std::vector<bool> input_bits_;
41 };
42 
44 class SN74HC165GPIOPin : public GPIOPin, public Parented<SN74HC165Component> {
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_pin(uint16_t pin) { pin_ = pin; }
53  void set_inverted(bool inverted) { inverted_ = inverted; }
54 
55  protected:
56  uint16_t pin_;
57  bool inverted_;
58 };
59 
60 } // namespace sn74hc165
61 } // namespace esphome
float get_setup_priority() const override
Definition: sn74hc165.cpp:65
void set_inverted(bool inverted)
Definition: sn74hc165.h:53
const uint32_t flags
Definition: stm32flash.h:85
void digital_write(bool value) override
Definition: sn74hc165.h:49
void set_clock_inhibit_pin(GPIOPin *pin)
Definition: sn74hc165.h:24
void set_sr_count(uint8_t count)
Definition: sn74hc165.h:25
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Helper class to expose a SC74HC165 pin as an internal input GPIO pin.
Definition: sn74hc165.h:44
Helper class to easily give an object a parent of type T.
Definition: helpers.h:522
void pin_mode(gpio::Flags flags) override
Definition: sn74hc165.h:47