Skip to content

Commit f0232c9

Browse files
committed
Changes based on feedback in adafruit#600.
1 parent 15db026 commit f0232c9

1 file changed

Lines changed: 43 additions & 16 deletions

File tree

docs/design_guide.rst

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
Design Guide
22
============
33

4-
This guide covers a variety of development practices for CircuitPython core and library APIs. Consistency with these practices ensures that beginners can learn a pattern once and apply it throughout the CircuitPython ecosystem.
4+
This guide covers a variety of development practices for CircuitPython core and library APIs. These
5+
APIs are both `built-into CircuitPython
6+
<https://github.com/adafruit/circuitpython/tree/master/shared-bindings>`_ and those that are
7+
`distributed on GitHub <https://github.com/search?utf8=%E2%9C%93&q=topic%3Acircuitpython&type=>`_
8+
and in the `Adafruit <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_ and `Community
9+
<https://github.com/adafruit/CircuitPython_Community_Bundle/>`_ bundles. Consistency with these
10+
practices ensures that beginners can learn a pattern once and apply it throughout the CircuitPython
11+
ecosystem.
512

613
Start libraries with the cookiecutter
714
-------------------------------------
815

9-
Cookiecutter is a cool tool that lets you bootstrap a new repo based on another
10-
repo. We've made one `here <https://github.com/adafruit/cookiecutter-adafruit-circuitpython>`_
16+
Cookiecutter is a tool that lets you bootstrap a new repo based on another repo.
17+
We've made one `here <https://github.com/adafruit/cookiecutter-adafruit-circuitpython>`_
1118
for CircuitPython libraries that include configs for Travis CI and ReadTheDocs
1219
along with a setup.py, license, code of conduct and readme.
1320

@@ -18,6 +25,10 @@ along with a setup.py, license, code of conduct and readme.
1825
1926
cookiecutter gh:adafruit/cookiecutter-adafruit-circuitpython
2027
28+
Cookiecutter will provide a series of prompts relating to the library and then create a new
29+
directory with all of the files. See `the CircuitPython cookiecutter README
30+
<https://github.com/adafruit/cookiecutter-adafruit-circuitpython#introduction>`_ for more details.
31+
2132
Module Naming
2233
-------------
2334

@@ -26,7 +37,11 @@ Adafruit funded libraries should be under the
2637
``Adafruit_CircuitPython_<name>`` and have a corresponding ``adafruit_<name>``
2738
directory (aka package) or ``adafruit_<name>.py`` file (aka module).
2839

29-
Community created libraries should have the format ``CircuitPython_<name>`` and
40+
If the name would normally have a space, such as "Thermal Printer", use an underscore instead
41+
("Thermal_Printer"). This underscore will be used everywhere even when the separation between
42+
"adafruit" and "circuitpython" is done with a ``-``. Use the underscore in the cookiecutter prompts.
43+
44+
Community created libraries should have the repo format ``CircuitPython_<name>`` and
3045
not have the ``adafruit_`` module or package prefix.
3146

3247
Both should have the CircuitPython repository topic on GitHub.
@@ -88,7 +103,7 @@ Verify your device
88103
--------------------------------------------------------------------------------
89104

90105
Whenever possible, make sure device you are talking to is the device you expect.
91-
If not, raise a ValueError. Beware that I2C addresses can be identical on
106+
If not, raise a RuntimeError. Beware that I2C addresses can be identical on
92107
different devices so read registers you know to make sure they match your
93108
expectation. Validating this upfront will help catch mistakes.
94109

@@ -123,6 +138,18 @@ modules to add extra functionality. By distinguishing API boundaries at modules
123138
you increase the likelihood that incorrect expectations are found on import and
124139
not randomly during runtime.
125140

141+
When adding a new module for additional functionality related to a CPython
142+
module do NOT simply prefix it with u. This is not a large enough differentiation
143+
from CPython. This is the MicroPython convention and they use u* modules
144+
interchangeably with the CPython name. This is confusing. Instead, think up a
145+
new name that is related to the extra functionality you are adding.
146+
147+
For example, storage mounting and unmounting related functions were moved from
148+
``uos`` into a new `storage` module. Terminal related functions were moved into
149+
`multiterminal`. These names better match their functionality and do not
150+
conflict with CPython names. Make sure to check that you don't conflict with
151+
CPython libraries too. That way we can port the API to CPython in the future.
152+
126153
Example
127154
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128155

@@ -196,7 +223,7 @@ goes.
196223
Regardless of how the attribute is implemented, it should have a short
197224
description of what state it represents including the type, possible values and/or
198225
units. It should be marked as ``(read-only)`` or ``(write-only)`` at the end of
199-
the first line for attributes that are not both readable and writeable.
226+
the first line for attributes that are not both readable and writable.
200227

201228
Instance attributes
202229
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -248,7 +275,7 @@ Read-only example::
248275
@property
249276
def temperature(self):
250277
"""
251-
The current temperature in degrees Celcius. (read-only)
278+
The current temperature in degrees Celsius. (read-only)
252279

253280
The device may require calibration to get accurate readings.
254281
"""
@@ -260,7 +287,7 @@ Renders as:
260287
.. py:attribute:: temperature
261288
:noindex:
262289

263-
The current temperature in degrees Celcius. (read-only)
290+
The current temperature in degrees Celsius. (read-only)
264291

265292
The device may require calibration to get accurate readings.
266293

@@ -464,14 +491,14 @@ properties.
464491
+-----------------------+-----------------------+-------------------------------------------------------------------------+
465492
| ``datetime`` | time.struct | date and time |
466493
+-----------------------+-----------------------+-------------------------------------------------------------------------+
467-
468-
Common APIs
469-
--------------------------------------------------------------------------------
470-
471-
Outside of sensors, having common methods amongst drivers for similar devices
472-
such as devices can be really useful. Its early days however. For now, try to
473-
adhere to guidelines in this document. Once a design is settled on, add it as a
474-
subsection to this one.
494+
| ``duty_cycle`` | int | 16-bit PWM duty cycle (regardless of output resolution) |
495+
+-----------------------+-----------------------+-------------------------------------------------------------------------+
496+
| ``frequency`` | int | Hertz |
497+
+-----------------------+-----------------------+-------------------------------------------------------------------------+
498+
| ``value`` | bool | Digital logic |
499+
+-----------------------+-----------------------+-------------------------------------------------------------------------+
500+
| ``value`` | int | 16-bit Analog value, unit-less |
501+
+-----------------------+-----------------------+-------------------------------------------------------------------------+
475502

476503
Adding native modules
477504
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)