-
-
Notifications
You must be signed in to change notification settings - Fork 18
Description
My use case for blinka is talking a program that ran on a raspberry pi using the blinka library
I am replacing the blinka powered raspberry pi gpio with a belay powered mcu.
(need gpio, i2c, onewire, and addressable led support)
I was thinking it would be nice if the built in interfaces of the mcu (gpio, i2c, spi, serial, etc), could be abstracted in belay to blinka drop in compatible objects
So you could replace:
# raspberry pi
import board
import digitalio
led = digitalio.DigitalInOut(board.D18)
led.direction = digitalio.Direction.OUTPUT
led.value = True
With:
# belay micropython mcu
import belay
device = belay.Device("/dev/ttyUSB0")
led = device.digitalio.DigitalInOut(device.board.D18)
led.direction = device.digitalio.Direction.OUTPUT
led.value = True
Basically mirroring the "device", "board", and "busio" interfaces from micropython into belay native objects.
I am willing to make the implementation, but was wondering if you had any suggestions about the direction to go.
I am unsure if trying to do this in the belay syntactical sugar way would work well. Or If a hardcoded version of the "device", "board", and "busio" classes that set themselves up on connection would be the easiest option. Subclassing could sort of do this if you built up a full class structure.
As far as I can tell, it's not possible to "mirror/link" an object from the mcu running micropython into the full computer side python environment.
It would be nice to do something like
device = belay.Device("/dev/ttyUSB0")
i2c = device.getreference("busio.I2C(board.SCL, board.SDA)")
And then use "i2c" as a native object that I can pass to device drivers and such. With tab autocompletion when using something like ptpython.
Which means that it would need to be aware of the full underlying tree structure of the object.
Being able to reference any object in that complete of a way seems like it might be difficult to me. So I think only having the "device", "board", and "busio" objects linked would be the most useful and easier to implement.
Thoughts?