-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pin.Configuration: a way to specify pin setup for constructors that take pins #9845
Comments
EDIT to number proposal: Proposal 2I said that above, but it's possible that perhaps it's not really necessary, and the parameters could be changed later. In that case, here's a simpler alternative: Add properties The values for the properties should be available by reading the hardware, so that the |
Overall, I like the PinConfiguration object idea. I wouldn't do Do we want to accept
I think the risk of this approach is that other things can change these settings too. There isn't some implicit ownership like the
This isn't always true. I think there are some DigitalInOuts that have to cache these properties. |
The use of such "factory" functions is pretty rare in Python, so that's OK with me.
A number of the constructors take multiple pins, so passing a parallel sequence of The comments below are re Proposal 2 above. I gave that as a bit of a strawman, but it's lower level and you have pointed out the disadvantages.
|
(This issue is an offshoot of #1270.)
A number of open issues (#1270, #6009, #7206, #8315, #8941, #8945, #9373, #9821, #9823) have asked for the ability to set pin drive mode, drive strength, or a pull for various
*io
and other objects. Currently these classes provide limited access to some of these settings, and sometimes don't provide them at all. For instance, drive strength is not available at all, and specific pull settings are not available in classes that could use them.In more recent posts in #1270, there has been some discussion of how to to do this in general way, maybe by introducing a
Pad
class or makingPin
objects mutable.I have an idea for an upward-compatible addition which takes a different approach. In most or all API's which currently take a
Pin
, I propose the ability to additionally take aPin.Configuration
object, which specifies both thePin
and the desiredPin.DriveMode
,Pin.Pull
, and drive strength settings. APin.Configuration
object would not change the pin: it's instead just some settings that are desired when the pin is set up. Some of the settings could be left unspecified for the particular class to choose.DriveMode
andPull
would be moved fromdigitalio
. For drive strength, I propose passing an integer, which must be one of the integers inPin.drive_strengths
, as described #1270 (comment). So there is noPin.DriveStrength
enum.Here is a rough pseudo-definition in Python:
Right now, PWMOut can take a pin:
But it could also take a
Pin.Configuration
, say to set the drive strength:Internally, in the
shared-bindings
constructors that takePin
s as arguments, any barePin
would be converted to aPin.Configuration
, and theConfiguration
objects would be what are passed to all thecommon-hal/
constructors. Theshared-binding/
andcommon-hal/
constructors could reject invalid configurations if they made no sense for that kind of object or that particular port (e.g., the chip doesn't support the configuration on the peripheral). The constructors would call some shared setup routines to do the GPIO configuration as needed on pins or pass the appropriate arguments to the port-specific HAL layerI am not wedded to
Configuration
as the name of the class. I also thought of:It is important to emphasize that a
Pin.Configuration
does not make any changes itself to the pin settings. It's just a carrier of requested settings. This is because for some HAL layers, the pin is not alway set up by GPIO operations. For instance, in ESP-IDF, pulls are sometimes specified at the driver level for a particular peripheral, in a driver-specific configuration structure.Pin.Configuration
does not replace existing dynamic mode setting needs. For instance,DigitalInOut
would still provide dynamic setting ofPull
andDriveMode
, since that is often necessary for matrix, scanning, bidirectional buses, etc.The generalized mechanism provided by
Pin.Configuration
can make some currentpull=
and similar arguments unneeded. For instance,keypad.Keys
takes apull
argument. Instead, the pull would be specified in the pins argument:This proposal is the result of some 3am thinking, so maybe I am missing something obvious. But I like the idea.
The text was updated successfully, but these errors were encountered: