Skip to content

Commit 51f0544

Browse files
committed
protmatter: Update to version that supports tiling
1 parent 4241fd4 commit 51f0544

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

shared-bindings/rgbmatrix/RGBMatrix.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include <stdlib.h>
28+
2729
#include "py/obj.h"
2830
#include "py/objproperty.h"
2931
#include "py/runtime.h"
@@ -132,11 +134,11 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
132134
}
133135
}
134136

135-
//| def __init__(self, *, width: int, bit_depth: int, rgb_pins: Sequence[digitalio.DigitalInOut], addr_pins: Sequence[digitalio.DigitalInOut], clock_pin: digitalio.DigitalInOut, latch_pin: digitalio.DigitalInOut, output_enable_pin: digitalio.DigitalInOut, doublebuffer: bool = True, framebuffer: Optional[WriteableBuffer] = None, height: int = 0) -> None:
137+
//| def __init__(self, *, width: int, bit_depth: int, rgb_pins: Sequence[digitalio.DigitalInOut], addr_pins: Sequence[digitalio.DigitalInOut], clock_pin: digitalio.DigitalInOut, latch_pin: digitalio.DigitalInOut, output_enable_pin: digitalio.DigitalInOut, doublebuffer: bool = True, framebuffer: Optional[WriteableBuffer] = None, height: int = 0, tile: int = 1, serpentine: bool = False) -> None:
136138
//| """Create a RGBMatrix object with the given attributes. The height of
137-
//| the display is determined by the number of rgb and address pins:
138-
//| len(rgb_pins) // 3 * 2 ** len(address_pins). With 6 RGB pins and 4
139-
//| address lines, the display will be 32 pixels tall. If the optional height
139+
//| the display is determined by the number of rgb and address pins and the number of tiles:
140+
//| ``len(rgb_pins) // 3 * 2 ** len(address_pins) * abs(tile)``. With 6 RGB pins, 4
141+
//| address lines, and a single matrix, the display will be 32 pixels tall. If the optional height
140142
//| parameter is specified and is not 0, it is checked against the calculated
141143
//| height.
142144
//|
@@ -172,7 +174,7 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
172174

173175
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) {
174176
enum { ARG_width, ARG_bit_depth, ARG_rgb_list, ARG_addr_list,
175-
ARG_clock_pin, ARG_latch_pin, ARG_output_enable_pin, ARG_doublebuffer, ARG_framebuffer, ARG_height };
177+
ARG_clock_pin, ARG_latch_pin, ARG_output_enable_pin, ARG_doublebuffer, ARG_framebuffer, ARG_height, ARG_tile, ARG_serpentine };
176178
static const mp_arg_t allowed_args[] = {
177179
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
178180
{ MP_QSTR_bit_depth, MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
@@ -184,6 +186,8 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
184186
{ MP_QSTR_doublebuffer, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = true } },
185187
{ MP_QSTR_framebuffer, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
186188
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 0 } },
189+
{ MP_QSTR_tile, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 1 } },
190+
{ MP_QSTR_serpentine, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
187191
};
188192
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
189193
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -210,15 +214,20 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
210214
mp_raise_ValueError_varg(translate("Must use a multiple of 6 rgb pins, not %d"), rgb_count);
211215
}
212216

213-
// TODO(@jepler) Use fewer than all rows of pixels if height < computed_height
217+
int tile = args[ARG_tile].u_int;
218+
214219
if (args[ARG_height].u_int != 0) {
215-
int computed_height = (rgb_count / 3) << (addr_count);
220+
int computed_height = (rgb_count / 3) << (addr_count) * abs(tile);
216221
if (computed_height != args[ARG_height].u_int) {
217222
mp_raise_ValueError_varg(
218-
translate("%d address pins and %d rgb pins indicate a height of %d, not %d"), addr_count, rgb_count, computed_height, args[ARG_height].u_int);
223+
translate("%d address pins, %d rgb pins and %d tiles indicate a height of %d, not %d"), addr_count, rgb_count, tile, computed_height, args[ARG_height].u_int);
219224
}
220225
}
221226

227+
if (args[ARG_serpentine].u_bool) {
228+
tile = -tile;
229+
}
230+
222231
if (args[ARG_width].u_int <= 0) {
223232
mp_raise_ValueError(translate("width must be greater than zero"));
224233
}
@@ -239,7 +248,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
239248
addr_count, addr_pins,
240249
clock_pin, latch_pin, output_enable_pin,
241250
args[ARG_doublebuffer].u_bool,
242-
framebuffer, NULL);
251+
framebuffer, tile, NULL);
243252

244253
claim_and_never_reset_pins(args[ARG_rgb_list].u_obj);
245254
claim_and_never_reset_pins(args[ARG_addr_list].u_obj);

shared-bindings/rgbmatrix/RGBMatrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
3333

34-
void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t* self, int width, int bit_depth, uint8_t rgb_count, uint8_t* rgb_pins, uint8_t addr_count, uint8_t* addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, void* timer);
34+
void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t* self, int width, int bit_depth, uint8_t rgb_count, uint8_t* rgb_pins, uint8_t addr_count, uint8_t* addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, int8_t tile, void* timer);
3535
void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t*);
3636
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t*);
3737
void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self, mp_obj_t framebuffer);

shared-module/rgbmatrix/RGBMatrix.c

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

4343
extern Protomatter_core *_PM_protoPtr;
4444

45-
void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, int width, int bit_depth, uint8_t rgb_count, uint8_t *rgb_pins, uint8_t addr_count, uint8_t *addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, void *timer) {
45+
void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, int width, int bit_depth, uint8_t rgb_count, uint8_t *rgb_pins, uint8_t addr_count, uint8_t *addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, int8_t tile, void *timer) {
4646
self->width = width;
4747
self->bit_depth = bit_depth;
4848
self->rgb_count = rgb_count;
@@ -53,6 +53,7 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
5353
self->oe_pin = oe_pin;
5454
self->latch_pin = latch_pin;
5555
self->doublebuffer = doublebuffer;
56+
self->tile = tile;
5657

5758
self->timer = timer ? timer : common_hal_rgbmatrix_timer_allocate();
5859
if (self->timer == NULL) {
@@ -95,7 +96,7 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
9596
self->rgb_count/6, self->rgb_pins,
9697
self->addr_count, self->addr_pins,
9798
self->clock_pin, self->latch_pin, self->oe_pin,
98-
self->doublebuffer, self->timer);
99+
self->doublebuffer, self->tile, self->timer);
99100

100101
if (stat == PROTOMATTER_OK) {
101102
_PM_protoPtr = &self->protomatter;

shared-module/rgbmatrix/RGBMatrix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ typedef struct {
4444
bool core_is_initialized;
4545
bool paused;
4646
bool doublebuffer;
47+
int8_t tile;
4748
} rgbmatrix_rgbmatrix_obj_t;

0 commit comments

Comments
 (0)