Skip to content

Commit 29c5857

Browse files
committed
Removed prints updated brightness
1 parent d063bf2 commit 29c5857

File tree

3 files changed

+56
-80
lines changed

3 files changed

+56
-80
lines changed

shared-bindings/is31fl3741/is31fl3741.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ STATIC mp_obj_t is31fl3741_is31fl3741_make_new(const mp_obj_type_t *type, size_t
9797
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
9898
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
9999

100-
mp_printf(&mp_plat_print, "IS make new\n");
101-
102100
mp_obj_t i2c = mp_arg_validate_type(args[ARG_i2c].u_obj, &busio_i2c_type, MP_QSTR_i2c_bus);
103101

104102
is31fl3741_is31fl3741_obj_t *self = &allocate_display_bus_or_raise()->is31fl3741;
@@ -108,16 +106,13 @@ STATIC mp_obj_t is31fl3741_is31fl3741_make_new(const mp_obj_type_t *type, size_t
108106
mp_raise_ValueError(translate("width must be greater than zero"));
109107
}
110108

111-
mp_printf(&mp_plat_print, "w %d h %d\n", args[ARG_width].u_int, args[ARG_height].u_int);
112-
113109
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
114110
if (framebuffer == mp_const_none) {
115111
int width = args[ARG_width].u_int;
116112
int height = args[ARG_height].u_int;
117113
int bufsize = 4 * width * height;
118114
framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
119115
}
120-
mp_printf(&mp_plat_print, "framebuffer is %x\n", MP_OBJ_TO_PTR(framebuffer));
121116

122117
common_hal_is31fl3741_is31fl3741_construct(self,
123118
args[ARG_width].u_int,
@@ -137,7 +132,6 @@ STATIC mp_obj_t is31fl3741_is31fl3741_make_new(const mp_obj_type_t *type, size_t
137132
//| ...
138133
//|
139134
STATIC mp_obj_t is31fl3741_is31fl3741_deinit(mp_obj_t self_in) {
140-
mp_printf(&mp_plat_print, "IS Deinit\n");
141135
is31fl3741_is31fl3741_obj_t *self = (is31fl3741_is31fl3741_obj_t *)self_in;
142136
common_hal_is31fl3741_is31fl3741_deinit(self);
143137
return mp_const_none;
@@ -158,7 +152,10 @@ static void check_for_deinit(is31fl3741_is31fl3741_obj_t *self) {
158152
STATIC mp_obj_t is31fl3741_is31fl3741_get_brightness(mp_obj_t self_in) {
159153
is31fl3741_is31fl3741_obj_t *self = (is31fl3741_is31fl3741_obj_t *)self_in;
160154
check_for_deinit(self);
161-
return mp_obj_new_float(common_hal_is31fl3741_is31fl3741_get_paused(self)? 0.0f : 1.0f);
155+
uint8_t current = common_hal_is31fl3741_is31fl3741_get_global_current(self);
156+
157+
float brightness = (float)current / (float)0xFF;
158+
return mp_obj_new_float(brightness);
162159
}
163160
MP_DEFINE_CONST_FUN_OBJ_1(is31fl3741_is31fl3741_get_brightness_obj, is31fl3741_is31fl3741_get_brightness);
164161

@@ -169,7 +166,9 @@ STATIC mp_obj_t is31fl3741_is31fl3741_set_brightness(mp_obj_t self_in, mp_obj_t
169166
if (brightness < 0.0f || brightness > 1.0f) {
170167
mp_raise_ValueError(translate("Brightness must be 0-1.0"));
171168
}
172-
common_hal_is31fl3741_is31fl3741_set_paused(self, brightness <= 0);
169+
170+
uint8_t current = (uint8_t)(brightness * 0xFF);
171+
common_hal_is31fl3741_is31fl3741_set_global_current(self, current);
173172

174173
return mp_const_none;
175174
}
@@ -190,7 +189,7 @@ const mp_obj_property_t is31fl3741_is31fl3741_brightness_obj = {
190189
STATIC mp_obj_t is31fl3741_is31fl3741_refresh(mp_obj_t self_in) {
191190
is31fl3741_is31fl3741_obj_t *self = (is31fl3741_is31fl3741_obj_t *)self_in;
192191
check_for_deinit(self);
193-
common_hal_is31fl3741_is31fl3741_refresh(self);
192+
common_hal_is31fl3741_is31fl3741_refresh(self, 0);
194193
return mp_const_none;
195194
}
196195
MP_DEFINE_CONST_FUN_OBJ_1(is31fl3741_is31fl3741_refresh_obj, is31fl3741_is31fl3741_refresh);
@@ -238,7 +237,6 @@ STATIC MP_DEFINE_CONST_DICT(is31fl3741_is31fl3741_locals_dict, is31fl3741_is31fl
238237

239238
STATIC void is31fl3741_is31fl3741_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *bufinfo) {
240239
is31fl3741_is31fl3741_obj_t *self = (is31fl3741_is31fl3741_obj_t *)self_in;
241-
// mp_printf(&mp_plat_print, "IS get bufinfo %x\n", self->bufinfo.buf);
242240
check_for_deinit(self);
243241

244242
*bufinfo = self->bufinfo;
@@ -247,49 +245,42 @@ STATIC void is31fl3741_is31fl3741_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t
247245
// These version exists so that the prototype matches the protocol,
248246
// avoiding a type cast that can hide errors
249247
STATIC void is31fl3741_is31fl3741_swapbuffers(mp_obj_t self_in, uint8_t *dirty_row_bitmap) {
250-
// mp_printf(&mp_plat_print, "IS swapbuffers\n");
251-
(void)dirty_row_bitmap;
252-
common_hal_is31fl3741_is31fl3741_refresh(self_in);
248+
common_hal_is31fl3741_is31fl3741_refresh(self_in, dirty_row_bitmap);
253249
}
254250

255251
STATIC void is31fl3741_is31fl3741_deinit_proto(mp_obj_t self_in) {
256-
mp_printf(&mp_plat_print, "IS deinit proto\n");
257252
common_hal_is31fl3741_is31fl3741_deinit(self_in);
258253
}
259254

260255
STATIC float is31fl3741_is31fl3741_get_brightness_proto(mp_obj_t self_in) {
261-
mp_printf(&mp_plat_print, "IS get brigthness\n");
262256
return common_hal_is31fl3741_is31fl3741_get_paused(self_in) ? 0.0f : 1.0f;
263257
}
264258

265259
STATIC bool is31fl3741_is31fl3741_set_brightness_proto(mp_obj_t self_in, mp_float_t value) {
266-
mp_printf(&mp_plat_print, "IS set brightness\n");
267260
common_hal_is31fl3741_is31fl3741_set_paused(self_in, value <= 0);
268261
return true;
269262
}
270263

271264
STATIC int is31fl3741_is31fl3741_get_width_proto(mp_obj_t self_in) {
272-
mp_printf(&mp_plat_print, "IS get width\n");
273265
return common_hal_is31fl3741_is31fl3741_get_width(self_in);
274266
}
275267

276268
STATIC int is31fl3741_is31fl3741_get_height_proto(mp_obj_t self_in) {
277-
mp_printf(&mp_plat_print, "IS get height\n");
278269
return common_hal_is31fl3741_is31fl3741_get_height(self_in);
279270
}
280271

281272
STATIC int is31fl3741_is31fl3741_get_color_depth_proto(mp_obj_t self_in) {
282-
mp_printf(&mp_plat_print, "IS get color depth\n");
273+
// The way displayio works depth is used to calculate bytes
274+
// We use an uint32_t for color already so setting to 24 causes
275+
// more changes required
283276
return 32;
284277
}
285278

286279
STATIC int is31fl3741_is31fl3741_get_bytes_per_cell_proto(mp_obj_t self_in) {
287-
mp_printf(&mp_plat_print, "IS get bytes per cell\n");
288280
return 1;
289281
}
290282

291283
STATIC int is31fl3741_is31fl3741_get_native_frames_per_second_proto(mp_obj_t self_in) {
292-
mp_printf(&mp_plat_print, "IS get fps\n");
293284
return 60;
294285
}
295286

@@ -311,7 +302,6 @@ STATIC const framebuffer_p_t is31fl3741_is31fl3741_proto = {
311302
STATIC mp_int_t is31fl3741_is31fl3741_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
312303
is31fl3741_is31fl3741_obj_t *self = (is31fl3741_is31fl3741_obj_t *)self_in;
313304
// a readonly framebuffer would be unusual but not impossible
314-
mp_printf(&mp_plat_print, "IS IS get buffer\n");
315305
if ((flags & MP_BUFFER_WRITE) && !(self->bufinfo.typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) {
316306
return 1;
317307
}

shared-bindings/is31fl3741/is31fl3741.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ void common_hal_is31fl3741_is31fl3741_deinit(is31fl3741_is31fl3741_obj_t *);
3838
int common_hal_is31fl3741_is31fl3741_get_width(is31fl3741_is31fl3741_obj_t *self);
3939
int common_hal_is31fl3741_is31fl3741_get_height(is31fl3741_is31fl3741_obj_t *self);
4040

41+
void common_hal_is31fl3741_is31fl3741_set_global_current(is31fl3741_is31fl3741_obj_t *self, uint8_t current);
42+
uint8_t common_hal_is31fl3741_is31fl3741_get_global_current(is31fl3741_is31fl3741_obj_t *self);
43+
4144
void common_hal_is31fl3741_is31fl3741_set_paused(is31fl3741_is31fl3741_obj_t *self, bool paused);
4245
bool common_hal_is31fl3741_is31fl3741_get_paused(is31fl3741_is31fl3741_obj_t *self);
43-
void common_hal_is31fl3741_is31fl3741_refresh(is31fl3741_is31fl3741_obj_t *self);
46+
void common_hal_is31fl3741_is31fl3741_refresh(is31fl3741_is31fl3741_obj_t *self, uint8_t *dirtyrows);
4447

4548
void common_hal_is31fl3741_is31fl3741_reconstruct(is31fl3741_is31fl3741_obj_t *self, mp_obj_t framebuffer);
4649
/*
4750
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t *);
48-
49-
5051
*/

shared-module/is31fl3741/is31fl3741.c

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void set_page(busio_i2c_obj_t *i2c, uint8_t addr, uint8_t p) {
6363

6464
uint8_t page[2] = { 0xFD, 0x00 }; // page command
6565
page[1] = p;
66-
// mp_printf(&mp_plat_print, "Set Page %x -> %x\n", page[0], page[1]);
6766
uint8_t result = common_hal_busio_i2c_write(i2c, addr, page, 2, true);
6867
if (result != 0) {
6968
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) {
7776
if (result != 0) {
7877
mp_printf(&mp_plat_print, "Enable error %x\n", result);
7978
}
80-
mp_printf(&mp_plat_print, "CH IS construct: enable\n");
8179
}
8280

8381
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) {
8785
if (result != 0) {
8886
mp_printf(&mp_plat_print, "reset error %x\n", result);
8987
}
90-
mp_printf(&mp_plat_print, "CH IS construct: reset\n");
9188
}
9289

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) {
9491
set_page(i2c, addr, 4);
9592
uint8_t gcur[2] = { 0x01, 0x00 }; // global current command
96-
gcur[1] = cur;
93+
gcur[1] = current;
9794
uint8_t result = common_hal_busio_i2c_write(i2c, addr, gcur, 2, true);
9895
if (result != 0) {
9996
mp_printf(&mp_plat_print, "set current error %x\n", result);
10097
}
101-
mp_printf(&mp_plat_print, "CH IS construct: set global current\n");
10298
}
10399

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+
104119
void set_led(busio_i2c_obj_t *i2c, uint8_t addr, uint16_t led, uint8_t level, uint8_t page) {
105120
uint8_t cmd[2] = { 0x00, 0x00 };
106121

@@ -118,7 +133,6 @@ void set_led(busio_i2c_obj_t *i2c, uint8_t addr, uint16_t led, uint8_t level, ui
118133
if (result != 0) {
119134
mp_printf(&mp_plat_print, "set led error %x\n", result);
120135
}
121-
// mp_printf(&mp_plat_print, "CH IS construct: set led %x -> %x\n", led, level);
122136
}
123137

124138
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_
134148
set_led(i2c, addr, ridx, r, 0);
135149
set_led(i2c, addr, gidx, g, 0);
136150
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);
140151
}
141-
142152
}
143153

144-
145-
146-
147154
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);
149155
self->width = width;
150156
self->height = height;
151157

@@ -168,7 +174,6 @@ void common_hal_is31fl3741_is31fl3741_construct(is31fl3741_is31fl3741_obj_t *sel
168174
common_hal_busio_i2c_write(i2c, addr, &command, 1, false);
169175
uint8_t data = 0;
170176
common_hal_busio_i2c_read(i2c, addr, &data, 1);
171-
mp_printf(&mp_plat_print, "CH IS construct device %x\n", data);
172177

173178
send_reset(i2c, addr);
174179
send_enable(i2c, addr);
@@ -179,38 +184,24 @@ void common_hal_is31fl3741_is31fl3741_construct(is31fl3741_is31fl3741_obj_t *sel
179184
set_led(i2c, addr, i, 0xFF, 2);
180185
}
181186

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-
192187
common_hal_busio_i2c_unlock(i2c);
193-
194-
195188
}
196189

197190
void common_hal_is31fl3741_is31fl3741_reconstruct(is31fl3741_is31fl3741_obj_t *self, mp_obj_t framebuffer) {
198191
self->paused = 1;
199192

200193
if (framebuffer) {
201-
mp_printf(&mp_plat_print, "CH IS reconstruct framebuffer %x\n", MP_OBJ_TO_PTR(framebuffer));
202194
self->framebuffer = framebuffer;
203195
mp_get_buffer_raise(self->framebuffer, &self->bufinfo, MP_BUFFER_READ);
204196
if (mp_get_buffer(self->framebuffer, &self->bufinfo, MP_BUFFER_RW)) {
205197
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
206198
} else {
207199
self->bufinfo.typecode = 'H';
208200
}
209-
mp_printf(&mp_plat_print, "CH IS reconstruct self->bufinfo is %x\n", self->bufinfo.buf);
201+
210202
// verify that the matrix is big enough
211203
mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize - 1), false);
212204
} else {
213-
mp_printf(&mp_plat_print, "CH IS reconstruct NO framebuffer\n");
214205
common_hal_is31fl3741_free_impl(self->bufinfo.buf);
215206

216207
self->framebuffer = NULL;
@@ -263,7 +254,6 @@ void common_hal_is31fl3741_is31fl3741_reconstruct(is31fl3741_is31fl3741_obj_t *s
263254
}
264255

265256
void common_hal_is31fl3741_is31fl3741_deinit(is31fl3741_is31fl3741_obj_t *self) {
266-
mp_printf(&mp_plat_print, "IS CH Deinit\n");
267257
/*
268258
if (self->timer) {
269259
common_hal_is31fl3741_timer_free(self->timer);
@@ -291,58 +281,53 @@ void common_hal_is31fl3741_is31fl3741_deinit(is31fl3741_is31fl3741_obj_t *self)
291281
}
292282

293283
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-
}*/
302284
self->paused = paused;
303285
}
304286

305287
bool common_hal_is31fl3741_is31fl3741_get_paused(is31fl3741_is31fl3741_obj_t *self) {
306-
mp_printf(&mp_plat_print, "CH IS get paused\n");
307288
return self->paused;
308289
}
309290

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+
}
312304

313305
if (!self->paused) {
314306
uint32_t *buffer = self->bufinfo.buf;
315307
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+
}
320313
}
321-
// mp_printf(&mp_plat_print, "\n");
322314
}
323-
//
324-
// _PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
325-
// _PM_swapbuffer_maybe(&self->protomatter);
326315
}
327316
}
328317

329318
int common_hal_is31fl3741_is31fl3741_get_width(is31fl3741_is31fl3741_obj_t *self) {
330-
mp_printf(&mp_plat_print, "CH IS get width\n");
331319
return self->width;
332320
}
333321

334322
int common_hal_is31fl3741_is31fl3741_get_height(is31fl3741_is31fl3741_obj_t *self) {
335-
mp_printf(&mp_plat_print, "CH IS get height\n");
336323
return self->height;
337324
}
338325

339326
void *common_hal_is31fl3741_allocator_impl(size_t sz) {
340-
mp_printf(&mp_plat_print, "CH IS allocator\n");
341327
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false, true);
342328
return allocation ? allocation->ptr : NULL;
343329
}
344330

345331
void common_hal_is31fl3741_free_impl(void *ptr_in) {
346-
mp_printf(&mp_plat_print, "CH IS free\n");
347332
free_memory(allocation_from_ptr(ptr_in));
348333
}

0 commit comments

Comments
 (0)