From b6178c9d85876c771b08188373df568da0acda87 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Thu, 25 Jul 2019 15:05:30 -0400 Subject: WIP on exposing fill_area --- shared-bindings/displayio/Display.c | 116 ++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 361a37ece..2b9c74066 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -348,10 +348,125 @@ const mp_obj_property_t displayio_display_bus_obj = { }; +//| .. attribute:: screenshot +//| +//| Take a screenshot. +//| +//| +/* STATIC mp_obj_t displayio_display_obj_get_screenshot(mp_obj_t self_in) { */ +/* displayio_display_obj_t *self = native_display(self_in); */ +/* return mp_const_none; */ +/* } */ +/* MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_screenshot_obj, displayio_display_obj_get_screenshot); */ + +/* const mp_obj_property_t displayio_display_screenshot_obj = { */ +/* .base.type = &mp_type_property, */ +/* .proxy = {(mp_obj_t)&displayio_display_get_screenshot_obj, */ +/* (mp_obj_t)&mp_const_none_obj, */ +/* (mp_obj_t)&mp_const_none_obj}, */ +/* }; */ + + +#include "py/objarray.h" +mp_obj_array_t *array_new(char typecode, size_t n); +mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value); + +//| .. method:: fill_area(x, y, w, h) +//| +//| Switches to displaying the given group of layers. When group is None, the default +//| CircuitPython terminal will be shown. +//| +//| :param int x: The left edge of the area +//| :param int y: The top edge of the area +//| :param int w: The width of the area +//| :param int h: The height of the area +STATIC mp_obj_t displayio_display_obj_fill_area(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_x, ARG_y, ARG_width, ARG_height }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, + { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, + { MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, + { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + displayio_display_obj_t *self = native_display(pos_args[0]); + mp_int_t x = args[ARG_x].u_int; + mp_int_t y = args[ARG_y].u_int; + mp_int_t w = args[ARG_width].u_int; + mp_int_t h = args[ARG_height].u_int; + + uint16_t buffer_size = 128; // In uint32_ts + displayio_area_t area = { + .x1 = x, + .y1 = y, + .x2 = x + w, + .y2 = y + h + }; + displayio_area_t clipped; + // Clip the area to the display by overlapping the areas. If there is no overlap then we're done. + if (!displayio_display_clip_area(self, &area, &clipped)) { + return mp_const_none; + } + uint16_t subrectangles = 1; + uint16_t rows_per_buffer = displayio_area_height(&clipped); + uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / self->colorspace.depth; + uint16_t pixels_per_buffer = displayio_area_size(&clipped); + if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { + rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped); + if (rows_per_buffer == 0) { + rows_per_buffer = 1; + } + // If pixels are packed by column then ensure rows_per_buffer is on a byte boundary. + if (self->colorspace.depth < 8 && !self->colorspace.pixels_in_byte_share_row) { + uint8_t pixels_per_byte = 8 / self->colorspace.depth; + if (rows_per_buffer % pixels_per_byte != 0) { + rows_per_buffer -= rows_per_buffer % pixels_per_byte; + } + } + subrectangles = displayio_area_height(&clipped) / rows_per_buffer; + if (displayio_area_height(&clipped) % rows_per_buffer != 0) { + subrectangles++; + } + pixels_per_buffer = rows_per_buffer * displayio_area_width(&clipped); + buffer_size = pixels_per_buffer / pixels_per_word; + if (pixels_per_buffer % pixels_per_word) { + buffer_size += 1; + } + } + + // Allocated and shared as a uint32_t array so the compiler knows the + // alignment everywhere. + uint32_t buffer[buffer_size]; + volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1; + uint32_t mask[mask_length]; + + for (uint16_t k = 0; k < mask_length; k++) { + mask[k] = 0x00000000; + } + for (uint16_t k = 0; k < buffer_size; k++) { + buffer[k] = 0x00000000; + } + + displayio_display_fill_area(self, &area, mask, buffer); + + mp_obj_array_t *result = array_new(BYTEARRAY_TYPECODE, buffer_size); + for (int offset = 0; offset < buffer_size; offset++) { + array_subscr(result, MP_OBJ_NEW_SMALL_INT(offset), MP_OBJ_NEW_SMALL_INT(buffer[offset])); + } + return result; +} +MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_fill_area_obj, 1, displayio_display_obj_fill_area); + + + + STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_display_show_obj) }, { MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_display_refresh_soon_obj) }, { MP_ROM_QSTR(MP_QSTR_wait_for_frame), MP_ROM_PTR(&displayio_display_wait_for_frame_obj) }, + { MP_ROM_QSTR(MP_QSTR_fill_area), MP_ROM_PTR(&displayio_display_fill_area_obj) }, { MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&displayio_display_brightness_obj) }, { MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&displayio_display_auto_brightness_obj) }, @@ -359,6 +474,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) }, { MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) }, + // { MP_ROM_QSTR(MP_QSTR_screenshot), MP_ROM_PTR(&displayio_display_screenshot_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table); -- cgit v1.2.3 From 741cd9c40a4b3368ffa92286498883bd29b0fb70 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Wed, 31 Jul 2019 12:47:32 -0400 Subject: Get fill_area working --- shared-bindings/displayio/Display.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 2b9c74066..6338fe459 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -451,9 +451,15 @@ STATIC mp_obj_t displayio_display_obj_fill_area(size_t n_args, const mp_obj_t *p displayio_display_fill_area(self, &area, mask, buffer); - mp_obj_array_t *result = array_new(BYTEARRAY_TYPECODE, buffer_size); - for (int offset = 0; offset < buffer_size; offset++) { - array_subscr(result, MP_OBJ_NEW_SMALL_INT(offset), MP_OBJ_NEW_SMALL_INT(buffer[offset])); + mp_obj_array_t *result = array_new(BYTEARRAY_TYPECODE, buffer_size * 4); + int byte_offset = 0; + for (int word_offset = 0; word_offset < buffer_size; word_offset++) { + uint32_t word = buffer[word_offset]; + for (int byte_count = 0; byte_count < 4; byte_count++) { + array_subscr(result, MP_OBJ_NEW_SMALL_INT(byte_offset), MP_OBJ_NEW_SMALL_INT(word & 0x000000FF)); + word >>= 8; + byte_offset++; + } } return result; } -- cgit v1.2.3 From 1f9cb44fa3a09996d042b7b9e01864bf2feac363 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Wed, 31 Jul 2019 15:00:21 -0400 Subject: Expose rotation with a property --- shared-bindings/displayio/Display.c | 18 ++++++++++++++++++ shared-bindings/displayio/Display.h | 1 + shared-module/displayio/Display.c | 6 +++++- shared-module/displayio/Display.h | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 6338fe459..ab9bad19c 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -329,6 +329,23 @@ const mp_obj_property_t displayio_display_height_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| .. attribute:: rotation +//| +//| The rotation of the display as an int in degrees. +//| +STATIC mp_obj_t displayio_display_obj_get_rotation(mp_obj_t self_in) { + displayio_display_obj_t *self = native_display(self_in); + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_rotation(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_rotation_obj, displayio_display_obj_get_rotation); + +const mp_obj_property_t displayio_display_rotation_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_display_get_rotation_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + //| .. attribute:: bus //| //| The bus being used by the display @@ -479,6 +496,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) }, + { MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&displayio_display_rotation_obj) }, { MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) }, // { MP_ROM_QSTR(MP_QSTR_screenshot), MP_ROM_PTR(&displayio_display_screenshot_obj) }, }; diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index e765e6f25..40793be14 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -68,6 +68,7 @@ void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* s uint16_t common_hal_displayio_display_get_width(displayio_display_obj_t* self); uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t* self); +uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self); mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t* self); bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, mp_float_t brightness); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index a8515b9e5..74a96fac2 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -119,7 +119,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->width = width; self->height = height; - rotation = rotation % 360; + self->rotation = rotation % 360; self->transform.x = 0; self->transform.y = 0; self->transform.scale = 1; @@ -242,6 +242,10 @@ uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t* self){ return self->height; } +uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self){ + return self->rotation; +} + void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* self, bool auto_brightness) { self->auto_brightness = auto_brightness; } diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 96d1c06d5..74ae175b1 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -55,6 +55,7 @@ typedef struct { mp_float_t current_brightness; uint16_t width; uint16_t height; + uint16_t rotation; _displayio_colorspace_t colorspace; int16_t colstart; int16_t rowstart; -- cgit v1.2.3 From 263f6f439b659b31f283b40a1a14baac489e0ed9 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Wed, 7 Aug 2019 15:27:04 -0400 Subject: Remove obsolete experimental property --- shared-bindings/displayio/Display.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index b3ac532a3..e4e580d27 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -373,23 +373,6 @@ const mp_obj_property_t displayio_display_bus_obj = { }; -//| .. attribute:: screenshot -//| -//| Take a screenshot. -//| -//| -/* STATIC mp_obj_t displayio_display_obj_get_screenshot(mp_obj_t self_in) { */ -/* displayio_display_obj_t *self = native_display(self_in); */ -/* return mp_const_none; */ -/* } */ -/* MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_screenshot_obj, displayio_display_obj_get_screenshot); */ - -/* const mp_obj_property_t displayio_display_screenshot_obj = { */ -/* .base.type = &mp_type_property, */ -/* .proxy = {(mp_obj_t)&displayio_display_get_screenshot_obj, */ -/* (mp_obj_t)&mp_const_none_obj, */ -/* (mp_obj_t)&mp_const_none_obj}, */ -/* }; */ #include "py/objarray.h" -- cgit v1.2.3 From 239ad197657ffbfcaa95a095c6f0773033dd608a Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Wed, 7 Aug 2019 15:27:43 -0400 Subject: Pass in preallocated result buffer --- shared-bindings/displayio/Display.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index e4e580d27..91b03de4f 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -389,12 +389,13 @@ mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value); //| :param int w: The width of the area //| :param int h: The height of the area STATIC mp_obj_t displayio_display_obj_fill_area(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_x, ARG_y, ARG_width, ARG_height }; + enum { ARG_x, ARG_y, ARG_width, ARG_height, ARG_buffer }; static const mp_arg_t allowed_args[] = { { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, { MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, + { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_KW_ONLY, {} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -404,6 +405,11 @@ STATIC mp_obj_t displayio_display_obj_fill_area(size_t n_args, const mp_obj_t *p mp_int_t y = args[ARG_y].u_int; mp_int_t w = args[ARG_width].u_int; mp_int_t h = args[ARG_height].u_int; + mp_obj_array_t *result = (mp_obj_array_t *)(args[ARG_buffer].u_obj); + + if (result->typecode != BYTEARRAY_TYPECODE) { + mp_raise_ValueError(translate("Buffer is not a bytearray")); + } uint16_t buffer_size = 128; // In uint32_ts displayio_area_t area = { @@ -459,17 +465,20 @@ STATIC mp_obj_t displayio_display_obj_fill_area(size_t n_args, const mp_obj_t *p displayio_display_fill_area(self, &area, mask, buffer); - mp_obj_array_t *result = array_new(BYTEARRAY_TYPECODE, buffer_size * 4); - int byte_offset = 0; - for (int word_offset = 0; word_offset < buffer_size; word_offset++) { - uint32_t word = buffer[word_offset]; - for (int byte_count = 0; byte_count < 4; byte_count++) { - array_subscr(result, MP_OBJ_NEW_SMALL_INT(byte_offset), MP_OBJ_NEW_SMALL_INT(word & 0x000000FF)); - word >>= 8; - byte_offset++; + if ((result->len + result->free) >= (buffer_size * 4)) { + int byte_offset = 0; + for (int word_offset = 0; word_offset < buffer_size; word_offset++) { + uint32_t word = buffer[word_offset]; + for (int byte_count = 0; byte_count < 4; byte_count++) { + array_subscr(result, MP_OBJ_NEW_SMALL_INT(byte_offset), MP_OBJ_NEW_SMALL_INT(word & 0x000000FF)); + word >>= 8; + byte_offset++; + } } + return result; + } else { + mp_raise_ValueError(translate("Buffer is too small")); } - return result; } MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_fill_area_obj, 1, displayio_display_obj_fill_area); -- cgit v1.2.3 From 7a235f3746291d2cf8d11f52e7d211b98d535f98 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Fri, 16 Aug 2019 21:10:09 -0400 Subject: Simplify to only extracting one line Since this was the usecase, doing so simplifies the function significantly. --- shared-bindings/displayio/Display.c | 72 ++++++++++--------------------------- 1 file changed, 18 insertions(+), 54 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 91b03de4f..b14533ab2 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -373,81 +373,46 @@ const mp_obj_property_t displayio_display_bus_obj = { }; - - #include "py/objarray.h" mp_obj_array_t *array_new(char typecode, size_t n); mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value); -//| .. method:: fill_area(x, y, w, h) +//| .. method:: fill_row(y, buffer) //| -//| Switches to displaying the given group of layers. When group is None, the default -//| CircuitPython terminal will be shown. +//| Extract the pixels fro a single row //| -//| :param int x: The left edge of the area //| :param int y: The top edge of the area -//| :param int w: The width of the area -//| :param int h: The height of the area -STATIC mp_obj_t displayio_display_obj_fill_area(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_x, ARG_y, ARG_width, ARG_height, ARG_buffer }; +//| :param bytearray buffer: The buffer in which to place the pixel data +STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_y, ARG_buffer }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, - { MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, - { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_KW_ONLY, {} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - displayio_display_obj_t *self = native_display(pos_args[0]); - mp_int_t x = args[ARG_x].u_int; mp_int_t y = args[ARG_y].u_int; - mp_int_t w = args[ARG_width].u_int; - mp_int_t h = args[ARG_height].u_int; mp_obj_array_t *result = (mp_obj_array_t *)(args[ARG_buffer].u_obj); if (result->typecode != BYTEARRAY_TYPECODE) { - mp_raise_ValueError(translate("Buffer is not a bytearray")); + mp_raise_ValueError(translate("Buffer is not a bytearray.")); + } + if (self->colorspace.depth != 16) { + mp_raise_ValueError(translate("Display must have a 16 bit colorspace.")); } - uint16_t buffer_size = 128; // In uint32_ts displayio_area_t area = { - .x1 = x, + .x1 = 0, .y1 = y, - .x2 = x + w, - .y2 = y + h + .x2 = self->width, + .y2 = y + 1 }; - displayio_area_t clipped; - // Clip the area to the display by overlapping the areas. If there is no overlap then we're done. - if (!displayio_display_clip_area(self, &area, &clipped)) { - return mp_const_none; - } - uint16_t subrectangles = 1; - uint16_t rows_per_buffer = displayio_area_height(&clipped); uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / self->colorspace.depth; - uint16_t pixels_per_buffer = displayio_area_size(&clipped); - if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { - rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped); - if (rows_per_buffer == 0) { - rows_per_buffer = 1; - } - // If pixels are packed by column then ensure rows_per_buffer is on a byte boundary. - if (self->colorspace.depth < 8 && !self->colorspace.pixels_in_byte_share_row) { - uint8_t pixels_per_byte = 8 / self->colorspace.depth; - if (rows_per_buffer % pixels_per_byte != 0) { - rows_per_buffer -= rows_per_buffer % pixels_per_byte; - } - } - subrectangles = displayio_area_height(&clipped) / rows_per_buffer; - if (displayio_area_height(&clipped) % rows_per_buffer != 0) { - subrectangles++; - } - pixels_per_buffer = rows_per_buffer * displayio_area_width(&clipped); - buffer_size = pixels_per_buffer / pixels_per_word; - if (pixels_per_buffer % pixels_per_word) { - buffer_size += 1; - } + uint16_t buffer_size = self->width / pixels_per_word; + uint16_t pixels_per_buffer = displayio_area_size(&area); + if (pixels_per_buffer % pixels_per_word) { + buffer_size += 1; } // Allocated and shared as a uint32_t array so the compiler knows the @@ -480,7 +445,7 @@ STATIC mp_obj_t displayio_display_obj_fill_area(size_t n_args, const mp_obj_t *p mp_raise_ValueError(translate("Buffer is too small")); } } -MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_fill_area_obj, 1, displayio_display_obj_fill_area); +MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_fill_row_obj, 1, displayio_display_obj_fill_row); @@ -489,7 +454,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_display_show_obj) }, { MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_display_refresh_soon_obj) }, { MP_ROM_QSTR(MP_QSTR_wait_for_frame), MP_ROM_PTR(&displayio_display_wait_for_frame_obj) }, - { MP_ROM_QSTR(MP_QSTR_fill_area), MP_ROM_PTR(&displayio_display_fill_area_obj) }, + { MP_ROM_QSTR(MP_QSTR_fill_row), MP_ROM_PTR(&displayio_display_fill_row_obj) }, { MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&displayio_display_brightness_obj) }, { MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&displayio_display_auto_brightness_obj) }, @@ -498,7 +463,6 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) }, { MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&displayio_display_rotation_obj) }, { MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) }, - // { MP_ROM_QSTR(MP_QSTR_screenshot), MP_ROM_PTR(&displayio_display_screenshot_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table); -- cgit v1.2.3 From 2b7897cdeddd2651996fc1c3afff060a42d1609b Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 20 Aug 2019 10:03:36 -0400 Subject: Fix typo --- shared-bindings/displayio/Display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index b14533ab2..4ae3687b3 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -379,7 +379,7 @@ mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value); //| .. method:: fill_row(y, buffer) //| -//| Extract the pixels fro a single row +//| Extract the pixels from a single row //| //| :param int y: The top edge of the area //| :param bytearray buffer: The buffer in which to place the pixel data -- cgit v1.2.3 From 10bc0d29d11b1806bd5620850daf3c6708643125 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 20 Aug 2019 10:05:09 -0400 Subject: Switch to positional parameters --- shared-bindings/displayio/Display.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 4ae3687b3..4afc4ca74 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -384,10 +384,10 @@ mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value); //| :param int y: The top edge of the area //| :param bytearray buffer: The buffer in which to place the pixel data STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_y, ARG_buffer }; + enum { ARG_y, ARG_buffer }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, - { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_KW_ONLY, {} }, + { MP_QSTR_y, MP_ARG_INT | MP_ARG_REQUIRED, {.u_int = -1} }, + { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); -- cgit v1.2.3 From 53bb95a0233baa8cae7bbb36f2887a9475c1e37f Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 20 Aug 2019 10:05:41 -0400 Subject: Rework to simplify --- shared-bindings/displayio/Display.c | 53 ++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 4afc4ca74..508d10ea4 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -415,31 +415,36 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po buffer_size += 1; } - // Allocated and shared as a uint32_t array so the compiler knows the - // alignment everywhere. - uint32_t buffer[buffer_size]; - volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1; - uint32_t mask[mask_length]; - - for (uint16_t k = 0; k < mask_length; k++) { - mask[k] = 0x00000000; - } - for (uint16_t k = 0; k < buffer_size; k++) { - buffer[k] = 0x00000000; - } - - displayio_display_fill_area(self, &area, mask, buffer); - - if ((result->len + result->free) >= (buffer_size * 4)) { - int byte_offset = 0; - for (int word_offset = 0; word_offset < buffer_size; word_offset++) { - uint32_t word = buffer[word_offset]; - for (int byte_count = 0; byte_count < 4; byte_count++) { - array_subscr(result, MP_OBJ_NEW_SMALL_INT(byte_offset), MP_OBJ_NEW_SMALL_INT(word & 0x000000FF)); - word >>= 8; - byte_offset++; - } + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE); + uint32_t *result_buffer = bufinfo.buf; + size_t result_buffer_size = bufinfo.len; + + if (result_buffer_size >= (buffer_size * 4)) { + // Allocated and shared as a uint32_t array so the compiler knows the + // alignment everywhere. + /* uint32_t buffer[buffer_size]; */ + volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1; + uint32_t mask[mask_length]; + + for (uint16_t k = 0; k < mask_length; k++) { + mask[k] = 0x00000000; } + /* for (uint16_t k = 0; k < buffer_size; k++) { */ + /* buffer[k] = 0x00000000; */ + /* } */ + + + displayio_display_fill_area(self, &area, mask, result_buffer); + /* int byte_offset = 0; */ + /* for (int word_offset = 0; word_offset < buffer_size; word_offset++) { */ + /* uint32_t word = buffer[word_offset]; */ + /* for (int byte_count = 0; byte_count < 4; byte_count++) { */ + /* array_subscr(result, MP_OBJ_NEW_SMALL_INT(byte_offset), MP_OBJ_NEW_SMALL_INT(word & 0x000000FF)); */ + /* word >>= 8; */ + /* byte_offset++; */ + /* } */ + /* } */ return result; } else { mp_raise_ValueError(translate("Buffer is too small")); -- cgit v1.2.3 From f3d476aad85ba497c060f44dee3009d018802b0e Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 20 Aug 2019 12:25:56 -0400 Subject: Remove temporarily comments code --- shared-bindings/displayio/Display.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 508d10ea4..df6dde53a 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -421,30 +421,14 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po size_t result_buffer_size = bufinfo.len; if (result_buffer_size >= (buffer_size * 4)) { - // Allocated and shared as a uint32_t array so the compiler knows the - // alignment everywhere. - /* uint32_t buffer[buffer_size]; */ volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1; uint32_t mask[mask_length]; for (uint16_t k = 0; k < mask_length; k++) { mask[k] = 0x00000000; } - /* for (uint16_t k = 0; k < buffer_size; k++) { */ - /* buffer[k] = 0x00000000; */ - /* } */ - displayio_display_fill_area(self, &area, mask, result_buffer); - /* int byte_offset = 0; */ - /* for (int word_offset = 0; word_offset < buffer_size; word_offset++) { */ - /* uint32_t word = buffer[word_offset]; */ - /* for (int byte_count = 0; byte_count < 4; byte_count++) { */ - /* array_subscr(result, MP_OBJ_NEW_SMALL_INT(byte_offset), MP_OBJ_NEW_SMALL_INT(word & 0x000000FF)); */ - /* word >>= 8; */ - /* byte_offset++; */ - /* } */ - /* } */ return result; } else { mp_raise_ValueError(translate("Buffer is too small")); -- cgit v1.2.3 From 0fd886fa7f923c6c8a1473712d238084d9004432 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 20 Aug 2019 13:45:58 -0400 Subject: Remove array cast --- shared-bindings/displayio/Display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index df6dde53a..b7b9a6981 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -393,7 +393,7 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); displayio_display_obj_t *self = native_display(pos_args[0]); mp_int_t y = args[ARG_y].u_int; - mp_obj_array_t *result = (mp_obj_array_t *)(args[ARG_buffer].u_obj); + mp_obj_array_t *result = args[ARG_buffer].u_obj; if (result->typecode != BYTEARRAY_TYPECODE) { mp_raise_ValueError(translate("Buffer is not a bytearray.")); -- cgit v1.2.3 From eb0a8cc0bf5ccb93a4ad89e2cf965a45986fec2e Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 20 Aug 2019 13:48:12 -0400 Subject: Move the get_buffer call earlier --- shared-bindings/displayio/Display.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index b7b9a6981..099035f41 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -402,6 +402,9 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po mp_raise_ValueError(translate("Display must have a 16 bit colorspace.")); } + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE); + displayio_area_t area = { .x1 = 0, .y1 = y, @@ -415,8 +418,6 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po buffer_size += 1; } - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE); uint32_t *result_buffer = bufinfo.buf; size_t result_buffer_size = bufinfo.len; -- cgit v1.2.3 From 56aad056daf1a3377e437d011da4f6cf9a7c82ba Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 20 Aug 2019 17:00:24 -0400 Subject: getting the buffer info should happen first (due to its check) --- shared-bindings/displayio/Display.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 099035f41..c8cb66f69 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -395,6 +395,9 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po mp_int_t y = args[ARG_y].u_int; mp_obj_array_t *result = args[ARG_buffer].u_obj; + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE); + if (result->typecode != BYTEARRAY_TYPECODE) { mp_raise_ValueError(translate("Buffer is not a bytearray.")); } @@ -402,9 +405,6 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po mp_raise_ValueError(translate("Display must have a 16 bit colorspace.")); } - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE); - displayio_area_t area = { .x1 = 0, .y1 = y, -- cgit v1.2.3 From 8bbab0131671e5a30606ebaba11c8c38487344e3 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Wed, 21 Aug 2019 13:57:52 -0400 Subject: Remove unneeded lines --- shared-bindings/displayio/Display.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index c8cb66f69..92af86929 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -373,10 +373,6 @@ const mp_obj_property_t displayio_display_bus_obj = { }; -#include "py/objarray.h" -mp_obj_array_t *array_new(char typecode, size_t n); -mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value); - //| .. method:: fill_row(y, buffer) //| //| Extract the pixels from a single row -- cgit v1.2.3 From 99a3da3b60d518ee3b590fb6c693c1e189e3bb30 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Wed, 21 Aug 2019 15:24:39 -0400 Subject: Get rid of the last bits of array dependancy --- shared-bindings/displayio/Display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 92af86929..0c48b0cc5 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -389,12 +389,12 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); displayio_display_obj_t *self = native_display(pos_args[0]); mp_int_t y = args[ARG_y].u_int; - mp_obj_array_t *result = args[ARG_buffer].u_obj; + mp_obj_t *result = args[ARG_buffer].u_obj; mp_buffer_info_t bufinfo; mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE); - if (result->typecode != BYTEARRAY_TYPECODE) { + if (bufinfo.typecode != BYTEARRAY_TYPECODE) { mp_raise_ValueError(translate("Buffer is not a bytearray.")); } if (self->colorspace.depth != 16) { -- cgit v1.2.3