8000 Merge pull request #4068 from jepler/update-protomatter-tiling · adafruit/circuitpython@45b3c9a · GitHub
[go: up one dir, main page]

Skip to content
Commit 45b3c9a
Browse files
authored
Merge pull request #4068 from jepler/update-protomatter-tiling
protomatter: Update to version that supports tiling
2 parents 351a0e7 + 189ec2f commit 45b3c9a

File tree

6 files changed

+35
-18
lines changed

6 files changed

+35
-18
lines changed

locale/circuitpython.pot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ msgstr ""
5858

5959
#: shared-bindings/rgbmatrix/RGBMatrix.c
6060
#, c-format
61-
msgid "%d address pins and %d rgb pins indicate a height of %d, not %d"
61+
msgid ""
62+
"%d address pins, %d rgb pins and %d tiles indicate a height of %d, not %d"
6263
msgstr ""
6364

6465
#: ports/atmel-samd/common-hal/sdioio/SDCard.c
@@ -516,7 +517,6 @@ msgstr ""
516517
msgid "Buffer must be a multiple of 512 bytes"
517518
msgstr ""
518519

519-
#: shared-bindings/adafruit_bus_device/I2CDevice.c
520520
#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c
521521
msgid "Buffer must be at least length 1"
522522
msgstr ""
@@ -3714,6 +3714,10 @@ msgstr ""
37143714
msgid "threshold must be in the range 0-65536"
37153715
msgstr ""
37163716

3717+
#: shared-bindings/rgbmatrix/RGBMatrix.c
3718+
msgid "tile must be greater than zero"
3719+
msgstr ""
3720+
37173721
#: shared-bindings/time/__init__.c
37183722
msgid "time.struct_time() takes a 9-sequence"
37193723
msgstr ""

shared-bindings/rgbmatrix/RGBMatrix.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
132132
}
133133
}
134134

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:
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, tile: int = 1, serpentine: bool = False) -> None:
136136
//| """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
137+
//| the display is determined by the number of rgb and address pins and the number of tiles:
138+
//| ``len(rgb_pins) // 3 * 2 ** len(address_pins) * abs(tile)``. With 6 RGB pins, 4
139+
//| address lines, and a single matrix, the display will be 32 pixels tall. If the optional height
140140
//| parameter is specified and is not 0, it is checked against the calculated
141141
//| height.
142142
//|
@@ -172,7 +172,7 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
172172

173173
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) {
174174
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 };
175+
ARG_clock_pin, ARG_latch_pin, ARG_output_enable_pin, ARG_doublebuffer, ARG_framebuffer, ARG_height, ARG_tile, ARG_serpentine };
176176
static const mp_arg_t allowed_args[] = {
177177
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
178178
{ MP_QSTR_bit_depth, MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
@@ -184,6 +184,8 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
184184
{ MP_QSTR_doublebuffer, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = true } },
185185
{ MP_QSTR_framebuffer, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
186186
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 0 } },
187+
{ MP_QSTR_tile, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 1 } },
188+
{ MP_QSTR_serpentine, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
187189
};
188190
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
189191
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -210,12 +212,18 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
210212
mp_raise_ValueError_varg(translate("Must use a multiple of 6 rgb pins, not %d"), rgb_count);
211213
}
212214

213-
// TODO(@jepler) Use fewer than all rows of pixels if height < computed_height
215+
int tile = args[ARG_tile].u_int;
216+
217+
if (tile <= 0) {
218+
mp_raise_ValueError_varg(
219+
translate("tile must be greater than zero"));
220+
}
221+
222+
int computed_height = (rgb_count / 3) * (1 << (addr_count)) * tile;
214223
if (args[ARG_height].u_int != 0) {
215-
int computed_height = (rgb_count / 3) << (addr_count);
216224
if (computed_height != args[ARG_height].u_int) {
217225
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);
226+
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);
219227
}
220228
}
221229

@@ -228,7 +236,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
228236
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
229237
if (framebuffer == mp_const_none) {
230238
int width = args[ARG_width].u_int;
231-
int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
239+
int bufsize = 2 * width * computed_height;
232240
framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
233241
}
234242

@@ -239,7 +247,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
239247
addr_count, addr_pins,
240248
clock_pin, latch_pin, output_enable_pin,
241249
args[ARG_doublebuffer].u_bool,
242-
framebuffer, NULL);
250+
framebuffer, tile, args[ARG_serpentine].u_bool, NULL);
243251

244252
claim_and_never_reset_pins(args[ARG_rgb_list].u_obj);
245253
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, bool serpentine, 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: 7 additions & 4 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, bool serpentine, void *timer) {
4646
self->width = width;
4747
self->bit_depth = bit_depth;
4848
self->rgb_count = rgb_count;
@@ -53,14 +53,16 @@ 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;
57+
self->serpentine = serpentine;
5658

5759
self->timer = timer ? timer : common_hal_rgbmatrix_timer_allocate();
5860
if (self->timer == NULL) {
5961
mp_raise_ValueError(translate("No timer available"));
6062
}
6163

6264
self->width = width;
63-
self->bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
65+
self->bufsize = 2 * width * common_hal_rgbmatrix_rgbmatrix_get_height(self);
6466

6567
common_hal_rgbmatrix_rgbmatrix_reconstruct(self, framebuffer);
6668
}
@@ -95,7 +97,8 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
9597
self->rgb_count/6, self->rgb_pins,
9698
self->addr_count, self->addr_pins,
9799
self->clock_pin, self->latch_pin, self->oe_pin,
98-
self->doublebuffer, self->timer);
100+
self->doublebuffer, self->serpentine ? -self->tile : self->tile,
101+
self->timer);
99102

100103
if (stat == PROTOMATTER_OK) {
101104
_PM_protoPtr = &self->protomatter;
@@ -209,7 +212,7 @@ int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
209212
}
210213

211214
int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
212-
int computed_height = (self->rgb_count / 3) << (self->addr_count);
215+
int computed_height = (self->rgb_count / 3) * (1 << (self->addr_count)) * self->tile;
213< 8157 code>216
return computed_height;
214217
}
215218

shared-module/rgbmatrix/RGBMatrix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ typedef struct {
4444
bool core_is_initialized;
4545
bool paused;
4646
bool doublebuffer;
47+
bool serpentine;
48+
int8_t tile;
4749
} rgbmatrix_rgbmatrix_obj_t;

0 commit comments

Comments
 (0)
0