quick2wire.gpio Pin classes now follow same API conventions as those in ...#22
Conversation
…in the mcp23x17 module. GPIO pins now have open() and close() methods and act as their own context managers. They export the pin to userspace on open() and reset the pin state and unexport it on close(). THIS IS A BREAKING API CHANGE
|
Few minor nitpicks. LGTM |
…oC pin number. This is fist step to introducing pin banks for on-board GPIO
Different pin-banks are exported from the quick2wire.gpio module:
gpio - GPIO pins numbered 0..8
pi_header_1 - the pins on the Pi's header 1, except power and
those labeled do-not-use, numbered 1..26
pi_broadcom_soc - pins identified by Broadcom SoC pin number
|
I dunno... I still think quick2wire.gpio.gpio_breakout is kinda ugly. PEP8 also frowns upon the prefix: "The X11 library uses a leading X for all its public functions. In Python, this style is generally deemed unnecessary because attribute and method names are prefixed with an object, and function names are prefixed with a module name." How about quick2wire.gpio.breakout instead? |
|
I don't think the PEP8 warning applies here. I don't use gpio_ as a prefix I also think it's will be very rare to refer to the GPIO PinBank as I think breakout is weirder. with breakout.pin(1) as p: That makes me think "which breakout?" Our board breaks out GPIO, i2C and --Nat On Thursday, January 31, 2013, Joe Walnes wrote:
|
|
How about just quick2wire.gpio? |
|
So would that be a class in the quick2wire module or a module? What would the code look like? On Thursday, January 31, 2013, Joe Walnes wrote:
|
|
Usage: Implementation wise, something like: In |
|
I think that's confusing when you import all the constants you need to work with GPIO pins from quick2wire import gpio Maybe In, Out, etc. should be in Quick2Wire as well but what about the I2C breakout, the SPI breakout, etc.? It just begs the question why they are not all exported from quick2wire. Should they be? I think we really need to represent the platform separately from the I/O interface. So then we'd have from quick2wire.platform import gpio pin = gpio.pin(1) Would that be better? |
|
It would be good to have i2c, spi, etc having a similar structure. What's the difference between platform and gpio? On Thu, Jan 31, 2013 at 11:10 AM, Nat Pryce notifications@github.comwrote:
|
|
platform would export the PinBanks defined by the systems. E.g. broadcom_soc, header_1, gpio on the Raspberry Pi. gpio would contain the classes that implement the PinBanks. But... I've come round to the idea of just calling it "pins". E.g. "from quick2wire.gpio import pins" would import the GPIO breakout with pins P0...P8, while "from quick2wire.gpio import pi_header_1" would import the pinbank for header 1 on the Pi. |
|
If there are no objections I'll rename gpio_breakout to pins & merge this in ASAP. |
|
Sounds good. On Saturday, February 2, 2013, Nat Pryce wrote:
|
quick2wire.gpio Pin classes now follow same API conventions as those in ...
...the mcp23x17 module.
GPIO pins now have open() and close() methods and act as their own context managers. They export
the pin to userspace on open() and reset the pin state and unexport it on close().
THIS IS A BREAKING API CHANGE
Closes #17