Skip to content

Commit

Permalink
fix potential hang (esphome#6976)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Sieb <[email protected]>
  • Loading branch information
ssieb and Samuel Sieb authored Jun 24, 2024
1 parent f7af51b commit b186812
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions esphome/components/gpio/one_wire/gpio_one_wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ bool HOT IRAM_ATTR GPIOOneWireBus::read_bit_() {

// measure from start value directly, to get best accurate timing no matter
// how long pin_mode/delayMicroseconds took
delayMicroseconds(12 - (micros() - start));
uint32_t now = micros();
if (now - start < 12)
delayMicroseconds(12 - (now - start));

// sample bus to read bit from peer
bool r = pin_.digital_read();

// read slot is at least 60µs; get as close to 60µs to spend less time with interrupts locked
uint32_t now = micros();
now = micros();
if (now - start < 60)
delayMicroseconds(60 - (now - start));

Expand Down

0 comments on commit b186812

Please sign in to comment.