Skip to content

Get machine resource by name in addition to by id #16135

@alonbl

Description

@alonbl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementationsportsRelates to multiple ports, or a new/proposed port

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy