Skip to content

Commit 368977f

Browse files
committed
RGBMatrix: Additional tile tweaks
* Introduce explicit serpentine: bool argument instead of using negative numbers (thanks, ghost of @tannewt sitting on one shoulder) * Fix several calculations of height Testing performed (matrixportal): * set up a serpentine 64x64 virtual display with 2 64x32 tiles * tried all 4 rotations * looked at output of REPL
1 parent 345c2ae commit 368977f

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

shared-bindings/rgbmatrix/RGBMatrix.c

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

27-
#include <stdlib.h>
28-
2927
#include "py/obj.h"
3028
#include "py/objproperty.h"
3129
#include "py/runtime.h"
@@ -216,18 +214,19 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
216214

217215
int tile = args[ARG_tile].u_int;
218216

217+
if (tile < 0) {
218+
mp_raise_ValueError_varg(
219+
translate("tile must be greater than or equal to zero"));
220+
}
221+
219222
if (args[ARG_height].u_int != 0) {
220-
int computed_height = (rgb_count / 3) << (addr_count) * abs(tile);
223+
int computed_height = (rgb_count / 3) * (1 << (addr_count)) * tile;
221224
if (computed_height != args[ARG_height].u_int) {
222225
mp_raise_ValueError_varg(
223226
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);
224227
}
225228
}
226229

227-
if (args[ARG_serpentine].u_bool) {
228-
tile = -tile;
229-
}
230-
231230
if (args[ARG_width].u_int <= 0) {
232231
mp_raise_ValueError(translate("width must be greater than zero"));
233232
}
@@ -237,7 +236,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
237236
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
238237
if (framebuffer == mp_const_none) {
239238
int width = args[ARG_width].u_int;
240-
int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
239+
int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count) * tile;
241240
framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
242241
}
243242

@@ -248,7 +247,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
248247
addr_count, addr_pins,
249248
clock_pin, latch_pin, output_enable_pin,
250249
args[ARG_doublebuffer].u_bool,
251-
framebuffer, tile, NULL);
250+
framebuffer, tile, args[ARG_serpentine].u_bool, NULL);
252251

253252
claim_and_never_reset_pins(args[ARG_rgb_list].u_obj);
254253
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, int8_t tile, 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: 6 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, int8_t tile, 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;
@@ -54,14 +54,15 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
5454
self->latch_pin = latch_pin;
5555
self->doublebuffer = doublebuffer;
5656
self->tile = tile;
57+
self->serpentine = serpentine;
5758

5859
self->timer = timer ? timer : common_hal_rgbmatrix_timer_allocate();
5960
if (self->timer == NULL) {
6061
mp_raise_ValueError(translate("No timer available"));
6162
}
6263

6364
self->width = width;
64-
self->bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
65+
self->bufsize = 2 * width * rgb_count / 3 * (1 << addr_count) * tile;
6566

6667
common_hal_rgbmatrix_rgbmatrix_reconstruct(self, framebuffer);
6768
}
@@ -96,7 +97,8 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
9697
self->rgb_count/6, self->rgb_pins,
9798
self->addr_count, self->addr_pins,
9899
self->clock_pin, self->latch_pin, self->oe_pin,
99-
self->doublebuffer, self->tile, self->timer);
100+
self->doublebuffer, self->serpentine ? -self->tile : self->tile,
101+
self->timer);
100102

101103
if (stat == PROTOMATTER_OK) {
102104
_PM_protoPtr = &self->protomatter;
@@ -210,7 +212,7 @@ int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
210212
}
211213

212214
int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
213-
int computed_height = (self->rgb_count / 3) << (self->addr_count);
215+
int computed_height = (self->rgb_count / 3) * (1 << (self->addr_count)) * self->tile;
214216
return computed_height;
215217
}
216218

shared-module/rgbmatrix/RGBMatrix.h

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy