@@ -132,11 +132,11 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
132
132
}
133
133
}
134
134
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:
136
136
//| """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
140
140
//| parameter is specified and is not 0, it is checked against the calculated
141
141
//| height.
142
142
//|
@@ -172,7 +172,7 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
172
172
173
173
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 ) {
174
174
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 };
176
176
static const mp_arg_t allowed_args [] = {
177
177
{ MP_QSTR_width , MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
178
178
{ 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
184
184
{ MP_QSTR_doublebuffer , MP_ARG_BOOL | MP_ARG_KW_ONLY , { .u_bool = true } },
185
185
{ MP_QSTR_framebuffer , MP_ARG_OBJ | MP_ARG_KW_ONLY , { .u_obj = mp_const_none } },
186
186
{ 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 } },
187
189
};
188
190
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
189
191
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
210
212
mp_raise_ValueError_varg (translate ("Must use a multiple of 6 rgb pins, not %d" ), rgb_count );
211
213
}
212
214
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 ;
214
223
if (args [ARG_height ].u_int != 0 ) {
215
- int computed_height = (rgb_count / 3 ) << (addr_count );
216
224
if (computed_height != args [ARG_height ].u_int ) {
217
225
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 );
219
227
}
220
228
}
221
229
@@ -228,7 +236,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
228
236
mp_obj_t framebuffer = args [ARG_framebuffer ].u_obj ;
229
237
if (framebuffer == mp_const_none ) {
230
238
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 ;
232
240
framebuffer = mp_obj_new_bytearray_of_zeros (bufsize );
233
241
}
234
242
@@ -239,7 +247,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
239
247
addr_count , addr_pins ,
240
248
clock_pin , latch_pin , output_enable_pin ,
241
249
args [ARG_doublebuffer ].u_bool ,
242
- framebuffer , NULL );
250
+ framebuffer , tile , args [ ARG_serpentine ]. u_bool , NULL );
243
251
244
252
claim_and_never_reset_pins (args [ARG_rgb_list ].u_obj );
245
253
claim_and_never_reset_pins (args [ARG_addr_list ].u_obj );
0 commit comments