ESPHome 2026.6.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
5
6static const char *const TAG = "sn74hc165";
7
9 // initialize pins
10 this->clock_pin_->setup();
11 this->data_pin_->setup();
12 this->load_pin_->setup();
13 this->clock_pin_->digital_write(false);
14 this->load_pin_->digital_write(false);
15
16 if (this->clock_inhibit_pin_ != nullptr) {
19 }
20
21 // read state from shift register
22 this->read_gpio_();
23}
24
26
27void SN74HC165Component::dump_config() { ESP_LOGCONFIG(TAG, "SN74HC165:"); }
28
30 if (pin >= this->sr_count_ * 8) {
31 ESP_LOGE(TAG, "Pin %u is out of range! Maximum pin number with %u chips in series is %u", pin, this->sr_count_,
32 (this->sr_count_ * 8) - 1);
33 return false;
34 }
35 return this->input_bits_[pin];
36}
37
39 this->load_pin_->digital_write(false);
41 this->load_pin_->digital_write(true);
43
44 if (this->clock_inhibit_pin_ != nullptr)
46
47 for (uint8_t i = 0; i < this->sr_count_; i++) {
48 for (uint8_t j = 0; j < 8; j++) {
49 this->input_bits_[(i * 8) + (7 - j)] = this->data_pin_->digital_read();
50
51 this->clock_pin_->digital_write(true);
53 this->clock_pin_->digital_write(false);
55 }
56 }
57
58 if (this->clock_inhibit_pin_ != nullptr)
60}
61
63
64bool SN74HC165GPIOPin::digital_read() { return this->parent_->digital_read_(this->pin_) != this->inverted_; }
65
66size_t SN74HC165GPIOPin::dump_summary(char *buffer, size_t len) const {
67 return buf_append_printf(buffer, len, 0, "%u via SN74HC165", this->pin_);
68}
69
70} // namespace esphome::sn74hc165
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:62
size_t dump_summary(char *buffer, size_t len) const override
Definition sn74hc165.cpp:66
constexpr float IO
For components that represent GPIO pins like PCF8573.
Definition component.h:39
const void size_t len
Definition hal.h:64
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition hal.cpp:48