Skip to content

Commit

Permalink
Merge branch 'main' into c3_short_send
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt authored Aug 11, 2022
2 parents f1053fb + f9b9f55 commit 5823bcc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
69 changes: 67 additions & 2 deletions docs/design_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,45 @@ backticks ``:class:`~adafruit_motor.servo.Servo```. You must also add the refer

"adafruit_motor": ("https://circuitpython.readthedocs.io/projects/motor/en/latest/", None,),

Use ``adafruit_register`` when possible
--------------------------------------------------------------------------------
`Register <https://github.com/adafruit/Adafruit_CircuitPython_Register>`_ is
a foundational library that manages packing and unpacking data from I2C device
registers. There is also `Register SPI <https://github.com/adafruit/Adafruit_CircuitPython_Register_SPI>`_
for SPI devices. When possible, use one of these libraries for unpacking and
packing registers. This ensures the packing code is shared amongst all
registers (even across drivers). Furthermore, it simplifies device definitions
by making them declarative (only data.)

Values with non-consecutive bits in a register or that represent FIFO endpoints
may not map well to existing register classes. In unique cases like these, it is
ok to read and write the register directly.

*Do not* add all registers from a datasheet upfront. Instead, only add the ones
necessary for the functionality the driver exposes. Adding them all will lead to
unnecessary file size and API clutter. See `this video about outside-in design
from @tannewt <https://www.youtube.com/watch?v=3QewiyfBQh8>`_.

I2C Example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
from adafruit_register import i2c_bit
from adafruit_bus_device import i2c_device
class HelloWorldDevice:
"""Device with two bits to control when the words 'hello' and 'world' are lit."""
hello = i2c_bit.RWBit(0x0, 0x0)
"""Bit to indicate if hello is lit."""
world = i2c_bit.RWBit(0x1, 0x0)
"""Bit to indicate if world is lit."""
def __init__(self, i2c, device_address=0x0):
self.i2c_device = i2c_device.I2CDevice(i2c, device_address)
Use BusDevice
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -668,8 +707,24 @@ when using ``const()``, keep in mind these general guide lines:

- Always use via an import, ex: ``from micropython import const``
- Limit use to global (module level) variables only.
- If user will not need access to variable, prefix name with a leading
underscore, ex: ``_SOME_CONST``.
- Only used when the user will not need access to variable and prefix name with
a leading underscore, ex: ``_SOME_CONST``.

Example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
from adafruit_bus_device import i2c_device
from micropython import const
_DEFAULT_I2C_ADDR = const(0x42)
class Widget:
"""A generic widget."""
def __init__(self, i2c, address=_DEFAULT_I2C_ADDR):
self.i2c_device = i2c_device.I2CDevice(i2c, address)
Libraries Examples
------------------
Expand Down Expand Up @@ -751,6 +806,16 @@ properties.
| ``sound_level`` | float | non-unit-specific sound level (monotonic but not actual decibels) |
+-----------------------+-----------------------+-------------------------------------------------------------------------+

Driver constant naming
--------------------------------------------------------------------------------

When adding variables for constant values for a driver. Do not include the
device's name in the variable name. For example, in ``adafruit_fancy123.py``,
variables should not start with ``FANCY123_``. Adding this prefix increases RAM
usage and .mpy file size because variable names are preserved. User code should
refer to these constants as ``adafruit_fancy123.HELLO_WORLD`` for clarity.
``adafruit_fancy123.FANCY123_HELLO_WORLD`` would be overly verbose.

Adding native modules
--------------------------------------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions ports/espressif/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
return WIFI_RADIO_ERROR_NO_AP_FOUND;
}
return self->last_disconnect_reason;
} else {
// We're connected, allow us to retry if we get disconnected.
self->retries_left = self->starting_retries;
}
return WIFI_RADIO_ERROR_NONE;
}
Expand Down
3 changes: 0 additions & 3 deletions supervisor/shared/web_workflow/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ static void _websocket_send(_websocket *ws, const char *text, size_t len) {
web_workflow_send_raw(&ws->socket, extended_len, 4);
}
web_workflow_send_raw(&ws->socket, (const uint8_t *)text, len);
char copy[len];
memcpy(copy, text, len);
copy[len] = '\0';
}

void websocket_write(const char *text, size_t len) {
Expand Down
4 changes: 2 additions & 2 deletions tools/ci_set_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def set_boards_to_build(build_all):
if p in IGNORE:
continue

# Boards don't run tests so ignore those as well.
if p.startswith("tests"):
# Boards don't run tests or docs so ignore those as well.
if p.startswith("tests") or p.startswith("docs"):
continue

# As a (nearly) last resort, for some certain files, we compute the settings from the
Expand Down

0 comments on commit 5823bcc

Please sign in to comment.