Skip to content

Commit 1a1dbef

Browse files
committed
Hook up the terminal based on the first display.
1 parent 590e029 commit 1a1dbef

20 files changed

Lines changed: 454 additions & 126 deletions

File tree

main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ bool run_code_py(safe_mode_t safe_mode) {
209209
#endif
210210
stop_mp();
211211
free_memory(heap);
212+
supervisor_move_memory();
212213

213214
reset_port();
214215
reset_board_busses();
@@ -221,6 +222,10 @@ bool run_code_py(safe_mode_t safe_mode) {
221222
}
222223

223224
// Wait for connection or character.
225+
if (!serial_connected_at_start) {
226+
serial_write_compressed(translate("\nCode done running. Waiting for USB.\n"));
227+
}
228+
224229
bool serial_connected_before_animation = false;
225230
rgb_status_animation_t animation;
226231
prep_rgb_status_animation(&result, found_main, safe_mode, &animation);
@@ -342,6 +347,7 @@ void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
342347
reset_board();
343348
stop_mp();
344349
free_memory(heap);
350+
supervisor_move_memory();
345351
}
346352
}
347353

@@ -362,6 +368,7 @@ int run_repl(void) {
362368
reset_board();
363369
stop_mp();
364370
free_memory(heap);
371+
supervisor_move_memory();
365372
autoreload_resume();
366373
return exit_code;
367374
}

ports/atmel-samd/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ extern const struct _mp_obj_module_t pixelbuf_module;
467467
mp_obj_t rtc_time_source; \
468468
FLASH_ROOT_POINTERS \
469469
mp_obj_t gamepad_singleton; \
470+
mp_obj_t terminal_tilegrid_tiles; \
470471
NETWORK_ROOT_POINTERS \
471472

472473
void run_background_tasks(void);

shared-bindings/displayio/Display.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
133133
//|
134134
STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
135135
displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in);
136-
mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type);
137-
if (native_layer == MP_OBJ_NULL) {
138-
mp_raise_ValueError(translate("Must be a Group subclass."));
136+
displayio_group_t* group = NULL;
137+
if (group_in != mp_const_none) {
138+
mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type);
139+
if (native_layer == MP_OBJ_NULL) {
140+
mp_raise_ValueError(translate("Must be a Group subclass."));
141+
}
142+
group = MP_OBJ_TO_PTR(native_layer);
139143
}
140-
displayio_group_t* group = MP_OBJ_TO_PTR(native_layer);
144+
141145
common_hal_displayio_display_show(self, group);
142146
return mp_const_none;
143147
}

shared-bindings/displayio/TileGrid.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_
138138

139139
displayio_tilegrid_t *self = m_new_obj(displayio_tilegrid_t);
140140
self->base.type = &displayio_tilegrid_type;
141-
common_hal_displayio_tilegrid_construct(self, native, args[ARG_pixel_shader].u_obj,
142-
args[ARG_width].u_int, args[ARG_height].u_int, tile_width, tile_height, x, y,
143-
args[ARG_default_tile].u_int);
141+
common_hal_displayio_tilegrid_construct(self, native, bitmap_width / tile_width,
142+
args[ARG_pixel_shader].u_obj, args[ARG_width].u_int, args[ARG_height].u_int,
143+
tile_width, tile_height, x, y, args[ARG_default_tile].u_int);
144144
return MP_OBJ_FROM_PTR(self);
145145
}
146146

shared-bindings/displayio/TileGrid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
extern const mp_obj_type_t displayio_tilegrid_type;
3333

3434
void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_t bitmap,
35-
mp_obj_t pixel_shader, uint16_t width, uint16_t height,
35+
uint16_t bitmap_width_in_tiles, mp_obj_t pixel_shader, uint16_t width, uint16_t height,
3636
uint16_t tile_width, uint16_t tile_height, uint16_t x, uint16_t y, uint8_t default_tile);
3737

3838
void common_hal_displayio_tilegrid_get_position(displayio_tilegrid_t *self, int16_t* x, int16_t* y);

shared-module/displayio/Display.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "shared-bindings/displayio/FourWire.h"
3131
#include "shared-bindings/displayio/ParallelBus.h"
3232
#include "shared-bindings/time/__init__.h"
33+
#include "shared-module/displayio/__init__.h"
34+
#include "supervisor/shared/display.h"
3335

3436
#include <stdint.h>
3537

@@ -47,6 +49,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4749
self->set_column_command = set_column_command;
4850
self->set_row_command = set_row_command;
4951
self->write_ram_command = write_ram_command;
52+
self->refresh = false;
5053
self->current_group = NULL;
5154
self->colstart = colstart;
5255
self->rowstart = rowstart;
@@ -86,9 +89,19 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
8689
i += 2 + data_size;
8790
}
8891
self->end_transaction(self->bus);
92+
93+
supervisor_start_terminal(width, height);
94+
95+
// Set the group after initialization otherwise we may send pixels while we delay in
96+
// initialization.
97+
self->refresh = true;
98+
self->current_group = &circuitpython_splash;
8999
}
90100

91101
void common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
102+
if (root_group == NULL) {
103+
root_group = &circuitpython_splash;
104+
}
92105
self->current_group = root_group;
93106
common_hal_displayio_display_refresh_soon(self);
94107
}

shared-module/displayio/Group.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,19 @@ bool displayio_group_needs_refresh(displayio_group_t *self) {
105105
}
106106
for (int32_t i = self->size - 1; i >= 0 ; i--) {
107107
mp_obj_t layer = self->children[i];
108-
if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
108+
if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) {
109+
if (displayio_tilegrid_needs_refresh(layer)) {
110+
return true;
111+
}
112+
} else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) {
113+
if (displayio_group_needs_refresh(layer)) {
114+
return true;
115+
}
116+
} else if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
109117
if (displayio_sprite_needs_refresh(layer)) {
110118
return true;
111119
}
112120
}
113-
// TODO: Tiled layer
114121
}
115122
return false;
116123
}
@@ -119,9 +126,12 @@ void displayio_group_finish_refresh(displayio_group_t *self) {
119126
self->needs_refresh = false;
120127
for (int32_t i = self->size - 1; i >= 0 ; i--) {
121128
mp_obj_t layer = self->children[i];
122-
if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
129+
if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) {
130+
displayio_tilegrid_finish_refresh(layer);
131+
} else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) {
132+
displayio_group_finish_refresh(layer);
133+
} else if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
123134
displayio_sprite_finish_refresh(layer);
124135
}
125-
// TODO: Tiled layer
126136
}
127137
}

shared-module/displayio/TileGrid.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "shared-bindings/displayio/Shape.h"
3434

3535
void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_t bitmap,
36+
uint16_t bitmap_width_in_tiles,
3637
mp_obj_t pixel_shader, uint16_t width, uint16_t height,
3738
uint16_t tile_width, uint16_t tile_height, uint16_t x, uint16_t y, uint8_t default_tile) {
3839
uint32_t total_tiles = width * height;
@@ -44,8 +45,9 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_
4445
self->tiles = (uint8_t*) m_malloc(total_tiles, false);
4546
self->inline_tiles = false;
4647
}
48+
self->bitmap_width_in_tiles = bitmap_width_in_tiles;
4749
self->width_in_tiles = width;
48-
self->height_in_tiles = width;
50+
self->height_in_tiles = height;
4951
self->total_width = width * tile_width;
5052
self->total_height = height * tile_height;
5153
self->tile_width = tile_width;
@@ -87,10 +89,13 @@ bool displayio_tilegrid_get_pixel(displayio_tilegrid_t *self, int16_t x, int16_t
8789
if (self->inline_tiles) {
8890
tiles = (uint8_t*) &self->tiles;
8991
}
92+
if (tiles == NULL) {
93+
return false;
94+
}
9095
uint16_t tile_location = (y / self->tile_height) * self->width_in_tiles + x / self->tile_width;
9196
uint8_t tile = tiles[tile_location];
92-
uint16_t tile_x = tile_x = (tile % self->width_in_tiles) * self->tile_width + x % self->tile_width;
93-
uint16_t tile_y = tile_y = (tile / self->width_in_tiles) * self->tile_height + y % self->tile_height;
97+
uint16_t tile_x = tile_x = (tile % self->bitmap_width_in_tiles) * self->tile_width + x % self->tile_width;
98+
uint16_t tile_y = tile_y = (tile / self->bitmap_width_in_tiles) * self->tile_height + y % self->tile_height;
9499

95100
uint32_t value = 0;
96101
if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_bitmap_type)) {
@@ -118,7 +123,11 @@ void common_hal_displayio_textgrid_set_tile(displayio_tilegrid_t *self, uint16_t
118123
if (self->inline_tiles) {
119124
tiles = (uint8_t*) &self->tiles;
120125
}
126+
if (tiles == NULL) {
127+
return;
128+
}
121129
tiles[y * self->width_in_tiles + x] = tile_index;
130+
self->needs_refresh = true;
122131
}
123132

124133
bool displayio_tilegrid_needs_refresh(displayio_tilegrid_t *self) {

shared-module/displayio/TileGrid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef struct {
3838
mp_obj_t pixel_shader;
3939
uint16_t x;
4040
uint16_t y;
41+
uint16_t bitmap_width_in_tiles;
4142
uint16_t width_in_tiles;
4243
uint16_t height_in_tiles;
4344
uint16_t total_width;

shared-module/displayio/__init__.c

Lines changed: 19 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shared-bindings/displayio/Palette.h"
1010
#include "shared-bindings/displayio/Sprite.h"
1111
#include "supervisor/shared/display.h"
12+
#include "supervisor/memory.h"
1213
#include "supervisor/usb.h"
1314

1415
primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];
@@ -68,76 +69,24 @@ void displayio_refresh_displays(void) {
6869
}
6970
}
7071

71-
uint32_t blinka_bitmap_data[32] = {
72-
0x00000011, 0x11000000,
73-
0x00000111, 0x53100000,
74-
0x00000111, 0x56110000,
75-
0x00000111, 0x11140000,
76-
0x00000111, 0x20002000,
77-
0x00000011, 0x13000000,
78-
0x00000001, 0x11200000,
79-
0x00000000, 0x11330000,
80-
0x00000000, 0x01122000,
81-
0x00001111, 0x44133000,
82-
0x00032323, 0x24112200,
83-
0x00111114, 0x44113300,
84-
0x00323232, 0x34112200,
85-
0x11111144, 0x44443300,
86-
0x11111111, 0x11144401,
87-
0x23232323, 0x21111110
88-
};
89-
90-
displayio_bitmap_t blinka_bitmap = {
91-
.base = {.type = &displayio_bitmap_type },
92-
.width = 16,
93-
.height = 16,
94-
.data = blinka_bitmap_data,
95-
.stride = 2,
96-
.bits_per_value = 4,
97-
.x_shift = 3,
98-
.x_mask = 0x7,
99-
.bitmask = 0xf
100-
};
101-
102-
uint32_t blinka_transparency[1] = {0x80000000};
103-
104-
// These colors are RGB 565 with the bytes swapped.
105-
uint32_t blinka_colors[8] = {0x78890000, 0x9F86B8FC, 0xffff0D5A, 0x0000f501,
106-
0x00000000, 0x00000000, 0x00000000, 0x00000000};
107-
108-
displayio_palette_t blinka_palette = {
109-
.base = {.type = &displayio_palette_type },
110-
.opaque = blinka_transparency,
111-
.colors = blinka_colors,
112-
.color_count = 16,
113-
.needs_refresh = false
114-
};
115-
116-
displayio_sprite_t blinka_sprite = {
117-
.base = {.type = &displayio_sprite_type },
118-
.bitmap = &blinka_bitmap,
119-
.pixel_shader = &blinka_palette,
120-
.x = 0,
121-
.y = 0,
122-
.width = 16,
123-
.height = 16,
124-
.needs_refresh = false
125-
};
126-
127-
mp_obj_t splash_children[1] = {
128-
&blinka_sprite,
129-
};
72+
void common_hal_displayio_release_displays(void) {
73+
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
74+
mp_const_obj_t bus_type = displays[i].fourwire_bus.base.type;
75+
if (bus_type == NULL) {
76+
continue;
77+
} else if (bus_type == &displayio_fourwire_type) {
78+
common_hal_displayio_fourwire_deinit(&displays[i].fourwire_bus);
79+
} else if (bus_type == &displayio_parallelbus_type) {
80+
common_hal_displayio_parallelbus_deinit(&displays[i].parallel_bus);
81+
}
82+
displays[i].fourwire_bus.base.type = &mp_type_NoneType;
83+
}
84+
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
85+
displays[i].display.base.type = &mp_type_NoneType;
86+
}
13087

131-
displayio_group_t splash = {
132-
.base = {.type = &displayio_group_type },
133-
.x = 0,
134-
.y = 0,
135-
.scale = 2,
136-
.size = 1,
137-
.max_size = 1,
138-
.children = splash_children,
139-
.needs_refresh = true
140-
};
88+
supervisor_stop_terminal();
89+
}
14190

14291
void reset_displays(void) {
14392
// The SPI buses used by FourWires may be allocated on the heap so we need to move them inline.
@@ -168,23 +117,6 @@ void reset_displays(void) {
168117
continue;
169118
}
170119
displayio_display_obj_t* display = &displays[i].display;
171-
common_hal_displayio_display_show(display, &splash);
172-
}
173-
}
174-
175-
void common_hal_displayio_release_displays(void) {
176-
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
177-
mp_const_obj_t bus_type = displays[i].fourwire_bus.base.type;
178-
if (bus_type == NULL) {
179-
continue;
180-
} else if (bus_type == &displayio_fourwire_type) {
181-
common_hal_displayio_fourwire_deinit(&displays[i].fourwire_bus);
182-
} else if (bus_type == &displayio_parallelbus_type) {
183-
common_hal_displayio_parallelbus_deinit(&displays[i].parallel_bus);
184-
}
185-
displays[i].fourwire_bus.base.type = &mp_type_NoneType;
186-
}
187-
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
188-
displays[i].display.base.type = &mp_type_NoneType;
120+
common_hal_displayio_display_show(display, &circuitpython_splash);
189121
}
190122
}

0 commit comments

Comments
 (0)