Skip to content

Commit 66edcf5

Browse files
committed
Add PicoDVI support
PicoDVI in CP support 640x480 and 800x480 on Feather DVI, Pico and Pico W. 1 and 2 bit grayscale are full resolution. 8 and 16 bit color are half resolution. Memory layout is modified to give the top most 4k of ram to the second core. Its MPU is used to prevent flash access after startup. The port saved word is moved to a watchdog scratch register so that it doesn't get overwritten by other things in RAM. Right align status bar and scroll area. This normally gives a few pixels of padding on the left hand side and improves the odds it is readable in a case. Fixes #7562 Fixes c stack checking. The length was correct but the top was being set to the current stack pointer instead of the correct top. Fixes #7643 This makes Bitmap subscr raise IndexError instead of ValueError when the index arguments are wrong.
1 parent 09c2c5e commit 66edcf5

File tree

35 files changed

+1134
-409
lines changed

35 files changed

+1134
-409
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,7 @@
331331
[submodule "ports/silabs/tools/slc_cli_linux"]
332332
path = ports/silabs/tools/slc_cli_linux
333333
url = https://github.com/SiliconLabs/circuitpython_slc_cli_linux
334+
[submodule "ports/raspberrypi/lib/PicoDVI"]
335+
path = ports/raspberrypi/lib/PicoDVI
336+
url = https://github.com/circuitpython/PicoDVI.git
337+
branch = circuitpython

locale/circuitpython.pot

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ msgstr ""
9898
#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
9999
#: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c
100100
#: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c
101+
#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c
102+
#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c
103+
#: shared-bindings/keypad/ShiftRegisterKeys.c
101104
msgid "%q"
102105
msgstr ""
103106

@@ -123,6 +126,7 @@ msgstr ""
123126

124127
#: ports/espressif/common-hal/espulp/ULP.c
125128
#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
129+
#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c
126130
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
127131
#: shared-bindings/digitalio/DigitalInOut.c
128132
#: shared-bindings/microcontroller/Pin.c
@@ -161,11 +165,11 @@ msgstr ""
161165
msgid "%q length must be >= %d"
162166
msgstr ""
163167

164-
#: py/argcheck.c
168+
#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c
165169
msgid "%q must be %d"
166170
msgstr ""
167171

168-
#: py/argcheck.c
172+
#: py/argcheck.c shared-bindings/displayio/Bitmap.c
169173
msgid "%q must be %d-%d"
170174
msgstr ""
171175

@@ -193,7 +197,7 @@ msgstr ""
193197
msgid "%q must be array of type 'H'"
194198
msgstr ""
195199

196-
#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c
200+
#: shared-module/synthio/__init__.c
197201
msgid "%q must be array of type 'h'"
198202
msgstr ""
199203

@@ -465,6 +469,7 @@ msgstr ""
465469
msgid "All event channels in use"
466470
msgstr ""
467471

472+
#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c
468473
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
469474
msgid "All state machines in use"
470475
msgstr ""
@@ -473,6 +478,7 @@ msgstr ""
473478
msgid "All sync event channels in use"
474479
msgstr ""
475480

481+
#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c
476482
#: shared-bindings/pwmio/PWMOut.c
477483
msgid "All timers for this pin are in use"
478484
msgstr ""
@@ -1117,10 +1123,6 @@ msgstr ""
11171123
msgid "I2C peripheral in use"
11181124
msgstr ""
11191125

1120-
#: shared-bindings/audiobusio/I2SOut.c
1121-
msgid "I2SOut not available"
1122-
msgstr ""
1123-
11241126
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
11251127
msgid "In-buffer elements must be <= 4 bytes long"
11261128
msgstr ""
@@ -1223,7 +1225,9 @@ msgid "Interrupt error."
12231225
msgstr ""
12241226

12251227
#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
1226-
#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c
1228+
#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c
1229+
#: ports/raspberrypi/bindings/picodvi/Framebuffer.c
1230+
#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c
12271231
#: shared-bindings/digitalio/DigitalInOut.c
12281232
#: shared-bindings/displayio/EPaperDisplay.c
12291233
msgid "Invalid %q"
@@ -1708,10 +1712,6 @@ msgstr ""
17081712
msgid "Oversample must be multiple of 8."
17091713
msgstr ""
17101714

1711-
#: shared-bindings/audiobusio/PDMIn.c
1712-
msgid "PDMIn not available"
1713-
msgstr ""
1714-
17151715
#: shared-bindings/pwmio/PWMOut.c
17161716
msgid ""
17171717
"PWM frequency not writable when variable_frequency is False on construction."

main.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,15 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack
153153
supervisor_workflow_reset();
154154

155155
// Stack limit should be less than real stack size, so we have a chance
156-
// to recover from limit hit. (Limit is measured in bytes.)
156+
// to recover from limit hit. (Limit is measured in bytes.) The top of the
157+
// stack is set to our current state. Not the actual top.
157158
mp_stack_ctrl_init();
158159

159-
if (stack_get_bottom() != NULL) {
160-
mp_stack_set_limit(stack_get_length() - 1024);
160+
uint32_t *stack_bottom = stack_get_bottom();
161+
if (stack_bottom != NULL) {
162+
size_t stack_length = stack_get_length();
163+
mp_stack_set_top(stack_bottom + (stack_length / sizeof(uint32_t)));
164+
mp_stack_set_limit(stack_length - 1024);
161165
}
162166

163167

ports/broadcom/common-hal/videocore/Framebuffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void common_hal_videocore_framebuffer_deinit(videocore_framebuffer_obj_t *self)
4242
if (vcmailbox_release_framebuffer()) {
4343
self->framebuffer = NULL;
4444
}
45+
self->base.type = &mp_type_NoneType;
4546
}
4647

4748
bool common_hal_videocore_framebuffer_deinited(videocore_framebuffer_obj_t *self) {

ports/raspberrypi/Makefile

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ INC_CYW43 := \
3333
-isystem lib/cyw43-driver/firmware \
3434
-isystem lib/cyw43-driver/src \
3535
-isystem lib/lwip/src/include \
36-
-isystem sdk/src/rp2_common/pico_async_context/include/ \
36+
-isystem sdk/src/rp2_common/pico_async_context/include/ \
3737
-isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \
3838
-isystem sdk/src/rp2_common/pico_cyw43_driver/include/ \
3939
-isystem sdk/src/rp2_common/pico_lwip/include/ \
40-
-isystem sdk/src/rp2_common/pico_rand/include/ \
40+
-isystem sdk/src/rp2_common/pico_rand/include/ \
4141

4242
CFLAGS_CYW43 := -DCYW43_LWIP=1 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25 -DIGNORE_GPIO23 -DIGNORE_GPIO24 -DCYW43_LOGIC_DEBUG=0 -DCYW43_NETUTILS=1
4343
SRC_SDK_CYW43 := \
@@ -105,6 +105,7 @@ INC += \
105105
-isystem sdk/src/common/pico_util/include/ \
106106
-isystem sdk/src/rp2040/hardware_regs/include/ \
107107
-isystem sdk/src/rp2040/hardware_structs/include/ \
108+
-isystem sdk/src/rp2_common/cmsis/ \
108109
-isystem sdk/src/rp2_common/hardware_adc/include/ \
109110
-isystem sdk/src/rp2_common/hardware_base/include/ \
110111
-isystem sdk/src/rp2_common/hardware_claim/include/ \
@@ -113,16 +114,19 @@ INC += \
113114
-isystem sdk/src/rp2_common/hardware_dma/include/ \
114115
-isystem sdk/src/rp2_common/hardware_flash/include/ \
115116
-isystem sdk/src/rp2_common/hardware_gpio/include/ \
117+
-isystem sdk/src/rp2_common/hardware_interp/include/ \
116118
-isystem sdk/src/rp2_common/hardware_irq/include/ \
117119
-isystem sdk/src/rp2_common/hardware_i2c/include/ \
118120
-isystem sdk/src/rp2_common/hardware_pio/include/ \
119121
-isystem sdk/src/rp2_common/hardware_pll/include/ \
122+
-isystem sdk/src/rp2_common/hardware_pwm/include/ \
120123
-isystem sdk/src/rp2_common/hardware_resets/include/ \
121124
-isystem sdk/src/rp2_common/hardware_rtc/include/ \
122125
-isystem sdk/src/rp2_common/hardware_spi/include/ \
123126
-isystem sdk/src/rp2_common/hardware_sync/include/ \
124127
-isystem sdk/src/rp2_common/hardware_timer/include/ \
125128
-isystem sdk/src/rp2_common/hardware_uart/include/ \
129+
-isystem sdk/src/rp2_common/hardware_vreg/include/ \
126130
-isystem sdk/src/rp2_common/hardware_watchdog/include/ \
127131
-isystem sdk/src/rp2_common/hardware_xosc/include/ \
128132
-isystem sdk/src/rp2_common/pico_multicore/include/ \
@@ -131,7 +135,7 @@ INC += \
131135
-isystem sdk/src/rp2_common/pico_printf/include/ \
132136
-isystem sdk/src/rp2_common/pico_float/include/ \
133137
-isystem sdk/src/rp2_common/pico_platform/include/ \
134-
-isystem sdk/src/rp2_common/pico_runtime/printf/include/ \
138+
-isystem sdk/src/rp2_common/pico_runtime/include/ \
135139
-isystem sdk/src/rp2_common/pico_bootrom/include/ \
136140
-isystem sdk/src/rp2_common/pico_unique_id/include/ \
137141
$(INC_CYW43) \
@@ -141,7 +145,7 @@ INC += \
141145
-I$(BUILD)
142146

143147
# Pico specific configuration
144-
CFLAGS += -DRASPBERRYPI -DPICO_ON_DEVICE=1 -DPICO_NO_BINARY_INFO=0 -DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=0 -DPICO_DIVIDER_CALL_IDIV0=0 -DPICO_DIVIDER_CALL_LDIV0=0 -DPICO_DIVIDER_HARDWARE=1 -DPICO_DOUBLE_ROM=1 -DPICO_FLOAT_ROM=1 -DPICO_MULTICORE=1 -DPICO_BITS_IN_RAM=0 -DPICO_DIVIDER_IN_RAM=0 -DPICO_DOUBLE_PROPAGATE_NANS=0 -DPICO_DOUBLE_IN_RAM=0 -DPICO_MEM_IN_RAM=0 -DPICO_FLOAT_IN_RAM=0 -DPICO_FLOAT_PROPAGATE_NANS=1 -DPICO_NO_FLASH=0 -DPICO_COPY_TO_RAM=0 -DPICO_DISABLE_SHARED_IRQ_HANDLERS=0 -DPICO_NO_BI_BOOTSEL_VIA_DOUBLE_RESET=0
148+
CFLAGS += -DRASPBERRYPI -DPICO_ON_DEVICE=1 -DPICO_NO_BINARY_INFO=0 -DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=0 -DPICO_DIVIDER_CALL_IDIV0=0 -DPICO_DIVIDER_CALL_LDIV0=0 -DPICO_DIVIDER_HARDWARE=1 -DPICO_DOUBLE_ROM=1 -DPICO_FLOAT_ROM=1 -DPICO_MULTICORE=1 -DPICO_BITS_IN_RAM=0 -DPICO_DIVIDER_IN_RAM=0 -DPICO_DOUBLE_PROPAGATE_NANS=0 -DPICO_DOUBLE_IN_RAM=0 -DPICO_MEM_IN_RAM=0 -DPICO_FLOAT_IN_RAM=0 -DPICO_FLOAT_PROPAGATE_NANS=1 -DPICO_NO_FLASH=0 -DPICO_COPY_TO_RAM=0 -DPICO_DISABLE_SHARED_IRQ_HANDLERS=0 -DPICO_NO_BI_BOOTSEL_VIA_DOUBLE_RESET=0 -DDVI_1BPP_BIT_REVERSE=0
145149
OPTIMIZATION_FLAGS ?= -O3
146150
# TinyUSB defines
147151
CFLAGS += -DTUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX=1 -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024
@@ -172,8 +176,8 @@ DISABLE_WARNINGS = -Wno-stringop-overflow -Wno-cast-align
172176
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes
173177

174178
CFLAGS += \
175-
-march=armv6-m \
176-
-mthumb \
179+
-march=armv6-m \
180+
-mthumb \
177181
-mabi=aapcs-linux \
178182
-mcpu=cortex-m0plus \
179183
-msoft-float \
@@ -195,13 +199,15 @@ SRC_SDK := \
195199
src/common/pico_time/time.c \
196200
src/common/pico_time/timeout_helper.c \
197201
src/common/pico_util/pheap.c \
202+
src/common/pico_util/queue.c \
198203
src/rp2_common/hardware_adc/adc.c \
199204
src/rp2_common/hardware_claim/claim.c \
200205
src/rp2_common/hardware_clocks/clocks.c \
201206
src/rp2_common/hardware_dma/dma.c \
202207
src/rp2_common/hardware_flash/flash.c \
203208
src/rp2_common/hardware_gpio/gpio.c \
204209
src/rp2_common/hardware_i2c/i2c.c \
210+
src/rp2_common/hardware_interp/interp.c \
205211
src/rp2_common/hardware_irq/irq.c \
206212
src/rp2_common/hardware_pio/pio.c \
207213
src/rp2_common/hardware_pll/pll.c \
@@ -210,6 +216,7 @@ SRC_SDK := \
210216
src/rp2_common/hardware_sync/sync.c \
211217
src/rp2_common/hardware_timer/timer.c \
212218
src/rp2_common/hardware_uart/uart.c \
219+
src/rp2_common/hardware_vreg/vreg.c \
213220
src/rp2_common/hardware_watchdog/watchdog.c \
214221
src/rp2_common/hardware_xosc/xosc.c \
215222
src/rp2_common/pico_bootrom/bootrom.c \
@@ -223,6 +230,7 @@ SRC_SDK := \
223230
src/rp2_common/pico_printf/printf.c \
224231
src/rp2_common/pico_runtime/runtime.c \
225232
src/rp2_common/pico_stdio/stdio.c \
233+
src/rp2_common/pico_stdlib/stdlib.c \
226234
src/rp2_common/pico_unique_id/unique_id.c \
227235
$(SRC_SDK_CYW43) \
228236

@@ -240,12 +248,24 @@ SRC_C += \
240248
background.c \
241249
peripherals/pins.c \
242250
lib/crypto-algorithms/sha256.c \
251+
lib/PicoDVI/software/libdvi/dvi.c \
252+
lib/PicoDVI/software/libdvi/dvi_serialiser.c \
253+
lib/PicoDVI/software/libdvi/dvi_timing.c \
254+
lib/PicoDVI/software/libdvi/tmds_encode.c \
243255
lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c \
244256
lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c \
245257
mphalport.c \
246258
$(SRC_CYW43) \
247259
$(SRC_LWIP) \
248260

261+
ifeq ($(CIRCUITPY_PICODVI),1)
262+
SRC_C += \
263+
bindings/picodvi/__init__.c \
264+
bindings/picodvi/Framebuffer.c \
265+
common-hal/picodvi/Framebuffer.c \
266+
267+
endif
268+
249269
ifeq ($(CIRCUITPY_SSL),1)
250270
CFLAGS += -isystem $(TOP)/mbedtls/include
251271
SRC_MBEDTLS := $(addprefix lib/mbedtls/library/, \
@@ -359,6 +379,7 @@ SRC_S_UPPER = sdk/src/rp2_common/hardware_divider/divider.S \
359379
sdk/src/rp2_common/pico_int64_ops/pico_int64_ops_aeabi.S \
360380
sdk/src/rp2_common/pico_mem_ops/mem_ops_aeabi.S \
361381
sdk/src/rp2_common/pico_standard_link/crt0.S \
382+
lib/PicoDVI/software/libdvi/tmds_encode_asm.S \
362383

363384
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
364385
OBJ += $(addprefix $(BUILD)/, $(SRC_SDK:.c=.o))
@@ -405,13 +426,19 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_M
405426

406427
all: $(BUILD)/firmware.uf2
407428

408-
LINK_LD := $(firstword $(wildcard boards/$(BOARD)/link.ld link.ld))
409-
$(BUILD)/firmware.elf: $(OBJ) $(LINK_LD)
429+
BOARD_LD := $(wildcard boards/$(BOARD)/link.ld)
430+
431+
ifneq ($(BOARD_LD),)
432+
LINKER_SCRIPTS = -Wl,-T,$(BOARD_LD)
433+
endif
434+
435+
LINKER_SCRIPTS += -Wl,-T,link.ld
436+
437+
$(BUILD)/firmware.elf: $(OBJ) $(BOARD_LD) link.ld
410438
$(STEPECHO) "LINK $@"
411439
$(Q)echo $(OBJ) > $(BUILD)/firmware.objs
412440
$(Q)echo $(PICO_LDFLAGS) > $(BUILD)/firmware.ldflags
413-
$(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags -Wl,-T,$(LINK_LD) -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs -Wl,-lc
414-
$(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINK_LD) $(BUILD)
441+
$(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags $(LINKER_SCRIPTS) -Wl,--print-memory-usage -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs -Wl,-lc
415442

416443
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
417444
$(STEPECHO) "Create $@"

ports/raspberrypi/audio_dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
3939

40-
#if CIRCUITPY_AUDIOPWMIO || CIRCUITPY_AUDIOBUSIO
40+
#if CIRCUITPY_AUDIOCORE
4141

4242
void audio_dma_reset(void) {
4343
for (size_t channel = 0; channel < NUM_DMA_CHANNELS; channel++) {

0 commit comments

Comments
 (0)