Skip to content

Commit f12715b

Browse files
committed
Finished documenting GPIO
1 parent 6e9ea92 commit f12715b

File tree

4 files changed

+124
-26
lines changed

4 files changed

+124
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ docs/_templates
5959

6060
# vim temp files
6161
*~
62+
*.swp

Adafruit_BBIO/Encoder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
The channel identifiers are available as module variables :data:`eQEP0`,
1010
:data:`eQEP1`, :data:`eQEP2` and :data:`eQEP2b`.
1111
12+
======= ======= ======= ===================================================
13+
Channel Pin A Pin B Notes
14+
======= ======= ======= ===================================================
15+
eQEP0 P9.27 P9.92
16+
eQEP1 P8.33 P8.35 Only available with video disabled
17+
eQEP2 P8.11 P8.12 Only available with eQEP2b unused (same channel)
18+
eQEP2b P8.41 P8.42 Only available with video disabled and eQEP2 unused
19+
======= ======= ======= ===================================================
20+
1221
Example:
1322
To use the module, you can connect a rotary encoder to your Beaglebone
1423
and then simply instantiate the :class:`RotaryEncoder` class to read its

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
# built documents.
5555
#
5656
# The short X.Y version.
57-
version = u''
57+
version = u'1.0'
5858
# The full version, including alpha/beta/rc tags.
59-
release = u'1.0.9'
59+
release = u''
6060

6161
# The language for content autogenerated by Sphinx. Refer to documentation
6262
# for a list of supported languages.

docs/index.rst

Lines changed: 112 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ADC, UART and eQEP hardware modules from Python programs.
2222
:mod:`PWM` --- Pulse Width Modulation interface
2323
-----------------------------------------------
2424

25-
Enables access to the Pulse Width Modulation (PWM) module, to easily and
25+
Enables access to the Pulse Width Modulation (PWM) module, to easily and
2626
accurately generate a PWM output signal of a given duty cycle and
2727
frequency.
2828

@@ -160,7 +160,7 @@ This module defines an object type that allows Serial Peripheral Interface
160160
(SPI) bus transactions on hosts running the Linux kernel. The host kernel
161161
must have SPI support and SPI device interface support.
162162

163-
Because the SPI device interface is opened R/W, users of this module
163+
Because the SPI device interface is opened R/W, users of this module
164164
usually must have root permissions or be members of a group with granted
165165
access rights.
166166

@@ -184,22 +184,22 @@ Example::
184184
# /dev/spidev0.0
185185
spi = SPI(1, 0)
186186
print(spi.xfer2([32, 11, 110, 22, 220]))
187-
spi.close()
187+
spi.close()
188188

189189
# /dev/spidev0.1
190190
spi = SPI(1, 1)
191191
print(spi.xfer2([32, 11, 110, 22, 220]))
192-
spi.close()
192+
spi.close()
193193

194194
# /dev/spidev1.0
195195
spi = SPI(2, 0)
196196
print(spi.xfer2([32, 11, 110, 22, 220]))
197-
spi.close()
197+
spi.close()
198198

199199
# /dev/spidev1.1
200200
spi = SPI(2, 1)
201201
print(spi.xfer2([32, 11, 110, 22, 220]))
202-
spi.close()
202+
spi.close()
203203

204204
.. module:: Adafruit_BBIO.SPI
205205

@@ -290,7 +290,8 @@ Example::
290290
:mod:`GPIO` --- General Purpose I/O interface
291291
---------------------------------------------
292292

293-
TODO
293+
This module provides access and control of pins set up as General Purpose
294+
I/O (GPIO).
294295

295296
.. note::
296297

@@ -302,8 +303,10 @@ TODO
302303

303304
.. note::
304305

305-
When coding with this module, you will often be using pin names for
306-
better readability. For easy reference, you can use the
306+
When coding with this module, you will be using pin names for
307+
better readability. As such, you can specify them in the header 8 or 9
308+
form (e.g. "P8_16") or in pin name form (e.g. "GPIO1_14").
309+
For easy reference, you can use the
307310
`Beaglebone pin names table <https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/source/common.c#L73>`_
308311

309312

@@ -326,10 +329,106 @@ Example::
326329

327330
.. module:: Adafruit_BBIO.GPIO
328331

329-
.. function:: setup()
332+
.. function:: setup(channel, direction[, pull_up_down=:data:`PUD_OFF`, initial=None, delay=0])
330333

331-
:param str channel: UART channel to set up. One of "UART1", "UART2",
332-
"UART4" or "UART5"
334+
Set up the given GPIO channel, its direction and (optional) pull/up down control
335+
336+
:param str channel: GPIO channel to set up (e.g. "P8_16").
337+
:param int direction: GPIO channel direction (:data:`IN` or :data:`OUT`).
338+
:param int pull_up_down: pull-up/pull-down resistor configuration
339+
(:data:`PUD_OFF`, :data:`PUD_UP` or :data:`PUD_DOWN`).
340+
:param int initial: initial value for an output channel (:data:`LOW`/:data:`HIGH`).
341+
:param int delay: time in milliseconds to wait after exporting the GPIO pin.
342+
343+
.. function:: cleanup()
344+
345+
Clean up by resetting all GPIO channels that have been used by
346+
the application to :data:`IN` with no pullup/pulldown and no event
347+
detection.
348+
349+
.. function:: output(channel, value)
350+
351+
Set the given output channel to the given digital value.
352+
353+
:param str channel: GPIO channel to output the value to (e.g. "P8_16").
354+
:param value: value to set the output to-- 0/1 or False/True
355+
or :data:`LOW`/:data:`HIGH`.
356+
:type value: int or bool
357+
358+
.. function:: input(channel)
359+
360+
Get the given input channel's digital value.
361+
362+
:param str channel: GPIO channel to read the value from (e.g. "P8_16").
363+
:returns: Channel value–– 0 or 1.
364+
:rtype: int
365+
366+
.. function:: add_event_detect(channel, edge[, callback=None, bouncetime=0])
367+
368+
Enable edge detection events for the given GPIO channel.
369+
370+
:param str channel: GPIO channel to detect events from (e.g. "P8_16").
371+
:param int edge: edge to detect–– :data:`RISING`, :data:`FALLING`
372+
or :data:`BOTH`
373+
:param func callback: a function to call once the event has been detected.
374+
:param int bouncetime: switch bounce timeout in ms for the callback.
375+
376+
.. function:: remove_event_detect(channel)
377+
378+
Remove edge detection for the given GPIO channel.
379+
380+
:param str channel: GPIO channel to remove event detection
381+
from (e.g. "P8_16").
382+
383+
.. function:: event_detected(channel)
384+
385+
Checks if an edge event has occured on a given GPIO.
386+
387+
:note: You need to enable edge detection using :func:`add_event_detect()` first.
388+
389+
:param str channel: GPIO channel to check for event detection
390+
for (e.g. "P8_16").
391+
:returns: True if an edge has occured on a given GPIO, False otherwise
392+
:rtype: bool
393+
394+
.. function:: add_event_callback(channel, callback[, bouncetime=0])
395+
396+
Add a callback for an event already defined using :func:`add_event_detect()`
397+
398+
:param str channel: GPIO channel to add a callback to (e.g. "P8_16").
399+
:param func callback: a function to call once the event has been detected.
400+
:param int bouncetime: switch bounce timeout in ms for the callback.
401+
402+
.. function:: wait_for_edge(channel, edge[, timeout=-1])
403+
404+
Wait for an edge on the given channel.
405+
406+
:param str channel: GPIO channel to wait on (e.g. "P8_16").
407+
:param int edge: edge to detect–– :data:`RISING`, :data:`FALLING`
408+
or :data:`BOTH`
409+
:param int timeout: time to wait for an edge, in milliseconds.
410+
-1 will wait forever.
411+
412+
.. function:: gpio_function(channel)
413+
414+
Return the current GPIO function
415+
(:data:`IN`, :data:`IN`, :data:`ALT0`) of the given pin.
416+
417+
:warning: Currently only returning the direction of the
418+
pin (input or output) is supported.
419+
420+
:param str channel: GPIO pin to query the status of.
421+
:returns: 0 if :data:`IN`, 1 if :data:`OUT`
422+
:rtype: int
423+
424+
.. function:: setwarnings(gpio_warnings)
425+
426+
Enable or disable GPIO warning messages.
427+
428+
:warning: Currently enabling or disabling warnings
429+
has no effect.
430+
431+
:param int gpio_warnings: 0–– disable warnings; 1–– enable warnings
333432

334433
.. attribute:: ALT0
335434

@@ -377,18 +476,7 @@ Example::
377476

378477
.. attribute:: VERSION
379478

380-
GPIO module version.
381-
382-
.. function:: cleanup()
383-
.. function:: output()
384-
.. function:: input()
385-
.. function:: add_event_detect()
386-
.. function:: remove_event_detect()
387-
.. function:: add_event_detected()
388-
.. function:: add_event_callback()
389-
.. function:: wait_for_edge()
390-
.. function:: gpio_function()
391-
.. function:: setwarnings()
479+
GPIO module version. Currently unused.
392480

393481
Indices and tables
394482
==================

0 commit comments

Comments
 (0)