-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Description
Hello,
It would be useful that similar to machine.Pin
class, the Led, UART, SPI, I2C and other classes will be able to receive a string identifier, so that the logical name can be acquired.
I apologize if this was considered before, I am new to micropython and looked for similar cases but could not find any.
The logical name may be used to reduce synchronization between application and board settings and to allow the same application run on different boards and board variants without modifications.
For example:
import machine
machine.UART("DEBUG").write("Hello\r\n");
machine.UART("UI").write("Hello\r\n");
machine.LED("OK").on()
machine.LED("CONNECTED").on()
This should be backward compatible as we can distinguish between string id and numeric id.
Another option is to provide board specific constants exposed to user as a pattern, in this case we may add a machine.registry
object and the code will look like:
import machine
machine.UART(machine.registry["UART_DEBUG"]).write("Hello\r\n");
machine.UART(machine.registry["UART_UI"]).write("Hello\r\n");
machine.LED(machine.registry["LEDOK"]).on()
machine.LED(machine.registry["CONNECTED"]).on()
The registry approach is less intrusive to current implementation, easier to add, but not as intuitive as expected, and error prone, as board configuration requires to refer the same entity in two different locations.
What do you think?
BTW: it would be handy to have a machine.board_id()
which will return a machine friendly board class unique identifier similar to os.uname().machine
human friendly identifier for cases in which this feature is rejected and registry should be constructed outside of the board support.
Thanks,
Code Size
This is similar to Pin class, I would like to assume that if logical name for pin is acceptable, then logical name for lower number of peripherals is also acceptable.
Implementation
I intend to implement this feature and would submit a Pull Request if desirable
Code of Conduct
Yes, I agree