displayio: implement, use allocate_display_or_raise

This commit is contained in:
Jeff Epler 2020-03-28 10:34:18 -05:00
parent ada102dd98
commit 6378d600c4
4 changed files with 25 additions and 22 deletions

View File

@ -152,17 +152,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
}
displayio_display_obj_t *self = NULL;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].display.base.type == NULL ||
displays[i].display.base.type == &mp_type_NoneType) {
self = &displays[i].display;
break;
}
}
if (self == NULL) {
mp_raise_RuntimeError(translate("Too many displays"));
}
primary_display_t *disp = allocate_display_or_raise();
displayio_display_obj_t *self = &disp->display;;
self->base.type = &displayio_display_type;
common_hal_displayio_display_construct(
self,

View File

@ -136,17 +136,8 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
}
displayio_epaperdisplay_obj_t *self = NULL;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].display.base.type == NULL ||
displays[i].display.base.type == &mp_type_NoneType) {
self = &displays[i].epaper_display;
break;
}
}
if (self == NULL) {
mp_raise_RuntimeError(translate("Too many displays"));
}
primary_display_t *disp = allocate_display_or_raise();
displayio_epaperdisplay_obj_t *self = &disp->epaper_display;;
mp_float_t refresh_time = mp_obj_get_float(args[ARG_refresh_time].u_obj);
mp_float_t seconds_per_frame = mp_obj_get_float(args[ARG_seconds_per_frame].u_obj);

View File

@ -308,3 +308,21 @@ void displayio_area_transform_within(bool mirror_x, bool mirror_y, bool transpos
transformed->x1 = whole->x1 + (y1 - whole->y1);
}
}
primary_display_t *allocate_display() {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
mp_const_obj_t display_type = displays[i].display.base.type;
if (display_type == NULL || display_type == &mp_type_NoneType) {
return &displays[i];
}
}
return NULL;
primary_display_t *allocate_display_or_raise() {
primary_display_t *result = allocate_display();
if (!result) {
mp_raise_RuntimeError(translate("Too many displays"));
}
}
}

View File

@ -54,4 +54,7 @@ void displayio_background(void);
void reset_displays(void);
void displayio_gc_collect(void);
primary_display_t *allocate_display(void);
primary_display_t *allocate_display_or_raise(void);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO___INIT___H