Cleanup and i2c fix
This commit is contained in:
parent
e877449ae0
commit
2f277eba3e
|
@ -223,11 +223,33 @@ void reset_displays(void) {
|
|||
#endif
|
||||
#if CIRCUITPY_IS31FL3741
|
||||
} else if (displays[i].is31fl3741.base.type == &is31fl3741_is31fl3741_type) {
|
||||
is31fl3741_is31fl3741_obj_t *pm = &displays[i].is31fl3741;
|
||||
if (!any_display_uses_this_framebuffer(&pm->base)) {
|
||||
common_hal_is31fl3741_is31fl3741_deinit(pm);
|
||||
is31fl3741_is31fl3741_obj_t *is31 = &displays[i].is31fl3741;
|
||||
if (((uint32_t)is31->i2c) < ((uint32_t)&displays) ||
|
||||
((uint32_t)is31->i2c) > ((uint32_t)&displays + CIRCUITPY_DISPLAY_LIMIT)) {
|
||||
busio_i2c_obj_t *original_i2c = is31->i2c;
|
||||
#if BOARD_I2C
|
||||
// We don't need to move original_i2c if it is the board.I2C object because it is
|
||||
// statically allocated already. (Doing so would also make it impossible to reference in
|
||||
// a subsequent VM run.)
|
||||
if (original_i2c == common_hal_board_get_i2c()) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
memcpy(&is31->inline_i2c, original_i2c, sizeof(busio_i2c_obj_t));
|
||||
is31->i2c = &is31->inline_i2c;
|
||||
// Check for other displays that use the same i2c bus and swap them too.
|
||||
/*for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) {
|
||||
if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type &&
|
||||
displays[i].i2cdisplay_bus.bus == original_i2c) {
|
||||
displays[i].i2cdisplay_bus.bus = &i2c->inline_bus;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if (!any_display_uses_this_framebuffer(&is31->base)) {
|
||||
common_hal_is31fl3741_is31fl3741_deinit(is31);
|
||||
} else {
|
||||
common_hal_is31fl3741_is31fl3741_set_paused(pm, true);
|
||||
common_hal_is31fl3741_is31fl3741_set_paused(is31, true);
|
||||
}
|
||||
#endif
|
||||
#if CIRCUITPY_SHARPDISPLAY
|
||||
|
|
|
@ -54,6 +54,10 @@ void common_hal_is31fl3741_is31fl3741_construct(is31fl3741_is31fl3741_obj_t *sel
|
|||
|
||||
self->i2c = i2c;
|
||||
self->device_address = addr;
|
||||
common_hal_busio_i2c_never_reset(self->i2c);
|
||||
// Our object is statically allocated off the heap so make sure the bus object lives to the end
|
||||
// of the heap as well.
|
||||
gc_never_free(self->i2c);
|
||||
|
||||
common_hal_is31fl3741_is31fl3741_reconstruct(self, framebuffer);
|
||||
}
|
||||
|
@ -83,14 +87,14 @@ void common_hal_is31fl3741_is31fl3741_reconstruct(is31fl3741_is31fl3741_obj_t *s
|
|||
|
||||
common_hal_displayio_is31fl3741_begin_transaction(self);
|
||||
|
||||
uint8_t command = 0xFC;
|
||||
uint8_t command = 0xFC; // device ID
|
||||
common_hal_busio_i2c_write(self->i2c, self->device_address, &command, 1, false);
|
||||
uint8_t data = 0;
|
||||
common_hal_busio_i2c_read(self->i2c, self->device_address, &data, 1);
|
||||
|
||||
is31fl3741_send_reset(self->i2c, self->device_address);
|
||||
is31fl3741_send_enable(self->i2c, self->device_address);
|
||||
is31fl3741_set_current(self->i2c, self->device_address, 0x08);
|
||||
is31fl3741_set_current(self->i2c, self->device_address, 0xFF);
|
||||
|
||||
// set scale to max for all
|
||||
for (int i; i < 351; i++) {
|
||||
|
@ -103,6 +107,12 @@ void common_hal_is31fl3741_is31fl3741_reconstruct(is31fl3741_is31fl3741_obj_t *s
|
|||
}
|
||||
|
||||
void common_hal_is31fl3741_is31fl3741_deinit(is31fl3741_is31fl3741_obj_t *self) {
|
||||
common_hal_displayio_is31fl3741_end_transaction(self); // in case we still had a lock
|
||||
|
||||
if (self->i2c == &self->inline_i2c) {
|
||||
common_hal_busio_i2c_deinit(self->i2c);
|
||||
}
|
||||
|
||||
self->base.type = NULL;
|
||||
|
||||
// If a framebuffer was passed in to the constructor, NULL the reference
|
||||
|
|
|
@ -37,6 +37,7 @@ typedef struct {
|
|||
mp_buffer_info_t bufinfo;
|
||||
uint16_t bufsize, width, height, scale_width, scale_height;
|
||||
busio_i2c_obj_t *i2c;
|
||||
busio_i2c_obj_t inline_i2c;
|
||||
uint8_t device_address;
|
||||
uint8_t bit_depth;
|
||||
bool paused;
|
||||
|
|
Loading…
Reference in New Issue