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
This commit is contained in:
parent
345c2ae8a9
commit
368977fb90
|
@ -24,8 +24,6 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/objproperty.h"
|
||||
#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
|
|||
|
||||
int tile = args[ARG_tile].u_int;
|
||||
|
||||
if (tile < 0) {
|
||||
mp_raise_ValueError_varg(
|
||||
translate("tile must be greater than or equal to zero"));
|
||||
}
|
||||
|
||||
if (args[ARG_height].u_int != 0) {
|
||||
int computed_height = (rgb_count / 3) << (addr_count) * abs(tile);
|
||||
int computed_height = (rgb_count / 3) * (1 << (addr_count)) * tile;
|
||||
if (computed_height != args[ARG_height].u_int) {
|
||||
mp_raise_ValueError_varg(
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (args[ARG_serpentine].u_bool) {
|
||||
tile = -tile;
|
||||
}
|
||||
|
||||
if (args[ARG_width].u_int <= 0) {
|
||||
mp_raise_ValueError(translate("width must be greater than zero"));
|
||||
}
|
||||
|
@ -237,7 +236,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
|
|||
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
|
||||
if (framebuffer == mp_const_none) {
|
||||
int width = args[ARG_width].u_int;
|
||||
int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
|
||||
int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count) * tile;
|
||||
framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
|
||||
}
|
||||
|
||||
|
@ -248,7 +247,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
|
|||
addr_count, addr_pins,
|
||||
clock_pin, latch_pin, output_enable_pin,
|
||||
args[ARG_doublebuffer].u_bool,
|
||||
framebuffer, tile, NULL);
|
||||
framebuffer, tile, args[ARG_serpentine].u_bool, NULL);
|
||||
|
||||
claim_and_never_reset_pins(args[ARG_rgb_list].u_obj);
|
||||
claim_and_never_reset_pins(args[ARG_addr_list].u_obj);
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
|
||||
|
||||
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);
|
||||
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);
|
||||
void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t*);
|
||||
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t*);
|
||||
void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self, mp_obj_t framebuffer);
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
extern Protomatter_core *_PM_protoPtr;
|
||||
|
||||
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) {
|
||||
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) {
|
||||
self->width = width;
|
||||
self->bit_depth = bit_depth;
|
||||
self->rgb_count = rgb_count;
|
||||
|
@ -54,6 +54,7 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
|
|||
self->latch_pin = latch_pin;
|
||||
self->doublebuffer = doublebuffer;
|
||||
self->tile = tile;
|
||||
self->serpentine = serpentine;
|
||||
|
||||
self->timer = timer ? timer : common_hal_rgbmatrix_timer_allocate();
|
||||
if (self->timer == NULL) {
|
||||
|
@ -61,7 +62,7 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
|
|||
}
|
||||
|
||||
self->width = width;
|
||||
self->bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
|
||||
self->bufsize = 2 * width * rgb_count / 3 * (1 << addr_count) * tile;
|
||||
|
||||
common_hal_rgbmatrix_rgbmatrix_reconstruct(self, framebuffer);
|
||||
}
|
||||
|
@ -96,7 +97,8 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
|
|||
self->rgb_count/6, self->rgb_pins,
|
||||
self->addr_count, self->addr_pins,
|
||||
self->clock_pin, self->latch_pin, self->oe_pin,
|
||||
self->doublebuffer, self->tile, self->timer);
|
||||
self->doublebuffer, self->serpentine ? -self->tile : self->tile,
|
||||
self->timer);
|
||||
|
||||
if (stat == PROTOMATTER_OK) {
|
||||
_PM_protoPtr = &self->protomatter;
|
||||
|
@ -210,7 +212,7 @@ int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
|
|||
}
|
||||
|
||||
int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
|
||||
int computed_height = (self->rgb_count / 3) << (self->addr_count);
|
||||
int computed_height = (self->rgb_count / 3) * (1 << (self->addr_count)) * self->tile;
|
||||
return computed_height;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,5 +44,6 @@ typedef struct {
|
|||
bool core_is_initialized;
|
||||
bool paused;
|
||||
bool doublebuffer;
|
||||
bool serpentine;
|
||||
int8_t tile;
|
||||
} rgbmatrix_rgbmatrix_obj_t;
|
||||
|
|
Loading…
Reference in New Issue