More improvements to Terminal:

* Fix Hallowing.
* Fix builds without displayio.
* Fix y bounds that appears as untrollable row of pixels.
* Add scrolling to TileGrid.
* Remove Sprite to save space. TileGrid is a drop in replacement.
This commit is contained in:
Scott Shawcroft 2019-01-29 15:04:07 -08:00
parent 6145f08cc8
commit 601a910f4e
No known key found for this signature in database
GPG Key ID: FD0EDC4B6C53CA59
18 changed files with 42 additions and 422 deletions

7
main.c
View File

@ -44,6 +44,7 @@
#include "lib/utils/pyexec.h"
#include "mpconfigboard.h"
#include "shared-module/displayio/__init__.h"
#include "supervisor/cpu.h"
#include "supervisor/memory.h"
#include "supervisor/port.h"
@ -61,10 +62,6 @@
#include "shared-module/network/__init__.h"
#endif
#ifdef CIRCUITPY_DISPLAYIO
#include "shared-module/displayio/__init__.h"
#endif
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
if (lex == NULL) {
@ -203,10 +200,8 @@ bool run_code_py(safe_mode_t safe_mode) {
serial_write_compressed(translate("WARNING: Your code filename has two extensions\n"));
}
}
#ifdef CIRCUITPY_DISPLAYIO
// Turn off the display before the heap disappears.
reset_displays();
#endif
stop_mp();
free_memory(heap);
supervisor_move_memory();

View File

@ -388,7 +388,6 @@ SRC_SHARED_MODULE = \
displayio/OnDiskBitmap.c \
displayio/Palette.c \
displayio/Shape.c \
displayio/Sprite.c \
displayio/TileGrid.c \
gamepad/__init__.c \
gamepad/GamePad.c \

View File

@ -84,13 +84,14 @@ void board_init(void) {
128, // Width
128, // Height
2, // column start
0, // row start
1, // row start
16, // Color depth
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
display_init_sequence,
sizeof(display_init_sequence));
sizeof(display_init_sequence),
&pin_PA00);
}
bool board_requests_safe_mode(void) {

View File

@ -351,6 +351,7 @@ extern const struct _mp_obj_module_t pixelbuf_module;
#define MICROPY_PY_BUILTINS_COMPLEX (0)
#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (0)
#define CIRCUITPY_DISPLAYIO (0)
#define CIRCUITPY_DISPLAY_LIMIT (0)
#endif

View File

@ -1,195 +0,0 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "shared-bindings/displayio/Sprite.h"
#include <stdint.h>
#include "lib/utils/context_manager_helpers.h"
#include "py/binary.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "shared-bindings/displayio/Bitmap.h"
#include "shared-bindings/displayio/ColorConverter.h"
#include "shared-bindings/displayio/OnDiskBitmap.h"
#include "shared-bindings/displayio/Palette.h"
#include "shared-bindings/displayio/Shape.h"
#include "supervisor/shared/translate.h"
static void unpack_position(mp_obj_t position_obj, int16_t* x, int16_t* y) {
// TODO(tannewt): Support any value sequence such as bytearray or bytes.
mp_obj_tuple_t *position = MP_OBJ_TO_PTR(position_obj);
if (MP_OBJ_IS_TYPE(position_obj, &mp_type_tuple) && position->len == 2) {
*x = mp_obj_get_int(position->items[0]);
*y = mp_obj_get_int(position->items[1]);
} else if (position != mp_const_none) {
mp_raise_TypeError(translate("position must be 2-tuple"));
}
}
//| .. currentmodule:: displayio
//|
//| :class:`Sprite` -- A particular copy of an image to display
//| ==========================================================================
//|
//| Position a particular image and pixel_shader combination. Multiple sprites can share bitmaps
//| pixel shaders.
//|
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
//|
//| .. class:: Sprite(bitmap, *, pixel_shader, position, width, height)
//|
//| Create a Sprite object. The bitmap is source for 2d pixels. The pixel_shader is used to
//| convert the value and its location to a display native pixel color. This may be a simple color
//| palette lookup, a gradient, a pattern or a color transformer.
//|
//|
STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_bitmap, ARG_pixel_shader, ARG_position, ARG_width, ARG_height };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY },
{ MP_QSTR_position, MP_ARG_OBJ | MP_ARG_KW_ONLY },
{ 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, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_obj_t bitmap = args[ARG_bitmap].u_obj;
uint16_t width;
uint16_t height;
mp_obj_t native = mp_instance_cast_to_native_base(bitmap, &displayio_shape_type);
if (native != MP_OBJ_NULL) {
displayio_shape_t* bmp = MP_OBJ_TO_PTR(native);
width = bmp->width;
height = bmp->height;
} else if (MP_OBJ_IS_TYPE(bitmap, &displayio_bitmap_type)) {
displayio_bitmap_t* bmp = MP_OBJ_TO_PTR(bitmap);
native = bitmap;
width = bmp->width;
height = bmp->height;
} else if (MP_OBJ_IS_TYPE(bitmap, &displayio_ondiskbitmap_type)) {
displayio_ondiskbitmap_t* bmp = MP_OBJ_TO_PTR(bitmap);
native = bitmap;
width = bmp->width;
height = bmp->height;
} else {
mp_raise_TypeError(translate("unsupported bitmap type"));
}
int16_t x = 0;
int16_t y = 0;
mp_obj_t position_obj = args[ARG_position].u_obj;
unpack_position(position_obj, &x, &y);
displayio_sprite_t *self = m_new_obj(displayio_sprite_t);
self->base.type = &displayio_sprite_type;
common_hal_displayio_sprite_construct(self, native, args[ARG_pixel_shader].u_obj,
width, height, x, y);
return MP_OBJ_FROM_PTR(self);
}
//| .. attribute:: position
//|
//| The position of the top-left corner of the sprite.
//|
STATIC mp_obj_t displayio_sprite_obj_get_position(mp_obj_t self_in) {
displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
int16_t x;
int16_t y;
common_hal_displayio_sprite_get_position(self, &x, &y);
mp_obj_t coords[2];
coords[0] = mp_obj_new_int(x);
coords[1] = mp_obj_new_int(y);
return mp_obj_new_tuple(2, coords);
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_sprite_get_position_obj, displayio_sprite_obj_get_position);
STATIC mp_obj_t displayio_sprite_obj_set_position(mp_obj_t self_in, mp_obj_t value) {
displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
int16_t x = 0;
int16_t y = 0;
unpack_position(value, &x, &y);
common_hal_displayio_sprite_set_position(self, x, y);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_sprite_set_position_obj, displayio_sprite_obj_set_position);
const mp_obj_property_t displayio_sprite_position_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_sprite_get_position_obj,
(mp_obj_t)&displayio_sprite_set_position_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: pixel_shader
//|
//| The pixel shader of the sprite.
//|
STATIC mp_obj_t displayio_sprite_obj_get_pixel_shader(mp_obj_t self_in) {
displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
return common_hal_displayio_sprite_get_pixel_shader(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_sprite_get_pixel_shader_obj, displayio_sprite_obj_get_pixel_shader);
STATIC mp_obj_t displayio_sprite_obj_set_pixel_shader(mp_obj_t self_in, mp_obj_t pixel_shader) {
displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
if (!MP_OBJ_IS_TYPE(pixel_shader, &displayio_palette_type) && !MP_OBJ_IS_TYPE(pixel_shader, &displayio_colorconverter_type)) {
mp_raise_TypeError(translate("pixel_shader must be displayio.Palette or displayio.ColorConverter"));
}
common_hal_displayio_sprite_set_pixel_shader(self, pixel_shader);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_sprite_set_pixel_shader_obj, displayio_sprite_obj_set_pixel_shader);
const mp_obj_property_t displayio_sprite_pixel_shader_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_sprite_get_pixel_shader_obj,
(mp_obj_t)&displayio_sprite_set_pixel_shader_obj,
(mp_obj_t)&mp_const_none_obj},
};
STATIC const mp_rom_map_elem_t displayio_sprite_locals_dict_table[] = {
// Properties
{ MP_ROM_QSTR(MP_QSTR_position), MP_ROM_PTR(&displayio_sprite_position_obj) },
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&displayio_sprite_pixel_shader_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_sprite_locals_dict, displayio_sprite_locals_dict_table);
const mp_obj_type_t displayio_sprite_type = {
{ &mp_type_type },
.name = MP_QSTR_Sprite,
.make_new = displayio_sprite_make_new,
.locals_dict = (mp_obj_dict_t*)&displayio_sprite_locals_dict,
};

View File

@ -1,43 +0,0 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H
#include "shared-module/displayio/Sprite.h"
extern const mp_obj_type_t displayio_sprite_type;
void common_hal_displayio_sprite_construct(displayio_sprite_t *self, mp_obj_t bitmap,
mp_obj_t pixel_shader, uint16_t width, uint16_t height, uint16_t x, uint16_t y);
void common_hal_displayio_sprite_get_position(displayio_sprite_t *self, int16_t* x, int16_t* y);
void common_hal_displayio_sprite_set_position(displayio_sprite_t *self, int16_t x, int16_t y);
mp_obj_t common_hal_displayio_sprite_get_pixel_shader(displayio_sprite_t *self);
void common_hal_displayio_sprite_set_pixel_shader(displayio_sprite_t *self, mp_obj_t pixel_shader);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H

View File

@ -42,5 +42,6 @@ mp_obj_t common_hal_displayio_tilegrid_get_pixel_shader(displayio_tilegrid_t *se
void common_hal_displayio_tilegrid_set_pixel_shader(displayio_tilegrid_t *self, mp_obj_t pixel_shader);
void common_hal_displayio_textgrid_set_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y, uint8_t tile_index);
void common_hal_displayio_textgrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_TILEGRID_H

View File

@ -96,7 +96,6 @@ STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_OnDiskBitmap), MP_ROM_PTR(&displayio_ondiskbitmap_type) },
{ MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) },
{ MP_ROM_QSTR(MP_QSTR_Shape), MP_ROM_PTR(&displayio_shape_type) },
{ MP_ROM_QSTR(MP_QSTR_Sprite), MP_ROM_PTR(&displayio_sprite_type) },
{ MP_ROM_QSTR(MP_QSTR_TileGrid), MP_ROM_PTR(&displayio_tilegrid_type) },
{ MP_ROM_QSTR(MP_QSTR_FourWire), MP_ROM_PTR(&displayio_fourwire_type) },

View File

@ -178,8 +178,8 @@ void displayio_display_start_region_update(displayio_display_obj_t* self, uint16
data[1] = __builtin_bswap16(x1 - 1 + self->colstart);
self->send(self->bus, false, (uint8_t*) data, 4);
self->send(self->bus, true, &self->set_row_command, 1);
data[0] = __builtin_bswap16(y0 + 1 + self->rowstart);
data[1] = __builtin_bswap16(y1 + self->rowstart);
data[0] = __builtin_bswap16(y0 + self->rowstart);
data[1] = __builtin_bswap16(y1 - 1 + self->rowstart);
self->send(self->bus, false, (uint8_t*) data, 4);
self->send(self->bus, true, &self->write_ram_command, 1);
}

View File

@ -40,9 +40,6 @@ void common_hal_displayio_group_append(displayio_group_t* self, mp_obj_t layer)
mp_raise_RuntimeError(translate("Group full"));
}
mp_obj_t native_layer = mp_instance_cast_to_native_base(layer, &displayio_group_type);
if (native_layer == MP_OBJ_NULL) {
native_layer = mp_instance_cast_to_native_base(layer, &displayio_sprite_type);
}
if (native_layer == MP_OBJ_NULL) {
native_layer = mp_instance_cast_to_native_base(layer, &displayio_tilegrid_type);
}
@ -85,10 +82,6 @@ bool displayio_group_get_pixel(displayio_group_t *self, int16_t x, int16_t y, ui
if (displayio_tilegrid_get_pixel(layer, x, y, pixel)) {
return true;
}
} else if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
if (displayio_sprite_get_pixel(layer, x, y, pixel)) {
return true;
}
} else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) {
if (displayio_group_get_pixel(layer, x, y, pixel)) {
return true;
@ -113,10 +106,6 @@ bool displayio_group_needs_refresh(displayio_group_t *self) {
if (displayio_group_needs_refresh(layer)) {
return true;
}
} else if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
if (displayio_sprite_needs_refresh(layer)) {
return true;
}
}
}
return false;
@ -130,8 +119,6 @@ void displayio_group_finish_refresh(displayio_group_t *self) {
displayio_tilegrid_finish_refresh(layer);
} else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) {
displayio_group_finish_refresh(layer);
} else if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
displayio_sprite_finish_refresh(layer);
}
}
}

View File

@ -1,102 +0,0 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "shared-bindings/displayio/Sprite.h"
#include "shared-bindings/displayio/Bitmap.h"
#include "shared-bindings/displayio/ColorConverter.h"
#include "shared-bindings/displayio/OnDiskBitmap.h"
#include "shared-bindings/displayio/Palette.h"
#include "shared-bindings/displayio/Shape.h"
void common_hal_displayio_sprite_construct(displayio_sprite_t *self, mp_obj_t bitmap,
mp_obj_t pixel_shader, uint16_t width, uint16_t height, uint16_t x, uint16_t y) {
self->width = width;
self->height = height;
self->bitmap = bitmap;
self->pixel_shader = pixel_shader;
self->x = x;
self->y = y;
}
void common_hal_displayio_sprite_get_position(displayio_sprite_t *self, int16_t* x, int16_t* y) {
*x = self->x;
*y = self->y;
}
void common_hal_displayio_sprite_set_position(displayio_sprite_t *self, int16_t x, int16_t y) {
self->x = x;
self->y = y;
self->needs_refresh = true;
}
mp_obj_t common_hal_displayio_sprite_get_pixel_shader(displayio_sprite_t *self) {
return self->pixel_shader;
}
void common_hal_displayio_sprite_set_pixel_shader(displayio_sprite_t *self, mp_obj_t pixel_shader) {
self->pixel_shader = pixel_shader;
self->needs_refresh = true;
}
bool displayio_sprite_get_pixel(displayio_sprite_t *self, int16_t x, int16_t y, uint16_t* pixel) {
x -= self->x;
y -= self->y;
if (y < 0 || y >= self->height || x >= self->width || x < 0) {
return false;
}
uint32_t value = 0;
if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_bitmap_type)) {
value = common_hal_displayio_bitmap_get_pixel(self->bitmap, x, y);
} else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_shape_type)) {
value = common_hal_displayio_shape_get_pixel(self->bitmap, x, y);
} else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_ondiskbitmap_type)) {
value = common_hal_displayio_ondiskbitmap_get_pixel(self->bitmap, x, y);
}
if (self->pixel_shader == mp_const_none) {
*pixel = value;
return true;
} else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type) && displayio_palette_get_color(self->pixel_shader, value, pixel)) {
return true;
} else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type) && common_hal_displayio_colorconverter_convert(self->pixel_shader, value, pixel)) {
return true;
}
return false;
}
bool displayio_sprite_needs_refresh(displayio_sprite_t *self) {
return self->needs_refresh || displayio_palette_needs_refresh(self->pixel_shader);
}
void displayio_sprite_finish_refresh(displayio_sprite_t *self) {
self->needs_refresh = false;
displayio_palette_finish_refresh(self->pixel_shader);
// TODO(tannewt): We could double buffer changes to position and move them over here.
// That way they won't change during a refresh and tear.
}

View File

@ -1,50 +0,0 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SPRITE_H
#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SPRITE_H
#include <stdbool.h>
#include <stdint.h>
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
mp_obj_t bitmap;
mp_obj_t pixel_shader;
uint16_t x;
uint16_t y;
uint16_t width;
uint16_t height;
bool needs_refresh;
} displayio_sprite_t;
bool displayio_sprite_get_pixel(displayio_sprite_t *sprite, int16_t x, int16_t y, uint16_t *pixel);
bool displayio_sprite_needs_refresh(displayio_sprite_t *self);
void displayio_sprite_finish_refresh(displayio_sprite_t *self);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SPRITE_H

View File

@ -92,7 +92,7 @@ bool displayio_tilegrid_get_pixel(displayio_tilegrid_t *self, int16_t x, int16_t
if (tiles == NULL) {
return false;
}
uint16_t tile_location = (y / self->tile_height) * self->width_in_tiles + x / self->tile_width;
uint16_t tile_location = ((y / self->tile_height + self->top_left_y) % self->height_in_tiles) * self->width_in_tiles + (x / self->tile_width + self->top_left_x) % self->width_in_tiles;
uint8_t tile = tiles[tile_location];
uint16_t tile_x = tile_x = (tile % self->bitmap_width_in_tiles) * self->tile_width + x % self->tile_width;
uint16_t tile_y = tile_y = (tile / self->bitmap_width_in_tiles) * self->tile_height + y % self->tile_height;
@ -130,6 +130,12 @@ void common_hal_displayio_textgrid_set_tile(displayio_tilegrid_t *self, uint16_t
self->needs_refresh = true;
}
void common_hal_displayio_textgrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y) {
self->top_left_x = x;
self->top_left_y = y;
}
bool displayio_tilegrid_needs_refresh(displayio_tilegrid_t *self) {
return self->needs_refresh || displayio_palette_needs_refresh(self->pixel_shader);
}

View File

@ -45,6 +45,8 @@ typedef struct {
uint16_t total_height;
uint16_t tile_width;
uint16_t tile_height;
uint16_t top_left_x;
uint16_t top_left_y;
uint8_t* tiles;
bool needs_refresh;
bool inline_tiles;

View File

@ -91,6 +91,7 @@ void common_hal_displayio_release_displays(void) {
}
void reset_displays(void) {
#if CIRCUITPY_DISPLAYIO
// The SPI buses used by FourWires may be allocated on the heap so we need to move them inline.
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].fourwire_bus.base.type != &displayio_fourwire_type) {
@ -122,4 +123,5 @@ void reset_displays(void) {
display->auto_brightness = true;
common_hal_displayio_display_show(display, &circuitpython_splash);
}
#endif
}

View File

@ -26,9 +26,10 @@
#include "shared-module/terminalio/Terminal.h"
#include "shared-module/displayio/__init__.h"
#include "shared-bindings/displayio/TileGrid.h"
void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t* tilegrid, const uint8_t* unicode_characters, uint16_t unicode_characters_len) {
void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t* tilegrid, const uint8_t* unicode_characters, size_t unicode_characters_len) {
self->cursor_x = 0;
self->cursor_y = 0;
self->tilegrid = tilegrid;
@ -115,6 +116,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
common_hal_displayio_textgrid_set_tile(self->tilegrid, j, self->cursor_y, 0);
start_y = self->cursor_y;
}
common_hal_displayio_textgrid_set_top_left(self->tilegrid, 0, (start_y + self->tilegrid->height_in_tiles + 1) % self->tilegrid->height_in_tiles);
}
}
return i - data;

View File

@ -87,6 +87,7 @@ void supervisor_stop_terminal(void) {
}
void supervisor_display_move_memory(void) {
#if CIRCUITPY_DISPLAYIO
displayio_tilegrid_t* grid = &supervisor_terminal_text_grid;
if (MP_STATE_VM(terminal_tilegrid_tiles) == NULL || grid->tiles != MP_STATE_VM(terminal_tilegrid_tiles)) {
return;
@ -102,6 +103,7 @@ void supervisor_display_move_memory(void) {
grid->inline_tiles = false;
}
MP_STATE_VM(terminal_tilegrid_tiles) = NULL;
#endif
}
uint32_t blinka_bitmap_data[32] = {
@ -149,15 +151,24 @@ displayio_palette_t blinka_palette = {
.needs_refresh = false
};
displayio_sprite_t blinka_sprite = {
.base = {.type = &displayio_sprite_type },
displayio_tilegrid_t blinka_sprite = {
.base = {.type = &displayio_tilegrid_type },
.bitmap = &blinka_bitmap,
.pixel_shader = &blinka_palette,
.x = 0,
.y = 0,
.width = 16,
.height = 16,
.needs_refresh = false
.bitmap_width_in_tiles = 1,
.width_in_tiles = 1,
.height_in_tiles = 1,
.total_width = 16,
.total_height = 16,
.tile_width = 16,
.tile_height = 16,
.top_left_x = 16,
.top_left_y = 16,
.tiles = 0,
.needs_refresh = false,
.inline_tiles = true
};
mp_obj_t splash_children[2] = {

View File

@ -26,6 +26,8 @@
#include <string.h>
#include "py/mpconfig.h"
#include "supervisor/shared/display.h"
#include "shared-bindings/terminalio/Terminal.h"
#include "supervisor/serial.h"
@ -50,8 +52,10 @@ bool serial_bytes_available(void) {
}
void serial_write_substring(const char* text, uint32_t length) {
#if CIRCUITPY_DISPLAYIO
int errcode;
common_hal_terminalio_terminal_write(&supervisor_terminal, (const uint8_t*) text, length, &errcode);
#endif
if (!tud_cdc_connected()) {
return;
}