fix potential hang (#6976)

Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
Samuel Sieb 2024-06-24 04:21:28 -07:00 committed by Jesse Hills
parent 5bd5b777a6
commit c5aae8ee25
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -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));