diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-01-29 15:04:07 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2019-01-31 11:42:14 -0800 |
| commit | 601a910f4eb83cf1ae7516a25c011b469ac76b8b (patch) | |
| tree | 54b8921c1f6efb0826fe9c011956d79dbfb292f5 /shared-module | |
| parent | 6145f08cc89946d138737b149d390265def67077 (diff) | |
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.
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/displayio/Display.c | 4 | ||||
| -rw-r--r-- | shared-module/displayio/Group.c | 13 | ||||
| -rw-r--r-- | shared-module/displayio/Sprite.c | 102 | ||||
| -rw-r--r-- | shared-module/displayio/Sprite.h | 50 | ||||
| -rw-r--r-- | shared-module/displayio/TileGrid.c | 8 | ||||
| -rw-r--r-- | shared-module/displayio/TileGrid.h | 2 | ||||
| -rw-r--r-- | shared-module/displayio/__init__.c | 2 | ||||
| -rw-r--r-- | shared-module/terminalio/Terminal.c | 4 |
8 files changed, 16 insertions, 169 deletions
diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index a2a60227d..ac1d0e933 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -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); } diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index bbbd83486..c31bfe841 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -41,9 +41,6 @@ void common_hal_displayio_group_append(displayio_group_t* self, mp_obj_t layer) } 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); } if (native_layer == MP_OBJ_NULL) { @@ -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); } } } diff --git a/shared-module/displayio/Sprite.c b/shared-module/displayio/Sprite.c deleted file mode 100644 index da6eff896..000000000 --- a/shared-module/displayio/Sprite.c +++ /dev/null @@ -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. -} diff --git a/shared-module/displayio/Sprite.h b/shared-module/displayio/Sprite.h deleted file mode 100644 index dc368c4b7..000000000 --- a/shared-module/displayio/Sprite.h +++ /dev/null @@ -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 diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index ed724bf10..b90603afe 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -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); } diff --git a/shared-module/displayio/TileGrid.h b/shared-module/displayio/TileGrid.h index 84e3e7ef2..59645553d 100644 --- a/shared-module/displayio/TileGrid.h +++ b/shared-module/displayio/TileGrid.h @@ -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; diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 8e4904954..38349e9a3 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -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 } diff --git a/shared-module/terminalio/Terminal.c b/shared-module/terminalio/Terminal.c index 444bf53ad..6734fa30e 100644 --- a/shared-module/terminalio/Terminal.c +++ b/shared-module/terminalio/Terminal.c @@ -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; |
