adafruit / Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
https://learn.adafruit.com/circuitpython-on-raspberrypi-linux
MIT License
437 stars 327 forks source link

Fix MCP2221 I2C NACK Error #864

Open brentru opened 1 week ago

brentru commented 1 week ago

The MCP2221 reports a RuntimeError when the i2c_scan function encounters a failure. This differs from CircuitPython, where it throws an OSError. Further, most sensor drivers with a "double-retry" (see this driver) are written to catch an OSError, rather than a RuntimeError.

This PR raises an OSError for the MCP2221 platform where it's expected, to fix I2C devices not initializing or being scanned correctly.

I've tested it with the MCP2221 and the MAX17048 as has @tyeth

Related: https://github.com/adafruit/Adafruit_Wippersnapper_Python/issues/173 https://github.com/adafruit/Adafruit_Wippersnapper_Python/pull/172#issue-2360866531

caternuson commented 1 week ago

This should be fine. Pretty sure I went with RuntimeError for lack of a better choice at the time. So there's no special magic there.