forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Auto-configure display on some RP2350 boards #10028
New issue
8000
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
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
db8d517
Auto-configure display on Feather RP2350
jepler 4c61d61
Use module attribute delegation to make board.DISPLAY always work
jepler 890c7f2
Move MaTouch link to the right spot
jepler 9cbfc41
Document RP2350 DVI display configuration
jepler 7e373ad
Add preflight function for picodvi display
jepler 8675097
picodvi_autoconstruct: preflight settings, use width=0 to disable
jepler 22f25c5
board: fix build errors
jepler 551b981
metro rp2350: configure display pins & autoconstruct
jepler 8be1681
remove this, it got moved to common code
jepler 61ea718
eliminate a bit more code if the DVI/hstx pins aren't defined
jepler 3a84599
fix the DISPLAYIO_ITEMS they were backwards
jepler e820416
Add an environment variable to disable or force picodvi
jepler 1d9b83f
Merge remote-tracking branch 'origin/main' into feather-rp2350-autodvi
jepler 201bc69
Remove a comment that refers to previously deleted code
jepler f0e3130
picodvi: Fall back to the default mode if preflight fails
jepler 0846aa4
circuitpy_mpconfig: fix build config
jepler 025f4fd
fix WIDTH unintentionally changed to HEIGHT
jepler 4aeddf2
spell out environment variable names in full
jepler 86fe684
Move the new display accessor to supervisor.runtime.display
jepler 83415e7
Make primary display settable, defaults to None unless set by board_init
jepler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
<
8000
/div>
View file
Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// This file is part of the CircuitPython project: https://circuitpython.org | ||
// | ||
// SPDX-FileCopyrightText: Copyright (c) 2025 Jeff Epler for Adafruit Industries | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include "common-hal/picodvi/__init__.h" | ||
#include "common-hal/picodvi/Framebuffer.h" | ||
#include "bindings/picodvi/Framebuffer.h" | ||
#include "shared-bindings/busio/I2C.h" | ||
#include "shared-bindings/board/__init__.h" | ||
#include "shared-module/displayio/__init__.h" | ||
#include "shared-module/os/__init__.h" | ||
#include "supervisor/shared/safe_mode.h" | ||
#include "py/gc.h" | ||
#include "py/runtime.h" | ||
#include "supervisor/port_heap.h" | ||
|
||
#if defined(DEFAULT_DVI_BUS_CLK_DP) | ||
static bool picodvi_autoconstruct_enabled(void) { | ||
char buf[sizeof("detect")]; | ||
buf[0] = 0; | ||
|
||
// (any failure leaves the content of buf untouched: an empty nul-terminated string | ||
(void)common_hal_os_getenv_str("CIRCUITPY_PICODVI_ENABLE", buf, sizeof(buf)); | ||
|
||
if (!strcasecmp(buf, "never")) { | ||
return false; | ||
} | ||
if (!strcasecmp(buf, "always")) { | ||
return true; | ||
} | ||
|
||
// It's "detect" or else an invalid value which is treated the same as "detect". | ||
|
||
// check if address 0x50 is live on the I2C bus | ||
busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0); | ||
if (!i2c) { | ||
return false; | ||
} | ||
if (!common_hal_busio_i2c_try_lock(i2c)) { | ||
return false; | ||
} | ||
bool probed = common_hal_busio_i2c_probe(i2c, 0x50); | ||
common_hal_busio_i2c_unlock(i2c); | ||
return probed; | ||
} | ||
|
||
// For picodvi_autoconstruct to work, the 8 DVI/HSTX pin names must be defined, AND | ||
// i2c bus 0 must also be connected to DVI with on-board pull ups | ||
void picodvi_autoconstruct(void) { | ||
if (get_safe_mode() != SAFE_MODE_NONE) { | ||
return; | ||
} | ||
|
||
if (!picodvi_autoconstruct_enabled()) { | ||
return; | ||
} | ||
|
||
mp_int_t width = 320; | ||
mp_int_t height = 0; | ||
mp_int_t color_depth = 16; | ||
mp_int_t rotation = 0; | ||
|
||
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_WIDTH", &width); | ||
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_HEIGHT", &height); | ||
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_COLOR_DEPTH", &color_depth); | ||
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_ROTATION", &rotation); | ||
|
||
if (height == 0) { | ||
switch (width) { | ||
case 640: | ||
height = 480; | ||
break; | ||
case 320: | ||
height = 240; | ||
break; | ||
} | ||
} | ||
|
||
if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270) { | ||
// invalid rotation | ||
rotation = 0; | ||
} | ||
|
||
if (!common_hal_picodvi_framebuffer_preflight(width, height, color_depth)) { | ||
// invalid configuration, set back to default | ||
width = 320; | ||
height = 240; | ||
color_depth = 16; | ||
} | ||
|
||
// construct framebuffer and display | ||
picodvi_framebuffer_obj_t *fb = &allocate_display_bus_or_raise()->picodvi; | ||
fb->base.type = &picodvi_framebuffer_type; | ||
common_hal_picodvi_framebuffer_construct(fb, | ||
width, height, | ||
DEFAULT_DVI_BUS_CLK_DP, | ||
DEFAULT_DVI_BUS_CLK_DN, | ||
DEFAULT_DVI_BUS_RED_DP, | ||
DEFAULT_DVI_BUS_RED_DN, | ||
DEFAULT_DVI_BUS_GREEN_DP, | ||
DEFAULT_DVI_BUS_GREEN_DN, | ||
DEFAULT_DVI_BUS_BLUE_DP, | ||
DEFAULT_DVI_BUS_BLUE_DN, | ||
color_depth); | ||
|
||
framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; | ||
display->base.type = &framebufferio_framebufferdisplay_type; | ||
common_hal_framebufferio_framebufferdisplay_construct( | ||
display, | ||
MP_OBJ_FROM_PTR(fb), | ||
rotation, | ||
true); | ||
} | ||
#else | ||
void picodvi_autoconstruct(void) { | ||
} | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// This file is part of the CircuitPython project: https://circuitpython.org | ||
// | ||
// SPDX-FileCopyrightText: Copyright (c) 2025 Jeff Epler for Adafruit Industries | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#pragma once | ||
|
||
extern void picodvi_autoconstruct(void); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no
30A3
changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.