Include display objects in gc.

This commit is contained in:
Dan Halbert 2019-06-06 17:49:32 -04:00
parent c90ce2b9fa
commit 62de2506e4
9 changed files with 36 additions and 8 deletions

5
main.c
View File

@ -455,6 +455,11 @@ void gc_collect(void) {
// This collects root pointers from the VFS mount table. Some of them may
// have lost their references in the VM even though they are mounted.
gc_collect_root((void**)&MP_STATE_VM(vfs_mount_table), sizeof(mp_vfs_mount_t) / sizeof(mp_uint_t));
#if CIRCUITPY_DISPLAYIO
displayio_gc_collect();
#endif
// This naively collects all object references from an approximate stack
// range.
gc_collect_root((void**)sp, ((uint32_t)&_estack - sp) / sizeof(uint32_t));

View File

@ -29,7 +29,7 @@
#include "supervisor/usb.h"
#include "supervisor/shared/stack.h"
#ifdef CIRCUITPY_DISPLAYIO
#if CIRCUITPY_DISPLAYIO
#include "shared-module/displayio/__init__.h"
#endif
@ -48,7 +48,7 @@ void run_background_tasks(void) {
filesystem_background();
usb_background();
#ifdef CIRCUITPY_DISPLAYIO
#if CIRCUITPY_DISPLAYIO
displayio_refresh_displays();
#endif
running_background_tasks = false;

View File

@ -93,16 +93,22 @@ void reset_port(void) {
i2c_reset();
spi_reset();
uart_reset();
#if CIRCUITPY_PULSEIO
pwmout_reset();
pulseout_reset();
pulsein_reset();
#endif
timers_reset();
#if CIRCUITPY_RTC
#if CIRCUITPY_RTC
rtc_reset();
#endif
#endif
#if CIRCUITPY_BLEIO
bleio_reset();
#endif
reset_all_pins();
}

View File

@ -383,6 +383,10 @@ void gc_collect_start(void) {
#endif
}
void gc_collect_ptr(void *ptr) {
gc_mark(ptr);
}
void gc_collect_root(void **ptrs, size_t len) {
for (size_t i = 0; i < len; i++) {
void *ptr = ptrs[i];

View File

@ -43,6 +43,7 @@ bool gc_is_locked(void);
// A given port must implement gc_collect by using the other collect functions.
void gc_collect(void);
void gc_collect_start(void);
void gc_collect_ptr(void *ptr);
void gc_collect_root(void **ptrs, size_t len);
void gc_collect_end(void);

View File

@ -34,7 +34,6 @@
//|
//| .. module:: board
//| :synopsis: Board specific pin names
//| :platform: SAMD21
//|
//| Common container for board base pin names. These will vary from board to
//| board so don't expect portability when using this module.

View File

@ -103,7 +103,7 @@ void reset_board_busses(void) {
#endif
#if BOARD_SPI
bool display_using_spi = false;
#ifdef CIRCUITPY_DISPLAYIO
#if CIRCUITPY_DISPLAYIO
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].fourwire_bus.bus == spi_singleton) {
display_using_spi = true;

View File

@ -3,6 +3,7 @@
#include "shared-module/displayio/__init__.h"
#include "lib/utils/interrupt_char.h"
#include "py/gc.h"
#include "py/reload.h"
#include "py/runtime.h"
#include "shared-bindings/board/__init__.h"
@ -181,7 +182,6 @@ void common_hal_displayio_release_displays(void) {
}
void reset_displays(void) {
#if CIRCUITPY_DISPLAYIO
// The SPI buses used by FourWires may be allocated on the heap so we need to move them inline.
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].fourwire_bus.base.type != &displayio_fourwire_type) {
@ -218,5 +218,17 @@ void reset_displays(void) {
display->auto_brightness = true;
common_hal_displayio_display_show(display, &circuitpython_splash);
}
#endif
}
void displayio_gc_collect(void) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].display.base.type == NULL) {
continue;
}
// Alternatively, we could use gc_collect_root over the whole object,
// but this is more precise, and is the only field that needs marking.
gc_collect_ptr(displays[i].display.current_group);
}
}

View File

@ -46,5 +46,6 @@ extern displayio_group_t circuitpython_splash;
void displayio_refresh_displays(void);
void reset_displays(void);
void displayio_gc_collect(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H