Skip to content

Commit 26c4b37

Browse files
committed
Check if any of the displaytypes in the display structure are active
1 parent 68e3532 commit 26c4b37

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

shared-module/displayio/__init__.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,37 @@ void displayio_gc_collect(void) {
463463
}
464464
}
465465

466+
/*
466467
static bool is_display_active(mp_obj_base_t *display_maybe) {
467468
return display_maybe->type != &mp_type_NoneType && display_maybe->type != NULL;
468469
}
470+
*/
471+
472+
static bool is_any_display_active(primary_display_t *display_maybe) {
473+
if (display_maybe->display_base.type != &mp_type_NoneType && display_maybe->display_base.type != NULL) {
474+
return true;
475+
}
476+
#if CIRCUITPY_BUSDISPLAY
477+
if (display_maybe->display.base.type != &mp_type_NoneType && display_maybe->display.base.type != NULL) {
478+
return true;
479+
}
480+
#endif
481+
#if CIRCUITPY_FRAMEBUFFERIO
482+
if (display_maybe->framebuffer_display.base.type != &mp_type_NoneType && display_maybe->framebuffer_display.base.type != NULL) {
483+
return true;
484+
}
485+
#endif
486+
#if CIRCUITPY_EPAPERDISPLAY
487+
if (display_maybe->epaper_display.base.type != &mp_type_NoneType && display_maybe->epaper_display.base.type != NULL) {
488+
return true;
489+
}
490+
#endif
491+
return false;
492+
}
469493

470494
primary_display_t *allocate_display(void) {
471495
for (uint8_t i = 0; i < max_num_displays; i++) {
472-
if (!is_display_active(DYN_DISPLAYS_ADR(i, display_base))) {
496+
if (!is_any_display_active(DYN_DISPLAYS_ADR0(i))) {
473497
// Clear this memory so it is in a known state before init.
474498
memset(DYN_DISPLAYS_ADR0(i), 0, sizeof(displays[0]));
475499
// Default to None so that it works as board.DISPLAY.
@@ -529,8 +553,8 @@ mp_obj_t common_hal_displayio_get_primary_display(void) {
529553
if (primary_display_number == -1 || primary_display_number >= max_num_displays) {
530554
return mp_const_none;
531555
}
532-
mp_obj_base_t *primary_display = &displays[primary_display_number].display_base;
533-
if (is_display_active(primary_display)) {
556+
primary_display_t *primary_display = DYN_DISPLAYS_ADR0(primary_display_number);
557+
if (is_any_display_active(primary_display)) {
534558
return MP_OBJ_FROM_PTR(primary_display);
535559
}
536560
return mp_const_none;
@@ -543,7 +567,7 @@ void common_hal_displayio_set_primary_display(mp_obj_t new_primary_display) {
543567
}
544568
for (uint8_t i = 0; i < max_num_displays; i++) {
545569
mp_obj_t display = MP_OBJ_FROM_PTR(DYN_DISPLAYS_ADR0(i));
546-
if (new_primary_display == display && is_display_active(display)) {
570+
if (new_primary_display == display && is_any_display_active(display)) {
547571
primary_display_number = i;
548572
return;
549573
}
@@ -557,7 +581,7 @@ void common_hal_displayio_auto_primary_display(void) {
557581
return;
558582
}
559583
for (uint8_t i = 0; i < max_num_displays; i++) {
560-
if (is_display_active(DYN_DISPLAYS_ADR(i, display_base))) {
584+
if (is_any_display_active(DYN_DISPLAYS_ADR0(i))) {
561585
primary_display_number = i;
562586
return;
563587
}

0 commit comments

Comments
 (0)