summaryrefslogtreecommitdiff
path: root/shared-bindings/displayio
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-03-30 10:47:14 -0500
committerJeff Epler <jepler@gmail.com>2020-04-14 18:24:54 -0500
commit8cba145c90294a001ec5814fb501a7b96a055780 (patch)
treef66dd388907d61c38df378e51635ae7cc6db4224 /shared-bindings/displayio
parent6378d600c40d462836fd6599b9bdadf5e78df8f1 (diff)
displayio: implement, use allocate_new_display_bus_or_raise
Diffstat (limited to 'shared-bindings/displayio')
-rw-r--r--shared-bindings/displayio/FourWire.c13
-rw-r--r--shared-bindings/displayio/I2CDisplay.c13
-rw-r--r--shared-bindings/displayio/ParallelBus.c13
3 files changed, 3 insertions, 36 deletions
diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c
index 77329578a..1cd51b2e2 100644
--- a/shared-bindings/displayio/FourWire.c
+++ b/shared-bindings/displayio/FourWire.c
@@ -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) {
diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c
index 2e312aa14..dd3333f6d 100644
--- a/shared-bindings/displayio/I2CDisplay.c
+++ b/shared-bindings/displayio/I2CDisplay.c
@@ -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);
diff --git a/shared-bindings/displayio/ParallelBus.c b/shared-bindings/displayio/ParallelBus.c
index b3a876f90..4d9ffb0a1 100644
--- a/shared-bindings/displayio/ParallelBus.c
+++ b/shared-bindings/displayio/ParallelBus.c
@@ -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;