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
|
|
|
|
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
|
|
|
|
|
2022-08-28 21:55:13 -04:00
|
|
|
#if CIRCUITPY_STATUS_BAR
|
|
|
|
#include "supervisor/shared/status_bar.h"
|
|
|
|
#endif
|
|
|
|
|
2023-10-02 19:49:31 -04:00
|
|
|
#if CIRCUITPY_TERMINALIO
|
|
|
|
#include "supervisor/port.h"
|
|
|
|
#endif
|
|
|
|
|
2021-09-03 14:44:13 -04:00
|
|
|
#if CIRCUITPY_REPL_LOGO
|
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;
|
2021-09-03 14:44:13 -04:00
|
|
|
#endif
|
2019-01-25 19:59:18 -05:00
|
|
|
extern displayio_group_t circuitpython_splash;
|
|
|
|
|
2020-08-17 20:17:59 -04:00
|
|
|
#if CIRCUITPY_TERMINALIO
|
2023-10-02 19:49:31 -04:00
|
|
|
static uint8_t *tilegrid_tiles = NULL;
|
|
|
|
static size_t tilegrid_tiles_size = 0;
|
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) {
|
2023-10-17 19:09:47 -04:00
|
|
|
if (supervisor_terminal_started()) {
|
|
|
|
return;
|
|
|
|
}
|
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
|
2022-06-06 19:54:02 -04:00
|
|
|
displayio_tilegrid_t *scroll_area = &supervisor_terminal_scroll_area_text_grid;
|
2022-08-28 21:55:13 -04:00
|
|
|
displayio_tilegrid_t *status_bar = &supervisor_terminal_status_bar_text_grid;
|
2022-02-20 20:50:14 -05:00
|
|
|
bool reset_tiles = false;
|
2022-06-06 19:54:02 -04:00
|
|
|
uint16_t width_in_tiles = width_px / scroll_area->tile_width;
|
2022-08-03 15:13:27 -04:00
|
|
|
// determine scale based on width
|
2022-08-19 14:20:47 -04:00
|
|
|
if (width_in_tiles <= 80) {
|
2020-08-17 20:17:59 -04:00
|
|
|
scale = 1;
|
2019-01-25 19:59:18 -05:00
|
|
|
}
|
2020-09-01 11:29:10 -04:00
|
|
|
|
2022-11-17 11:31:36 -05:00
|
|
|
width_in_tiles = MAX(1, width_px / (scroll_area->tile_width * scale));
|
|
|
|
uint16_t height_in_tiles = MAX(2, height_px / (scroll_area->tile_height * scale));
|
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
|
2022-06-06 19:54:02 -04:00
|
|
|
if ((scroll_area->width_in_tiles != width_in_tiles) ||
|
|
|
|
(scroll_area->height_in_tiles != height_in_tiles - 1)) {
|
2022-02-21 15:58:16 -05:00
|
|
|
reset_tiles = true;
|
|
|
|
}
|
2020-10-11 14:39:19 -04:00
|
|
|
// Reuse the previous allocation if possible
|
|
|
|
if (tilegrid_tiles) {
|
2023-10-02 19:49:31 -04:00
|
|
|
if (tilegrid_tiles_size != total_tiles) {
|
|
|
|
port_free(tilegrid_tiles);
|
2020-10-11 14:39:19 -04:00
|
|
|
tilegrid_tiles = NULL;
|
2023-10-02 19:49:31 -04:00
|
|
|
tilegrid_tiles_size = 0;
|
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) {
|
2023-10-02 19:49:31 -04:00
|
|
|
tilegrid_tiles = port_malloc(total_tiles, false);
|
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) {
|
2023-04-07 14:59:55 -04:00
|
|
|
// Adjust the display dimensions to account for scale of the outer group.
|
|
|
|
width_px /= scale;
|
|
|
|
height_px /= scale;
|
|
|
|
|
|
|
|
// Number of tiles from the left edge to inset the status bar.
|
|
|
|
size_t min_left_padding = 0;
|
2021-09-03 14:44:13 -04:00
|
|
|
#if CIRCUITPY_REPL_LOGO
|
2023-04-07 14:59:55 -04:00
|
|
|
// Blinka + 1 px padding minimum
|
|
|
|
min_left_padding = supervisor_blinka_sprite.pixel_width + 1;
|
2022-08-28 21:55:13 -04:00
|
|
|
// Align the status bar to the bottom of the logo.
|
|
|
|
status_bar->y = supervisor_blinka_sprite.pixel_height - status_bar->tile_height;
|
2021-09-03 14:44:13 -04:00
|
|
|
#else
|
2022-08-28 21:55:13 -04:00
|
|
|
status_bar->y = 0;
|
2021-09-03 14:44:13 -04:00
|
|
|
#endif
|
2023-04-07 14:59:55 -04:00
|
|
|
status_bar->width_in_tiles = (width_px - min_left_padding) / status_bar->tile_width;
|
2022-08-28 21:55:13 -04:00
|
|
|
status_bar->height_in_tiles = 1;
|
2023-04-07 14:59:55 -04:00
|
|
|
status_bar->pixel_width = status_bar->width_in_tiles * status_bar->tile_width;
|
2022-08-28 21:55:13 -04:00
|
|
|
status_bar->pixel_height = status_bar->tile_height;
|
2023-04-07 14:59:55 -04:00
|
|
|
// Right align the status bar.
|
|
|
|
status_bar->x = width_px - status_bar->pixel_width;
|
|
|
|
status_bar->top_left_y = 0;
|
2023-10-02 19:49:31 -04:00
|
|
|
status_bar->tiles = tilegrid_tiles;
|
2022-08-28 21:55:13 -04:00
|
|
|
status_bar->full_change = true;
|
2022-02-21 15:58:16 -05:00
|
|
|
|
2022-06-06 19:54:02 -04:00
|
|
|
scroll_area->width_in_tiles = width_in_tiles;
|
2023-08-19 18:21:33 -04:00
|
|
|
// Leave space for the status bar, no matter if we have logo or not.
|
|
|
|
scroll_area->height_in_tiles = height_in_tiles - 1;
|
2023-04-07 14:59:55 -04:00
|
|
|
scroll_area->pixel_width = scroll_area->width_in_tiles * scroll_area->tile_width;
|
|
|
|
scroll_area->pixel_height = scroll_area->height_in_tiles * scroll_area->tile_height;
|
|
|
|
// Right align the scroll area to give margin to the start of each line.
|
|
|
|
scroll_area->x = width_px - scroll_area->pixel_width;
|
|
|
|
scroll_area->top_left_y = 0;
|
|
|
|
// Align the scroll area to the bottom so that the newest line isn't cutoff. The top line
|
|
|
|
// may be clipped by the status bar and that's ok.
|
|
|
|
scroll_area->y = height_px - scroll_area->pixel_height;
|
2023-10-02 19:49:31 -04:00
|
|
|
scroll_area->tiles = tilegrid_tiles + width_in_tiles;
|
2022-06-06 19:54:02 -04:00
|
|
|
scroll_area->full_change = true;
|
2022-02-21 15:58:16 -05:00
|
|
|
|
2022-08-28 21:55:13 -04:00
|
|
|
common_hal_terminalio_terminal_construct(&supervisor_terminal, scroll_area, &supervisor_terminal_font, status_bar);
|
2022-08-30 22:33:29 -04:00
|
|
|
|
|
|
|
// Do not update status bar until after boot.py has run, in case it is disabled.
|
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) {
|
2023-10-02 19:49:31 -04:00
|
|
|
port_free(tilegrid_tiles);
|
2019-04-03 18:24:15 -04:00
|
|
|
tilegrid_tiles = NULL;
|
2023-10-02 19:49:31 -04:00
|
|
|
tilegrid_tiles_size = 0;
|
2022-06-06 19:54:02 -04:00
|
|
|
supervisor_terminal_scroll_area_text_grid.tiles = NULL;
|
2022-08-28 21:55:13 -04:00
|
|
|
supervisor_terminal_status_bar_text_grid.tiles = NULL;
|
2022-06-06 19:54:02 -04:00
|
|
|
supervisor_terminal.scroll_area = NULL;
|
2022-08-28 21:55:13 -04:00
|
|
|
supervisor_terminal.status_bar = 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
|
|
|
}
|
|
|
|
|
2022-07-30 01:09:49 -04:00
|
|
|
bool supervisor_terminal_started(void) {
|
|
|
|
#if CIRCUITPY_TERMINALIO
|
|
|
|
return tilegrid_tiles != NULL;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-08-17 20:17:59 -04:00
|
|
|
#if CIRCUITPY_TERMINALIO
|
2021-09-03 14:44:13 -04:00
|
|
|
#if CIRCUITPY_REPL_LOGO
|
2022-08-28 21:55:13 -04:00
|
|
|
mp_obj_t members[] = { &supervisor_terminal_scroll_area_text_grid, &supervisor_blinka_sprite, &supervisor_terminal_status_bar_text_grid, };
|
2021-02-21 07:43:28 -05:00
|
|
|
mp_obj_list_t splash_children = {
|
|
|
|
.base = {.type = &mp_type_list },
|
2022-06-06 19:54:02 -04:00
|
|
|
.alloc = 3,
|
|
|
|
.len = 3,
|
2021-02-21 07:43:28 -05:00
|
|
|
.items = members,
|
2019-01-25 19:59:18 -05:00
|
|
|
};
|
2020-08-17 20:17:59 -04:00
|
|
|
#else
|
2023-08-14 00:47:22 -04:00
|
|
|
mp_obj_t members[] = { &supervisor_terminal_scroll_area_text_grid, &supervisor_terminal_status_bar_text_grid, };
|
2021-09-03 14:44:13 -04:00
|
|
|
mp_obj_list_t splash_children = {
|
|
|
|
.base = {.type = &mp_type_list },
|
2022-06-06 19:54:02 -04:00
|
|
|
.alloc = 2,
|
|
|
|
.len = 2,
|
2021-09-03 14:44:13 -04:00
|
|
|
.items = members,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CIRCUITPY_REPL_LOGO
|
2022-08-03 15:13:27 -04:00
|
|
|
mp_obj_t members[] = { &supervisor_blinka_sprite };
|
2021-02-21 07:43:28 -05:00
|
|
|
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
|
|
|
};
|
2021-09-03 14:44:13 -04:00
|
|
|
#else
|
|
|
|
mp_obj_t members[] = {};
|
|
|
|
mp_obj_list_t splash_children = {
|
|
|
|
.base = {.type = &mp_type_list },
|
|
|
|
.alloc = 0,
|
|
|
|
.len = 0,
|
|
|
|
.items = members,
|
|
|
|
};
|
|
|
|
#endif
|
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
|
|
|
};
|