xmos / lib_i2c

I2C peripheral library
Other
3 stars 22 forks source link

Hang if no pull-up present #97

Open xross opened 12 hours ago

xross commented 12 hours ago

The lib includes a wait on SCL high, this is either an event or a polling loop, dependent on implementation.

If this is called on a system where the pull up isn't present then the project can hang forever - not ideal.

If would be better if this error was detected and reported to the developer.

This could be done with timeouts or a simple check for pull-up present at init time.

Real world use case is running USB Audio project on a custom board - we ideally don't want it to hang.

XMOS-JoeG commented 11 hours ago

Example: https://github.com/xmos/lib_i2c/blob/648351bed1e78190c057105221055064cd881122/lib_i2c/src/i2c_master.xc#L58

in release_clock_and_wait function. Yes function should wait until clock goes high, but not forever!

Should timeout and report error or similar.

xross commented 11 hours ago

Polling loop example: https://github.com/xmos/lib_i2c/blob/82e82f27ad44671a66ca8550d7ce8a4847a3f927/lib_i2c/src/i2c_master_single_port.xc#L69