Implements a complete serial upload workflow that allows uploading and immediately testing Lua games via USB serial connection. New Components: - SerialUploader: Receives files via serial, writes to SD card - upload_game.py: Python tool for sending files from host computer - Protocol: Text-based with base64 encoding for reliability Key Features: - Uploads file to /games folder on SD card - Overwrites existing files (FA_CREATE_ALWAYS) - Auto-launches uploaded game immediately - Proper memory cleanup (prevents Lua state conflicts) SD Card Fixes: - Fixed SPI speed management (12.5MHz for SD, 32MHz for display) - Fixed SD write protocol (poll for data response token) - Added speed switching wrappers around all FatFS operations - Cleaned up excessive debug output Game Launcher Improvements: - Added clear_games() to prevent duplicate registrations - Added cleanup in select_game_by_name() to delete old instances - Added exact match priority in game selection - LuaGameLoader now has clear_factory_data() for memory cleanup Integration: - Added serial_uploader to CMakeLists.txt - Integrated into main loop in basic1.cpp - Re-scans games after upload to pick up new files Documentation: - UPLOAD_TOOL.md: Usage instructions - sd_card_best_practices.md: Critical lessons learned Known Issues: - Game launch after upload occasionally causes freeze (needs investigation) - Display may not refresh properly after upload Usage: python upload_game.py games/lua_examples/2048.lua /dev/tty.usbmodem101 Co-Authored-By: Claude <noreply@anthropic.com>
133 lines
3.8 KiB
CMake
133 lines
3.8 KiB
CMake
# Generated Cmake Pico project file
|
|
|
|
cmake_minimum_required(VERSION 3.13)
|
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
# Initialise pico_sdk from installed location
|
|
# (note this can come from environment, CMake cache etc)
|
|
|
|
# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
|
|
if(WIN32)
|
|
set(USERHOME $ENV{USERPROFILE})
|
|
else()
|
|
set(USERHOME $ENV{HOME})
|
|
endif()
|
|
set(sdkVersion 2.2.0)
|
|
set(toolchainVersion 14_2_Rel1)
|
|
set(picotoolVersion 2.2.0-a4)
|
|
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
|
|
if (EXISTS ${picoVscode})
|
|
include(${picoVscode})
|
|
endif()
|
|
# ====================================================================================
|
|
# Default to Feather RP2350, but allow override via -DPICO_BOARD=<board>
|
|
if(NOT PICO_BOARD)
|
|
set(PICO_BOARD adafruit_feather_rp2350 CACHE STRING "Board type")
|
|
endif()
|
|
message(STATUS "Building for board: ${PICO_BOARD}")
|
|
|
|
# Pull in Raspberry Pi Pico SDK (must be before project)
|
|
include(pico_sdk_import.cmake)
|
|
|
|
project(basic1 C CXX ASM)
|
|
|
|
# Initialise the Raspberry Pi Pico SDK
|
|
pico_sdk_init()
|
|
|
|
# Add executable. Default name is the project name, version 0.1
|
|
|
|
# Collect Lua source files
|
|
file(GLOB LUA_SOURCES
|
|
"${CMAKE_CURRENT_LIST_DIR}/lib/lua/*.c"
|
|
)
|
|
|
|
add_executable(basic1
|
|
basic1.cpp
|
|
lib/input_manager.cpp
|
|
lib/game_launcher.cpp
|
|
lib/serial_uploader.cpp
|
|
games/tic_tac_toe.cpp
|
|
games/demo_game.cpp
|
|
games/monopoly/monopoly_game.cpp
|
|
games/monopoly/player.c
|
|
games/lua_game.cpp
|
|
games/lua_bindings.cpp
|
|
games/lua_game_loader.cpp
|
|
lib/st7796/st7796.c
|
|
lib/st7789/st7789.c
|
|
lib/ft6336u/ft6336u.c
|
|
lib/sd_card/sd_card.c
|
|
display/low_level_render.cpp
|
|
display/low_level_gui.cpp
|
|
display/low_level_display_factory.cpp
|
|
display/low_level_display_st7796.cpp
|
|
display/low_level_display_st7789.cpp
|
|
display/low_level_display_epaper.cpp
|
|
display/low_level_touch_factory.cpp
|
|
display/low_level_touch_ft6336u.cpp
|
|
diskio_sdcard.c
|
|
fatfs_time.c
|
|
lib/fatfs/source/ff.c
|
|
lib/fatfs/source/ffsystem.c
|
|
lib/fatfs/source/ffunicode.c
|
|
lib/Pico_ePaper_Code/c/lib/Config/DEV_Config.c
|
|
lib/Pico_ePaper_Code/c/lib/e-Paper/EPD_4in2_V2.c
|
|
${LUA_SOURCES}
|
|
)
|
|
|
|
pico_set_program_name(basic1 "basic1")
|
|
pico_set_program_version(basic1 "0.1")
|
|
|
|
# Add compile definitions early (before headers are parsed)
|
|
target_compile_definitions(basic1 PRIVATE
|
|
PICO_BOARD_ADAFRUIT_FEATHER_RP2350=1
|
|
LUA_32BITS # Use 32-bit integers for Lua on embedded
|
|
)
|
|
|
|
# Modify the below lines to enable/disable output over UART/USB
|
|
pico_enable_stdio_uart(basic1 0)
|
|
pico_enable_stdio_usb(basic1 1)
|
|
|
|
# Add the standard library to the build
|
|
target_link_libraries(basic1
|
|
pico_stdlib
|
|
hardware_dma
|
|
hardware_spi
|
|
hardware_pwm
|
|
)
|
|
|
|
# Add the standard include files to the build
|
|
target_include_directories(basic1 PRIVATE
|
|
${CMAKE_CURRENT_LIST_DIR}
|
|
${CMAKE_CURRENT_LIST_DIR}/games
|
|
${CMAKE_CURRENT_LIST_DIR}/games/monopoly
|
|
${CMAKE_CURRENT_LIST_DIR}/lib
|
|
${CMAKE_CURRENT_LIST_DIR}/lib/lua
|
|
${CMAKE_CURRENT_LIST_DIR}/lib/fatfs/source
|
|
${CMAKE_CURRENT_LIST_DIR}/lib/st7796
|
|
${CMAKE_CURRENT_LIST_DIR}/lib/st7789
|
|
${CMAKE_CURRENT_LIST_DIR}/lib/ft6336u
|
|
${CMAKE_CURRENT_LIST_DIR}/lib/sd_card
|
|
${CMAKE_CURRENT_LIST_DIR}/display
|
|
${CMAKE_CURRENT_LIST_DIR}/lib/Pico_ePaper_Code/c/lib/Config
|
|
${CMAKE_CURRENT_LIST_DIR}/lib/Pico_ePaper_Code/c/lib/e-Paper
|
|
)
|
|
|
|
# Add any user requested libraries
|
|
target_link_libraries(basic1
|
|
hardware_spi
|
|
hardware_i2c
|
|
hardware_pwm
|
|
pico_multicore
|
|
m
|
|
)
|
|
|
|
pico_add_extra_outputs(basic1)
|
|
|
|
# RP2350-specific: Set the boot stage2 and ensure proper image definition
|
|
# This is critical for reliable cold boot on RP2350
|
|
pico_set_binary_type(basic1 default)
|