mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
sn74hc165 fixes (#4457)
* Add delay between clock changes on sn74hc165 * Increase to 10us * Add another delay after clock low * Print input bits every second * Fix pin order * Remove log * Fix for inverted pins * formatting
This commit is contained in:
parent
ceebe14628
commit
623e31ddee
1 changed files with 12 additions and 7 deletions
|
@ -40,17 +40,22 @@ bool SN74HC165Component::digital_read_(uint16_t pin) {
|
|||
|
||||
void SN74HC165Component::read_gpio_() {
|
||||
this->load_pin_->digital_write(false);
|
||||
delayMicroseconds(5);
|
||||
delayMicroseconds(10);
|
||||
this->load_pin_->digital_write(true);
|
||||
delayMicroseconds(5);
|
||||
delayMicroseconds(10);
|
||||
|
||||
if (this->clock_inhibit_pin_ != nullptr)
|
||||
this->clock_inhibit_pin_->digital_write(false);
|
||||
|
||||
for (int16_t i = (this->sr_count_ * 8) - 1; i >= 0; i--) {
|
||||
this->input_bits_[i] = this->data_pin_->digital_read();
|
||||
for (uint8_t i = 0; i < this->sr_count_; i++) {
|
||||
for (uint8_t j = 0; j < 8; j++) {
|
||||
this->input_bits_[(i * 8) + (7 - j)] = this->data_pin_->digital_read();
|
||||
|
||||
this->clock_pin_->digital_write(true);
|
||||
delayMicroseconds(10);
|
||||
this->clock_pin_->digital_write(false);
|
||||
delayMicroseconds(10);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->clock_inhibit_pin_ != nullptr)
|
||||
|
@ -59,7 +64,7 @@ void SN74HC165Component::read_gpio_() {
|
|||
|
||||
float SN74HC165Component::get_setup_priority() const { return setup_priority::IO; }
|
||||
|
||||
bool SN74HC165GPIOPin::digital_read() { return this->parent_->digital_read_(this->pin_); }
|
||||
bool SN74HC165GPIOPin::digital_read() { return this->parent_->digital_read_(this->pin_) != this->inverted_; }
|
||||
|
||||
std::string SN74HC165GPIOPin::dump_summary() const { return str_snprintf("%u via SN74HC165", 18, pin_); }
|
||||
|
||||
|
|
Loading…
Reference in a new issue