summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorKevin Matocha <kmatocha@icloud.com>2020-08-21 14:19:58 -0500
committerKevin Matocha <kmatocha@icloud.com>2020-08-21 14:19:58 -0500
commit3753ea3cd8cc8725ae39e4fd0e7660f62fa430cc (patch)
treef7ec40b336aeae4a1d8b908928057374268aa6af /shared-module
parent24ca133396574dba972baaecf211bdb2f7904469 (diff)
parent5771be9510be87c72a58cdf3f70ff3744d8ec169 (diff)
Merge remote-tracking branch 'source/main' into main
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/_pixelbuf/PixelBuf.c48
-rw-r--r--shared-module/board/__init__.c14
-rw-r--r--shared-module/displayio/__init__.c12
3 files changed, 56 insertions, 18 deletions
diff --git a/shared-module/_pixelbuf/PixelBuf.c b/shared-module/_pixelbuf/PixelBuf.c
index 9d671e454..f3e679631 100644
--- a/shared-module/_pixelbuf/PixelBuf.c
+++ b/shared-module/_pixelbuf/PixelBuf.c
@@ -132,6 +132,18 @@ void common_hal__pixelbuf_pixelbuf_set_brightness(mp_obj_t self_in, mp_float_t b
}
}
+uint8_t _pixelbuf_get_as_uint8(mp_obj_t obj) {
+ if (MP_OBJ_IS_SMALL_INT(obj)) {
+ return MP_OBJ_SMALL_INT_VALUE(obj);
+ } else if (MP_OBJ_IS_INT(obj)) {
+ return mp_obj_get_int_truncated(obj);
+ } else if (mp_obj_is_float(obj)) {
+ return (uint8_t)mp_obj_get_float(obj);
+ }
+ mp_raise_TypeError_varg(
+ translate("can't convert %q to %q"), mp_obj_get_type_qstr(obj), MP_QSTR_int);
+}
+
void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* w) {
pixelbuf_byteorder_details_t *byteorder = &self->byteorder;
// w is shared between white in NeoPixels and brightness in dotstars (so that DotStars can have
@@ -142,8 +154,8 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
*w = 0;
}
- if (MP_OBJ_IS_INT(color)) {
- mp_int_t value = mp_obj_get_int_truncated(color);
+ if (MP_OBJ_IS_INT(color) || mp_obj_is_float(color)) {
+ mp_int_t value = MP_OBJ_IS_INT(color) ? mp_obj_get_int_truncated(color) : mp_obj_get_float(color);
*r = value >> 16 & 0xff;
*g = (value >> 8) & 0xff;
*b = value & 0xff;
@@ -155,9 +167,9 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
mp_raise_ValueError_varg(translate("Expected tuple of length %d, got %d"), byteorder->bpp, len);
}
- *r = mp_obj_get_int_truncated(items[PIXEL_R]);
- *g = mp_obj_get_int_truncated(items[PIXEL_G]);
- *b = mp_obj_get_int_truncated(items[PIXEL_B]);
+ *r = _pixelbuf_get_as_uint8(items[PIXEL_R]);
+ *g = _pixelbuf_get_as_uint8(items[PIXEL_G]);
+ *b = _pixelbuf_get_as_uint8(items[PIXEL_B]);
if (len > 3) {
if (mp_obj_is_float(items[PIXEL_W])) {
*w = 255 * mp_obj_get_float(items[PIXEL_W]);
@@ -218,17 +230,35 @@ void _pixelbuf_set_pixel(pixelbuf_pixelbuf_obj_t* self, size_t index, mp_obj_t v
_pixelbuf_set_pixel_color(self, index, r, g, b, w);
}
-void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, mp_int_t step, size_t slice_len, mp_obj_t* values) {
+void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, mp_int_t step, size_t slice_len, mp_obj_t* values,
+ mp_obj_tuple_t *flatten_to)
+{
pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
- for (size_t i = 0; i < slice_len; i++) {
- _pixelbuf_set_pixel(self, start, values[i]);
- start+=step;
+ mp_obj_iter_buf_t iter_buf;
+ mp_obj_t iterable = mp_getiter(values, &iter_buf);
+ mp_obj_t item;
+ size_t i = 0;
+ bool flattened = flatten_to != mp_const_none;
+ if (flattened) flatten_to->len = self->bytes_per_pixel;
+ while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
+ if (flattened) {
+ flatten_to->items[i % self->bytes_per_pixel] = item;
+ if (++i % self->bytes_per_pixel == 0) {
+ _pixelbuf_set_pixel(self, start, flatten_to);
+ start+=step;
+ }
+ } else {
+ _pixelbuf_set_pixel(self, start, item);
+ start+=step;
+ }
}
if (self->auto_write) {
common_hal__pixelbuf_pixelbuf_show(self_in);
}
}
+
+
void common_hal__pixelbuf_pixelbuf_set_pixel(mp_obj_t self_in, size_t index, mp_obj_t value) {
pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
_pixelbuf_set_pixel(self, index, value);
diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c
index 2c9139d8a..265c6517f 100644
--- a/shared-module/board/__init__.c
+++ b/shared-module/board/__init__.c
@@ -39,6 +39,11 @@
#include "shared-module/displayio/__init__.h"
#endif
+#if CIRCUITPY_SHARPDISPLAY
+#include "shared-bindings/sharpdisplay/SharpMemoryFramebuffer.h"
+#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
+#endif
+
#if BOARD_I2C
// Statically allocate the I2C object so it can live past the end of the heap and into the next VM.
// That way it can be used by built-in I2CDisplay displays and be accessible through board.I2C().
@@ -148,10 +153,17 @@ void reset_board_busses(void) {
bool display_using_spi = false;
#if CIRCUITPY_DISPLAYIO
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- if (displays[i].fourwire_bus.bus == spi_singleton) {
+ mp_const_obj_t bus_type = displays[i].bus_base.type;
+ if (bus_type == &displayio_fourwire_type && displays[i].fourwire_bus.bus == spi_singleton) {
+ display_using_spi = true;
+ break;
+ }
+ #if CIRCUITPY_SHARPDISPLAY
+ if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type && displays[i].sharpdisplay.bus == spi_singleton) {
display_using_spi = true;
break;
}
+ #endif
}
#endif
if (!display_using_spi) {
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index 5afcba35e..101dac4b3 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -26,7 +26,7 @@
primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];
-#if CIRCUITPY_RGBMATRIX || CIRCUITPY_SHARPDISPLAY
+#if CIRCUITPY_RGBMATRIX
STATIC bool any_display_uses_this_framebuffer(mp_obj_base_t *obj) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].display_base.type == &framebufferio_framebufferdisplay_type) {
@@ -186,11 +186,7 @@ void reset_displays(void) {
#if CIRCUITPY_SHARPDISPLAY
} else if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
sharpdisplay_framebuffer_obj_t * sharp = &displays[i].sharpdisplay;
- if(any_display_uses_this_framebuffer(&sharp->base)) {
- common_hal_sharpdisplay_framebuffer_reset(sharp);
- } else {
- common_hal_sharpdisplay_framebuffer_deinit(sharp);
- }
+ common_hal_sharpdisplay_framebuffer_reset(sharp);
#endif
} else {
// Not an active display bus.
@@ -398,8 +394,8 @@ primary_display_t *allocate_display_or_raise(void) {
}
primary_display_t *allocate_display_bus(void) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- mp_const_obj_t display_type = displays[i].display.base.type;
- if (display_type == NULL || display_type == &mp_type_NoneType) {
+ mp_const_obj_t display_bus_type = displays[i].bus_base.type;
+ if (display_bus_type == NULL || display_bus_type == &mp_type_NoneType) {
return &displays[i];
}
}