1- # PIOKMbox - Raspberry Pi Pico USB HID Project
2- # CMake configuration file
1+ # Generated Cmake Pico project file
32
43cmake_minimum_required (VERSION 3.13)
54
6- # ==== Build Configuration ====
7- # Set build type if not specified
8- if (NOT CMAKE_BUILD_TYPE )
9- set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type: Debug or Release" FORCE)
10- endif ()
11- message (STATUS "Build type: ${CMAKE_BUILD_TYPE} " )
12-
13- # Set compiler standards and options
145set (CMAKE_C_STANDARD 11)
156set (CMAKE_CXX_STANDARD 17)
167set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
178
18- # Add optimization flags for Release builds
19- if (CMAKE_BUILD_TYPE STREQUAL "Release" )
20- add_compile_options (-O2)
21- add_compile_definitions (NDEBUG)
22- endif ()
23-
24- # ==== SDK Configuration ====
259# Initialise pico_sdk from installed location
26- # DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work
10+ # (note this can come from environment, CMake cache etc)
11+
12+ # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
2713if (WIN32 )
2814 set (USERHOME $ENV{USERPROFILE} )
2915else ()
@@ -33,171 +19,92 @@ set(sdkVersion 2.1.1)
3319set (toolchainVersion 14_2_Rel1)
3420set (picotoolVersion 2.1.1)
3521set (picoVscode ${USERHOME} /.pico-sdk/cmake/pico-vscode.cmake)
36- if (EXISTS ${picoVscode} )
22+ if (EXISTS ${picoVscode} )
3723 include (${picoVscode} )
3824endif ()
25+ # ====================================================================================
26+ set (PICO_BOARD pico CACHE STRING "Board type" )
3927
40- # ==== Board Configuration ====
41- # Define supported boards
42- set (SUPPORTED_BOARDS "pico;adafruit_feather_rp2040_usb_host;pico2;adafruit_feather_rp2350" )
43-
44- # Set board type based on TARGET_BOARD variable or default to pico (RP2040)
45- if (NOT DEFINED TARGET_BOARD)
46- set (TARGET_BOARD "pico" CACHE STRING "Target board type (${SUPPORTED_BOARDS} )" )
47- endif ()
48-
49- # Validate board type
50- if (TARGET_BOARD STREQUAL "adafruit_feather_rp2350" OR TARGET_BOARD STREQUAL "pico2" )
51- set (PICO_BOARD pico2 CACHE STRING "Board type" )
52- set (TARGET_CHIP "RP2350" )
53- message (STATUS "Building for ${TARGET_CHIP} (Pico 2)" )
54- elseif (TARGET_BOARD STREQUAL "adafruit_feather_rp2040_usb_host" OR TARGET_BOARD STREQUAL "pico" )
55- set (PICO_BOARD pico CACHE STRING "Board type" )
56- set (TARGET_CHIP "RP2040" )
57- message (STATUS "Building for ${TARGET_CHIP} (Pico)" )
58- else ()
59- message (FATAL_ERROR "Unsupported board type: ${TARGET_BOARD} . Supported: ${SUPPORTED_BOARDS} " )
60- endif ()
61-
62- # ==== SDK Initialization ====
6328# Pull in Raspberry Pi Pico SDK (must be before project)
6429include (pico_sdk_import.cmake)
6530
66- # Initialize project
6731project (PIOKMbox C CXX ASM)
6832
69- # Check if SDK is available
70- if (NOT PICO_SDK_PATH)
71- message (FATAL_ERROR "Pico SDK path not found. Please set PICO_SDK_PATH." )
72- endif ()
73-
7433# Initialise the Raspberry Pi Pico SDK
7534pico_sdk_init()
7635
77- # ==== Project Configuration ====
78- # Project metadata
79- set (PROJECT_VERSION "0.1" )
36+ # Add executable. Default name is the project name, version 0.1
8037
81- # ==== Source Files ====
82- # Define source files
83- set (PROJECT_SOURCES
38+ add_executable (PIOKMbox
8439 PIOKMbox.c
8540 led_control.c
8641 usb_hid.c
87- usb_hid_init.c
88- usb_hid_device.c
89- usb_hid_host.c
90- usb_hid_reports.c
91- usb_hid_descriptors.c
92- usb_hid_strings.c
93- usb_hid_callbacks.c
9442 watchdog.c
9543 init_state_machine.c
9644 state_management.c
97- dma_handlers.c
98- dma_manager.c
99- usb_locks.c
45+ kmbox_serial_handler.c
10046)
10147
102- # Add RP2350-specific source files
103- if (TARGET_CHIP STREQUAL "RP2350" )
104- list (APPEND PROJECT_SOURCES
105- rp2350_hw_accel.c
106- rp2350_tuh_task.c
107- rp2350_dma_handler.c
108- )
109- message (STATUS "Added RP2350 hardware acceleration source files" )
110- endif ()
111-
112- # Add executable
113- add_executable (PIOKMbox ${PROJECT_SOURCES} )
48+ # generate the header file into the source tree as it is included in the RP2040 datasheet
49+ pico_generate_pio_header(PIOKMbox ${CMAKE_CURRENT_LIST_DIR} /ws2812.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR} )
11450
115- # Now set program properties after the target is defined
11651pico_set_program_name(PIOKMbox "PIOKMbox" )
117- pico_set_program_version(PIOKMbox "${PROJECT_VERSION} " )
52+ pico_set_program_version(PIOKMbox "0.1" )
53+
54+ # Modify the below lines to enable/disable output over UART/USB
55+ pico_enable_stdio_uart(PIOKMbox 1)
56+ pico_enable_stdio_usb(PIOKMbox 0)
57+
58+ # Add the standard library to the build
59+ target_link_libraries (PIOKMbox
60+ pico_stdlib
61+ tinyusb_device
62+ tinyusb_host
63+ tinyusb_board
64+ hardware_pio
65+ hardware_dma
66+ hardware_watchdog
67+ hardware_uart
68+ hardware_irq
69+ pico_unique_id
70+ pico_multicore
71+ m)
11872
119- # ==== I/O Configuration ====
120- # Configure stdio output (UART/USB)
121- option (ENABLE_UART_OUTPUT "Enable UART output" ON )
122- option (ENABLE_USB_OUTPUT "Enable USB output" OFF )
123- pico_enable_stdio_uart(PIOKMbox ${ENABLE_UART_OUTPUT} )
124- pico_enable_stdio_usb(PIOKMbox ${ENABLE_USB_OUTPUT} )
73+ # Add PIO USB library
74+ add_subdirectory (lib/Pico-PIO-USB)
12575
126- # Generate PIO header file
127- pico_generate_pio_header(PIOKMbox ${CMAKE_CURRENT_LIST_DIR} /ws2812.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR} )
76+ # Add KMBox Commands library
77+ add_subdirectory (lib/kmbox-commands )
12878
129- # ==== Include Directories ====
130- target_include_directories (PIOKMbox PRIVATE
131- ${CMAKE_CURRENT_LIST_DIR}
132- ${CMAKE_CURRENT_LIST_DIR} /src
79+ # PIO USB library support (now enabled)
80+ message (STATUS "PIO USB library support enabled" )
81+ # Add compile definitions for TinyUSB and pin configurations
82+ target_compile_definitions (PIOKMbox PRIVATE
83+ CFG_TUSB_CONFIG_FILE="tusb_config.h"
84+ BOARD_TUH_RHPORT=1
85+ BOARD_TUD_RHPORT=0
86+ PIO_USB_USE_TINYUSB
87+ BUILD_CONFIG=BUILD_CONFIG_DEVELOPMENT
88+ PIO_USB_AVAILABLE=1
89+ CFG_TUH_RPI_PIO_USB=1
13390)
13491
135- # ==== PIO USB Configuration ====
136- # Add PIO USB library
137- add_subdirectory (lib/pio_usb)
138- message (STATUS "PIO USB library support enabled" )
92+ # Link PIO USB library
93+ target_link_libraries (PIOKMbox pico_pio_usb)
94+
95+ # Link KMBox Commands library
96+ target_link_libraries (PIOKMbox kmbox_commands)
13997
14098# Add PIO USB HCD implementation directly
14199target_sources (PIOKMbox PRIVATE
142100 ${PICO_TINYUSB_PATH} /src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
143101 ${PICO_TINYUSB_PATH} /src/portable/raspberrypi/pio_usb/hcd_pio_usb.c
144- )
102+ )
145103
146- # ==== Compile Definitions ====
147- # Common definitions for all boards
148- set (COMMON_DEFINITIONS
149- CFG_TUSB_CONFIG_FILE="tusb_config.h"
150- BOARD_TUH_RHPORT=1
151- BOARD_TUD_RHPORT=0
152- PIO_USB_USE_TINYUSB
153- BUILD_CONFIG=BUILD_CONFIG_DEVELOPMENT
154- PIO_USB_AVAILABLE=1
155- CFG_TUH_RPI_PIO_USB=1
156- USE_DMA_MANAGER=1
157- )
158-
159-
160- # Apply common definitions
161- target_compile_definitions (PIOKMbox PRIVATE ${COMMON_DEFINITIONS} )
162-
163- # Add board-specific definitions
164- if (TARGET_CHIP STREQUAL "RP2350" )
165- target_compile_definitions (PIOKMbox PRIVATE
166- TARGET_RP2350=1
167- PICO_RP2350=1
168- PIN_USB_HOST_DP=10
169- PIN_USB_HOST_DM=11
170- USE_HARDWARE_ACCELERATION=1
171- RP2350=1
172- )
173- message (STATUS "Added RP2350-specific definitions" )
174- else ()
175- target_compile_definitions (PIOKMbox PRIVATE
176- TARGET_RP2040=1
177- PICO_RP2040=1
178- )
179- message (STATUS "Added RP2040-specific definitions" )
180- endif ()
181-
182- # ==== Libraries ====
183- # Define all required libraries
184- set (PROJECT_LIBRARIES
185- pico_stdlib
186- tinyusb_device
187- tinyusb_host
188- tinyusb_board
189- hardware_pio
190- hardware_dma
191- hardware_watchdog
192- pico_unique_id
193- pico_multicore
194- pico_pio_usb
195- m
104+ # Add the standard include files to the build
105+ target_include_directories (PIOKMbox PRIVATE
106+ ${CMAKE_CURRENT_LIST_DIR}
107+ ${CMAKE_CURRENT_LIST_DIR} /src
196108)
197109
198- # Link libraries
199- target_link_libraries (PIOKMbox ${PROJECT_LIBRARIES} )
200-
201- # ==== Build Outputs ====
202- # Generate additional output files (.uf2, .hex, etc.)
203110pico_add_extra_outputs(PIOKMbox)
0 commit comments