2019-01-25 19:59:18 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 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 "supervisor/shared/display.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "py/mpstate.h"
|
2020-08-17 20:17:59 -04:00
|
|
|
#include "shared-bindings/displayio/Bitmap.h"
|
2019-01-25 19:59:18 -05:00
|
|
|
#include "shared-bindings/displayio/Group.h"
|
|
|
|
#include "shared-bindings/displayio/Palette.h"
|
2019-01-29 18:40:20 -05:00
|
|
|
#include "shared-bindings/displayio/TileGrid.h"
|
2019-01-25 19:59:18 -05:00
|
|
|
#include "supervisor/memory.h"
|
|
|
|
|
2020-04-15 16:01:24 -04:00
|
|
|
#if CIRCUITPY_RGBMATRIX
|
2020-04-01 17:10:19 -04:00
|
|
|
#include "shared-module/displayio/__init__.h"
|
|
|
|
#endif
|
|
|
|
|
2020-08-06 17:03:31 -04:00
|
|
|
#if CIRCUITPY_SHARPDISPLAY
|
2020-08-12 08:39:12 -04:00
|
|
|
#include "shared-module/displayio/__init__.h"
|
2020-08-06 17:03:31 -04:00
|
|
|
#include "shared-bindings/sharpdisplay/SharpMemoryFramebuffer.h"
|
|
|
|
#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
|
|
|
|
#endif
|
|
|
|
|
2021-08-04 19:27:54 -04:00
|
|
|
extern uint32_t blinka_bitmap_data[];
|
2019-01-25 19:59:18 -05:00
|
|
|
extern displayio_bitmap_t blinka_bitmap;
|
|
|
|
extern displayio_group_t circuitpython_splash;
|
|
|
|
|
2020-08-17 20:17:59 -04:00
|
|
|
#if CIRCUITPY_TERMINALIO
|
2021-03-15 09:57:36 -04:00
|
|
|
static supervisor_allocation *tilegrid_tiles = NULL;
|
2020-08-17 20:17:59 -04:00
|
|
|
#endif
|
2019-01-25 19:59:18 -05:00
|
|
|
|
|
|
|
void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
|
2020-08-17 20:17:59 -04:00
|
|
|
// Default the scale to 2 because we may show blinka without the terminal for
|
|
|
|
// languages that don't have font support.
|
|
|
|
uint8_t scale = 2;
|
|
|
|
|
|
|
|
#if CIRCUITPY_TERMINALIO
|
2021-03-15 09:57:36 -04:00
|
|
|
displayio_tilegrid_t *grid = &supervisor_terminal_text_grid;
|
2020-11-19 12:43:18 -05:00
|
|
|
bool tall = height_px > width_px;
|
2022-02-20 20:50:14 -05:00
|
|
|
bool reset_tiles = false;
|
2020-11-19 12:43:18 -05:00
|
|
|
uint16_t terminal_width_px = tall ? width_px : width_px - blinka_bitmap.width;
|
2021-03-15 09:57:36 -04:00
|
|
|
uint16_t terminal_height_px = tall ? height_px - blinka_bitmap.height : height_px;
|
2020-11-19 12:43:18 -05:00
|
|
|
uint16_t width_in_tiles = terminal_width_px / grid->tile_width;
|
2019-01-25 19:59:18 -05:00
|
|
|
// determine scale based on h
|
2020-08-17 20:17:59 -04:00
|
|
|
if (width_in_tiles < 80) {
|
|
|
|
scale = 1;
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
2020-09-01 11:29:10 -04:00
|
|
|
|
2020-11-19 12:43:18 -05:00
|
|
|
width_in_tiles = terminal_width_px / (grid->tile_width * scale);
|
2020-09-01 11:29:10 -04:00
|
|
|
if (width_in_tiles < 1) {
|
|
|
|
width_in_tiles = 1;
|
|
|
|
}
|
2020-11-19 12:43:18 -05:00
|
|
|
uint16_t height_in_tiles = terminal_height_px / (grid->tile_height * scale);
|
|
|
|
uint16_t remaining_pixels = tall ? 0 : terminal_height_px % (grid->tile_height * scale);
|
2020-09-01 11:29:10 -04:00
|
|
|
if (height_in_tiles < 1 || remaining_pixels > 0) {
|
2019-06-06 18:11:02 -04:00
|
|
|
height_in_tiles += 1;
|
|
|
|
}
|
2019-01-25 19:59:18 -05:00
|
|
|
|
|
|
|
uint16_t total_tiles = width_in_tiles * height_in_tiles;
|
|
|
|
|
2022-02-21 15:58:16 -05:00
|
|
|
// check if the terminal tile dimensions are the same
|
|
|
|
if ((grid->width_in_tiles != width_in_tiles) ||
|
|
|
|
(grid->height_in_tiles != height_in_tiles)) {
|
|
|
|
reset_tiles = true;
|
|
|
|
}
|
2020-10-11 14:39:19 -04:00
|
|
|
// Reuse the previous allocation if possible
|
|
|
|
if (tilegrid_tiles) {
|
|
|
|
if (get_allocation_length(tilegrid_tiles) != align32_size(total_tiles)) {
|
|
|
|
free_memory(tilegrid_tiles);
|
|
|
|
tilegrid_tiles = NULL;
|
2022-02-20 20:50:14 -05:00
|
|
|
reset_tiles = true;
|
2020-10-11 14:39:19 -04:00
|
|
|
}
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
2020-10-11 14:39:19 -04:00
|
|
|
if (!tilegrid_tiles) {
|
|
|
|
tilegrid_tiles = allocate_memory(align32_size(total_tiles), false, true);
|
2022-02-20 20:50:14 -05:00
|
|
|
reset_tiles = true;
|
2020-10-11 14:39:19 -04:00
|
|
|
if (!tilegrid_tiles) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
2020-10-11 14:39:19 -04:00
|
|
|
|
2022-02-21 15:58:16 -05:00
|
|
|
if (reset_tiles) {
|
|
|
|
uint8_t *tiles = (uint8_t *)tilegrid_tiles->ptr;
|
|
|
|
|
|
|
|
grid->y = tall ? blinka_bitmap.height : 0;
|
|
|
|
grid->x = tall ? 0 : blinka_bitmap.width;
|
|
|
|
grid->top_left_y = 0;
|
|
|
|
if (remaining_pixels > 0) {
|
|
|
|
grid->y -= (grid->tile_height - remaining_pixels);
|
|
|
|
}
|
|
|
|
grid->width_in_tiles = width_in_tiles;
|
|
|
|
grid->height_in_tiles = height_in_tiles;
|
|
|
|
assert(width_in_tiles > 0);
|
|
|
|
assert(height_in_tiles > 0);
|
|
|
|
grid->pixel_width = width_in_tiles * grid->tile_width;
|
|
|
|
grid->pixel_height = height_in_tiles * grid->tile_height;
|
|
|
|
grid->tiles = tiles;
|
|
|
|
|
|
|
|
grid->full_change = true;
|
|
|
|
|
|
|
|
common_hal_terminalio_terminal_construct(&supervisor_terminal, grid, &supervisor_terminal_font);
|
2019-06-06 18:11:02 -04:00
|
|
|
}
|
2020-08-17 20:17:59 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
circuitpython_splash.scale = scale;
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void supervisor_stop_terminal(void) {
|
2020-08-17 20:17:59 -04:00
|
|
|
#if CIRCUITPY_TERMINALIO
|
2019-01-25 19:59:18 -05:00
|
|
|
if (tilegrid_tiles != NULL) {
|
|
|
|
free_memory(tilegrid_tiles);
|
2019-04-03 18:24:15 -04:00
|
|
|
tilegrid_tiles = NULL;
|
2019-01-25 19:59:18 -05:00
|
|
|
supervisor_terminal_text_grid.tiles = NULL;
|
2021-08-02 21:37:19 -04:00
|
|
|
supervisor_terminal.tilegrid = NULL;
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
2020-08-17 20:17:59 -04:00
|
|
|
#endif
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void supervisor_display_move_memory(void) {
|
2020-08-17 20:17:59 -04:00
|
|
|
#if CIRCUITPY_TERMINALIO
|
2020-10-11 14:39:19 -04:00
|
|
|
if (tilegrid_tiles != NULL) {
|
2021-03-15 09:57:36 -04:00
|
|
|
supervisor_terminal_text_grid.tiles = (uint8_t *)tilegrid_tiles->ptr;
|
2020-10-11 14:39:19 -04:00
|
|
|
} else {
|
|
|
|
supervisor_terminal_text_grid.tiles = NULL;
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
2020-08-17 20:17:59 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_DISPLAYIO
|
2020-04-01 12:59:15 -04:00
|
|
|
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
|
2020-08-06 17:03:31 -04:00
|
|
|
#if CIRCUITPY_RGBMATRIX
|
2021-03-15 09:57:36 -04:00
|
|
|
if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) {
|
|
|
|
rgbmatrix_rgbmatrix_obj_t *pm = &displays[i].rgbmatrix;
|
|
|
|
common_hal_rgbmatrix_rgbmatrix_reconstruct(pm, NULL);
|
|
|
|
}
|
2020-08-06 17:03:31 -04:00
|
|
|
#endif
|
|
|
|
#if CIRCUITPY_SHARPDISPLAY
|
2021-03-15 09:57:36 -04:00
|
|
|
if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
|
|
|
|
sharpdisplay_framebuffer_obj_t *sharp = &displays[i].sharpdisplay;
|
|
|
|
common_hal_sharpdisplay_framebuffer_reconstruct(sharp);
|
|
|
|
}
|
2020-08-06 17:03:31 -04:00
|
|
|
#endif
|
2020-04-01 12:59:15 -04:00
|
|
|
}
|
|
|
|
#endif
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
|
|
|
|
2021-08-04 19:27:54 -04:00
|
|
|
uint32_t blinka_bitmap_data[32] = {
|
2019-01-25 19:59:18 -05:00
|
|
|
0x00000011, 0x11000000,
|
|
|
|
0x00000111, 0x53100000,
|
|
|
|
0x00000111, 0x56110000,
|
|
|
|
0x00000111, 0x11140000,
|
|
|
|
0x00000111, 0x20002000,
|
|
|
|
0x00000011, 0x13000000,
|
|
|
|
0x00000001, 0x11200000,
|
|
|
|
0x00000000, 0x11330000,
|
|
|
|
0x00000000, 0x01122000,
|
|
|
|
0x00001111, 0x44133000,
|
|
|
|
0x00032323, 0x24112200,
|
|
|
|
0x00111114, 0x44113300,
|
|
|
|
0x00323232, 0x34112200,
|
|
|
|
0x11111144, 0x44443300,
|
|
|
|
0x11111111, 0x11144401,
|
|
|
|
0x23232323, 0x21111110
|
|
|
|
};
|
|
|
|
|
|
|
|
displayio_bitmap_t blinka_bitmap = {
|
|
|
|
.base = {.type = &displayio_bitmap_type },
|
|
|
|
.width = 16,
|
|
|
|
.height = 16,
|
|
|
|
.data = blinka_bitmap_data,
|
|
|
|
.stride = 2,
|
|
|
|
.bits_per_value = 4,
|
|
|
|
.x_shift = 3,
|
|
|
|
.x_mask = 0x7,
|
2019-02-06 15:13:17 -05:00
|
|
|
.bitmask = 0xf,
|
|
|
|
.read_only = true
|
2019-01-25 19:59:18 -05:00
|
|
|
};
|
|
|
|
|
2019-07-05 22:01:54 -04:00
|
|
|
_displayio_color_t blinka_colors[7] = {
|
|
|
|
{
|
|
|
|
.rgb888 = 0x000000,
|
|
|
|
.rgb565 = 0x0000,
|
|
|
|
.luma = 0x00,
|
2019-08-02 19:17:38 -04:00
|
|
|
.chroma = 0,
|
2019-07-05 22:01:54 -04:00
|
|
|
.transparent = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.rgb888 = 0x8428bc,
|
2020-04-14 18:34:53 -04:00
|
|
|
.rgb565 = 0x8978,
|
2019-08-02 19:17:38 -04:00
|
|
|
.luma = 0xff, // We cheat the luma here. It is actually 0x60
|
|
|
|
.hue = 184,
|
|
|
|
.chroma = 148
|
2019-07-05 22:01:54 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.rgb888 = 0xff89bc,
|
2020-04-14 18:34:53 -04:00
|
|
|
.rgb565 = 0xFCB8,
|
2019-08-02 19:17:38 -04:00
|
|
|
.luma = 0xb5,
|
|
|
|
.hue = 222,
|
|
|
|
.chroma = 118
|
2019-07-05 22:01:54 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.rgb888 = 0x7beffe,
|
2020-04-14 18:34:53 -04:00
|
|
|
.rgb565 = 0x869F,
|
2019-08-02 19:17:38 -04:00
|
|
|
.luma = 0xe0,
|
|
|
|
.hue = 124,
|
|
|
|
.chroma = 131
|
2019-07-05 22:01:54 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.rgb888 = 0x51395f,
|
2020-04-14 18:34:53 -04:00
|
|
|
.rgb565 = 0x5A0D,
|
2019-08-02 19:17:38 -04:00
|
|
|
.luma = 0x47,
|
|
|
|
.hue = 185,
|
|
|
|
.chroma = 38
|
2019-07-05 22:01:54 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.rgb888 = 0xffffff,
|
|
|
|
.rgb565 = 0xffff,
|
2019-08-02 19:17:38 -04:00
|
|
|
.luma = 0xff,
|
|
|
|
.chroma = 0
|
2019-07-05 22:01:54 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.rgb888 = 0x0736a0,
|
2020-04-14 18:34:53 -04:00
|
|
|
.rgb565 = 0x01f5,
|
2019-08-02 19:17:38 -04:00
|
|
|
.luma = 0x44,
|
|
|
|
.hue = 147,
|
|
|
|
.chroma = 153
|
2019-07-05 22:01:54 -04:00
|
|
|
},
|
|
|
|
};
|
2019-01-25 19:59:18 -05:00
|
|
|
|
|
|
|
displayio_palette_t blinka_palette = {
|
|
|
|
.base = {.type = &displayio_palette_type },
|
|
|
|
.colors = blinka_colors,
|
2019-07-05 22:01:54 -04:00
|
|
|
.color_count = 7,
|
2019-01-25 19:59:18 -05:00
|
|
|
.needs_refresh = false
|
|
|
|
};
|
|
|
|
|
2019-01-29 18:04:07 -05:00
|
|
|
displayio_tilegrid_t blinka_sprite = {
|
|
|
|
.base = {.type = &displayio_tilegrid_type },
|
2019-01-25 19:59:18 -05:00
|
|
|
.bitmap = &blinka_bitmap,
|
|
|
|
.pixel_shader = &blinka_palette,
|
2019-06-06 18:11:02 -04:00
|
|
|
.x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.pixel_width = 16,
|
|
|
|
.pixel_height = 16,
|
2019-01-29 18:04:07 -05:00
|
|
|
.bitmap_width_in_tiles = 1,
|
|
|
|
.width_in_tiles = 1,
|
|
|
|
.height_in_tiles = 1,
|
|
|
|
.tile_width = 16,
|
|
|
|
.tile_height = 16,
|
|
|
|
.top_left_x = 16,
|
|
|
|
.top_left_y = 16,
|
|
|
|
.tiles = 0,
|
2019-06-06 18:11:02 -04:00
|
|
|
.partial_change = false,
|
|
|
|
.full_change = false,
|
2019-08-27 19:03:05 -04:00
|
|
|
.hidden = false,
|
|
|
|
.hidden_by_parent = false,
|
2019-06-06 18:11:02 -04:00
|
|
|
.moved = false,
|
|
|
|
.inline_tiles = true,
|
|
|
|
.in_group = true
|
2019-01-25 19:59:18 -05:00
|
|
|
};
|
|
|
|
|
2020-08-17 20:17:59 -04:00
|
|
|
#if CIRCUITPY_TERMINALIO
|
2021-02-21 07:43:28 -05:00
|
|
|
mp_obj_t members[] = { &blinka_sprite, &supervisor_terminal_text_grid, };
|
|
|
|
mp_obj_list_t splash_children = {
|
|
|
|
.base = {.type = &mp_type_list },
|
|
|
|
.alloc = 2,
|
|
|
|
.len = 2,
|
|
|
|
.items = members,
|
2019-01-25 19:59:18 -05:00
|
|
|
};
|
2020-08-17 20:17:59 -04:00
|
|
|
#else
|
2021-02-21 07:43:28 -05:00
|
|
|
mp_obj_t members[] = { &blinka_sprite };
|
|
|
|
mp_obj_list_t splash_children = {
|
|
|
|
.base = {.type = &mp_type_list },
|
|
|
|
.alloc = 1,
|
|
|
|
.len = 1,
|
|
|
|
.items = members,
|
2020-08-17 20:17:59 -04:00
|
|
|
};
|
|
|
|
#endif
|
2019-01-25 19:59:18 -05:00
|
|
|
|
|
|
|
displayio_group_t circuitpython_splash = {
|
|
|
|
.base = {.type = &displayio_group_type },
|
|
|
|
.x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.scale = 2,
|
2021-02-21 07:43:28 -05:00
|
|
|
.members = &splash_children,
|
2019-07-24 16:25:34 -04:00
|
|
|
.item_removed = false,
|
2019-08-27 19:03:05 -04:00
|
|
|
.in_group = false,
|
|
|
|
.hidden = false,
|
|
|
|
.hidden_by_parent = false
|
2019-01-25 19:59:18 -05:00
|
|
|
};
|