@@ -63,7 +63,6 @@ void set_page(busio_i2c_obj_t *i2c, uint8_t addr, uint8_t p) {
63
63
64
64
uint8_t page [2 ] = { 0xFD , 0x00 }; // page command
65
65
page [1 ] = p ;
66
- // mp_printf(&mp_plat_print, "Set Page %x -> %x\n", page[0], page[1]);
67
66
uint8_t result = common_hal_busio_i2c_write (i2c , addr , page , 2 , true);
68
67
if (result != 0 ) {
69
68
mp_printf (& mp_plat_print , "Set Page error %x\n" , result );
@@ -77,7 +76,6 @@ void send_enable(busio_i2c_obj_t *i2c, uint8_t addr) {
77
76
if (result != 0 ) {
78
77
mp_printf (& mp_plat_print , "Enable error %x\n" , result );
79
78
}
80
- mp_printf (& mp_plat_print , "CH IS construct: enable\n" );
81
79
}
82
80
83
81
void send_reset (busio_i2c_obj_t * i2c , uint8_t addr ) {
@@ -87,20 +85,37 @@ void send_reset(busio_i2c_obj_t *i2c, uint8_t addr) {
87
85
if (result != 0 ) {
88
86
mp_printf (& mp_plat_print , "reset error %x\n" , result );
89
87
}
90
- mp_printf (& mp_plat_print , "CH IS construct: reset\n" );
91
88
}
92
89
93
- void set_current (busio_i2c_obj_t * i2c , uint8_t addr , uint8_t cur ) {
90
+ void set_current (busio_i2c_obj_t * i2c , uint8_t addr , uint8_t current ) {
94
91
set_page (i2c , addr , 4 );
95
92
uint8_t gcur [2 ] = { 0x01 , 0x00 }; // global current command
96
- gcur [1 ] = cur ;
93
+ gcur [1 ] = current ;
97
94
uint8_t result = common_hal_busio_i2c_write (i2c , addr , gcur , 2 , true);
98
95
if (result != 0 ) {
99
96
mp_printf (& mp_plat_print , "set current error %x\n" , result );
100
97
}
101
- mp_printf (& mp_plat_print , "CH IS construct: set global current\n" );
102
98
}
103
99
100
+ uint8_t get_current (busio_i2c_obj_t * i2c , uint8_t addr ) {
101
+ set_page (i2c , addr , 4 );
102
+ uint8_t gcur = 0x01 ; // global current command
103
+
104
+ uint8_t result = common_hal_busio_i2c_write (i2c , addr , & gcur , 1 , true);
105
+ if (result != 0 ) {
106
+ mp_printf (& mp_plat_print , "get current error %x\n" , result );
107
+ }
108
+
109
+ uint8_t data = 0 ;
110
+ result = common_hal_busio_i2c_read (i2c , addr , & data , 1 );
111
+ if (result != 0 ) {
112
+ mp_printf (& mp_plat_print , "get current error %x\n" , result );
113
+ }
114
+
115
+ return data ;
116
+ }
117
+
118
+
104
119
void set_led (busio_i2c_obj_t * i2c , uint8_t addr , uint16_t led , uint8_t level , uint8_t page ) {
105
120
uint8_t cmd [2 ] = { 0x00 , 0x00 };
106
121
@@ -118,7 +133,6 @@ void set_led(busio_i2c_obj_t *i2c, uint8_t addr, uint16_t led, uint8_t level, ui
118
133
if (result != 0 ) {
119
134
mp_printf (& mp_plat_print , "set led error %x\n" , result );
120
135
}
121
- // mp_printf(&mp_plat_print, "CH IS construct: set led %x -> %x\n", led, level);
122
136
}
123
137
124
138
void drawPixel (busio_i2c_obj_t * i2c , uint8_t addr , int16_t x , int16_t y , uint32_t color ) {
@@ -134,18 +148,10 @@ void drawPixel(busio_i2c_obj_t *i2c, uint8_t addr, int16_t x, int16_t y, uint32_
134
148
set_led (i2c , addr , ridx , r , 0 );
135
149
set_led (i2c , addr , gidx , g , 0 );
136
150
set_led (i2c , addr , bidx , b , 0 );
137
- // mp_printf(&mp_plat_print, "drawPixel: x %d y %d r %02x g %02x b %02x ri %d gi %d bi %d\n", x, y, r, g, b, ridx, gidx, bidx);
138
- } else {
139
- // mp_printf(&mp_plat_print, "drawPixel: x %d y %d r %02x g %02x b %02x OOB\n", x, y, r, g, b);
140
151
}
141
-
142
152
}
143
153
144
-
145
-
146
-
147
154
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 ) {
148
- mp_printf (& mp_plat_print , "CH IS construct %x\n" , addr );
149
155
self -> width = width ;
150
156
self -> height = height ;
151
157
@@ -168,7 +174,6 @@ void common_hal_is31fl3741_is31fl3741_construct(is31fl3741_is31fl3741_obj_t *sel
168
174
common_hal_busio_i2c_write (i2c , addr , & command , 1 , false);
169
175
uint8_t data = 0 ;
170
176
common_hal_busio_i2c_read (i2c , addr , & data , 1 );
171
- mp_printf (& mp_plat_print , "CH IS construct device %x\n" , data );
172
177
173
178
send_reset (i2c , addr );
174
179
send_enable (i2c , addr );
@@ -179,38 +184,24 @@ void common_hal_is31fl3741_is31fl3741_construct(is31fl3741_is31fl3741_obj_t *sel
179
184
set_led (i2c , addr , i , 0xFF , 2 );
180
185
}
181
186
182
- // set_led(i2c, addr, 0x09, 0xA1, 0);
183
- // set_led(i2c, addr, 309, 0xA1, 0);
184
- // set_led(i2c, addr, 0x09, 0xCC, 2);
185
-
186
- // set_led(i2c, addr, 0x19, 0xA2, 0);
187
- // set_led(i2c, addr, 0x19, 0x02, 2);
188
-
189
- // set_led(i2c, addr, 0x2A, 0xA3, 1);
190
- // set_led(i2c, addr, 0x29, 0xEE, 3);
191
-
192
187
common_hal_busio_i2c_unlock (i2c );
193
-
194
-
195
188
}
196
189
197
190
void common_hal_is31fl3741_is31fl3741_reconstruct (is31fl3741_is31fl3741_obj_t * self , mp_obj_t framebuffer ) {
198
191
self -> paused = 1 ;
199
192
200
193
if (framebuffer ) {
201
- mp_printf (& mp_plat_print , "CH IS reconstruct framebuffer %x\n" , MP_OBJ_TO_PTR (framebuffer ));
202
194
self -> framebuffer = framebuffer ;
203
195
mp_get_buffer_raise (self -> framebuffer , & self -> bufinfo , MP_BUFFER_READ );
204
196
if (mp_get_buffer (self -> framebuffer , & self -> bufinfo , MP_BUFFER_RW )) {
205
197
self -> bufinfo .typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW ;
206
198
} else {
207
199
self -> bufinfo .typecode = 'H' ;
208
200
}
209
- mp_printf ( & mp_plat_print , "CH IS reconstruct self->bufinfo is %x\n" , self -> bufinfo . buf );
201
+
210
202
// verify that the matrix is big enough
211
203
mp_get_index (mp_obj_get_type (self -> framebuffer ), self -> bufinfo .len , MP_OBJ_NEW_SMALL_INT (self -> bufsize - 1 ), false);
212
204
} else {
213
- mp_printf (& mp_plat_print , "CH IS reconstruct NO framebuffer\n" );
214
205
common_hal_is31fl3741_free_impl (self -> bufinfo .buf );
215
206
216
207
self -> framebuffer = NULL ;
@@ -263,7 +254,6 @@ void common_hal_is31fl3741_is31fl3741_reconstruct(is31fl3741_is31fl3741_obj_t *s
263
254
}
264
255
265
256
void common_hal_is31fl3741_is31fl3741_deinit (is31fl3741_is31fl3741_obj_t * self ) {
266
- mp_printf (& mp_plat_print , "IS CH Deinit\n" );
267
257
/*
268
258
if (self->timer) {
269
259
common_hal_is31fl3741_timer_free(self->timer);
@@ -291,58 +281,53 @@ void common_hal_is31fl3741_is31fl3741_deinit(is31fl3741_is31fl3741_obj_t *self)
291
281
}
292
282
293
283
void common_hal_is31fl3741_is31fl3741_set_paused (is31fl3741_is31fl3741_obj_t * self , bool paused ) {
294
- mp_printf (& mp_plat_print , "CH IS set paused\n" );
295
- /*if (paused && !self->paused) {
296
- _PM_stop(&self->protomatter);
297
- } else if (!paused && self->paused) {
298
- _PM_resume(&self->protomatter);
299
- _PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
300
- _PM_swapbuffer_maybe(&self->protomatter);
301
- }*/
302
284
self -> paused = paused ;
303
285
}
304
286
305
287
bool common_hal_is31fl3741_is31fl3741_get_paused (is31fl3741_is31fl3741_obj_t * self ) {
306
- mp_printf (& mp_plat_print , "CH IS get paused\n" );
307
288
return self -> paused ;
308
289
}
309
290
310
- void common_hal_is31fl3741_is31fl3741_refresh (is31fl3741_is31fl3741_obj_t * self ) {
311
- // mp_printf(&mp_plat_print, "CH IS refresh len %x addr %x\n", self->bufinfo.len, self->bufinfo.buf);
291
+ void common_hal_is31fl3741_is31fl3741_set_global_current (is31fl3741_is31fl3741_obj_t * self , uint8_t current ) {
292
+ set_current (self -> i2c , self -> device_address , current );
293
+ }
294
+
295
+ uint8_t common_hal_is31fl3741_is31fl3741_get_global_current (is31fl3741_is31fl3741_obj_t * self ) {
296
+ return get_current (self -> i2c , self -> device_address );
297
+ }
298
+
299
+ void common_hal_is31fl3741_is31fl3741_refresh (is31fl3741_is31fl3741_obj_t * self , uint8_t * dirtyrows ) {
300
+ uint8_t dirty_row_flags = 0xFF ;
301
+ if (dirtyrows != 0 ) {
302
+ dirty_row_flags = * dirtyrows ;
303
+ }
312
304
313
305
if (!self -> paused ) {
314
306
uint32_t * buffer = self -> bufinfo .buf ;
315
307
for (int y = 0 ; y < 5 ; y ++ ) {
316
- for (int x = 0 ; x < 18 ; x ++ ) {
317
- drawPixel (self -> i2c , self -> device_address , x , y , * buffer );
318
- // mp_printf(&mp_plat_print, "%06x ", *buffer);
319
- buffer ++ ;
308
+ if ((dirty_row_flags >> y ) & 0x1 ) {
309
+ for (int x = 0 ; x < 18 ; x ++ ) {
310
+ drawPixel (self -> i2c , self -> device_address , x , y , * buffer );
311
+ buffer ++ ;
312
+ }
320
313
}
321
- // mp_printf(&mp_plat_print, "\n");
322
314
}
323
- //
324
- // _PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
325
- // _PM_swapbuffer_maybe(&self->protomatter);
326
315
}
327
316
}
328
317
329
318
int common_hal_is31fl3741_is31fl3741_get_width (is31fl3741_is31fl3741_obj_t * self ) {
330
- mp_printf (& mp_plat_print , "CH IS get width\n" );
331
319
return self -> width ;
332
320
}
333
321
334
322
int common_hal_is31fl3741_is31fl3741_get_height (is31fl3741_is31fl3741_obj_t * self ) {
335
- mp_printf (& mp_plat_print , "CH IS get height\n" );
336
323
return self -> height ;
337
324
}
338
325
339
326
void * common_hal_is31fl3741_allocator_impl (size_t sz ) {
340
- mp_printf (& mp_plat_print , "CH IS allocator\n" );
341
327
supervisor_allocation * allocation = allocate_memory (align32_size (sz ), false, true);
342
328
return allocation ? allocation -> ptr : NULL ;
343
329
}
344
330
345
331
void common_hal_is31fl3741_free_impl (void * ptr_in ) {
346
- mp_printf (& mp_plat_print , "CH IS free\n" );
347
332
free_memory (allocation_from_ptr (ptr_in ));
348
333
}
0 commit comments