lock SPI only when writing #71
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FunHouse()
object, and then trying to do some network activity.Before this fix, the
DotStar
object grabbed theSPI
lock forever. This is a problem on Espressif boards, which use a FreeRTOS mutex as the lock. See adafruit/circuitpython#10561 (comment) for details.The fix is only to grab the
SPI
lock when actually writing. We could do this withadafruit_bus_device
, but we don't need other aspects of that library, and we can save space just by doing the locking in the two places where it's needed.There isn't a reason to test that
self._spi.try_lock()
succeeds or fails, since it should always succeed. TheSPI
object is not used by anyone else.Tested on a FunHouse. It fixes the crash described in adafruit/circuitpython#10520. I also tested to make sure the DotStars are still functional.