Skip to content

quick2wire.gpio Pin classes now follow same API conventions as those in ...#22

Merged
npryce merged 10 commits into
romilly:masterfrom
npryce:gpio-improvements
Feb 3, 2013
Merged

quick2wire.gpio Pin classes now follow same API conventions as those in ...#22
npryce merged 10 commits into
romilly:masterfrom
npryce:gpio-improvements

Conversation

@npryce

@npryce npryce commented Jan 25, 2013

Copy link
Copy Markdown
Contributor

...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

…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
@joewalnes

Copy link
Copy Markdown

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
@joewalnes

Copy link
Copy Markdown

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?

@npryce

npryce commented Jan 31, 2013

Copy link
Copy Markdown
Contributor Author

I don't think the PEP8 warning applies here. I don't use gpio_ as a prefix
for everything in the module. Only to identify those GPIO pins that the Pi
header names as GPIO0..7.

I also think it's will be very rare to refer to the GPIO PinBank as
quick2wire.gpio.gpio - there's just no need to. This isn't Java: Python has
import as and from ... import to avoid that verbosity.

I think breakout is weirder.

with breakout.pin(1) as p:
...

That makes me think "which breakout?" Our board breaks out GPIO, i2C and
SPI.

--Nat

On Thursday, January 31, 2013, Joe Walnes wrote:

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?


Reply to this email directly or view it on GitHubhttps://github.com//pull/22#issuecomment-12946341.

@joewalnes

Copy link
Copy Markdown

How about just quick2wire.gpio?

@npryce

npryce commented Jan 31, 2013

Copy link
Copy Markdown
Contributor Author

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:

How about just quick2wire.gpio?


Reply to this email directly or view it on GitHubhttps://github.com//pull/22#issuecomment-12947833.

@joewalnes

Copy link
Copy Markdown

Usage:

from quick2wire import gpio
with gpio.pin(1): ...

Implementation wise, something like:

In quick2wire/gpio/__init__.py:

pin = # delegate to real symbol

@npryce

npryce commented Jan 31, 2013

Copy link
Copy Markdown
Contributor Author

I think that's confusing when you import all the constants you need to work with GPIO pins

from quick2wire import gpio
from quick2wire.gpio import In, Out, ...

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
from quick2wire.gpio import In, Out

pin = gpio.pin(1)

Would that be better?

@joewalnes

Copy link
Copy Markdown

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:

I think that looks a bit odd when you import all the constants you need to
work with GPIO pins

from quick2wire import gpio
from quick2wire.gpio import In, Out, ...

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
from quick2wire.gpio import In, Out

pin = gpio.pin(1)

Would that be better?


Reply to this email directly or view it on GitHubhttps://github.com//pull/22#issuecomment-12953088.

@npryce

npryce commented Jan 31, 2013

Copy link
Copy Markdown
Contributor Author

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.

@npryce

npryce commented Feb 2, 2013

Copy link
Copy Markdown
Contributor Author

If there are no objections I'll rename gpio_breakout to pins & merge this in ASAP.

@joewalnes

Copy link
Copy Markdown

Sounds good.

On Saturday, February 2, 2013, Nat Pryce wrote:

If there are no objections I'll rename gpio_breakout to pins & merge this
in ASAP.


Reply to this email directly or view it on GitHubhttps://github.com//pull/22#issuecomment-13036653.

npryce added a commit that referenced this pull request Feb 3, 2013
quick2wire.gpio Pin classes now follow same API conventions as those in ...
@npryce npryce merged commit c69382c into romilly:master Feb 3, 2013
@npryce npryce deleted the gpio-improvements branch February 3, 2013 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unexport does not reset GPIO to initial state (only removes it from device list)

2 participants