displayio: implement, use allocate_new_display_bus_or_raise

crypto-aes
Jeff Epler 3 years ago
parent 6378d600c4
commit 8cba145c90
  1. 13
      shared-bindings/displayio/FourWire.c
  2. 13
      shared-bindings/displayio/I2CDisplay.c
  3. 13
      shared-bindings/displayio/ParallelBus.c
  4. 17
      shared-module/displayio/__init__.c
  5. 2
      shared-module/displayio/__init__.h

@ -82,19 +82,8 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj);
mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj);
displayio_fourwire_obj_t* self = NULL;
mp_obj_t spi = args[ARG_spi_bus].u_obj;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].fourwire_bus.base.type == NULL ||
displays[i].fourwire_bus.base.type == &mp_type_NoneType) {
self = &displays[i].fourwire_bus;
self->base.type = &displayio_fourwire_type;
break;
}
}
if (self == NULL) {
mp_raise_RuntimeError(translate("Too many display busses"));
}
displayio_fourwire_obj_t* self = &allocate_display_bus_or_raise()->fourwire_bus;
uint8_t polarity = args[ARG_polarity].u_int;
if (polarity != 0 && polarity != 1) {

@ -71,19 +71,8 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t
mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj);
displayio_i2cdisplay_obj_t* self = NULL;
mp_obj_t i2c = args[ARG_i2c_bus].u_obj;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].i2cdisplay_bus.base.type == NULL ||
displays[i].i2cdisplay_bus.base.type == &mp_type_NoneType) {
self = &displays[i].i2cdisplay_bus;
self->base.type = &displayio_i2cdisplay_type;
break;
}
}
if (self == NULL) {
mp_raise_RuntimeError(translate("Too many display busses"));
}
displayio_i2cdisplay_obj_t* self = &allocate_display_bus_or_raise()->i2cdisplay_bus;
common_hal_displayio_i2cdisplay_construct(self,
MP_OBJ_TO_PTR(i2c), args[ARG_device_address].u_int, reset);

@ -83,18 +83,7 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t
mcu_pin_obj_t *read = validate_obj_is_free_pin(args[ARG_read].u_obj);
mcu_pin_obj_t *reset = validate_obj_is_free_pin(args[ARG_reset].u_obj);
displayio_parallelbus_obj_t* self = NULL;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].parallel_bus.base.type== NULL ||
displays[i].parallel_bus.base.type == &mp_type_NoneType) {
self = &displays[i].parallel_bus;
self->base.type = &displayio_parallelbus_type;
break;
}
}
if (self == NULL) {
mp_raise_RuntimeError(translate("Too many display busses"));
}
displayio_parallelbus_obj_t* self = &allocate_display_bus_or_raise()->parallel_bus;
common_hal_displayio_parallelbus_construct(self, data0, command, chip_select, write, read, reset);
return self;

@ -326,3 +326,20 @@ primary_display_t *allocate_display_or_raise() {
}
}
primary_display_t *allocate_display_bus(void) {
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_bus_or_raise(void) {
primary_display_t *result = allocate_display_bus();
if (result) {
return result;
}
mp_raise_RuntimeError(translate("Too many display busses"));
}

@ -56,5 +56,7 @@ void displayio_gc_collect(void);
primary_display_t *allocate_display(void);
primary_display_t *allocate_display_or_raise(void);
primary_display_t *allocate_display_bus(void);
primary_display_t *allocate_display_bus_or_raise(void);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO___INIT___H

Loading…
Cancel
Save