Skip to content

Commit fe57d1f

Browse files
authored
Merge pull request #221 from dplanella/readthedocs
Separate API docs into modules
2 parents f2f5c0a + 14f1f79 commit fe57d1f

File tree

9 files changed

+510
-480
lines changed

9 files changed

+510
-480
lines changed

docs/ADC.rst

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
:mod:`ADC` --- A/D Converter input interface
2+
--------------------------------------------
3+
4+
This module enables reading analog input values from the analog to digital
5+
converter (ADC) on the Beaglebone processor.
6+
7+
Example::
8+
9+
import Adafruit_BBIO.ADC as ADC
10+
11+
ADC.setup()
12+
13+
# The read method returns normalized values from 0 to 1.0
14+
value = ADC.read("P9_40")
15+
16+
# The read_raw returns non-normalized values from 0 to 4095
17+
value = ADC.read_raw("P9_40")
18+
19+
.. module:: Adafruit_BBIO.ADC
20+
21+
.. function:: setup_adc()
22+
23+
Setup and start the ADC hardware.
24+
25+
.. function:: setup_read(channel)
26+
27+
Read the normalized analog value for the channel.
28+
29+
:param str channel: GPIO channel to read the value from (e.g. "P8_16").
30+
:returns: normalized value reading from 0.0 to 1.0
31+
:rtype: float
32+
33+
34+
.. function:: setup_read_raw(channel)
35+
36+
Read the raw analog value for the channel.
37+
38+
:note: Kernels older than 4.1.x returned a raw value range based on
39+
the reference voltage of 1.8 V–– from 0 to 1800.
40+
41+
:param str channel: GPIO channel to read the value from (e.g. "P8_16").
42+
:returns: raw value reading from 0 to 4095 (12 bits).
43+
:rtype: float
44+
45+

docs/Encoder.rst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:mod:`Encoder` --- Quadrature Encoder interface
2+
-----------------------------------------------
3+
4+
.. automodule:: Adafruit_BBIO.Encoder
5+
:members:

docs/GPIO.rst

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
:mod:`GPIO` --- General Purpose I/O interface
2+
---------------------------------------------
3+
4+
This module provides access and control of pins set up as General Purpose
5+
I/O (GPIO).
6+
7+
.. note::
8+
9+
You need to be part of the ``gpio`` group of the OS running on the
10+
Beaglebone to be able to run GPIO code as a non-root user. The default
11+
user created upon the Debian image installation should already be
12+
part of the group. Otherwise, you can use
13+
``sudo usermod -a -G gpio userName`` to add ``userName`` to the group.
14+
15+
.. note::
16+
17+
When coding with this module, you will be using pin names for
18+
better readability. As such, you can specify them in the header 8 or 9
19+
form (e.g. "P8_16") or in pin name form (e.g. "GPIO1_14").
20+
For easy reference, you can use the
21+
`Beaglebone pin names table <https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/source/common.c#L73>`_
22+
23+
24+
Example::
25+
26+
# Use the config-pin command line tool to set a pin's function to GPIO
27+
# Then you can control it with the GPIO module from Python
28+
config-pin P9_14 gpio
29+
30+
import Adafruit_BBIO.GPIO as GPIO
31+
32+
# Set up pins as inputs or outputs
33+
GPIO.setup("P8_13", GPIO.IN)
34+
GPIO.setup("P8_14", GPIO.OUT)
35+
GPIO.setup("GPIO0_26", GPIO.OUT) # Alternative: use actual pin names
36+
37+
# Write a logic high or logic low
38+
GPIO.output("P8_14", GPIO.HIGH) # You can also write '1' instead
39+
GPIO.output("P8_14", GPIO.LOW) # You can also write '0' instead
40+
41+
.. module:: Adafruit_BBIO.GPIO
42+
43+
.. function:: setup(channel, direction[, pull_up_down=PUD_OFF, initial=None, delay=0])
44+
45+
Set up the given GPIO channel, its direction and (optional) pull/up down control
46+
47+
:param str channel: GPIO channel to set up (e.g. "P8_16").
48+
:param int direction: GPIO channel direction (:data:`IN` or :data:`OUT`).
49+
:param int pull_up_down: pull-up/pull-down resistor configuration
50+
(:data:`PUD_OFF`, :data:`PUD_UP` or :data:`PUD_DOWN`).
51+
:param int initial: initial value for an output channel (:data:`LOW`/:data:`HIGH`).
52+
:param int delay: time in milliseconds to wait after exporting the GPIO pin.
53+
54+
.. function:: cleanup()
55+
56+
Clean up by resetting all GPIO channels that have been used by
57+
the application to :data:`IN` with no pullup/pulldown and no event
58+
detection.
59+
60+
:note: It's recommended that you call this function upon exiting your
61+
application.
62+
63+
.. function:: output(channel, value)
64+
65+
Set the given output channel to the given digital value.
66+
67+
:param str channel: GPIO channel to output the value to (e.g. "P8_16").
68+
:param value: value to set the output to-- 0/1 or False/True
69+
or :data:`LOW`/:data:`HIGH`.
70+
:type value: int or bool
71+
72+
.. function:: input(channel)
73+
74+
Get the given input channel's digital value.
75+
76+
:param str channel: GPIO channel to read the value from (e.g. "P8_16").
77+
:returns: Channel value–– 0 or 1.
78+
:rtype: int
79+
80+
.. function:: add_event_detect(channel, edge[, callback=None, bouncetime=0])
81+
82+
Enable edge detection events for the given GPIO channel.
83+
84+
:param str channel: GPIO channel to detect events from (e.g. "P8_16").
85+
:param int edge: edge to detect–– :data:`RISING`, :data:`FALLING`
86+
or :data:`BOTH`
87+
:param func callback: a function to call once the event has been detected.
88+
:param int bouncetime: switch bounce timeout in ms for the callback.
89+
90+
.. function:: remove_event_detect(channel)
91+
92+
Remove edge detection for the given GPIO channel.
93+
94+
:param str channel: GPIO channel to remove event detection
95+
from (e.g. "P8_16").
96+
97+
.. function:: event_detected(channel)
98+
99+
Checks if an edge event has occured on a given GPIO.
100+
101+
:note: You need to enable edge detection using :func:`add_event_detect()` first.
102+
103+
:param str channel: GPIO channel to check for event detection
104+
for (e.g. "P8_16").
105+
:returns: True if an edge has occured on a given GPIO, False otherwise
106+
:rtype: bool
107+
108+
.. function:: add_event_callback(channel, callback[, bouncetime=0])
109+
110+
Add a callback for an event already defined using :func:`add_event_detect()`
111+
112+
:param str channel: GPIO channel to add a callback to (e.g. "P8_16").
113+
:param func callback: a function to call once the event has been detected.
114+
:param int bouncetime: switch bounce timeout in ms for the callback.
115+
116+
.. function:: wait_for_edge(channel, edge[, timeout=-1])
117+
118+
Wait for an edge on the given channel.
119+
120+
:param str channel: GPIO channel to wait on (e.g. "P8_16").
121+
:param int edge: edge to detect–– :data:`RISING`, :data:`FALLING`
122+
or :data:`BOTH`
123+
:param int timeout: time to wait for an edge, in milliseconds.
124+
-1 will wait forever.
125+
126+
.. function:: gpio_function(channel)
127+
128+
Return the current GPIO function
129+
(:data:`IN`, :data:`IN`, :data:`ALT0`) of the given pin.
130+
131+
:warning: Currently only returning the direction of the
132+
pin (input or output) is supported.
133+
134+
:param str channel: GPIO pin to query the status of.
135+
:returns: 0 if :data:`IN`, 1 if :data:`OUT`
136+
:rtype: int
137+
138+
.. function:: setwarnings(gpio_warnings)
139+
140+
Enable or disable GPIO warning messages.
141+
142+
:warning: Currently enabling or disabling warnings
143+
has no effect.
144+
145+
:param int gpio_warnings: 0–– disable warnings; 1–– enable warnings
146+
147+
.. attribute:: ALT0
148+
149+
Pin mode-- alternate function 0.
150+
151+
.. attribute:: BOTH
152+
153+
Edge detection-- detect both edges.
154+
155+
.. attribute:: FALLING
156+
157+
Edge detection-- detect falling edge.
158+
159+
.. attribute:: HIGH
160+
161+
Pin status-- logic low.
162+
163+
.. attribute:: IN
164+
165+
Pin mode-- input.
166+
167+
.. attribute:: LOW
168+
169+
Pin status-- logic low.
170+
171+
.. attribute:: OUT
172+
173+
Pin mode-- output.
174+
175+
.. attribute:: PUD_OFF
176+
177+
Pull-up/pull-down resistor type-- no pull-up/pull-down.
178+
179+
.. attribute:: PUD_DOWN
180+
181+
Pull-up/pull-down resistor type-- pull-down.
182+
183+
.. attribute:: PUD_UP
184+
185+
Pull-up/pull-down resistor type-- pull-up.
186+
187+
.. attribute:: RISING
188+
189+
Edge detection-- detect rising edge.
190+
191+
.. attribute:: VERSION
192+
193+
GPIO module version. Currently unused.
194+

docs/PWM.rst

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
:mod:`PWM` --- Pulse Width Modulation interface
2+
-----------------------------------------------
3+
4+
Enables access to the Pulse Width Modulation (PWM) module, to easily and
5+
accurately generate a PWM output signal of a given duty cycle and
6+
frequency.
7+
8+
.. note::
9+
10+
You need to be part of the ``pwm`` group of the OS running on the
11+
Beaglebone to be able to run PWM code as a non-root user. The default
12+
user created upon the Debian image installation should already be
13+
part of the group. Otherwise, you can use
14+
``sudo usermod -a -G pwm userName`` to add ``userName`` to the group.
15+
16+
.. module:: Adafruit_BBIO.PWM
17+
18+
.. function:: start(channel, duty_cycle[, frequency=2000, polarity=0])
19+
20+
Set up and start the given PWM channel.
21+
22+
:param str channel: PWM channel. It can be specified in the form
23+
of of 'P8_10', or 'EHRPWM2A'.
24+
:param int duty_cycle: PWM duty cycle. It must have a value from 0 to 100.
25+
:param int frequency: PWM frequency, in Hz. It must be greater than 0.
26+
:param int polarity: defines whether the value for ``duty_cycle`` affects the
27+
rising edge or the falling edge of the waveform. Allowed values -- 0
28+
(rising edge, default) or 1 (falling edge).
29+
30+
.. function:: stop(channel)
31+
32+
Stop the given PWM channel.
33+
34+
:param str channel: PWM channel. It can be specified in the form
35+
of of 'P8_10', or 'EHRPWM2A'.
36+
37+
.. function:: set_duty_cycle(channel, duty_cycle)
38+
39+
Change the duty cycle of the given PWM channel.
40+
41+
:note: You must have started the PWM channel with :func:`start()`
42+
once, before changing the duty cycle.
43+
44+
:param str channel: PWM channel. It can be specified in the form
45+
of of 'P8_10', or 'EHRPWM2A'.
46+
:param int duty_cycle: PWM duty cycle. It must have a value from 0 to 100.
47+
48+
.. function:: set_frequency(channel, frequency)
49+
50+
Change the frequency of the given PWM channel.
51+
52+
:note: You must have started the PWM channel with :func:`start()`
53+
once, before changing the frequency.
54+
55+
:param str channel: PWM channel. It can be specified in the form
56+
of of 'P8_10', or 'EHRPWM2A'.
57+
:param int frequency: PWM frequency. It must be greater than 0.
58+
59+
.. function:: cleanup()
60+
61+
Clean up by resetting all GPIO channels that have been used by this
62+
program to INPUT, with no pullup/pulldown and no event detection.

docs/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Generating API documentation
22

3-
This folder contains the required files to automatically generate the Adafruit Beaglebone I/O Python API documentation, partly from the code docstrings and partly from a reStructuredText-formatted `index.rst` file.
3+
This folder contains the required files to automatically generate the Adafruit Beaglebone I/O Python API documentation, partly from the code docstrings and partly from files in reStructuredText format.
44

55
```
66
├── conf.py <- Sphinx configuration file
7-
├── index.rst <- Documentation will be generated based on this
7+
├── index.rst <- Documentation will be generated based on the master index
88
└── Makefile <- Auxiliary Makefile to build documentation
99
```
1010

11-
The tools used are [Sphinx](http://www.sphinx-doc.org) to extract the documentation and publish it in HTML format for online viewing, in combination with [Readthedocs](http://readthedocs.io), which automatically executes Sphinx via webhooks triggered by Github commits, and publishes the resulting docs for all tracked branches. Generally Readthedocs will be set up to track stable release branches and master.
11+
The tools used are [Sphinx](http://www.sphinx-doc.org) to extract the documentation and publish it in HTML format for online viewing, in combination with [Readthedocs](http://readthedocs.io). Readthedocs automatically executes Sphinx via webhooks triggered by Github commits, and publishes the resulting docs for all tracked branches or tags. Generally Readthedocs will be set up to track stable release tags and the master branch.
1212

1313
## Building the documentation
1414

@@ -36,7 +36,7 @@ Notes:
3636

3737
## Readthedocs maintenance
3838

39-
At every release that includes documenation (most probably 1.0.10 will be the first one), the release's branch needs to be selected in the web UI and marked as active.
39+
At every release that includes documenation (most probably 1.0.10 will be the first one), the release's branch or tag needs to be selected in the web UI and marked as active.
4040

4141
After this, documentation will automatically be generated and published for that release. It will be available at the same URL as the main documentation, and a link with the version number will be shown, where it can be accessed from.
4242

@@ -50,11 +50,11 @@ Ideally, all API documentation would be written in the source files as Python do
5050

5151
However, most of the code is written as C extensions. While they do provide docstrings once they are built, Sphinx does not natively support extracting them. There is [a workaround](https://stackoverflow.com/a/30110104/9022675) to do this, but it involves first building the extensions, installing them and hardcoding a path. While it might work for locally-built documentation, it's unlikely that readthedocs support this option.
5252

53-
For the sake of keeping things simple and with less maintenance, the approach of documenting the C-generated API in the `index.rst` file has been taken.
53+
For the sake of keeping things simple and with less maintenance, the approach of documenting the C-generated API in separate `.rst` files (one for each Python module) has been taken.
5454

55-
This has the advantage of having a definition of the API in one place, but it also poses the disadvantage of some duplication, as the C modules do define some docstrings for their objects. Then again, the API itself has hardly changed in the last few years, and the Beaglebone is a mature platform, so it's unlikely that this will pose a significant maintenance overhead.
55+
This has the advantage of having a definition of the API in one place, but it also poses the disadvantage of some duplication, as the C modules do define some docstrings for their objects. Then again, the API itself has hardly changed in the last few years, and the Beaglebone is a mature platform, so it's unlikely that this will add a significant maintenance overhead.
5656

57-
- The documentation in the `index.rst` file is written in [reStructuredText](http://docutils.sourceforge.net/rst.html), extended with Sphinx markup for defining the objects.
57+
- The documentation in the `.rst` files is written in [reStructuredText](http://docutils.sourceforge.net/rst.html), extended with Sphinx markup for defining the objects.
5858
- The documentation in Python modules follows the Google readable docstring markup, which also builds upon reStructuredText and is fully supported by Sphinx.
5959

6060
## Further reference

0 commit comments

Comments
 (0)