Skip to content

Commit de2efe0

Browse files
committed
Fix cardputer boot loop, and do some cleanup.
- For `cardputer_keyboard.c`, allocate `DemuxKeyMatrix` it creates and the objects it holds (all the way down) on the port heap, because it lives past VM's. - To do the above, add support for non-VM heap for `DemuxKeyMatrix` and the `keypad` allocations it needs by passing an arg `use_gc_allocator`, as is done in `lvfontio`. - Add `mp_obj_port_malloc()`, `mp_obj_port_malloc_var()`, `mp_obj_new_port_tuple()`, all of which allocate on the port heap, not the VM heap. - Add `port_malloc_zero()`, because `port_malloc()` did not zero out its allocation, unlike VM heap allocations. I got caught by this. - Move `port_gc_collect()` from `main.c` to `supervisor/port.c` for consistency. This function is not actually used by anyone, but I was considering using it. - Add an `MP_WEAK` `mp_board_init()`, for board-specific initializations needed when a VM starts. Also considered, but not used. Added anyway for possible future use. - Add an `MP_WEAK` `board_gc_collect()`, for board-specific gc. Not used. - Add an `MP_WEAK` `port_gc_collect()`, for port-specific gc. Not used. - Don't duplicate keyboard code between `boards/m5stack_cardputer` and `boards/m5stack_cardputer_ros`. Instead, add a `ports/espressif/module` directory for this code, in the style of a port-specific `module` directory, like the port-specific `bindings` directories.
1 parent 0707e28 commit de2efe0

File tree

23 files changed

+140
-509
lines changed

23 files changed

+140
-509
lines changed

main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ static void start_mp(safe_mode_t safe_mode) {
207207

208208
// Always return to root
209209
common_hal_os_chdir("/");
210+
211+
// Initialization for individual boards when a VM starts.
212+
mp_board_init();
210213
}
211214

212215
static void stop_mp(void) {
@@ -1149,6 +1152,7 @@ void gc_collect(void) {
11491152
gc_collect_root((void **)&MP_STATE_VM(vfs_mount_table), sizeof(mp_vfs_mount_t) / sizeof(mp_uint_t));
11501153

11511154
port_gc_collect();
1155+
board_gc_collect();
11521156

11531157
background_callback_gc_collect();
11541158

@@ -1179,10 +1183,6 @@ void gc_collect(void) {
11791183
gc_collect_end();
11801184
}
11811185

1182-
// Ports may provide an implementation of this function if it is needed
1183-
MP_WEAK void port_gc_collect(void) {
1184-
}
1185-
11861186
size_t gc_get_max_new_split(void) {
11871187
return port_heap_get_largest_free_size();
11881188
}

ports/espressif/boards/m5stack_cardputer/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ CIRCUITPY_ESP_FLASH_SIZE = 8MB
1313
CIRCUITPY_ESPCAMERA = 0
1414
CIRCUITPY_MAX3421E = 0
1515

16-
SRC_C += boards/$(BOARD)/cardputer_keyboard.c
16+
SRC_C += module/cardputer_keyboard.c

ports/espressif/boards/m5stack_cardputer_ros/cardputer_keyboard.c

Lines changed: 0 additions & 238 deletions
This file was deleted.

0 commit comments

Comments
 (0)