On top of #873, tested on a XIAO nRF52840 with SCL tied to GND:
- the STOP/SUSPEND waits broke out without setting timed_out, so an empty
probe on a stuck bus returned 0, "device ACKed" (every RTC address of an
autodiscovery scan looked present); requestFrom() alike;
- after a timeout the TWIM stayed wedged once the bus was released: every
call timed out until a reboot. A disable/enable cycle recovers it.
Result: stuck bus -> error 4 after ~100 ms per call, no hang; bus released
-> NACK 2 / ACK 0 again in under 1 ms, without a reboot.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
endTransmission() and requestFrom() both spin on unbounded while(!EVENT)
loops waiting on the TWIM peripheral. Several of these loops - notably
the EVENTS_STOPPED wait - have no EVENTS_ERROR escape at all, so if the
hardware never raises the expected event (e.g. probing an I2C address
on a bus with nothing attached and no pull-ups), the call never
returns and the whole single-threaded firmware hangs forever.
Reported in #771 with the same root cause already identified in the
issue thread. Also affects boards that probe for an optional/absent
I2C device at boot before anything else initializes - e.g. MeshCore's
Xiao_nrf52 target, which runs an RTC autodiscovery scan in radio_init()
and hangs on every cold boot when no RTC is wired up (no serial, no
BLE - see meshcore-dev/MeshCore#2068).
Adds a bounded I2C_TWIM_TIMEOUT_MS (default 100ms, overridable) to
every wait loop in both functions. A timeout that occurs before the
hardware transaction actually completed is surfaced as a proper error
return (endTransmission: 4 "other error"; requestFrom: 0 bytes read)
rather than silently falling through to a success path - a timeout on
the address/data phase must not be reported as if a device ACKed.
Tested on a Seeed XIAO nRF52840 + Wio-SX1262 board that reliably hung
at boot (via MeshCore's RTC autodiscovery probe) after every power
cycle. With this patch the same probe now completes (with a timeout)
in well under a second per address instead of hanging indefinitely,
and the board boots and runs normally.
Fix semaphore leak bug that causes device lockup when BLE central disconnects unexpectedly (e.g., going out of range, supervision timeout).
Co-authored-by: liquidraver <504870+liquidraver@users.noreply.github.com>
Co-authored-by: liamcottle <liam@liamcottle.com>
File names are returned unterminated in the edge case where their length
is max size This is due to the fact that strncpy does terminate the
destination string when the source string is greater than or equal to
the specifid maximum length.
Clearing `_file` and `_dir` pointers after freeing on failure to open
just in case close() is later called.
To elaborate, the `_file` and `_dir` pointers are normally freed and
cleared by _close(), but when a failure occurs upon opening, these
pointers were being left orphaned since calling close() after failure to
open doesn't make much sense, and indeed caused serious issues within
lfs.
I'm working on a project that has 3 rotary encoders. When I used this libary, I couldn't get the 3 switches to properly increment / decrement the steps when I called readAbs().
Looking back at the code, I see there was a change in 351cd82 which seemed to have caused the issue.
If I look previous to 351cd82, the _irq_handler was using digitalRead. I think switching to bitRead caused a mix up between the physical pin number vs. the port pin? I'm not entirely sure.
I reimplemented the pre 351cd82 code and used the new ada_callback. Seems to be working great now!