Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix REPL terminal garbled characters upon code.py finished #6077

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shared-bindings/terminalio/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ STATIC mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n
terminalio_terminal_obj_t *self = m_new_obj(terminalio_terminal_obj_t);
self->base.type = &terminalio_terminal_type;

common_hal_terminalio_terminal_construct(self, tilegrid, font, true);
common_hal_terminalio_terminal_construct(self, tilegrid, font);
return MP_OBJ_FROM_PTR(self);
}

Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/terminalio/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
extern const mp_obj_type_t terminalio_terminal_type;

extern void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self,
displayio_tilegrid_t *tilegrid, const fontio_builtinfont_t *font, const bool reset_tiles);
displayio_tilegrid_t *tilegrid, const fontio_builtinfont_t *font);

// Write characters. len is in characters NOT bytes!
extern size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self,
Expand Down
11 changes: 4 additions & 7 deletions shared-module/terminalio/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@
#include "shared-bindings/displayio/TileGrid.h"
#include "shared-bindings/terminalio/Terminal.h"

void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t *tilegrid, const fontio_builtinfont_t *font, const bool reset_tiles) {
void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t *tilegrid, const fontio_builtinfont_t *font) {
self->cursor_x = 0;
self->cursor_y = 0;
self->font = font;
self->tilegrid = tilegrid;
self->first_row = 0;

if (reset_tiles) {
for (uint16_t x = 0; x < self->tilegrid->width_in_tiles; x++) {
for (uint16_t y = 0; y < self->tilegrid->height_in_tiles; y++) {
common_hal_displayio_tilegrid_set_tile(self->tilegrid, x, y, 0);
}
for (uint16_t x = 0; x < self->tilegrid->width_in_tiles; x++) {
for (uint16_t y = 0; y < self->tilegrid->height_in_tiles; y++) {
common_hal_displayio_tilegrid_set_tile(self->tilegrid, x, y, 0);
}
}

Expand Down
41 changes: 25 additions & 16 deletions supervisor/shared/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {

uint16_t total_tiles = width_in_tiles * height_in_tiles;

// 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;
}
// Reuse the previous allocation if possible
if (tilegrid_tiles) {
if (get_allocation_length(tilegrid_tiles) != align32_size(total_tiles)) {
Expand All @@ -97,24 +102,28 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
return;
}
}
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;
if (reset_tiles) {
uint8_t *tiles = (uint8_t *)tilegrid_tiles->ptr;

common_hal_terminalio_terminal_construct(&supervisor_terminal, grid, &supervisor_terminal_font, reset_tiles);
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);
}
#endif

circuitpython_splash.scale = scale;
Expand Down