Skip to content

Commit af313b3

Browse files
authored
Merge pull request #44 from jepler/doc-improvements
Improve documentation
2 parents e3909d4 + 309d248 commit af313b3

12 files changed

+255
-24
lines changed

adafruit_seesaw/analoginput.py

+14
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@
2121
# THE SOFTWARE.
2222
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods
2323

24+
"""
25+
`adafruit_seesaw.analoginput`
26+
====================================================
27+
"""
28+
2429
__version__ = "0.0.0-auto.0"
2530
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"
2631

2732
class AnalogInput:
33+
"""CircuitPython-compatible class for analog inputs
34+
35+
This class is intended to be a compatible subset of `analogio.AnalogIn`
36+
37+
:param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device
38+
:param int pin: The pin number on the device
39+
"""
2840
def __init__(self, seesaw, pin):
2941
self._seesaw = seesaw
3042
self._pin = pin
@@ -34,8 +46,10 @@ def deinit(self):
3446

3547
@property
3648
def value(self):
49+
"""The current analog value on the pin, as an integer from 0..65535 (inclusive)"""
3750
return self._seesaw.analog_read(self._pin)
3851

3952
@property
4053
def reference_voltage(self):
54+
"""The reference voltage for the pin"""
4155
return 3.3

adafruit_seesaw/crickit.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
# THE SOFTWARE.
2222
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods
2323

24-
from micropython import const
24+
"""
25+
`adafruit_seesaw.crickit` - Pin definition for Adafruit CRICKIT
26+
===============================================================
27+
"""
28+
29+
try:
30+
from micropython import const
31+
except ImportError:
32+
def const(x):
33+
return x
2534

2635
__version__ = "0.0.0-auto.0"
2736
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"

adafruit_seesaw/digitalio.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,26 @@
2121
# THE SOFTWARE.
2222
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods
2323

24+
"""
25+
`adafruit_seesaw.digitalio`
26+
====================================================
27+
"""
28+
2429
import digitalio
2530

2631
__version__ = "0.0.0-auto.0"
2732
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"
2833

2934
class DigitalIO:
35+
"""CircuitPython-compatible class for digital I/O pins
36+
37+
This class is intended to be a compatible subset of `digitalio.DigitalInOut`.
38+
39+
Due to technical limitations, PULL_DOWNs are not supported.
40+
41+
:param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device
42+
:param int pin: The pin number on the device
43+
"""
3044
def __init__(self, seesaw, pin):
3145
self._seesaw = seesaw
3246
self._pin = pin
@@ -39,22 +53,25 @@ def deinit(self):
3953
pass
4054

4155
def switch_to_output(self, value=False, drive_mode=digitalio.DriveMode.PUSH_PULL):
56+
"""Switch the pin to output mode"""
4257
self._seesaw.pin_mode(self._pin, self._seesaw.OUTPUT)
4358
self._seesaw.digital_write(self._pin, value)
4459
self._drive_mode = drive_mode
4560
self._pull = None
4661

4762
def switch_to_input(self, pull=None):
63+
"""Switch the pin to input mode"""
4864
if pull == digitalio.Pull.DOWN:
4965
raise ValueError("Pull Down currently not supported")
50-
elif pull == digitalio.Pull.UP:
66+
if pull == digitalio.Pull.UP:
5167
self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLUP)
5268
else:
5369
self._seesaw.pin_mode(self._pin, self._seesaw.INPUT)
5470
self._pull = pull
5571

5672
@property
5773
def direction(self):
74+
"""Retrieve or set the direction of the pin"""
5875
return self._direction
5976

6077
@direction.setter
@@ -69,6 +86,7 @@ def direction(self, value):
6986

7087
@property
7188
def value(self):
89+
"""Retrieve or set the value of the pin"""
7290
if self._direction == digitalio.Direction.OUTPUT:
7391
return self._value
7492
return self._seesaw.digital_read(self._pin)
@@ -82,6 +100,7 @@ def value(self, val):
82100

83101
@property
84102
def drive_mode(self):
103+
"""Retrieve or set the drive mode of an output pin"""
85104
return self._drive_mode
86105

87106
@drive_mode.setter
@@ -90,15 +109,16 @@ def drive_mode(self, mode):
90109

91110
@property
92111
def pull(self):
112+
"""Retrieve or set the pull mode of an input pin"""
93113
return self._pull
94114

95115
@pull.setter
96116
def pull(self, mode):
97117
if self._direction == digitalio.Direction.OUTPUT:
98118
raise AttributeError("cannot set pull on an output pin")
99-
elif mode == digitalio.Pull.DOWN:
119+
if mode == digitalio.Pull.DOWN:
100120
raise ValueError("Pull Down currently not supported")
101-
elif mode == digitalio.Pull.UP:
121+
if mode == digitalio.Pull.UP:
102122
self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLUP)
103123
elif mode is None:
104124
self._seesaw.pin_mode(self._pin, self._seesaw.INPUT)

adafruit_seesaw/keypad.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
# THE SOFTWARE.
2222
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods
2323

24-
from micropython import const
24+
"""
25+
`adafruit_seesaw.keypad`
26+
====================================================
27+
"""
28+
29+
try:
30+
from micropython import const
31+
except ImportError:
32+
def const(x):
33+
return x
2534
from adafruit_seesaw.seesaw import Seesaw
2635

2736
__version__ = "0.0.0-auto.0"
@@ -38,16 +47,30 @@
3847

3948
# pylint: disable=too-few-public-methods
4049
class KeyEvent:
50+
"""Holds information about a key event in its properties
51+
52+
:param int num: The number of the key
53+
:param int edge: One of the EDGE propertes of `adafruit_seesaw.keypad.Keypad`
54+
"""
4155
def __init__(self, num, edge):
4256
self.number = int(num)
4357
self.edge = int(edge)
4458
# pylint: enable=too-few-public-methods
4559

4660
class Keypad(Seesaw):
61+
"""On compatible SeeSaw devices, reads from a keypad.
62+
63+
:param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to
64+
:param int addr: I2C address of the SeeSaw device
65+
:param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output"""
4766

67+
#: Indicates that the key is currently pressed
4868
EDGE_HIGH = 0
69+
#: Indicates that the key is currently released
4970
EDGE_LOW = 1
71+
#: Indicates that the key was recently pressed
5072
EDGE_FALLING = 2
73+
#: Indicates that the key was recently released
5174
EDGE_RISING = 3
5275

5376
def __init__(self, i2c_bus, addr=0x49, drdy=None):
@@ -56,6 +79,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None):
5679

5780
@property
5881
def interrupt_enabled(self):
82+
"""Retrieve or set the interrupt enable flag"""
5983
return self._interrupt_enabled
6084

6185
@interrupt_enabled.setter
@@ -71,6 +95,7 @@ def interrupt_enabled(self, value):
7195

7296
@property
7397
def count(self):
98+
"""Retrieve or set the number of keys"""
7499
return self.read8(_KEYPAD_BASE, _KEYPAD_COUNT)
75100

76101
# pylint: disable=unused-argument, no-self-use
@@ -80,6 +105,12 @@ def count(self, value):
80105
# pylint: enable=unused-argument, no-self-use
81106

82107
def set_event(self, key, edge, enable):
108+
"""Control which kinds of events are set
109+
110+
:param int key: The key number
111+
:param int edge: The type of event
112+
:param bool enable: True to enable the event, False to disable it"""
113+
83114
if enable not in (True, False):
84115
raise ValueError("event enable must be True or False")
85116
if edge > 3 or edge < 0:
@@ -92,6 +123,9 @@ def set_event(self, key, edge, enable):
92123
self.write(_KEYPAD_BASE, _KEYPAD_EVENT, cmd)
93124

94125
def read_keypad(self, num):
126+
"""Read data from the keypad
127+
128+
:param int num: The number of bytes to read"""
95129
ret = bytearray(num)
96130
self.read(_KEYPAD_BASE, _KEYPAD_FIFO, ret)
97131
return ret

adafruit_seesaw/neopixel.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@
2121
# THE SOFTWARE.
2222
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods
2323

24+
"""
25+
`adafruit_seesaw.neopixel`
26+
====================================================
27+
"""
28+
2429
try:
2530
import struct
2631
except ImportError:
2732
import ustruct as struct
28-
from micropython import const
33+
try:
34+
from micropython import const
35+
except ImportError:
36+
def const(x):
37+
return x
2938

3039
__version__ = "1.2.3"
3140
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"
@@ -50,6 +59,17 @@
5059
"""Green Red Blue White"""
5160

5261
class NeoPixel:
62+
"""Control NeoPixels connected to a seesaw
63+
64+
:param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device
65+
:param int pin: The pin number on the device
66+
:param int n: The number of pixels
67+
:param int bpp: The number of bytes per pixel
68+
:param float brightness: The brightness, from 0.0 to 1.0
69+
:param bool auto_write: Automatically update the pixels when changed
70+
:param tuple pixel_order: The layout of the pixels.
71+
Use one of the order constants such as RGBW.
72+
"""
5373
def __init__(self, seesaw, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None):
5474
# TODO: brightness not yet implemented.
5575
self._seesaw = seesaw
@@ -84,6 +104,7 @@ def __len__(self):
84104
return self._n
85105

86106
def __setitem__(self, key, color):
107+
"""Set one pixel to a new value"""
87108
cmd = bytearray(2 + self._bpp)
88109
struct.pack_into(">H", cmd, 0, key * self._bpp)
89110
if isinstance(color, int):
@@ -127,6 +148,7 @@ def __getitem__(self, key):
127148
pass
128149

129150
def fill(self, color):
151+
"""Set all pixels to the same value"""
130152
# Suppress auto_write while filling.
131153
current_auto_write = self.auto_write
132154
self.auto_write = False
@@ -137,4 +159,5 @@ def fill(self, color):
137159
self.auto_write = current_auto_write
138160

139161
def show(self):
162+
"""Update the pixels even if auto_write is False"""
140163
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_SHOW)

adafruit_seesaw/pwmout.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
# THE SOFTWARE.
2222
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods
2323

24+
"""
25+
`adafruit_seesaw.pwmout`
26+
====================================================
27+
"""
28+
2429
__version__ = "0.0.0-auto.0"
2530
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"
2631

@@ -34,7 +39,7 @@ def __init__(self, seesaw, pin):
3439

3540
@property
3641
def frequency(self):
37-
"""The overall PWM frequency in herz."""
42+
"""The overall PWM frequency in Hertz."""
3843
return self._frequency
3944

4045
@frequency.setter

adafruit_seesaw/robohat.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
# THE SOFTWARE.
2222
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods
2323

24-
from micropython import const
24+
"""
25+
`adafruit_seesaw.robohat` - Pin definition for RoboHAT
26+
======================================================
27+
"""
28+
29+
try:
30+
from micropython import const
31+
except ImportError:
32+
def const(x):
33+
return x
2534

2635
__version__ = "0.0.0-auto.0"
2736
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"
@@ -73,22 +82,30 @@
7382
# PB<nn> pins are 32+nn
7483

7584
class MM1_Pinmap:
85+
"""This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when
86+
a RoboHAT board is detected.
87+
88+
It is also a reference for the capabilities of each pin."""
7689
# seesaw firmware (mm1_hat) analog pin map:
7790
# analog[0]:47 analog[1]:48 analog[2]: analog[3]:
7891
# analog[4]: analog[5]: analog[6]: analog[7]:
7992
#
93+
#: The pins capable of analog output
8094
analog_pins = (_MM1_D3, _MM1_D2)
8195

96+
#: The effective bit resolution of the PWM pins
8297
pwm_width = 16
8398

8499
# seesaw firmware (mm1_hat) pwm pin map:
85100
# pwm[0]:16 pwm[1]:17 pwm[2]:18 pwm[3]:19 pwm[4]:11 pwm[5]:10
86101
# pwm[6]:9 pwm[7]:8 pwm[8]:40 pwm[9]:41 pwm[10]:42 pwm[11]:43
87102
#
103+
#: The pins capable of PWM output
88104
pwm_pins = (_MM1_SERVO1, _MM1_SERVO2, _MM1_SERVO3, _MM1_SERVO4,
89105
_MM1_SERVO5, _MM1_SERVO6, _MM1_SERVO7, _MM1_SERVO8,
90106
_MM1_D12, _MM1_D10, _MM1_D11, _MM1_D9)
91107

92108
# seesaw firmware touch pin map:
93109
# touch[0]: 7 touch[1]: 6 touch[2]: 5 touch[3]: 4
110+
#: The pins capable of touch input
94111
touch_pins = (_MM1_RCH1, _MM1_RCH2, _MM1_RCH3, _MM1_RCH4)

adafruit_seesaw/samd09.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
# THE SOFTWARE.
2222
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods
2323

24-
from micropython import const
24+
"""
25+
`adafruit_seesaw.samd09` - Pin definition for Adafruit SAMD09 Breakout with seesaw
26+
==================================================================================
27+
"""
28+
29+
try:
30+
from micropython import const
31+
except ImportError:
32+
def const(x):
33+
return x
2534

2635
__version__ = "0.0.0-auto.0"
2736
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"
@@ -37,11 +46,20 @@
3746
_PWM_3_PIN = const(0x07)
3847

3948
class SAMD09_Pinmap:
49+
"""This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when
50+
a SAMD09 Breakout is detected.
51+
52+
It is also a reference for the capabilities of each pin."""
53+
54+
#: The pins capable of analog output
4055
analog_pins = (_ADC_INPUT_0_PIN, _ADC_INPUT_1_PIN,
4156
_ADC_INPUT_2_PIN, _ADC_INPUT_3_PIN)
4257

58+
"""The effective bit resolution of the PWM pins"""
4359
pwm_width = 8
4460

61+
"""The pins capable of PWM output"""
4562
pwm_pins = (_PWM_0_PIN, _PWM_1_PIN, _PWM_2_PIN, _PWM_3_PIN)
4663

64+
"""No pins on this board are capable of touch input"""
4765
touch_pins = ()

0 commit comments

Comments
 (0)