Merge pull request #2063 from tannewt/fix_i2cdisplay
Fix I2CDisplay lifecycle and splash lifecycle.
This commit is contained in:
commit
fc772b42dd
@ -273,13 +273,7 @@ extern const struct _mp_obj_module_t board_module;
|
|||||||
#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI))
|
#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI))
|
||||||
#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX))
|
#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX))
|
||||||
|
|
||||||
#if BOARD_I2C
|
// I2C and SPI are always allocated off the heap.
|
||||||
#define BOARD_I2C_ROOT_POINTER mp_obj_t shared_i2c_bus;
|
|
||||||
#else
|
|
||||||
#define BOARD_I2C_ROOT_POINTER
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SPI is always allocated off the heap.
|
|
||||||
|
|
||||||
#if BOARD_UART
|
#if BOARD_UART
|
||||||
#define BOARD_UART_ROOT_POINTER mp_obj_t shared_uart_bus;
|
#define BOARD_UART_ROOT_POINTER mp_obj_t shared_uart_bus;
|
||||||
@ -289,7 +283,6 @@ extern const struct _mp_obj_module_t board_module;
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
#define BOARD_MODULE
|
#define BOARD_MODULE
|
||||||
#define BOARD_I2C_ROOT_POINTER
|
|
||||||
#define BOARD_UART_ROOT_POINTER
|
#define BOARD_UART_ROOT_POINTER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -647,7 +640,6 @@ extern const struct _mp_obj_module_t ustack_module;
|
|||||||
GAMEPAD_ROOT_POINTERS \
|
GAMEPAD_ROOT_POINTERS \
|
||||||
mp_obj_t pew_singleton; \
|
mp_obj_t pew_singleton; \
|
||||||
mp_obj_t terminal_tilegrid_tiles; \
|
mp_obj_t terminal_tilegrid_tiles; \
|
||||||
BOARD_I2C_ROOT_POINTER \
|
|
||||||
BOARD_UART_ROOT_POINTER \
|
BOARD_UART_ROOT_POINTER \
|
||||||
FLASH_ROOT_POINTERS \
|
FLASH_ROOT_POINTERS \
|
||||||
NETWORK_ROOT_POINTERS \
|
NETWORK_ROOT_POINTERS \
|
||||||
|
@ -40,17 +40,25 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if BOARD_I2C
|
#if BOARD_I2C
|
||||||
|
// Statically allocate the I2C object so it can live past the end of the heap and into the next VM.
|
||||||
|
// That way it can be used by built-in I2CDisplay displays and be accessible through board.I2C().
|
||||||
|
STATIC busio_i2c_obj_t i2c_obj;
|
||||||
|
STATIC mp_obj_t i2c_singleton = NULL;
|
||||||
|
|
||||||
mp_obj_t common_hal_board_get_i2c(void) {
|
mp_obj_t common_hal_board_get_i2c(void) {
|
||||||
return MP_STATE_VM(shared_i2c_bus);
|
return i2c_singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t common_hal_board_create_i2c(void) {
|
mp_obj_t common_hal_board_create_i2c(void) {
|
||||||
busio_i2c_obj_t *self = m_new_ll_obj(busio_i2c_obj_t);
|
if (i2c_singleton != NULL) {
|
||||||
|
return i2c_singleton;
|
||||||
|
}
|
||||||
|
busio_i2c_obj_t *self = &i2c_obj;
|
||||||
self->base.type = &busio_i2c_type;
|
self->base.type = &busio_i2c_type;
|
||||||
|
|
||||||
common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
|
common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
|
||||||
MP_STATE_VM(shared_i2c_bus) = MP_OBJ_FROM_PTR(self);
|
i2c_singleton = (mp_obj_t)self;
|
||||||
return MP_STATE_VM(shared_i2c_bus);
|
return i2c_singleton;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -101,7 +109,18 @@ mp_obj_t common_hal_board_create_uart(void) {
|
|||||||
|
|
||||||
void reset_board_busses(void) {
|
void reset_board_busses(void) {
|
||||||
#if BOARD_I2C
|
#if BOARD_I2C
|
||||||
MP_STATE_VM(shared_i2c_bus) = NULL;
|
bool display_using_i2c = false;
|
||||||
|
#if CIRCUITPY_DISPLAYIO
|
||||||
|
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
|
||||||
|
if (displays[i].i2cdisplay_bus.bus == i2c_singleton) {
|
||||||
|
display_using_i2c = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (!display_using_i2c) {
|
||||||
|
i2c_singleton = NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if BOARD_SPI
|
#if BOARD_SPI
|
||||||
bool display_using_spi = false;
|
bool display_using_spi = false;
|
||||||
|
@ -199,19 +199,26 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
|
|||||||
|
|
||||||
bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
|
bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
|
||||||
if (root_group == NULL) {
|
if (root_group == NULL) {
|
||||||
|
if (!circuitpython_splash.in_group) {
|
||||||
root_group = &circuitpython_splash;
|
root_group = &circuitpython_splash;
|
||||||
|
} else if (self->current_group == &circuitpython_splash) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (root_group == self->current_group) {
|
if (root_group == self->current_group) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (root_group->in_group) {
|
if (root_group != NULL && root_group->in_group) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (self->current_group != NULL) {
|
if (self->current_group != NULL) {
|
||||||
self->current_group->in_group = false;
|
self->current_group->in_group = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root_group != NULL) {
|
||||||
displayio_group_update_transform(root_group, &self->transform);
|
displayio_group_update_transform(root_group, &self->transform);
|
||||||
root_group->in_group = true;
|
root_group->in_group = true;
|
||||||
|
}
|
||||||
self->current_group = root_group;
|
self->current_group = root_group;
|
||||||
self->full_refresh = true;
|
self->full_refresh = true;
|
||||||
common_hal_displayio_display_refresh_soon(self);
|
common_hal_displayio_display_refresh_soon(self);
|
||||||
@ -402,6 +409,10 @@ void displayio_display_update_backlight(displayio_display_obj_t* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void release_display(displayio_display_obj_t* self) {
|
void release_display(displayio_display_obj_t* self) {
|
||||||
|
if (self->current_group != NULL) {
|
||||||
|
self->current_group->in_group = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (self->backlight_pwm.base.type == &pulseio_pwmout_type) {
|
if (self->backlight_pwm.base.type == &pulseio_pwmout_type) {
|
||||||
common_hal_pulseio_pwmout_reset_ok(&self->backlight_pwm);
|
common_hal_pulseio_pwmout_reset_ok(&self->backlight_pwm);
|
||||||
common_hal_pulseio_pwmout_deinit(&self->backlight_pwm);
|
common_hal_pulseio_pwmout_deinit(&self->backlight_pwm);
|
||||||
|
@ -163,7 +163,7 @@ void displayio_refresh_displays(void) {
|
|||||||
void common_hal_displayio_release_displays(void) {
|
void common_hal_displayio_release_displays(void) {
|
||||||
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
|
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
|
||||||
mp_const_obj_t bus_type = displays[i].fourwire_bus.base.type;
|
mp_const_obj_t bus_type = displays[i].fourwire_bus.base.type;
|
||||||
if (bus_type == NULL) {
|
if (bus_type == NULL || bus_type == &mp_type_NoneType) {
|
||||||
continue;
|
continue;
|
||||||
} else if (bus_type == &displayio_fourwire_type) {
|
} else if (bus_type == &displayio_fourwire_type) {
|
||||||
common_hal_displayio_fourwire_deinit(&displays[i].fourwire_bus);
|
common_hal_displayio_fourwire_deinit(&displays[i].fourwire_bus);
|
||||||
@ -235,12 +235,14 @@ void reset_displays(void) {
|
|||||||
// Not an active display.
|
// Not an active display.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
|
||||||
// Reset the displayed group. Only the first will get the terminal but
|
// Reset the displayed group. Only the first will get the terminal but
|
||||||
// that's ok.
|
// that's ok.
|
||||||
displayio_display_obj_t* display = &displays[i].display;
|
displayio_display_obj_t* display = &displays[i].display;
|
||||||
display->auto_brightness = true;
|
display->auto_brightness = true;
|
||||||
common_hal_displayio_display_show(display, &circuitpython_splash);
|
common_hal_displayio_display_show(display, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user