Did rgbmatrix, rotaryio, and RTC

This commit is contained in:
dherrada 2020-05-11 13:00:19 -04:00
parent 838b6c5685
commit c7a9d49cba
No known key found for this signature in database
GPG Key ID: CE2ADBAB8775CE81
6 changed files with 132 additions and 131 deletions

View File

@ -38,10 +38,11 @@
#include "shared-module/framebufferio/__init__.h"
#include "shared-module/framebufferio/FramebufferDisplay.h"
//| .. currentmodule:: rgbmatrix
//| class RGBMatrix:
//| """.. currentmodule:: rgbmatrix
//|
//| :class:`RGBMatrix` -- Driver for HUB75-style RGB LED matrices
//| ================================================================
//| :class:`RGBMatrix` -- Driver for HUB75-style RGB LED matrices
//| ================================================================
//|
extern Protomatter_core *_PM_protoPtr;
@ -133,45 +134,45 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
}
}
//| :class:`~rgbmatrix.RGBMatrix` displays an in-memory framebuffer to an LED matrix.
//| :class:`~rgbmatrix.RGBMatrix` displays an in-memory framebuffer to an LED matrix."""
//|
//| .. class:: RGBMatrix(*, width, bit_depth, rgb_pins, addr_pins, clock_pin, latch_pin, output_enable_pin, doublebuffer=True, framebuffer=None, height=0)
//| def __init__(self, *, width: Any, bit_depth: Any, rgb_pins: Any, addr_pins: Any, clock_pin: Any, latch_pin: Any, output_enable_pin: Any, doublebuffer: Any = True, framebuffer: Any = None, height: Any = 0):
//| """Create a RGBMatrix object with the given attributes. The height of
//| the display is determined by the number of rgb and address pins:
//| len(rgb_pins) // 3 * 2 ** len(address_pins). With 6 RGB pins and 4
//| address lines, the display will be 32 pixels tall. If the optional height
//| parameter is specified and is not 0, it is checked against the calculated
//| height.
//|
//| Create a RGBMatrix object with the given attributes. The height of
//| the display is determined by the number of rgb and address pins:
//| len(rgb_pins) // 3 * 2 ** len(address_pins). With 6 RGB pins and 4
//| address lines, the display will be 32 pixels tall. If the optional height
//| parameter is specified and is not 0, it is checked against the calculated
//| height.
//| Up to 30 RGB pins and 8 address pins are supported.
//|
//| Up to 30 RGB pins and 8 address pins are supported.
//| The RGB pins must be within a single "port" and performance and memory
//| usage are best when they are all within "close by" bits of the port.
//| The clock pin must also be on the same port as the RGB pins. See the
//| documentation of the underlying protomatter C library for more
//| information. Generally, Adafruit's interface boards are designed so
//| that these requirements are met when matched with the intended
//| microcontroller board. For instance, the Feather M4 Express works
//| together with the RGB Matrix Feather.
//|
//| The RGB pins must be within a single "port" and performance and memory
//| usage are best when they are all within "close by" bits of the port.
//| The clock pin must also be on the same port as the RGB pins. See the
//| documentation of the underlying protomatter C library for more
//| information. Generally, Adafruit's interface boards are designed so
//| that these requirements are met when matched with the intended
//| microcontroller board. For instance, the Feather M4 Express works
//| together with the RGB Matrix Feather.
//| The framebuffer is in "RGB565" format.
//|
//| The framebuffer is in "RGB565" format.
//| "RGB565" means that it is organized as a series of 16-bit numbers
//| where the highest 5 bits are interpreted as red, the next 6 as
//| green, and the final 5 as blue. The object can be any buffer, but
//| `array.array` and `ulab.array` objects are most often useful.
//| To update the content, modify the framebuffer and call refresh.
//|
//| "RGB565" means that it is organized as a series of 16-bit numbers
//| where the highest 5 bits are interpreted as red, the next 6 as
//| green, and the final 5 as blue. The object can be any buffer, but
//| `array.array` and `ulab.array` objects are most often useful.
//| To update the content, modify the framebuffer and call refresh.
//| If a framebuffer is not passed in, one is allocated and initialized
//| to all black. In any case, the framebuffer can be retrieved
//| by passing the RGBMatrix object to memoryview().
//|
//| If a framebuffer is not passed in, one is allocated and initialized
//| to all black. In any case, the framebuffer can be retrieved
//| by passing the RGBMatrix object to memoryview().
//| If doublebuffer is False, some memory is saved, but the display may
//| flicker during updates.
//|
//| If doublebuffer is False, some memory is saved, but the display may
//| flicker during updates.
//|
//| A RGBMatrix is often used in conjunction with a
//| `framebufferio.FramebufferDisplay`.
//| A RGBMatrix is often used in conjunction with a
//| `framebufferio.FramebufferDisplay`."""
//|
STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@ -245,11 +246,11 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit
//|
//| Free the resources (pins, timers, etc.) associated with this
//| rgbmatrix instance. After deinitialization, no further operations
//| may be performed.
//| def deinit(self, ) -> Any:
//| """Free the resources (pins, timers, etc.) associated with this
//| rgbmatrix instance. After deinitialization, no further operations
//| may be performed."""
//| ...
//|
STATIC mp_obj_t rgbmatrix_rgbmatrix_deinit(mp_obj_t self_in) {
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t*)self_in;
@ -265,10 +266,9 @@ static void check_for_deinit(rgbmatrix_rgbmatrix_obj_t *self) {
}
}
//| .. attribute:: brightness
//|
//| In the current implementation, 0.0 turns the display off entirely
//| and any other value up to 1.0 turns the display on fully.
//| brightness: Any = ...
//| """In the current implementation, 0.0 turns the display off entirely
//| and any other value up to 1.0 turns the display on fully."""
//|
STATIC mp_obj_t rgbmatrix_rgbmatrix_get_brightness(mp_obj_t self_in) {
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t*)self_in;
@ -297,10 +297,9 @@ const mp_obj_property_t rgbmatrix_rgbmatrix_brightness_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| .. method:: refresh()
//|
//| Transmits the color data in the buffer to the pixels so that
//| they are shown.
//| def refresh(self, ) -> Any: ...
//| """Transmits the color data in the buffer to the pixels so that
//| they are shown."""
//|
STATIC mp_obj_t rgbmatrix_rgbmatrix_refresh(mp_obj_t self_in) {
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t*)self_in;
@ -310,9 +309,8 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_refresh(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(rgbmatrix_rgbmatrix_refresh_obj, rgbmatrix_rgbmatrix_refresh);
//| .. attribute:: width
//|
//| The width of the display, in pixels
//| width: Any = ...
//| """The width of the display, in pixels"""
//|
STATIC mp_obj_t rgbmatrix_rgbmatrix_get_width(mp_obj_t self_in) {
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t*)self_in;
@ -327,9 +325,8 @@ const mp_obj_property_t rgbmatrix_rgbmatrix_width_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: height
//|
//| The height of the display, in pixels
//| height: Any = ...
//| """The height of the display, in pixels"""
//|
STATIC mp_obj_t rgbmatrix_rgbmatrix_get_height(mp_obj_t self_in) {
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t*)self_in;

View File

@ -31,7 +31,7 @@
#include "shared-bindings/rgbmatrix/RGBMatrix.h"
//| :mod:`rgbmatrix` --- Low-level routines for bitbanged LED matrices
//| """:mod:`rgbmatrix` --- Low-level routines for bitbanged LED matrices
//| =====================================================================
//|
//| .. module:: rgbmatrix
@ -40,7 +40,8 @@
//| .. toctree::
//| :maxdepth: 3
//|
//| RGBMatrix
//| RGBMatrix"""
//|
STATIC const mp_rom_map_elem_t rgbmatrix_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_rgbmatrix) },

View File

@ -34,35 +34,36 @@
#include "shared-bindings/rotaryio/IncrementalEncoder.h"
#include "shared-bindings/util.h"
//| .. currentmodule:: rotaryio
//| class IncrementalEncoder:
//| """.. currentmodule:: rotaryio
//|
//| :class:`IncrementalEncoder` -- Track the relative position of an incremental encoder
//| ====================================================================================
//| :class:`IncrementalEncoder` -- Track the relative position of an incremental encoder
//| ====================================================================================
//|
//| IncrementalEncoder determines the relative rotational position based on two series of pulses.
//| IncrementalEncoder determines the relative rotational position based on two series of pulses."""
//|
//| .. class:: IncrementalEncoder(pin_a, pin_b)
//| def __init__(self, pin_a: microcontroller.Pin, pin_b: microcontroller.Pin):
//| """Create an IncrementalEncoder object associated with the given pins. It tracks the positional
//| state of an incremental rotary encoder (also known as a quadrature encoder.) Position is
//| relative to the position when the object is contructed.
//|
//| Create an IncrementalEncoder object associated with the given pins. It tracks the positional
//| state of an incremental rotary encoder (also known as a quadrature encoder.) Position is
//| relative to the position when the object is contructed.
//| :param ~microcontroller.Pin pin_a: First pin to read pulses from.
//| :param ~microcontroller.Pin pin_b: Second pin to read pulses from.
//|
//| :param ~microcontroller.Pin pin_a: First pin to read pulses from.
//| :param ~microcontroller.Pin pin_b: Second pin to read pulses from.
//| For example::
//|
//| For example::
//| import rotaryio
//| import time
//| from board import *
//|
//| import rotaryio
//| import time
//| from board import *
//|
//| enc = rotaryio.IncrementalEncoder(D1, D2)
//| last_position = None
//| while True:
//| position = enc.position
//| if last_position == None or position != last_position:
//| print(position)
//| last_position = position
//| enc = rotaryio.IncrementalEncoder(D1, D2)
//| last_position = None
//| while True:
//| position = enc.position
//| if last_position == None or position != last_position:
//| print(position)
//| last_position = position"""
//| ...
//|
STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_pin_a, ARG_pin_b };
@ -84,9 +85,9 @@ STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit()
//|
//| Deinitializes the IncrementalEncoder and releases any hardware resources for reuse.
//| def deinit(self, ) -> Any:
//| """Deinitializes the IncrementalEncoder and releases any hardware resources for reuse."""
//| ...
//|
STATIC mp_obj_t rotaryio_incrementalencoder_deinit(mp_obj_t self_in) {
rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -101,16 +102,16 @@ STATIC void check_for_deinit(rotaryio_incrementalencoder_obj_t *self) {
}
}
//| .. method:: __enter__()
//|
//| No-op used by Context Managers.
//| def __enter__(self, ) -> Any:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| .. method:: __exit__()
//|
//| Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info.
//| def __exit__(self, ) -> Any:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
STATIC mp_obj_t rotaryio_incrementalencoder_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
@ -120,10 +121,9 @@ STATIC mp_obj_t rotaryio_incrementalencoder_obj___exit__(size_t n_args, const mp
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rotaryio_incrementalencoder___exit___obj, 4, 4, rotaryio_incrementalencoder_obj___exit__);
//| .. attribute:: position
//|
//| The current position in terms of pulses. The number of pulses per rotation is defined by the
//| specific hardware.
//| position: Any = ...
//| """The current position in terms of pulses. The number of pulses per rotation is defined by the
//| specific hardware."""
//|
STATIC mp_obj_t rotaryio_incrementalencoder_obj_get_position(mp_obj_t self_in) {
rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in);

View File

@ -33,7 +33,7 @@
#include "shared-bindings/rotaryio/__init__.h"
#include "shared-bindings/rotaryio/IncrementalEncoder.h"
//| :mod:`rotaryio` --- Support for reading rotation sensors
//| """:mod:`rotaryio` --- Support for reading rotation sensors
//| ========================================================
//|
//| .. module:: rotaryio
@ -59,7 +59,7 @@
//| All classes change hardware state and should be deinitialized when they
//| are no longer needed if the program continues after use. To do so, either
//| call :py:meth:`!deinit` or use a context manager. See
//| :ref:`lifetime-and-contextmanagers` for more info.
//| :ref:`lifetime-and-contextmanagers` for more info."""
//|
STATIC const mp_rom_map_elem_t rotaryio_module_globals_table[] = {

View File

@ -38,14 +38,19 @@
const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}};
//| .. currentmodule:: rtc
//| class RTC:
//| """.. currentmodule:: rtc
//|
//| :class:`RTC` --- Real Time Clock
//| --------------------------------
//| :class:`RTC` --- Real Time Clock
//| --------------------------------"""
//|
//| .. class:: RTC()
//|
//| This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance.
//| def __init__(self, ):
//| """This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance."""
//| ...
//|
STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// No arguments
@ -55,25 +60,24 @@ STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, const
return (mp_obj_t)&rtc_rtc_obj;
}
//| .. attribute:: datetime
//| datetime: Any = ...
//| """The current date and time of the RTC as a `time.struct_time`.
//|
//| The current date and time of the RTC as a `time.struct_time`.
//| This must be set to the current date and time whenever the board loses power::
//|
//| This must be set to the current date and time whenever the board loses power::
//| import rtc
//| import time
//|
//| import rtc
//| import time
//|
//| r = rtc.RTC()
//| r.datetime = rtctime.struct_time((2019, 5, 29, 15, 14, 15, 0, -1, -1))
//| r = rtc.RTC()
//| r.datetime = rtctime.struct_time((2019, 5, 29, 15, 14, 15, 0, -1, -1))
//|
//|
//| Once set, the RTC will automatically update this value as time passes. You can read this
//| property to get a snapshot of the current time::
//| Once set, the RTC will automatically update this value as time passes. You can read this
//| property to get a snapshot of the current time::
//|
//| current_time = r.datetime
//| print(current_time)
//| # struct_time(tm_year=2019, tm_month=5, ...)
//| current_time = r.datetime
//| print(current_time)
//| # struct_time(tm_year=2019, tm_month=5, ...)"""
//|
STATIC mp_obj_t rtc_rtc_obj_get_datetime(mp_obj_t self_in) {
timeutils_struct_time_t tm;
@ -97,12 +101,11 @@ const mp_obj_property_t rtc_rtc_datetime_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: calibration
//|
//| The RTC calibration value as an `int`.
//| calibration: Any = ...
//| """The RTC calibration value as an `int`.
//|
//| A positive value speeds up the clock and a negative value slows it down.
//| Range and value is hardware specific, but one step is often approximately 1 ppm.
//| Range and value is hardware specific, but one step is often approximately 1 ppm."""
//|
STATIC mp_obj_t rtc_rtc_obj_get_calibration(mp_obj_t self_in) {
int calibration = common_hal_rtc_get_calibration();

View File

@ -31,7 +31,7 @@
#include "shared-bindings/rtc/RTC.h"
#include "shared-bindings/time/__init__.h"
//| :mod:`rtc` --- Real Time Clock
//| """:mod:`rtc` --- Real Time Clock
//| ========================================================
//|
//| .. module:: rtc
@ -47,7 +47,7 @@
//| .. toctree::
//| :maxdepth: 3
//|
//| RTC
//| RTC"""
//|
void rtc_reset(void) {
@ -62,22 +62,22 @@ mp_obj_t rtc_get_time_source_time(void) {
return struct_time_from_tm(&tm);
}
//| .. function:: set_time_source(rtc)
//| def set_time_source(rtc: Any) -> Any:
//| """Sets the RTC time source used by :func:`time.localtime`.
//| The default is :class:`rtc.RTC`, but it's useful to use this to override the
//| time source for testing purposes. For example::
//|
//| Sets the RTC time source used by :func:`time.localtime`.
//| The default is :class:`rtc.RTC`, but it's useful to use this to override the
//| time source for testing purposes. For example::
//| import rtc
//| import time
//|
//| import rtc
//| import time
//| class RTC(object):
//| @property
//| def datetime(self):
//| return time.struct_time((2018, 3, 17, 21, 1, 47, 0, 0, 0))
//|
//| class RTC(object):
//| @property
//| def datetime(self):
//| return time.struct_time((2018, 3, 17, 21, 1, 47, 0, 0, 0))
//|
//| r = RTC()
//| rtc.set_time_source(r)
//| r = RTC()
//| rtc.set_time_source(r)"""
//| ...
//|
STATIC mp_obj_t rtc_set_time_source(mp_obj_t time_source) {
MP_STATE_VM(rtc_time_source) = time_source;