@@ -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
173173STATIC 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 );
0 commit comments