Skip to content

Commit effa01e

Browse files
committed
Improve Fruit Jam
* Add bus, port_numbers and speed to USB devices. Allows for differentiating identical devices. * Autodetect display and adjust if widescreen * Enable I2S DAC via its reset pin * Show keyboard emoji in status bar. (Only works over serial connection now. Built in font doesn't have the emoji.)
1 parent e8de36a commit effa01e

File tree

23 files changed

+319
-34
lines changed

23 files changed

+319
-34
lines changed

.gitmodules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@
345345
url = https://github.com/adafruit/Adafruit_CircuitPython_Wave.git
346346
[submodule "ports/raspberrypi/lib/Pico-PIO-USB"]
347347
path = ports/raspberrypi/lib/Pico-PIO-USB
348-
url = https://github.com/adafruit/Pico-PIO-USB.git
348+
url = https://github.com/tannewt/Pico-PIO-USB.git
349+
branch = better_timeouts
349350
[submodule "lib/micropython-lib"]
350351
path = lib/micropython-lib
351352
url = https://github.com/micropython/micropython-lib.git

lib/tinyusb

Submodule tinyusb updated 105 files

ports/raspberrypi/boards/adafruit_fruit_jam/board.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "shared-bindings/usb_host/Port.h"
1010
#include "supervisor/board.h"
1111

12+
#include "common-hal/picodvi/__init__.h"
13+
1214
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
1315

1416

@@ -25,12 +27,22 @@ bool board_reset_pin_number(uint8_t pin_number) {
2527

2628
return true;
2729
}
30+
// Set I2S out of reset.
31+
if (pin_number == 22) {
32+
gpio_put(pin_number, 1);
33+
gpio_set_dir(pin_number, GPIO_OUT);
34+
gpio_set_function(pin_number, GPIO_FUNC_SIO);
35+
36+
return true;
37+
}
2838
return false;
2939
}
3040
#endif
3141

32-
#if defined(DEFAULT_USB_HOST_DATA_PLUS)
3342
void board_init(void) {
43+
#if defined(DEFAULT_USB_HOST_DATA_PLUS)
3444
common_hal_usb_host_port_construct(DEFAULT_USB_HOST_DATA_PLUS, DEFAULT_USB_HOST_DATA_MINUS);
45+
#endif
46+
47+
picodvi_autoconstruct();
3548
}
36-
#endif

ports/raspberrypi/boards/adafruit_fruit_jam/mpconfigboard.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,18 @@
2121
#define DEFAULT_USB_HOST_DATA_MINUS (&pin_GPIO2)
2222
#define DEFAULT_USB_HOST_5V_POWER (&pin_GPIO11)
2323

24+
#define DEFAULT_DVI_BUS_CLK_DN (&pin_GPIO12)
25+
#define DEFAULT_DVI_BUS_CLK_DP (&pin_GPIO13)
26+
#define DEFAULT_DVI_BUS_RED_DN (&pin_GPIO14)
27+
#define DEFAULT_DVI_BUS_RED_DP (&pin_GPIO15)
28+
#define DEFAULT_DVI_BUS_GREEN_DN (&pin_GPIO16)
29+
#define DEFAULT_DVI_BUS_GREEN_DP (&pin_GPIO17)
30+
#define DEFAULT_DVI_BUS_BLUE_DN (&pin_GPIO18)
31+
#define DEFAULT_DVI_BUS_BLUE_DP (&pin_GPIO19)
32+
2433
#define CIRCUITPY_PSRAM_CHIP_SELECT (&pin_GPIO47)
34+
35+
// #define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO44)
36+
// #define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO45)
37+
38+
// #define CIRCUITPY_DEBUG_TINYUSB 0

ports/raspberrypi/boards/adafruit_fruit_jam/mpconfigboard.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ CHIP_PACKAGE = B
88
CHIP_FAMILY = rp2
99

1010
EXTERNAL_FLASH_DEVICES = "W25Q128JVxQ"
11+
12+
# CIRCUITPY_DISPLAY_FONT = $(TOP)/tools/fonts/unifont-16.0.02-all.bdf
13+
# CIRCUITPY_FONT_EXTRA_CHARACTERS = "🖮🖱️"

ports/raspberrypi/boards/adafruit_fruit_jam/pins.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ static const mp_rom_map_elem_t board_module_globals_table[] = {
1515
{ MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO44) },
1616
{ MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO45) },
1717

18-
// On-board switch reverses D0 and D1 connections to RX and TX.
19-
2018
{ MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) },
2119
{ MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) },
2220
{ MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) },

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
271271
// streaming support.
272272
self->framebuffer = (uint32_t *)port_malloc(framebuffer_size * sizeof(uint32_t), true);
273273
if (self->framebuffer == NULL || ((size_t)self->framebuffer & 0xf0000000) == 0x10000000) {
274+
if (self->framebuffer != NULL) {
275+
// Return the memory in PSRAM.
276+
port_free(self->framebuffer);
277+
self->framebuffer = NULL;
278+
}
274279
m_malloc_fail(framebuffer_size * sizeof(uint32_t));
275280
return;
276281
}

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

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "supervisor/port_heap.h"
1818

1919
#if defined(DEFAULT_DVI_BUS_CLK_DP)
20-
static bool picodvi_autoconstruct_enabled(void) {
20+
static bool picodvi_autoconstruct_enabled(mp_int_t *default_width, mp_int_t *default_height) {
2121
char buf[sizeof("detect")];
2222
buf[0] = 0;
2323

@@ -42,6 +42,48 @@ static bool picodvi_autoconstruct_enabled(void) {
4242
return false;
4343
}
4444
bool probed = common_hal_busio_i2c_probe(i2c, 0x50);
45+
if (probed) {
46+
uint8_t edid[128];
47+
uint8_t out[1] = {0};
48+
common_hal_busio_i2c_write_read(i2c, 0x50, out, 1, edid, sizeof(edid));
49+
bool edid_ok = true;
50+
if (edid[0] != 0x00 || edid[1] != 0xFF || edid[2] != 0xFF || edid[3] != 0xFF || edid[4] != 0xFF || edid[5] != 0xFF || edid[6] != 0xFF || edid[7] != 0x00) {
51+
edid_ok = false;
52+
}
53+
uint8_t checksum = 0;
54+
for (size_t i = 0; i < sizeof(edid); i++) {
55+
checksum += edid[i];
56+
}
57+
if (checksum != 0) {
58+
edid_ok = false;
59+
}
60+
61+
if (edid_ok) {
62+
uint8_t established_timings = edid[35];
63+
if ((established_timings & 0xa0) == 0) {
64+
// Check that 720x400@70Hz or 640x480@60Hz is supported. If not
65+
// and we read EDID ok, then don't autostart.
66+
probed = false;
67+
} else {
68+
size_t offset = 54;
69+
uint16_t preferred_pixel_clock = edid[offset] | (edid[offset + 1] << 8);
70+
if (preferred_pixel_clock != 0) {
71+
size_t preferred_width = ((edid[offset + 4] & 0xf0) << 4) | edid[offset + 2];
72+
size_t preferred_height = ((edid[offset + 7] & 0xf0) << 4) | edid[offset + 5];
73+
// Use 720x400 on 1080p, 4k and 8k displays.
74+
if ((established_timings & 0x80) != 0 &&
75+
preferred_width % 1920 == 0 &&
76+
preferred_height % 1080 == 0) {
77+
*default_width = 720 / 2;
78+
*default_height = 400 / 2;
79+
} else {
80+
*default_width = 640 / 2;
81+
*default_height = 480 / 2;
82+
}
83+
}
84+
}
85+
}
86+
}
4587
common_hal_busio_i2c_unlock(i2c);
4688
return probed;
4789
}
@@ -53,11 +95,13 @@ void picodvi_autoconstruct(void) {
5395
return;
5496
}
5597

56-
if (!picodvi_autoconstruct_enabled()) {
98+
mp_int_t default_width = 320;
99+
mp_int_t default_height = 240;
100+
if (!picodvi_autoconstruct_enabled(&default_width, &default_height)) {
57101
return;
58102
}
59103

60-
mp_int_t width = 320;
104+
mp_int_t width = default_width;
61105
mp_int_t height = 0;
62106
mp_int_t color_depth = 16;
63107
mp_int_t rotation = 0;
@@ -75,6 +119,9 @@ void picodvi_autoconstruct(void) {
75119
case 320:
76120
height = 240;
77121
break;
122+
case 360:
123+
height = 200;
124+
break;
78125
}
79126
}
80127

@@ -85,8 +132,8 @@ void picodvi_autoconstruct(void) {
85132

86133
if (!common_hal_picodvi_framebuffer_preflight(width, height, color_depth)) {
87134
// invalid configuration, set back to default
88-
width = 320;
89-
height = 240;
135+
width = default_width;
136+
height = default_height;
90137
color_depth = 16;
91138
}
92139

py/circuitpy_defns.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ SRC_SHARED_MODULE_ALL = \
739739
usb/__init__.c \
740740
usb/core/__init__.c \
741741
usb/core/Device.c \
742+
usb/util/__init__.c \
742743
ustack/__init__.c \
743744
vectorio/Circle.c \
744745
vectorio/Polygon.c \

0 commit comments

Comments
 (0)