I have done 'this' but I am hesitant to say it is what you want.
https://github.com/evezor/Edge_Boards has the code that sets up pins:
Code: Select all
{
"name": "button_0",
"type": "button",
"pin": "D11",
"old": null
},
https://github.com/evezor/Edge_Boards/b ... son#L7-L12
Code: Select all
if parameter['type'] == "button":
self.pins[parameter['name']] = \
Pin(parameter['pin'], Pin.IN, Pin.PULL_UP)
elif parameter['type'] == "adc":
self.pins[parameter['name']] = \
pyb.ADC(parameter['pin'])
elif parameter['type'] == "led":
pin = Pin(parameter['pin'], Pin.OUT)
self.pins[parameter['name']] = pin
elif parameter['type'] == "pwm":
pin = Pin(parameter['pin'], Pin.OUT)
tim = Timer(3, freq=1000)
self.pins[parameter['name']] = \
tim.channel(2, Timer.PWM, pin=pin )
elif parameter['type'] == "neo":
pin = Pin(parameter['pin'], Pin.OUT)
self.pins[parameter['name']] = pin
https://github.com/evezor/Edge_Boards/b ... py#L33-L53
I think that is about what you are looking for.
I'm not super happy about the code I wrote. The lines are fine, but the overall abstractions... It works, but this project stalled and if it ever gets traction I expect to have to fill in some holes, like the way timers are handled.
We kinda got lost when it came to timers.
I would say the problem was: I was writing code that knew what was connected to the pin, like "button" and "led" - I should have put that code somewhere else and focused on just what an mcp pin does.
also the json file has similar issues: it is for managing what is connected to the pin, like should the led be set to on, and has its state changed (that is what "old" is for.)
If you want to know more about the system, start with
http://ide.evezor.com drag and drop and connect some pins, then hit Export JSON and see the config file that drives the code.