Skip to content

Commit c7a9d49

Browse files
committed
Did rgbmatrix, rotaryio, and RTC
1 parent 838b6c5 commit c7a9d49

File tree

6 files changed

+132
-131
lines changed

6 files changed

+132
-131
lines changed

shared-bindings/rgbmatrix/RGBMatrix.c

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
#include "shared-module/framebufferio/__init__.h"
3939
#include "shared-module/framebufferio/FramebufferDisplay.h"
4040

41-
//| .. currentmodule:: rgbmatrix
41+
//| class RGBMatrix:
42+
//| """.. currentmodule:: rgbmatrix
4243
//|
43-
//| :class:`RGBMatrix` -- Driver for HUB75-style RGB LED matrices
44-
//| ================================================================
44+
//| :class:`RGBMatrix` -- Driver for HUB75-style RGB LED matrices
45+
//| ================================================================
4546
//|
4647

4748
extern Protomatter_core *_PM_protoPtr;
@@ -133,45 +134,45 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
133134
}
134135
}
135136

136-
//| :class:`~rgbmatrix.RGBMatrix` displays an in-memory framebuffer to an LED matrix.
137-
//|
138-
//| .. class:: RGBMatrix(*, width, bit_depth, rgb_pins, addr_pins, clock_pin, latch_pin, output_enable_pin, doublebuffer=True, framebuffer=None, height=0)
137+
138+
//| :class:`~rgbmatrix.RGBMatrix` displays an in-memory framebuffer to an LED matrix."""
139139
//|
140-
//| Create a RGBMatrix object with the given attributes. The height of
141-
//| the display is determined by the number of rgb and address pins:
142-
//| len(rgb_pins) // 3 * 2 ** len(address_pins). With 6 RGB pins and 4
143-
//| address lines, the display will be 32 pixels tall. If the optional height
144-
//| parameter is specified and is not 0, it is checked against the calculated
145-
//| height.
140+
//| 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):
141+
//| """Create a RGBMatrix object with the given attributes. The height of
142+
//| the display is determined by the number of rgb and address pins:
143+
//| len(rgb_pins) // 3 * 2 ** len(address_pins). With 6 RGB pins and 4
144+
//| address lines, the display will be 32 pixels tall. If the optional height
145+
//| parameter is specified and is not 0, it is checked against the calculated
146+
//| height.
146147
//|
147-
//| Up to 30 RGB pins and 8 address pins are supported.
148+
//| Up to 30 RGB pins and 8 address pins are supported.
148149
//|
149-
//| The RGB pins must be within a single "port" and performance and memory
150-
//| usage are best when they are all within "close by" bits of the port.
151-
//| The clock pin must also be on the same port as the RGB pins. See the
152-
//| documentation of the underlying protomatter C library for more
153-
//| information. Generally, Adafruit's interface boards are designed so
154-
//| that these requirements are met when matched with the intended
155-
//| microcontroller board. For instance, the Feather M4 Express works
156-
//| together with the RGB Matrix Feather.
150+
//| The RGB pins must be within a single "port" and performance and memory
151+
//| usage are best when they are all within "close by" bits of the port.
152+
//| The clock pin must also be on the same port as the RGB pins. See the
153+
//| documentation of the underlying protomatter C library for more
154+
//| information. Generally, Adafruit's interface boards are designed so
155+
//| that these requirements are met when matched with the intended
156+
//| microcontroller board. For instance, the Feather M4 Express works
157+
//| together with the RGB Matrix Feather.
157158
//|
158-
//| The framebuffer is in "RGB565" format.
159+
//| The framebuffer is in "RGB565" format.
159160
//|
160-
//| "RGB565" means that it is organized as a series of 16-bit numbers
161-
//| where the highest 5 bits are interpreted as red, the next 6 as
162-
//| green, and the final 5 as blue. The object can be any buffer, but
163-
//| `array.array` and `ulab.array` objects are most often useful.
164-
//| To update the content, modify the framebuffer and call refresh.
161+
//| "RGB565" means that it is organized as a series of 16-bit numbers
162+
//| where the highest 5 bits are interpreted as red, the next 6 as
163+
//| green, and the final 5 as blue. The object can be any buffer, but
164+
//| `array.array` and `ulab.array` objects are most often useful.
165+
//| To update the content, modify the framebuffer and call refresh.
165166
//|
166-
//| If a framebuffer is not passed in, one is allocated and initialized
167-
//| to all black. In any case, the framebuffer can be retrieved
168-
//| by passing the RGBMatrix object to memoryview().
167+
//| If a framebuffer is not passed in, one is allocated and initialized
168+
//| to all black. In any case, the framebuffer can be retrieved
169+
//| by passing the RGBMatrix object to memoryview().
169170
//|
170-
//| If doublebuffer is False, some memory is saved, but the display may
171-
//| flicker during updates.
171+
//| If doublebuffer is False, some memory is saved, but the display may
172+
//| flicker during updates.
172173
//|
173-
//| A RGBMatrix is often used in conjunction with a
174-
//| `framebufferio.FramebufferDisplay`.
174+
//| A RGBMatrix is often used in conjunction with a
175+
//| `framebufferio.FramebufferDisplay`."""
175176
//|
176177

177178
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
245246
return MP_OBJ_FROM_PTR(self);
246247
}
247248

248-
//| .. method:: deinit
249-
//|
250-
//| Free the resources (pins, timers, etc.) associated with this
251-
//| rgbmatrix instance. After deinitialization, no further operations
252-
//| may be performed.
249+
//| def deinit(self, ) -> Any:
250+
//| """Free the resources (pins, timers, etc.) associated with this
251+
//| rgbmatrix instance. After deinitialization, no further operations
252+
//| may be performed."""
253+
//| ...
253254
//|
254255
STATIC mp_obj_t rgbmatrix_rgbmatrix_deinit(mp_obj_t self_in) {
255256
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) {
265266
}
266267
}
267268

268-
//| .. attribute:: brightness
269-
//|
270-
//| In the current implementation, 0.0 turns the display off entirely
271-
//| and any other value up to 1.0 turns the display on fully.
269+
//| brightness: Any = ...
270+
//| """In the current implementation, 0.0 turns the display off entirely
271+
//| and any other value up to 1.0 turns the display on fully."""
272272
//|
273273
STATIC mp_obj_t rgbmatrix_rgbmatrix_get_brightness(mp_obj_t self_in) {
274274
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t*)self_in;
@@ -297,10 +297,9 @@ const mp_obj_property_t rgbmatrix_rgbmatrix_brightness_obj = {
297297
(mp_obj_t)&mp_const_none_obj},
298298
};
299299

300-
//| .. method:: refresh()
301-
//|
302-
//| Transmits the color data in the buffer to the pixels so that
303-
//| they are shown.
300+
//| def refresh(self, ) -> Any: ...
301+
//| """Transmits the color data in the buffer to the pixels so that
302+
//| they are shown."""
304303
//|
305304
STATIC mp_obj_t rgbmatrix_rgbmatrix_refresh(mp_obj_t self_in) {
306305
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) {
310309
}
311310
MP_DEFINE_CONST_FUN_OBJ_1(rgbmatrix_rgbmatrix_refresh_obj, rgbmatrix_rgbmatrix_refresh);
312311

313-
//| .. attribute:: width
314-
//|
315-
//| The width of the display, in pixels
312+
//| width: Any = ...
313+
//| """The width of the display, in pixels"""
316314
//|
317315
STATIC mp_obj_t rgbmatrix_rgbmatrix_get_width(mp_obj_t self_in) {
318316
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t*)self_in;
@@ -327,9 +325,8 @@ const mp_obj_property_t rgbmatrix_rgbmatrix_width_obj = {
327325
(mp_obj_t)&mp_const_none_obj},
328326
};
329327

330-
//| .. attribute:: height
331-
//|
332-
//| The height of the display, in pixels
328+
//| height: Any = ...
329+
//| """The height of the display, in pixels"""
333330
//|
334331
STATIC mp_obj_t rgbmatrix_rgbmatrix_get_height(mp_obj_t self_in) {
335332
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t*)self_in;

shared-bindings/rgbmatrix/__init__.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "shared-bindings/rgbmatrix/RGBMatrix.h"
3333

34-
//| :mod:`rgbmatrix` --- Low-level routines for bitbanged LED matrices
34+
//| """:mod:`rgbmatrix` --- Low-level routines for bitbanged LED matrices
3535
//| =====================================================================
3636
//|
3737
//| .. module:: rgbmatrix
@@ -40,7 +40,8 @@
4040
//| .. toctree::
4141
//| :maxdepth: 3
4242
//|
43-
//| RGBMatrix
43+
//| RGBMatrix"""
44+
//|
4445

4546
STATIC const mp_rom_map_elem_t rgbmatrix_module_globals_table[] = {
4647
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_rgbmatrix) },

shared-bindings/rotaryio/IncrementalEncoder.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,36 @@
3434
#include "shared-bindings/rotaryio/IncrementalEncoder.h"
3535
#include "shared-bindings/util.h"
3636

37-
//| .. currentmodule:: rotaryio
37+
//| class IncrementalEncoder:
38+
//| """.. currentmodule:: rotaryio
3839
//|
39-
//| :class:`IncrementalEncoder` -- Track the relative position of an incremental encoder
40-
//| ====================================================================================
40+
//| :class:`IncrementalEncoder` -- Track the relative position of an incremental encoder
41+
//| ====================================================================================
4142
//|
42-
//| IncrementalEncoder determines the relative rotational position based on two series of pulses.
43+
//| IncrementalEncoder determines the relative rotational position based on two series of pulses."""
4344
//|
44-
//| .. class:: IncrementalEncoder(pin_a, pin_b)
45+
//| def __init__(self, pin_a: microcontroller.Pin, pin_b: microcontroller.Pin):
46+
//| """Create an IncrementalEncoder object associated with the given pins. It tracks the positional
47+
//| state of an incremental rotary encoder (also known as a quadrature encoder.) Position is
48+
//| relative to the position when the object is contructed.
4549
//|
46-
//| Create an IncrementalEncoder object associated with the given pins. It tracks the positional
47-
//| state of an incremental rotary encoder (also known as a quadrature encoder.) Position is
48-
//| relative to the position when the object is contructed.
50+
//| :param ~microcontroller.Pin pin_a: First pin to read pulses from.
51+
//| :param ~microcontroller.Pin pin_b: Second pin to read pulses from.
4952
//|
50-
//| :param ~microcontroller.Pin pin_a: First pin to read pulses from.
51-
//| :param ~microcontroller.Pin pin_b: Second pin to read pulses from.
53+
//| For example::
5254
//|
53-
//| For example::
55+
//| import rotaryio
56+
//| import time
57+
//| from board import *
5458
//|
55-
//| import rotaryio
56-
//| import time
57-
//| from board import *
58-
//|
59-
//| enc = rotaryio.IncrementalEncoder(D1, D2)
60-
//| last_position = None
61-
//| while True:
62-
//| position = enc.position
63-
//| if last_position == None or position != last_position:
64-
//| print(position)
65-
//| last_position = position
59+
//| enc = rotaryio.IncrementalEncoder(D1, D2)
60+
//| last_position = None
61+
//| while True:
62+
//| position = enc.position
63+
//| if last_position == None or position != last_position:
64+
//| print(position)
65+
//| last_position = position"""
66+
//| ...
6667
//|
6768
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) {
6869
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,
8485
return MP_OBJ_FROM_PTR(self);
8586
}
8687

87-
//| .. method:: deinit()
88-
//|
89-
//| Deinitializes the IncrementalEncoder and releases any hardware resources for reuse.
88+
//| def deinit(self, ) -> Any:
89+
//| """Deinitializes the IncrementalEncoder and releases any hardware resources for reuse."""
90+
//| ...
9091
//|
9192
STATIC mp_obj_t rotaryio_incrementalencoder_deinit(mp_obj_t self_in) {
9293
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) {
101102
}
102103
}
103104

104-
//| .. method:: __enter__()
105-
//|
106-
//| No-op used by Context Managers.
105+
//| def __enter__(self, ) -> Any:
106+
//| """No-op used by Context Managers."""
107+
//| ...
107108
//|
108109
// Provided by context manager helper.
109110

110-
//| .. method:: __exit__()
111-
//|
112-
//| Automatically deinitializes the hardware when exiting a context. See
113-
//| :ref:`lifetime-and-contextmanagers` for more info.
111+
//| def __exit__(self, ) -> Any:
112+
//| """Automatically deinitializes the hardware when exiting a context. See
113+
//| :ref:`lifetime-and-contextmanagers` for more info."""
114+
//| ...
114115
//|
115116
STATIC mp_obj_t rotaryio_incrementalencoder_obj___exit__(size_t n_args, const mp_obj_t *args) {
116117
(void)n_args;
@@ -120,10 +121,9 @@ STATIC mp_obj_t rotaryio_incrementalencoder_obj___exit__(size_t n_args, const mp
120121
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rotaryio_incrementalencoder___exit___obj, 4, 4, rotaryio_incrementalencoder_obj___exit__);
121122

122123

123-
//| .. attribute:: position
124-
//|
125-
//| The current position in terms of pulses. The number of pulses per rotation is defined by the
126-
//| specific hardware.
124+
//| position: Any = ...
125+
//| """The current position in terms of pulses. The number of pulses per rotation is defined by the
126+
//| specific hardware."""
127127
//|
128128
STATIC mp_obj_t rotaryio_incrementalencoder_obj_get_position(mp_obj_t self_in) {
129129
rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in);

shared-bindings/rotaryio/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "shared-bindings/rotaryio/__init__.h"
3434
#include "shared-bindings/rotaryio/IncrementalEncoder.h"
3535

36-
//| :mod:`rotaryio` --- Support for reading rotation sensors
36+
//| """:mod:`rotaryio` --- Support for reading rotation sensors
3737
//| ========================================================
3838
//|
3939
//| .. module:: rotaryio
@@ -59,7 +59,7 @@
5959
//| All classes change hardware state and should be deinitialized when they
6060
//| are no longer needed if the program continues after use. To do so, either
6161
//| call :py:meth:`!deinit` or use a context manager. See
62-
//| :ref:`lifetime-and-contextmanagers` for more info.
62+
//| :ref:`lifetime-and-contextmanagers` for more info."""
6363
//|
6464

6565
STATIC const mp_rom_map_elem_t rotaryio_module_globals_table[] = {

shared-bindings/rtc/RTC.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@
3838

3939
const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}};
4040

41-
//| .. currentmodule:: rtc
42-
//|
43-
//| :class:`RTC` --- Real Time Clock
44-
//| --------------------------------
41+
42+
43+
44+
45+
//| class RTC:
46+
//| """.. currentmodule:: rtc
4547
//|
46-
//| .. class:: RTC()
48+
//| :class:`RTC` --- Real Time Clock
49+
//| --------------------------------"""
4750
//|
48-
//| This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance.
51+
//| def __init__(self, ):
52+
//| """This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance."""
53+
//| ...
4954
//|
5055
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) {
5156
// 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
5560
return (mp_obj_t)&rtc_rtc_obj;
5661
}
5762

58-
//| .. attribute:: datetime
59-
//|
60-
//| The current date and time of the RTC as a `time.struct_time`.
63+
//| datetime: Any = ...
64+
//| """The current date and time of the RTC as a `time.struct_time`.
6165
//|
62-
//| This must be set to the current date and time whenever the board loses power::
66+
//| This must be set to the current date and time whenever the board loses power::
6367
//|
64-
//| import rtc
65-
//| import time
68+
//| import rtc
69+
//| import time
6670
//|
67-
//| r = rtc.RTC()
68-
//| r.datetime = rtctime.struct_time((2019, 5, 29, 15, 14, 15, 0, -1, -1))
71+
//| r = rtc.RTC()
72+
//| r.datetime = rtctime.struct_time((2019, 5, 29, 15, 14, 15, 0, -1, -1))
6973
//|
7074
//|
71-
//| Once set, the RTC will automatically update this value as time passes. You can read this
72-
//| property to get a snapshot of the current time::
75+
//| Once set, the RTC will automatically update this value as time passes. You can read this
76+
//| property to get a snapshot of the current time::
7377
//|
74-
//| current_time = r.datetime
75-
//| print(current_time)
76-
//| # struct_time(tm_year=2019, tm_month=5, ...)
78+
//| current_time = r.datetime
79+
//| print(current_time)
80+
//| # struct_time(tm_year=2019, tm_month=5, ...)"""
7781
//|
7882
STATIC mp_obj_t rtc_rtc_obj_get_datetime(mp_obj_t self_in) {
7983
timeutils_struct_time_t tm;
@@ -97,12 +101,11 @@ const mp_obj_property_t rtc_rtc_datetime_obj = {
97101
(mp_obj_t)&mp_const_none_obj},
98102
};
99103

100-
//| .. attribute:: calibration
101-
//|
102-
//| The RTC calibration value as an `int`.
104+
//| calibration: Any = ...
105+
//| """The RTC calibration value as an `int`.
103106
//|
104107
//| A positive value speeds up the clock and a negative value slows it down.
105-
//| Range and value is hardware specific, but one step is often approximately 1 ppm.
108+
//| Range and value is hardware specific, but one step is often approximately 1 ppm."""
106109
//|
107110
STATIC mp_obj_t rtc_rtc_obj_get_calibration(mp_obj_t self_in) {
108111
int calibration = common_hal_rtc_get_calibration();

0 commit comments

Comments
 (0)