-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Summary
Planned cross-platform machine.CAN
driver for Micropython.
Background
MicroPython currently only has one driver for a CAN bus controller, the pyb.CAN driver on STM32. Various folks have contributed functional and useful pull requests with CAN drivers for other ports. Many implement a machine.CAN
interface. Quite sensibly, these drivers have all based their new APIs on the pyb.CAN
driver. These efforts are hugely appreciated 🙏.
@jimmo, @dpgeorge, and I discussed this recently. We all agree MicroPython should have a cross-platform machine.CAN
interface. None of us want to use the pyb.CAN
API for this:
- The conventions used by
pyb.CAN
don't match the best conventions ofmachine
APIs. - It's not very ergonomic, compared to libraries such as CircuitPython canio or python-can.
- Some functions assume behaviour of the ST CAN hardware peripheral that is not common across platforms. Trying to adapt these to each port in turn is messy and difficult for both users and maintainers.
Goals
MicroPython should have a machine.CAN
interface which is:
- Similar to other cross-platform
machine
APIs. - Relatively easy to use.
- Still fast and light on resource usage.
- Easy to implement on new hardware platforms.
- Easy to extend for use with
asyncio
. - Easy to integrate with higher-level CAN-based driver layers such as canopen.
Also:
- The interface should be easy for the existing un-merged driver PRs to adapt to.
Plan
We plan to do the following:
- Write a
machine.CAN
API as a docs PR, discuss with other maintainers and the community. See docs: Add machine.CAN low-level API docs. #13149 - Implement common cross-port interface helpers as
extmod/machine_can.c
(similar toextmod/machine_pwm.c
, etc). - Create a compliant
machine.CAN
implementation on STM32 (this will be a thin wrapper aroundpyb.CAN
, which will remain for legacy compatibility.) - Work with the existing PR authors as needed/wanted to merge
machine.CAN
drivers for new ports.
GitHub sponsor funds have been allocated for the first three steps, and I plan to work on it. Currently other work (USB device driver functionality) is the priority, but this is the next priority after that.
This issue post will be updated with overall status of this effort.