Skip to content

Commit 5823bcc

Browse files
authored
Merge branch 'main' into c3_short_send
2 parents f1053fb + f9b9f55 commit 5823bcc

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

docs/design_guide.rst

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,45 @@ backticks ``:class:`~adafruit_motor.servo.Servo```. You must also add the refer
494494

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

497+
Use ``adafruit_register`` when possible
498+
--------------------------------------------------------------------------------
499+
`Register <https://github.com/adafruit/Adafruit_CircuitPython_Register>`_ is
500+
a foundational library that manages packing and unpacking data from I2C device
501+
registers. There is also `Register SPI <https://github.com/adafruit/Adafruit_CircuitPython_Register_SPI>`_
502+
for SPI devices. When possible, use one of these libraries for unpacking and
503+
packing registers. This ensures the packing code is shared amongst all
504+
registers (even across drivers). Furthermore, it simplifies device definitions
505+
by making them declarative (only data.)
506+
507+
Values with non-consecutive bits in a register or that represent FIFO endpoints
508+
may not map well to existing register classes. In unique cases like these, it is
509+
ok to read and write the register directly.
510+
511+
*Do not* add all registers from a datasheet upfront. Instead, only add the ones
512+
necessary for the functionality the driver exposes. Adding them all will lead to
513+
unnecessary file size and API clutter. See `this video about outside-in design
514+
from @tannewt <https://www.youtube.com/watch?v=3QewiyfBQh8>`_.
515+
516+
I2C Example
517+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
518+
519+
.. code-block:: python
520+
521+
from adafruit_register import i2c_bit
522+
from adafruit_bus_device import i2c_device
523+
524+
class HelloWorldDevice:
525+
"""Device with two bits to control when the words 'hello' and 'world' are lit."""
526+
527+
hello = i2c_bit.RWBit(0x0, 0x0)
528+
"""Bit to indicate if hello is lit."""
529+
530+
world = i2c_bit.RWBit(0x1, 0x0)
531+
"""Bit to indicate if world is lit."""
532+
533+
def __init__(self, i2c, device_address=0x0):
534+
self.i2c_device = i2c_device.I2CDevice(i2c, device_address)
535+
497536
Use BusDevice
498537
--------------------------------------------------------------------------------
499538

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

669708
- Always use via an import, ex: ``from micropython import const``
670709
- Limit use to global (module level) variables only.
671-
- If user will not need access to variable, prefix name with a leading
672-
underscore, ex: ``_SOME_CONST``.
710+
- Only used when the user will not need access to variable and prefix name with
711+
a leading underscore, ex: ``_SOME_CONST``.
712+
713+
Example
714+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
715+
716+
.. code-block:: python
717+
718+
from adafruit_bus_device import i2c_device
719+
from micropython import const
720+
721+
_DEFAULT_I2C_ADDR = const(0x42)
722+
723+
class Widget:
724+
"""A generic widget."""
725+
726+
def __init__(self, i2c, address=_DEFAULT_I2C_ADDR):
727+
self.i2c_device = i2c_device.I2CDevice(i2c, address)
673728
674729
Libraries Examples
675730
------------------
@@ -751,6 +806,16 @@ properties.
751806
| ``sound_level`` | float | non-unit-specific sound level (monotonic but not actual decibels) |
752807
+-----------------------+-----------------------+-------------------------------------------------------------------------+
753808

809+
Driver constant naming
810+
--------------------------------------------------------------------------------
811+
812+
When adding variables for constant values for a driver. Do not include the
813+
device's name in the variable name. For example, in ``adafruit_fancy123.py``,
814+
variables should not start with ``FANCY123_``. Adding this prefix increases RAM
815+
usage and .mpy file size because variable names are preserved. User code should
816+
refer to these constants as ``adafruit_fancy123.HELLO_WORLD`` for clarity.
817+
``adafruit_fancy123.FANCY123_HELLO_WORLD`` would be overly verbose.
818+
754819
Adding native modules
755820
--------------------------------------------------------------------------------
756821

ports/espressif/common-hal/wifi/Radio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
336336
return WIFI_RADIO_ERROR_NO_AP_FOUND;
337337
}
338338
return self->last_disconnect_reason;
339+
} else {
340+
// We're connected, allow us to retry if we get disconnected.
341+
self->retries_left = self->starting_retries;
339342
}
340343
return WIFI_RADIO_ERROR_NONE;
341344
}

supervisor/shared/web_workflow/websocket.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ static void _websocket_send(_websocket *ws, const char *text, size_t len) {
239239
web_workflow_send_raw(&ws->socket, extended_len, 4);
240240
}
241241
web_workflow_send_raw(&ws->socket, (const uint8_t *)text, len);
242-
char copy[len];
243-
memcpy(copy, text, len);
244-
copy[len] = '\0';
245242
}
246243

247244
void websocket_write(const char *text, size_t len) {

tools/ci_set_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def set_boards_to_build(build_all):
9696
if p in IGNORE:
9797
continue
9898

99-
# Boards don't run tests so ignore those as well.
100-
if p.startswith("tests"):
99+
# Boards don't run tests or docs so ignore those as well.
100+
if p.startswith("tests") or p.startswith("docs"):
101101
continue
102102

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

0 commit comments

Comments
 (0)