Skip to content
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

Pico loader #877

Draft
wants to merge 85 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
5de383f
pico: don't attempt picovision render before a mode is set
Daft-Freak Jul 17, 2023
62a9d04
Header function ptrs for pico builds too
Daft-Freak Mar 7, 2023
9a9dba1
pico: output a sort-of .blit file as well as a standalone .uf2
Daft-Freak Mar 3, 2023
e96d67a
pico: pass board defs to blit builds
Daft-Freak Mar 7, 2023
63cb767
pico: add list_installed_games
Daft-Freak Mar 3, 2023
f134e5c
pico: Add some launch support
Daft-Freak Mar 3, 2023
f77ffc8
Build launcher for pico
Daft-Freak Mar 3, 2023
a25705f
pico: some kind of basic loader
Daft-Freak Mar 6, 2023
36bb4a1
HACK: disable picosystem-hardware-test
Daft-Freak Mar 7, 2023
af43d0d
pico: WIP user split
Daft-Freak Mar 7, 2023
9a28365
pico: rework standalone/blit builds
Daft-Freak Mar 10, 2023
5491bcc
Revert "HACK: disable picosystem-hardware-test"
Daft-Freak Jul 13, 2023
0131a8b
Add an API to get screen.data to fix pico page-flipping
Daft-Freak Mar 7, 2023
7b637a3
pico: move framebuffer allocation to the other side of teh API
Daft-Freak Mar 7, 2023
8b116da
pico: change tick in launch API
Daft-Freak Mar 7, 2023
7464464
pico: delay launches
Daft-Freak Mar 8, 2023
409291f
pico: remove reset-based launch
Daft-Freak Mar 10, 2023
57724eb
pico: refactor multiplayer code into generic CDC command handling
Daft-Freak Mar 10, 2023
4c732ca
pico: CDC flash command
Daft-Freak Mar 10, 2023
bbdf1f5
pico: move disable_user_code after render decl
Daft-Freak Mar 10, 2023
46d0e06
pico: pass max hires bounds through set_framebuffer
Daft-Freak Mar 13, 2023
8e97ed9
pico: clamp display width to max game was built for
Daft-Freak Mar 13, 2023
b6b0f3c
pico: only include PROG command if building a loader with USB in devi…
Daft-Freak Mar 14, 2023
3aeb81c
pico: handle metadata for blits
Daft-Freak Jul 18, 2023
0ab3ee4
pico: fix save path for blits
Daft-Freak Jul 18, 2023
fd8e7db
pico: move code related to blit files and launching to its own file
Daft-Freak Jul 27, 2023
b2144e0
pico: refactor the flash writing part of the prog command into a class
Daft-Freak Jul 29, 2023
7c95c7a
pico: handle launching files from storage (SD card)
Daft-Freak Jul 30, 2023
cb3eb88
pico: auto install launcher from storage
Daft-Freak Jul 31, 2023
99fe415
ci: test building pico-blits for picosystem
Daft-Freak Jul 13, 2023
a438137
pico: don't init null command
Daft-Freak Jun 24, 2024
ed5129e
pico: allow overriding flash offset for blits
Daft-Freak Jun 24, 2024
e8005db
launcher: build at a lower offset for pico
Daft-Freak Jun 24, 2024
26b2f13
pico: list games with missing metadata
Daft-Freak Jun 25, 2024
5b802d4
pico: move game block size to header
Daft-Freak Jun 25, 2024
8bb79a4
pico: handle __LS command
Daft-Freak Jun 25, 2024
57c7ae3
pico: move filename/size parsing buffer out of PROG command
Daft-Freak Jun 26, 2024
d3124c3
pico: handle LNCH command
Daft-Freak Jun 26, 2024
bdbfd4a
pico: refactor some helpers out of list_installed_games
Daft-Freak Jun 27, 2024
4d25ab3
pico: implement erase_game API
Daft-Freak Jun 27, 2024
c2cc06b
pico: handle ERSE command
Daft-Freak Jun 28, 2024
d92e6ad
pico: refactor cdc buffer
Daft-Freak Jun 29, 2024
6aa1103
pico: update loader linker script
Daft-Freak Sep 4, 2024
e7805b7
pico: fixup blit build and update linker script
Daft-Freak Sep 4, 2024
388a19c
pico: link blits against pico_clib_interface
Daft-Freak Sep 4, 2024
a3f9688
pico: early out from dbi update if framebuffer not set yet
Daft-Freak Sep 4, 2024
27f3aac
pico: add linker scripts for rp2530 loader/blits
Daft-Freak Sep 4, 2024
88c7fbc
pico: add define for device id
Daft-Freak Sep 5, 2024
cff83a8
pico: add 2350 device id
Daft-Freak Sep 5, 2024
ca7ef78
pico: use untranslated flash addr for scanning and metadata
Daft-Freak Sep 5, 2024
4aa1bed
Move default value for blit offset to 32blit-pico
Daft-Freak Sep 5, 2024
655c94b
pico: fix indentation in BlitWriter::prepare_write
Daft-Freak Sep 5, 2024
a2fdcb6
pico: move helpers above api impl in blit-launch
Daft-Freak Sep 5, 2024
4129dd9
pico: support .blits flashed at any offset using address translation
Daft-Freak Sep 5, 2024
8ee3401
pico: set default flash offset for RP2350 to 4MB
Daft-Freak Sep 5, 2024
c9f27ff
pico: invalidate cache after setting up translation
Daft-Freak Sep 6, 2024
03b7948
pico: move fb size calcs to config.h and dedup
Daft-Freak Sep 6, 2024
30ccaa0
pico: implement the HOME button exit/reset
Daft-Freak Sep 6, 2024
1a06185
pico: fix non-loader fb size
Daft-Freak Oct 22, 2024
3963edc
pico: always use half fb size as page size
Daft-Freak Oct 30, 2024
48441cd
pico: rename blit-launch to blit_launch for consistency
Daft-Freak Oct 31, 2024
901121d
pico: avoid running pre-init code for blits
Daft-Freak Oct 31, 2024
6ea4e91
pico: set our board directory as an extra search path for the SDK
Daft-Freak Nov 7, 2024
78fe134
pico: helper for reading file metadata
Daft-Freak Nov 11, 2024
b515bc5
pico: check for existing copy of game before flashing
Daft-Freak Nov 11, 2024
5bab4cd
pico: cleanup duplicates after flashing new game
Daft-Freak Nov 12, 2024
0d15813
pico: restore pre-init on RP2040
Daft-Freak Nov 26, 2024
8fc0b65
pico: use cache API to invalidate after setting up translation
Daft-Freak Dec 30, 2024
e6cc24e
pico: set flash size to 4M for 2350 blits
Daft-Freak Jan 13, 2025
52fc237
pico: put fb in uninitialzed data
Daft-Freak Jan 13, 2025
7ac48d4
pico: add some pre-init code to reset API state before launching
Daft-Freak Feb 21, 2025
9332bbb
pico: remove printfs in PROG handling
Daft-Freak Feb 23, 2025
e3bf566
pico: refactor out a helper for reading strings for CDC commands
Daft-Freak Feb 24, 2025
9afb40a
pico: implement SAVE command
Daft-Freak Feb 24, 2025
9dbcc8a
pico: reset offset in SAVE command init
Daft-Freak Feb 25, 2025
18f19fb
pico: setup loader-side screen
Daft-Freak Feb 25, 2025
2b3184d
pico: add code to render an overlay in the loader
Daft-Freak Feb 26, 2025
c02acc7
pico: display progress bar for CDC SAVE
Daft-Freak Feb 26, 2025
f8db51b
pico: tweak overlay enable to handle disable_user_code changing render
Daft-Freak Feb 26, 2025
e7e44f8
pico: display progress bar for CDC PROG
Daft-Freak Feb 26, 2025
cf3a60d
pico: add helper to make sure overlay is rendered
Daft-Freak Feb 26, 2025
124a9cd
pico: display a message when erasing
Daft-Freak Feb 26, 2025
ed75dac
pico: move stdio setup into standalone branch
Daft-Freak Feb 26, 2025
cb2c0cd
pico: split board config detection to board-config.cmake
Daft-Freak Feb 26, 2025
af4aa05
pico: break out blit_executable like 32blit-stm32
Daft-Freak Feb 26, 2025
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
8 changes: 8 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ jobs:
apt-packages: ccache gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib pipx python3-requests

- os: ubuntu-22.04
pico-sdk: true
name: PicoSystem (.blit)
cache-key: picosystem-bl
release-suffix: PicoSystem-blit
cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE -DPICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk -DPICO_BOARD=pimoroni_picosystem -DBLIT_EXECUTABLE_PICO_BLIT=1 -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
apt-packages: ccache gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib python3-setuptools

- os: ubuntu-20.04
pico-sdk: true
name: PicoVision
cache-key: picovision
Expand Down
40 changes: 39 additions & 1 deletion 32blit-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,68 @@ if (NOT DEFINED BLIT_ONCE)
function(blit_executable_args)
set(SOURCES)

# enable one of the pico builds if neither set
if(NOT BLIT_EXECUTABLE_PICO_STANDALONE_UF2 AND NOT BLIT_EXECUTABLE_PICO_BLIT)
set(BLIT_EXECUTABLE_PICO_STANDALONE_UF2 TRUE)
endif()

# global overrides
if(DEFINED BLIT_EXECUTABLE_INTERNAL_FLASH)
set(INTERNAL_FLASH ${BLIT_EXECUTABLE_INTERNAL_FLASH})
else()
set(INTERNAL_FLASH FALSE)
endif()

if(DEFINED BLIT_EXECUTABLE_PICO_STANDALONE_UF2)
set(PICO_STANDALONE_UF2 ${BLIT_EXECUTABLE_PICO_STANDALONE_UF2})
else()
set(PICO_STANDALONE_UF2 FALSE)
endif()

if(DEFINED BLIT_EXECUTABLE_PICO_BLIT)
set(PICO_BLIT ${BLIT_EXECUTABLE_PICO_BLIT})
else()
set(PICO_BLIT FALSE)
endif()

if(DEFINED BLIT_EXECUTABLE_PICO_BLIT_OFFSET_KB)
set(PICO_BLIT_OFFSET_KB ${BLIT_EXECUTABLE_PICO_BLIT_OFFSET_KB})
endif()

foreach(arg IN LISTS ARGN)
if(arg STREQUAL "INTERNAL_FLASH")
set(${arg} TRUE)
elseif(arg STREQUAL "PICO_STANDALONE_UF2")
set(${arg} TRUE)
set(PICO_BLIT FALSE) # can't build both
elseif(arg STREQUAL "PICO_BLIT")
set(${arg} TRUE)
set(PICO_STANDALONE_UF2 FALSE)
# args with value
elseif(arg STREQUAL "PICO_BLIT_OFFSET_KB")
set(prev_arg ${arg})
# value for args with one
elseif(prev_arg STREQUAL "PICO_BLIT_OFFSET_KB")
set(${prev_arg} ${arg})
unset(prev_arg)
else()
list(APPEND SOURCES ${arg})
endif()
endforeach()

set(SOURCES ${SOURCES} PARENT_SCOPE)
set(INTERNAL_FLASH ${INTERNAL_FLASH} PARENT_SCOPE)
set(PICO_STANDALONE_UF2 ${PICO_STANDALONE_UF2} PARENT_SCOPE)
set(PICO_BLIT ${PICO_BLIT} PARENT_SCOPE)
set(PICO_BLIT_OFFSET_KB ${PICO_BLIT_OFFSET_KB} PARENT_SCOPE)
endfunction()

if (32BLIT_HW)
set(FLASH_PORT "AUTO" CACHE STRING "Port to use for flash")

include(${CMAKE_CURRENT_LIST_DIR}/32blit-stm32/executable.cmake)
elseif(PICO_SDK_PATH)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/32blit-pico 32blit-pico)
include(${CMAKE_CURRENT_LIST_DIR}/32blit-pico/executable.cmake)
else()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/32blit-sdl 32blit-sdl)
endif()
Expand Down
171 changes: 8 additions & 163 deletions 32blit-pico/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
cmake_policy(SET CMP0079 NEW) # target_link_libraries() allows use with targets in other directories.

set(CMAKE_C_STANDARD 11)

# Initialise the Pico SDK
set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}/board)
include (pico_sdk_import.cmake)

set(32BLIT_PICO 1 PARENT_SCOPE)
if(TARGET BlitHalPico)
return()
endif()

# prevent find_package errors in pico_add_uf2_output later
set(PICO_SDK_VERSION_MAJOR ${PICO_SDK_VERSION_MAJOR} PARENT_SCOPE)
set(PICO_SDK_VERSION_MINOR ${PICO_SDK_VERSION_MINOR} PARENT_SCOPE)
set(PICO_SDK_VERSION_REVISION ${PICO_SDK_VERSION_REVISION} PARENT_SCOPE)

# make sure BlitEngine is built with the right exception flags
target_link_libraries(BlitEngine PUBLIC pico_cxx_options pico_base_headers)

# also enable function/data sectons
target_compile_options(BlitEngine PRIVATE -ffunction-sections -fdata-sections)

add_subdirectory(../32blit-shared ../32blit-shared)

# driver helper
# can override driver choice by pre-setting BLIT_x_DRIVER
function(blit_driver DRV NAME)
set(var BLIT_${DRV}_DRIVER)
string(TOUPPER ${var} var)

if(NOT ${var})
set(${var} ${NAME} PARENT_SCOPE)
endif()
endfunction()

add_library(BlitHalPico INTERFACE)
target_sources(BlitHalPico INTERFACE
${CMAKE_CURRENT_LIST_DIR}/blit_launch.cpp
${CMAKE_CURRENT_LIST_DIR}/display.cpp
${CMAKE_CURRENT_LIST_DIR}/file.cpp
${CMAKE_CURRENT_LIST_DIR}/led.cpp
${CMAKE_CURRENT_LIST_DIR}/main.cpp
${CMAKE_CURRENT_LIST_DIR}/multiplayer.cpp
${CMAKE_CURRENT_LIST_DIR}/overlay.cpp
${CMAKE_CURRENT_LIST_DIR}/usb.cpp
${CMAKE_CURRENT_LIST_DIR}/usb_descriptors.c
)

Expand All @@ -47,6 +27,7 @@ target_link_libraries(BlitHalPico INTERFACE
pico_multicore pico_stdlib pico_unique_id pico_rand
tinyusb_device
FatFsBlitAPI
LauncherShared
)

target_include_directories(BlitHalPico INTERFACE
Expand All @@ -61,88 +42,6 @@ target_compile_options(BlitHalPico INTERFACE
-Wno-ignored-qualifiers # pico-sdk generates a lot of these
)

if(DEFINED PICO_ADDON)
# for boards that don't have a board in the pico sdk
# (usually because they are an add-on for a regular pico)
set(CONFIG_PATH ${CMAKE_CURRENT_LIST_DIR}/board/${PICO_ADDON})
set(BOARD_ID ${PICO_ADDON})
else()
set(CONFIG_PATH ${CMAKE_CURRENT_LIST_DIR}/board/${PICO_BOARD})
set(BOARD_ID ${PICO_BOARD})
endif()

if(NOT EXISTS ${CONFIG_PATH}/config.cmake)
set(CONFIG_PATH ${CMAKE_CURRENT_LIST_DIR}/board/pico)
if(DEFINED PICO_ADDON)
message(WARNING "Using default config for \"${PICO_BOARD}\", add-on \"${PICO_ADDON}\"...")
else()
message(WARNING "Using default config for \"${PICO_BOARD}\"...")
endif()
endif()

include(${CONFIG_PATH}/config.cmake)
message("Using board config \"${BLIT_BOARD_NAME}\"")

if(EXISTS ${CONFIG_PATH}/config.h)
list(APPEND BLIT_BOARD_DEFINITIONS "BLIT_BOARD_CONFIG=\"${CONFIG_PATH}/config.h\"")
endif()

# board id definition
string(TOUPPER ${BOARD_ID} BOARD_ID)
list(APPEND BLIT_BOARD_DEFINITIONS BLIT_BOARD_${BOARD_ID})

# default drivers
if(NOT BLIT_AUDIO_DRIVER)
set(BLIT_AUDIO_DRIVER "none")
endif()
if(NOT BLIT_DISPLAY_DRIVER)
set(BLIT_DISPLAY_DRIVER "none")
endif()
if(NOT BLIT_INPUT_DRIVER)
set(BLIT_INPUT_DRIVER "none")
endif()
if(NOT BLIT_STORAGE_DRIVER)
set(BLIT_STORAGE_DRIVER "flash")
endif()
if(NOT BLIT_USB_DRIVER)
set(BLIT_USB_DRIVER "device")
endif()

# driver dependencies
if(BLIT_AUDIO_DRIVER STREQUAL "pwm")
set(BLIT_REQUIRE_PICO_EXTRAS TRUE)
list(APPEND BLIT_BOARD_LIBRARIES pico_audio_pwm)
endif()

if(BLIT_DISPLAY_DRIVER STREQUAL "picovision")
list(APPEND BLIT_BOARD_LIBRARIES hardware_i2c aps6404 swd_load)
elseif(BLIT_DISPLAY_DRIVER STREQUAL "scanvideo")
set(BLIT_REQUIRE_PICO_EXTRAS TRUE)
set(BLIT_ENABLE_CORE1 TRUE)
list(APPEND BLIT_BOARD_LIBRARIES pico_scanvideo_dpi)
endif()

if(BLIT_INPUT_DRIVER STREQUAL "usb_hid")
list(APPEND BLIT_BOARD_DEFINITIONS INPUT_USB_HID)
endif()

if(BLIT_STORAGE_DRIVER STREQUAL "sd_spi")
list(APPEND BLIT_BOARD_DEFINITIONS STORAGE_SD)
endif()

if(BLIT_USB_DRIVER STREQUAL "host")
list(APPEND BLIT_BOARD_DEFINITIONS USB_HOST)
list(APPEND BLIT_BOARD_LIBRARIES tinyusb_host)
endif()

# late SDK init
# (pico_sdk_init needs to be after importing extras, which we don't know if we'll need until now)
if(BLIT_REQUIRE_PICO_EXTRAS)
include(pico_extras_import.cmake)
endif()

pico_sdk_init()

# generate PIO headers (has to be after SDK init)
pico_generate_pio_header(BlitHalPico ${CMAKE_CURRENT_LIST_DIR}/dbi-spi.pio)
pico_generate_pio_header(BlitHalPico ${CMAKE_CURRENT_LIST_DIR}/dbi-8bit.pio)
Expand Down Expand Up @@ -170,58 +69,4 @@ endif()
target_compile_definitions(BlitHalPico INTERFACE ${BLIT_BOARD_DEFINITIONS})
target_link_libraries(BlitHalPico INTERFACE ${BLIT_BOARD_LIBRARIES})

# functions
function(blit_executable NAME)
message(STATUS "Processing ${NAME}")
blit_executable_args(${ARGN})

add_executable(${NAME} ${SOURCES})
target_compile_definitions(${NAME} PRIVATE PICO_EMBED_XIP_SETUP=1)
target_link_libraries(${NAME} BlitHalPico BlitEngine)

pico_enable_stdio_uart(${NAME} 1)
pico_enable_stdio_usb(${NAME} 0)

pico_add_extra_outputs(${NAME})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.uf2
DESTINATION bin
)
endfunction()

function(blit_metadata TARGET FILE)
if(NOT IS_ABSOLUTE ${FILE})
set(FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
endif()

# cause cmake to reconfigure whenever the asset list changes
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${FILE})

# get the inputs/outputs for the asset tool (at configure time)
execute_process(
COMMAND ${32BLIT_TOOLS_EXECUTABLE} cmake --config ${FILE} --cmake ${CMAKE_CURRENT_BINARY_DIR}/metadata.cmake
RESULT_VARIABLE TOOL_RESULT
)
if(${TOOL_RESULT})
message(FATAL_ERROR "Reading metadata config failed!\n")
endif()

include(${CMAKE_CURRENT_BINARY_DIR}/metadata.cmake)

# create metadata/binary info source at build time
set(METADATA_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_binary_info.cpp")

add_custom_command(
OUTPUT ${METADATA_SOURCE}
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${32BLIT_TOOLS_EXECUTABLE} metadata --force --config ${FILE} --pico-bi ${METADATA_SOURCE}
DEPENDS ${FILE}
VERBATIM
)

# add the generated source
target_sources(${TARGET} PRIVATE ${METADATA_SOURCE})

# avoid the fallback to target name
target_compile_definitions(${TARGET} PRIVATE PICO_NO_BI_PROGRAM_NAME=1)

endfunction()
set(BLIT_BOARD_DEFINITIONS ${BLIT_BOARD_DEFINITIONS} PARENT_SCOPE)
Loading
Loading