Skip to content

Commit 9fa3fef

Browse files
committed
Cleanup
1 parent 2f277eb commit 9fa3fef

File tree

6 files changed

+28
-51
lines changed

6 files changed

+28
-51
lines changed

shared-bindings/is31fl3741/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
6+
* Copyright (c) 2021 Mark Komus
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal

shared-bindings/is31fl3741/is31fl3741.c

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
6+
* Copyright (c) 2021 Mark Komus
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -29,57 +29,29 @@
2929
#include "py/runtime.h"
3030
#include "py/objarray.h"
3131

32-
// #include "common-hal/is31fl3741/is31fl3741.h"
3332
#include "shared-bindings/is31fl3741/is31fl3741.h"
34-
#include "shared-bindings/microcontroller/Pin.h"
35-
#include "shared-bindings/microcontroller/__init__.h"
33+
// #include "shared-bindings/microcontroller/Pin.h"
34+
// #include "shared-bindings/microcontroller/__init__.h"
3635
#include "shared-bindings/util.h"
3736
#include "shared-module/displayio/__init__.h"
3837
#include "shared-module/framebufferio/__init__.h"
3938
#include "shared-module/framebufferio/FramebufferDisplay.h"
4039
#include "shared-bindings/busio/I2C.h"
4140

4241
//| class is31fl3741:
43-
//| """Displays an in-memory framebuffer to a HUB75-style RGB LED matrix."""
42+
//| """Displays an in-memory framebuffer to a IS31FL3741 drive display."""
4443
//|
4544

46-
// extern Protomatter_core *_PM_protoPtr;
47-
48-
4945
//| def __init__(self, *, width: int) -> None:
50-
//| """Create a Is31fl3741 object with the given attributes. The height of
51-
//| the display is determined by the number of rgb and address pins and the number of tiles:
52-
//| ``len(rgb_pins) // 3 * 2 ** len(address_pins) * abs(tile)``. With 6 RGB pins, 4
53-
//| address lines, and a single matrix, the display will be 32 pixels tall. If the optional height
54-
//| parameter is specified and is not 0, it is checked against the calculated
55-
//| height.
56-
//|
57-
//| Up to 30 RGB pins and 8 address pins are supported.
58-
//|
59-
//| The RGB pins must be within a single "port" and performance and memory
60-
//| usage are best when they are all within "close by" bits of the port.
61-
//| The clock pin must also be on the same port as the RGB pins. See the
62-
//| documentation of the underlying protomatter C library for more
63-
//| information. Generally, Adafruit's interface boards are designed so
64-
//| that these requirements are met when matched with the intended
65-
//| microcontroller board. For instance, the Feather M4 Express works
66-
//| together with the RGB Matrix Feather.
46+
//| """Create a Is31fl3741 object with the given attributes.
6747
//|
68-
//| The framebuffer is in "RGB565" format.
69-
//|
70-
//| "RGB565" means that it is organized as a series of 16-bit numbers
71-
//| where the highest 5 bits are interpreted as red, the next 6 as
72-
//| green, and the final 5 as blue. The object can be any buffer, but
73-
//| `array.array` and ``ulab.ndarray`` objects are most often useful.
74-
//| To update the content, modify the framebuffer and call refresh.
48+
//| The framebuffer is in "RGB888" format using 4 bytes per pixel.
49+
//| Bits 24-31 are ignored. The format is in RGB order.
7550
//|
7651
//| If a framebuffer is not passed in, one is allocated and initialized
7752
//| to all black. In any case, the framebuffer can be retrieved
7853
//| by passing the Is31fl3741 object to memoryview().
7954
//|
80-
//| If doublebuffer is False, some memory is saved, but the display may
81-
//| flicker during updates.
82-
//|
8355
//| A Is31fl3741 is often used in conjunction with a
8456
//| `framebufferio.FramebufferDisplay`."""
8557
//|
@@ -136,7 +108,7 @@ STATIC mp_obj_t is31fl3741_is31fl3741_make_new(const mp_obj_type_t *type, size_t
136108
}
137109

138110
//| def deinit(self) -> None:
139-
//| """Free the resources (pins, timers, etc.) associated with this
111+
//| """Free the resources associated with this
140112
//| is31fl3741 instance. After deinitialization, no further operations
141113
//| may be performed."""
142114
//| ...
@@ -150,9 +122,9 @@ STATIC mp_obj_t is31fl3741_is31fl3741_deinit(mp_obj_t self_in) {
150122
STATIC MP_DEFINE_CONST_FUN_OBJ_1(is31fl3741_is31fl3741_deinit_obj, is31fl3741_is31fl3741_deinit);
151123

152124
static void check_for_deinit(is31fl3741_is31fl3741_obj_t *self) {
153-
// if (!self->protomatter.rgbPins) {
154-
// raise_deinited_error();
155-
// }
125+
if (self->framebuffer == NULL) {
126+
raise_deinited_error();
127+
}
156128
}
157129

158130
//| brightness: float
@@ -252,8 +224,6 @@ STATIC void is31fl3741_is31fl3741_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t
252224
*bufinfo = self->bufinfo;
253225
}
254226

255-
// These version exists so that the prototype matches the protocol,
256-
// avoiding a type cast that can hide errors
257227
STATIC void is31fl3741_is31fl3741_swapbuffers(mp_obj_t self_in, uint8_t *dirty_row_bitmap) {
258228
common_hal_is31fl3741_is31fl3741_refresh(self_in, dirty_row_bitmap);
259229
}
@@ -291,10 +261,9 @@ STATIC int is31fl3741_is31fl3741_get_bytes_per_cell_proto(mp_obj_t self_in) {
291261
}
292262

293263
STATIC int is31fl3741_is31fl3741_get_native_frames_per_second_proto(mp_obj_t self_in) {
294-
return 60;
264+
return 60; // This was just chosen may vary based on LEDs used?
295265
}
296266

297-
298267
STATIC const framebuffer_p_t is31fl3741_is31fl3741_proto = {
299268
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer)
300269
.get_bufinfo = is31fl3741_is31fl3741_get_bufinfo,

shared-bindings/is31fl3741/is31fl3741.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
6+
* Copyright (c) 2021 Mark Komus
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -27,7 +27,6 @@
2727
#pragma once
2828

2929
#include "shared-module/is31fl3741/is31fl3741.h"
30-
// #include "lib/protomatter/src/core.h"
3130

3231
extern const mp_obj_type_t is31fl3741_is31fl3741_type;
3332

shared-module/is31fl3741/allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
6+
* Copyright (c) 2021 Mark Komus
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal

shared-module/is31fl3741/is31fl3741.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
6+
* Copyright (c) 2021 Mark Komus
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -96,7 +96,7 @@ void common_hal_is31fl3741_is31fl3741_reconstruct(is31fl3741_is31fl3741_obj_t *s
9696
is31fl3741_send_enable(self->i2c, self->device_address);
9797
is31fl3741_set_current(self->i2c, self->device_address, 0xFF);
9898

99-
// set scale to max for all
99+
// set scale (brightness) to max for all LEDs
100100
for (int i; i < 351; i++) {
101101
is31fl3741_set_led(self->i2c, self->device_address, i, 0xFF, 2);
102102
}
@@ -111,6 +111,7 @@ void common_hal_is31fl3741_is31fl3741_deinit(is31fl3741_is31fl3741_obj_t *self)
111111

112112
if (self->i2c == &self->inline_i2c) {
113113
common_hal_busio_i2c_deinit(self->i2c);
114+
self->i2c = NULL;
114115
}
115116

116117
self->base.type = NULL;
@@ -151,6 +152,7 @@ void common_hal_is31fl3741_is31fl3741_refresh(is31fl3741_is31fl3741_obj_t *self,
151152

152153
if (!self->paused) {
153154
if (self->scale) {
155+
// Based on the Arduino IS31FL3741 driver code
154156
uint32_t *buffer = self->bufinfo.buf;
155157

156158
for (int x = 0; x < self->scale_width; x++) {
@@ -165,7 +167,7 @@ void common_hal_is31fl3741_is31fl3741_refresh(is31fl3741_is31fl3741_obj_t *self,
165167
gsum += (rgb >> 8) & 0xFF;
166168
bsum += rgb & 0xFF;
167169
}
168-
ptr += self->width; // canvas->width(); // Advance one scan line
170+
ptr += self->width; // Advance one scan line
169171
}
170172
rsum = rsum / 9;
171173
gsum = gsum / 9;
@@ -217,6 +219,9 @@ int common_hal_is31fl3741_is31fl3741_get_height(is31fl3741_is31fl3741_obj_t *sel
217219
void common_hal_displayio_is31fl3741_begin_transaction(is31fl3741_is31fl3741_obj_t *self) {
218220
while (!common_hal_busio_i2c_try_lock(self->i2c)) {
219221
RUN_BACKGROUND_TASKS;
222+
if (mp_hal_is_interrupted()) {
223+
break;
224+
}
220225
}
221226
}
222227

@@ -237,6 +242,10 @@ void is31fl3741_is31fl3741_collect_ptrs(is31fl3741_is31fl3741_obj_t *self) {
237242
gc_collect_ptr(self->framebuffer);
238243
}
239244

245+
// The following are routines to manipulate the IS31FL3741 chip
246+
// They are not meant to be called by user code but only used
247+
// internally.
248+
240249
uint8_t cur_page = 99; // set to invalid page to start
241250

242251
void is31fl3741_send_unlock(busio_i2c_obj_t *i2c, uint8_t addr) {

shared-module/is31fl3741/is31fl3741.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
6+
* Copyright (c) 2021 Mark Komus
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)