24
24
* THE SOFTWARE.
25
25
*/
26
26
27
+ #include <stdlib.h>
28
+
27
29
#include "py/obj.h"
28
30
#include "py/objproperty.h"
29
31
#include "py/runtime.h"
@@ -132,11 +134,11 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
132
134
}
133
135
}
134
136
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:
137
+ //| 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
138
//| """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
139
+ //| the display is determined by the number of rgb and address pins and the number of tiles :
140
+ //| `` len(rgb_pins) // 3 * 2 ** len(address_pins) * abs(tile)`` . With 6 RGB pins, 4
141
+ //| address lines, and a single matrix, the display will be 32 pixels tall. If the optional height
140
142
//| parameter is specified and is not 0, it is checked against the calculated
141
143
//| height.
142
144
//|
@@ -172,7 +174,7 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
172
174
173
175
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
176
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 };
177
+ ARG_clock_pin , ARG_latch_pin , ARG_output_enable_pin , ARG_doublebuffer , ARG_framebuffer , ARG_height , ARG_tile , ARG_serpentine };
176
178
static const mp_arg_t allowed_args [] = {
177
179
{ MP_QSTR_width , MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
178
180
{ MP_QSTR_bit_depth , MP_ARG_INT | MP_ARG_REQUIRED | MP_ARG_KW_ONLY },
@@ -184,6 +186,8 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
184
186
{ MP_QSTR_doublebuffer , MP_ARG_BOOL | MP_ARG_KW_ONLY , { .u_bool = true } },
185
187
{ MP_QSTR_framebuffer , MP_ARG_OBJ | MP_ARG_KW_ONLY , { .u_obj = mp_const_none } },
186
188
{ MP_QSTR_height , MP_ARG_INT | MP_ARG_KW_ONLY , { .u_int = 0 } },
189
+ { MP_QSTR_tile , MP_ARG_INT | MP_ARG_KW_ONLY , { .u_int = 1 } },
190
+ { MP_QSTR_serpentine , MP_ARG_BOOL | MP_ARG_KW_ONLY , { .u_bool = false } },
187
191
};
188
192
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
189
193
mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
@@ -210,15 +214,20 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
210
214
mp_raise_ValueError_varg (translate ("Must use a multiple of 6 rgb pins, not %d" ), rgb_count );
211
215
}
212
216
213
- // TODO(@jepler) Use fewer than all rows of pixels if height < computed_height
217
+ int tile = args [ARG_tile ].u_int ;
218
+
214
219
if (args [ARG_height ].u_int != 0 ) {
215
- int computed_height = (rgb_count / 3 ) << (addr_count );
220
+ int computed_height = (rgb_count / 3 ) << (addr_count ) * abs ( tile ) ;
216
221
if (computed_height != args [ARG_height ].u_int ) {
217
222
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 );
223
+ 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
224
}
220
225
}
221
226
227
+ if (args [ARG_serpentine ].u_bool ) {
228
+ tile = - tile ;
229
+ }
230
+
222
231
if (args [ARG_width ].u_int <= 0 ) {
223
232
mp_raise_ValueError (translate ("width must be greater than zero" ));
224
233
}
@@ -239,7 +248,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
239
248
addr_count , addr_pins ,
240
249
clock_pin , latch_pin , output_enable_pin ,
241
250
args [ARG_doublebuffer ].u_bool ,
242
- framebuffer , NULL );
251
+ framebuffer , tile , NULL );
243
252
244
253
claim_and_never_reset_pins (args [ARG_rgb_list ].u_obj );
245
254
claim_and_never_reset_pins (args [ARG_addr_list ].u_obj );
0 commit comments