Skip to content

Commit e820416

Browse files
committed
Add an environment variable to disable or force picodvi
and auto-set height and support rotation similar to how it's done on some of those dot clock display espressif boards
1 parent 3a84599 commit e820416

File tree

2 files changed

+70
-19
lines changed

2 files changed

+70
-19
lines changed

docs/environment.rst

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ a rotation of 0. Attempting to initialize the screen with a rotation other than
121121
90, 180 or 270 is not supported and will result in an unexpected screen rotation.
122122

123123
`Sunton ESP32-8048S050 <https://circuitpython.org/board/sunton_esp32_8048S050/>`_
124+
`Adafruit Feather RP2350 <https://circuitpython.org/board/adafruit_feather_rp2350/>`_
125+
`Adafruit Metro RP2350 <https://circuitpython.org/board/adafruit_metro_rp2350/>`_
124126

125127
CIRCUITPY_DISPLAY_FREQUENCY
126128
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -132,6 +134,20 @@ display frequency.
132134

133135
`Sunton ESP32-8048S050 <https://circuitpython.org/board/sunton_esp32_8048S050/>`_
134136

137+
138+
CIRCUITPY_PICODVI_ENABLE
139+
~~~~~~~~~~~~~~~~~~~~~~~~
140+
Whether to configure the display at board initialization time, one of the following:
141+
142+
.. code-block::
143+
144+
CIRCUITPY_PICODVI_ENABLE="detect" # when EDID EEPROM is detected (default)
145+
CIRCUITPY_PICODVI_ENABLE="always"
146+
CIRCUITPY_PICODVI_ENABLE="never"
147+
148+
`Adafruit Feather RP2350 <https://circuitpython.org/board/adafruit_feather_rp2350/>`_
149+
`Adafruit Metro RP2350 <https://circuitpython.org/board/adafruit_metro_rp2350/>`_
150+
135151
CIRCUITPY_DISPLAY_WIDTH, _HEIGHT, and _COLOR_DEPTH (RP2350 boards with DVI or HSTX connector)
136152
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137153
Selects the desired resolution and color depth.
@@ -142,18 +158,14 @@ Supported resolutions are:
142158

143159
The default value, if unspecified, is 320x240 with 16 bits per pixel.
144160

145-
setting ``CIRCUITPY_DISPLAY_WIDTH = 0`` disables automatic display configuration. In this case, the other
146-
values are not used.
147-
148-
If an EDID EEPROM is not detected on the I2C bus, automatic display
149-
configuration is not performed.
161+
If height is unspecified, it is set from the width. For example, a width of 640
162+
implies a height of 480.
150163

151-
Example: Configure the display to 640x480 black and white (1bpp):
164+
Example: Configure the display to 640x480 black and white (1 bit per pixel):
152165

153166
.. code-block::
154167
155168
CIRCUITPY_DISPLAY_WIDTH=640
156-
CIRCUITPY_DISPLAY_WIDTH=480
157169
CIRCUITPY_DISPLAY_COLOR_DEPTH=1
158170
159171
`Adafruit Feather RP2350 <https://circuitpython.org/board/adafruit_feather_rp2350/>`_

ports/raspberrypi/common-hal/picodvi/__init__.c

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,73 @@
1616
#include "py/runtime.h"
1717
#include "supervisor/port_heap.h"
1818

19-
void picodvi_autoconstruct(void) {
20-
#if defined(DEFAULT_DVI_BUS_CLK_DP)
21-
if (get_safe_mode() != SAFE_MODE_NONE) {
22-
return;
19+
#if defined(DEFAULT_DVI_BUS_CLK_DP)
20+
static bool picodvi_autoconstruct_enabled(void) {
21+
char buf[sizeof("detect")];
22+
buf[0] = 0;
23+
24+
// (any failure leaves the content of buf untouched: an empty nul-terminated string
25+
(void)common_hal_os_getenv_str("CIRCUITPY_PICODVI_ENABLE", buf, sizeof(buf));
26+
27+
if (!strcasecmp(buf, "never")) {
28+
return false;
29+
}
30+
if (!strcasecmp(buf, "always")) {
31+
return true;
2332
}
24-
// check if address 0x50 is live on the I2C bus -- return if not
33+
34+
// It's "detect" or else an invalid value which is treated the same as "detect".
35+
36+
// check if address 0x50 is live on the I2C bus
2537
busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
2638
if (!i2c) {
27-
return;
39+
return false;
2840
}
2941
if (!common_hal_busio_i2c_try_lock(i2c)) {
30-
return;
42+
return false;
3143
}
3244
bool probed = common_hal_busio_i2c_probe(i2c, 0x50);
3345
common_hal_busio_i2c_unlock(i2c);
34-
if (!probed) {
46+
return probed;
47+
}
48+
49+
// For picodvi_autoconstruct to work, the 8 DVI/HSTX pin names must be defined, AND
50+
// i2c bus 0 must also be connected to DVI with on-board pull ups
51+
void picodvi_autoconstruct(void) {
52+
if (get_safe_mode() != SAFE_MODE_NONE) {
3553
return;
3654
}
3755

56+
if (!picodvi_autoconstruct_enabled()) {
57+
return;
58+
}
3859

3960
mp_int_t width = 320;
40-
mp_int_t height = 240;
61+
mp_int_t height = 0;
4162
mp_int_t color_depth = 16;
63+
mp_int_t rotation = 0;
4264

4365
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_WIDTH", &width);
4466
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_HEIGHT", &height);
4567
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_COLOR_DEPTH", &color_depth);
68+
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_ROTATION", &rotation);
4669

47-
if (width == 0) {
70+
if (height == 0) {
71+
switch (width) {
72+
case 640:
73+
height = 480;
74+
break;
75+
case 320:
76+
height = 240;
77+
break;
78+
}
79+
}
80+
81+
if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270) {
82+
// invalid rotation
4883
return;
4984
}
85+
5086
if (!common_hal_picodvi_framebuffer_preflight(width, height, color_depth)) {
5187
// TODO: User configuration can fail without a self-explanatory message.
5288
// sadly, a print from here does NOT reach boot_out.txt, so no point in
@@ -75,7 +111,10 @@ void picodvi_autoconstruct(void) {
75111
common_hal_framebufferio_framebufferdisplay_construct(
76112
display,
77113
MP_OBJ_FROM_PTR(fb),
78-
0,
114+
rotation,
79115
true);
80-
#endif
81116
}
117+
#else
118+
void picodvi_autoconstruct(void) {
119+
}
120+
#endif

0 commit comments

Comments
 (0)