40
40
#include "shared-module/framebufferio/FramebufferDisplay.h"
41
41
#include "shared-bindings/busio/I2C.h"
42
42
43
- void common_hal_is31fl3741_is31fl3741_construct (is31fl3741_is31fl3741_obj_t * self , int width , int height , mp_obj_t framebuffer , busio_i2c_obj_t * i2c , uint8_t addr ) {
43
+ void common_hal_is31fl3741_is31fl3741_construct (is31fl3741_is31fl3741_obj_t * self , int width , int height , mp_obj_t framebuffer , busio_i2c_obj_t * i2c , uint8_t addr , mp_obj_t mapping ) {
44
44
self -> width = width ;
45
45
self -> height = height ;
46
46
@@ -59,6 +59,21 @@ void common_hal_is31fl3741_is31fl3741_construct(is31fl3741_is31fl3741_obj_t *sel
59
59
// of the heap as well.
60
60
gc_never_free (self -> i2c );
61
61
62
+ // TODO mapping should be equal to height * width * 3
63
+ mp_obj_t * items ;
64
+ size_t len ;
65
+ mp_obj_list_get (mapping , & len , & items );
66
+
67
+ self -> mapping = common_hal_is31fl3741_allocator_impl (sizeof (uint16_t ) * len );
68
+ for (size_t i = 0 ; i < len ; i ++ ) {
69
+ mp_int_t value = mp_obj_get_int (items [i ]);
70
+ // We only store up to 16 bits
71
+ if (value > 0xFFFF ) {
72
+ value = 0xFFFF ;
73
+ }
74
+ self -> mapping [i ] = (uint16_t )value ;
75
+ }
76
+
62
77
common_hal_is31fl3741_is31fl3741_reconstruct (self , framebuffer );
63
78
}
64
79
@@ -114,6 +129,11 @@ void common_hal_is31fl3741_is31fl3741_deinit(is31fl3741_is31fl3741_obj_t *self)
114
129
self -> i2c = NULL ;
115
130
}
116
131
132
+ if (self -> mapping != 0 ) {
133
+ common_hal_is31fl3741_free_impl (self -> mapping );
134
+ self -> mapping = 0 ;
135
+ }
136
+
117
137
self -> base .type = NULL ;
118
138
119
139
// If a framebuffer was passed in to the constructor, NULL the reference
@@ -144,15 +164,12 @@ uint8_t common_hal_is31fl3741_is31fl3741_get_global_current(is31fl3741_is31fl374
144
164
145
165
void common_hal_is31fl3741_is31fl3741_refresh (is31fl3741_is31fl3741_obj_t * self , uint8_t * dirtyrows ) {
146
166
common_hal_displayio_is31fl3741_begin_transaction (self );
147
-
148
- uint8_t dirty_row_flags = 0xFF ; // only supports 8 rows gotta fix
149
- if (dirtyrows != 0 ) {
150
- dirty_row_flags = * dirtyrows ;
151
- }
152
-
153
167
if (!self -> paused ) {
168
+ uint8_t dirty_row_flags = 0xFF ; // only supports 8 rows gotta fix
169
+
154
170
if (self -> scale ) {
155
171
// Based on the Arduino IS31FL3741 driver code
172
+ // dirtyrows flag current not implemented for scaled displays
156
173
uint32_t * buffer = self -> bufinfo .buf ;
157
174
158
175
for (int x = 0 ; x < self -> scale_width ; x ++ ) {
@@ -180,13 +197,17 @@ void common_hal_is31fl3741_is31fl3741_refresh(is31fl3741_is31fl3741_obj_t *self,
180
197
} else {
181
198
color = (rsum << 16 ) + (gsum << 8 ) + bsum ;
182
199
}
183
- is31fl3741_draw_pixel (self -> i2c , self -> device_address , x , y , color );
200
+ is31fl3741_draw_pixel (self -> i2c , self -> device_address , x , y , color , self -> mapping );
184
201
}
185
202
}
186
203
} else {
187
204
uint32_t * buffer = self -> bufinfo .buf ;
188
205
for (int y = 0 ; y < self -> height ; y ++ ) {
189
- if ((dirty_row_flags >> y ) & 0x1 ) {
206
+ if ((dirtyrows != 0 ) && ((y % 8 ) == 0 )) {
207
+ dirty_row_flags = * dirtyrows ++ ;
208
+ }
209
+
210
+ if ((dirty_row_flags >> (y % 8 )) & 0x1 ) {
190
211
uint32_t color = 0 ;
191
212
if (self -> auto_gamma ) {
192
213
color = IS31GammaTable [((* buffer ) >> 16 & 0xFF )] +
@@ -197,7 +218,7 @@ void common_hal_is31fl3741_is31fl3741_refresh(is31fl3741_is31fl3741_obj_t *self,
197
218
}
198
219
199
220
for (int x = 0 ; x < self -> width ; x ++ ) {
200
- is31fl3741_draw_pixel (self -> i2c , self -> device_address , x , y , color );
221
+ is31fl3741_draw_pixel (self -> i2c , self -> device_address , x , y , color , self -> mapping );
201
222
buffer ++ ;
202
223
}
203
224
}
@@ -240,6 +261,7 @@ void common_hal_is31fl3741_free_impl(void *ptr_in) {
240
261
241
262
void is31fl3741_is31fl3741_collect_ptrs (is31fl3741_is31fl3741_obj_t * self ) {
242
263
gc_collect_ptr (self -> framebuffer );
264
+ gc_collect_ptr (self -> mapping );
243
265
}
244
266
245
267
// The following are routines to manipulate the IS31FL3741 chip
@@ -311,16 +333,16 @@ void is31fl3741_set_led(busio_i2c_obj_t *i2c, uint8_t addr, uint16_t led, uint8_
311
333
common_hal_busio_i2c_write (i2c , addr , cmd , 2 , true);
312
334
}
313
335
314
- void is31fl3741_draw_pixel (busio_i2c_obj_t * i2c , uint8_t addr , int16_t x , int16_t y , uint32_t color ) {
336
+ void is31fl3741_draw_pixel (busio_i2c_obj_t * i2c , uint8_t addr , int16_t x , int16_t y , uint32_t color , uint16_t * mapping ) {
315
337
uint8_t r = color >> 16 & 0xFF ;
316
338
uint8_t g = color >> 8 & 0xFF ;
317
339
uint8_t b = color & 0xFF ;
318
340
319
341
int16_t x1 = (x * 5 + y ) * 3 ;
320
- uint16_t ridx = glassesmatrix_ledmap [x1 + 2 ];
342
+ uint16_t ridx = mapping [x1 + 2 ];
321
343
if (ridx != 65535 ) {
322
- uint16_t gidx = glassesmatrix_ledmap [x1 + 1 ];
323
- uint16_t bidx = glassesmatrix_ledmap [x1 + 0 ];
344
+ uint16_t gidx = mapping [x1 + 1 ];
345
+ uint16_t bidx = mapping [x1 + 0 ];
324
346
is31fl3741_set_led (i2c , addr , ridx , r , 0 );
325
347
is31fl3741_set_led (i2c , addr , gidx , g , 0 );
326
348
is31fl3741_set_led (i2c , addr , bidx , b , 0 );
0 commit comments