ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
sn74hc165.cpp
Go to the documentation of this file.
1#include "sn74hc165.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace sn74hc165 {
6
7static const char *const TAG = "sn74hc165";
8
10 // initialize pins
11 this->clock_pin_->setup();
12 this->data_pin_->setup();
13 this->load_pin_->setup();
14 this->clock_pin_->digital_write(false);
15 this->load_pin_->digital_write(false);
16
17 if (this->clock_inhibit_pin_ != nullptr) {
20 }
21
22 // read state from shift register
23 this->read_gpio_();
24}
25
27
28void SN74HC165Component::dump_config() { ESP_LOGCONFIG(TAG, "SN74HC165:"); }
29
31 if (pin >= this->sr_count_ * 8) {
32 ESP_LOGE(TAG, "Pin %u is out of range! Maximum pin number with %u chips in series is %u", pin, this->sr_count_,
33 (this->sr_count_ * 8) - 1);
34 return false;
35 }
36 return this->input_bits_[pin];
37}
38
40 this->load_pin_->digital_write(false);
42 this->load_pin_->digital_write(true);
44
45 if (this->clock_inhibit_pin_ != nullptr)
47
48 for (uint8_t i = 0; i < this->sr_count_; i++) {
49 for (uint8_t j = 0; j < 8; j++) {
50 this->input_bits_[(i * 8) + (7 - j)] = this->data_pin_->digital_read();
51
52 this->clock_pin_->digital_write(true);
54 this->clock_pin_->digital_write(false);
56 }
57 }
58
59 if (this->clock_inhibit_pin_ != nullptr)
61}
62
64
65bool SN74HC165GPIOPin::digital_read() { return this->parent_->digital_read_(this->pin_) != this->inverted_; }
66
67std::string SN74HC165GPIOPin::dump_summary() const { return str_snprintf("%u via SN74HC165", 18, pin_); }
68
69} // namespace sn74hc165
70} // namespace esphome
virtual void setup()=0
virtual void digital_write(bool value)=0
virtual bool digital_read()=0
float get_setup_priority() const override
Definition sn74hc165.cpp:63
std::string dump_summary() const override
Definition sn74hc165.cpp:67
const float IO
For components that represent GPIO pins like PCF8573.
Definition component.cpp:48
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:31
std::string str_snprintf(const char *fmt, size_t len,...)
Definition helpers.cpp:194