Skip to content

Avoid crashing when display components are deinitialized #9568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ CHIP_FAMILY = samd21
SPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = "W25Q64JVxQ"
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
CIRCUITPY_PARALLELDISPLAYBUS = 0
3 changes: 3 additions & 0 deletions ports/atmel-samd/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
bool grabbed_lock = false;
CRITICAL_SECTION_ENTER()
if (!self->has_lock) {
Expand Down
3 changes: 3 additions & 0 deletions ports/atmel-samd/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
}

bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
bool grabbed_lock = false;
CRITICAL_SECTION_ENTER()
if (!self->has_lock) {
Expand Down
3 changes: 3 additions & 0 deletions ports/broadcom/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
bool grabbed_lock = false;
if (!self->has_lock) {
grabbed_lock = true;
Expand Down
3 changes: 3 additions & 0 deletions ports/broadcom/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
}

bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
bool grabbed_lock = false;
if (!self->has_lock) {
grabbed_lock = true;
Expand Down
3 changes: 3 additions & 0 deletions ports/cxd56/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
bool grabbed_lock = false;
if (!self->has_lock) {
grabbed_lock = true;
Expand Down
3 changes: 3 additions & 0 deletions ports/cxd56/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, ui
}

bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
bool grabbed_lock = false;
if (!self->has_lock) {
grabbed_lock = true;
Expand Down
3 changes: 3 additions & 0 deletions ports/espressif/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
if (self->has_lock) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions ports/mimxrt10xx/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
bool grabbed_lock = false;
// CRITICAL_SECTION_ENTER()
if (!self->has_lock) {
Expand Down
3 changes: 3 additions & 0 deletions ports/mimxrt10xx/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
}

bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
bool grabbed_lock = false;
// CRITICAL_SECTION_ENTER()
if (!self->has_lock) {
Expand Down
3 changes: 3 additions & 0 deletions ports/nordic/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
bool grabbed_lock = false;
// NRFX_CRITICAL_SECTION_ENTER();
if (!self->has_lock) {
Expand Down
3 changes: 3 additions & 0 deletions ports/nordic/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, ui
}

bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
bool grabbed_lock = false;
// NRFX_CRITICAL_SECTION_ENTER();
if (!self->has_lock) {
Expand Down
3 changes: 3 additions & 0 deletions ports/raspberrypi/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
bool grabbed_lock = false;
if (!self->has_lock) {
grabbed_lock = true;
Expand Down
3 changes: 3 additions & 0 deletions ports/raspberrypi/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
}

bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
bool grabbed_lock = false;
if (!self->has_lock) {
grabbed_lock = true;
Expand Down
3 changes: 3 additions & 0 deletions ports/renode/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions ports/renode/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
}

bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions ports/silabs/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {

// Lock I2C bus
bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
bool grabbed_lock = false;

if (!self->has_lock) {
Expand Down
3 changes: 3 additions & 0 deletions ports/silabs/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,

// Lock SPI bus
bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
bool grabbed_lock = false;
if (!self->has_lock) {
grabbed_lock = true;
Expand Down
3 changes: 3 additions & 0 deletions ports/stm/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
}
bool grabbed_lock = false;

// Critical section code that may be required at some point.
Expand Down
3 changes: 3 additions & 0 deletions ports/stm/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
}

bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return false;
}
bool grabbed_lock = false;

// Critical section code that may be required at some point.
Expand Down
4 changes: 4 additions & 0 deletions shared-module/displayio/bus_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ bool displayio_display_bus_is_free(displayio_display_bus_t *self) {
}

bool displayio_display_bus_begin_transaction(displayio_display_bus_t *self) {
mp_obj_base_t *bus_base = MP_OBJ_TO_PTR(self->bus);
if (bus_base->type == &mp_type_NoneType) {
return false;
}
return self->begin_transaction(self->bus);
}

Expand Down