Skip to content

sharpdisplay: Prevent 'ValueError: <pin> in use' exception #3277

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 4 commits into from
Aug 18, 2020
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
14 changes: 13 additions & 1 deletion shared-module/board/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#include "shared-module/displayio/__init__.h"
#endif

#if CIRCUITPY_SHARPDISPLAY
#include "shared-bindings/sharpdisplay/SharpMemoryFramebuffer.h"
#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
#endif

#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().
Expand Down Expand Up @@ -148,10 +153,17 @@ void reset_board_busses(void) {
bool display_using_spi = false;
#if CIRCUITPY_DISPLAYIO
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].fourwire_bus.bus == spi_singleton) {
mp_const_obj_t bus_type = displays[i].bus_base.type;
if (bus_type == &displayio_fourwire_type && displays[i].fourwire_bus.bus == spi_singleton) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for a fresh look! Instead of adding a special case I removed one, so it's sure to be right(-er) this time.

@tannewt Is this specific change (to check the type of the bus before checking its bus property) right? I assume it's right (because if it's, say an I2CDisplay then the content at that address is unrelated but also would never equal the spi_singleton) but if it's intentional I'd change it back and add a comment explaining it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, this looks correct to me. We check the type to know which union entry to use.

display_using_spi = true;
break;
}
#if CIRCUITPY_SHARPDISPLAY
if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type && displays[i].sharpdisplay.bus == spi_singleton) {
display_using_spi = true;
break;
}
#endif
}
#endif
if (!display_using_spi) {
Expand Down
8 changes: 2 additions & 6 deletions shared-module/displayio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];

#if CIRCUITPY_RGBMATRIX || CIRCUITPY_SHARPDISPLAY
#if CIRCUITPY_RGBMATRIX
STATIC bool any_display_uses_this_framebuffer(mp_obj_base_t *obj) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].display_base.type == &framebufferio_framebufferdisplay_type) {
Expand Down Expand Up @@ -186,11 +186,7 @@ void reset_displays(void) {
#if CIRCUITPY_SHARPDISPLAY
} else if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
sharpdisplay_framebuffer_obj_t * sharp = &displays[i].sharpdisplay;
if(any_display_uses_this_framebuffer(&sharp->base)) {
common_hal_sharpdisplay_framebuffer_reset(sharp);
} else {
common_hal_sharpdisplay_framebuffer_deinit(sharp);
}
common_hal_sharpdisplay_framebuffer_reset(sharp);
#endif
} else {
// Not an active display bus.
Expand Down