Skip to content

Commit

Permalink
Add beginnings of software implementation
Browse files Browse the repository at this point in the history
 - Software is based off my wifi pc remote button code, as well as my
   old SNES STM32 controller converter code for the TinyUSB descriptor.
 - This code relies on the following upstream PRs:
   - raspberrypi/pico-sdk#1530
   - FreeRTOS/FreeRTOS-Kernel#991
   - raspberrypi/pico-sdk#1635
  • Loading branch information
gemarcano committed Feb 15, 2024
1 parent 11529c5 commit bcdc418
Show file tree
Hide file tree
Showing 27 changed files with 3,693 additions and 2 deletions.
8 changes: 6 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ with or without fee is hereby granted." There are some exceptions, but I do not
believe we are using any of the models/designs from other manufacturers that
fall under those exceptions.

The rest of the files are licensed under the CERN Open Hardware Licence Version
2 - Weakly Reciprocal.
The KiCAD PCB design files are licensed under the CERN Open Hardware Licence
Version 2 - Weakly Reciprocal.

The software under the firmware folder is licensed under the GPL v2.0 or later,
or the LGPL v2.1 or later. More details can be found in the firmware/LICENSE
file.
2 changes: 2 additions & 0 deletions firmware/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/include/secrets.h
/build
54 changes: 54 additions & 0 deletions firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.20)

include(pico_sdk_import.cmake)
include(FreeRTOS_Kernel_import.cmake)

project(snes_controllers_to_usb)

pico_sdk_init()

add_executable(snes_controllers_to_usb
src/main.cpp
src/log.cpp
src/server.cpp
src/network_task.cpp
src/cli_task.cpp
src/FreeRTOS_support.cpp
src/usb_descriptors.c
src/syscalls.cpp
)

target_link_libraries(snes_controllers_to_usb
pico_cyw43_arch_lwip_sys_freertos
pico_stdlib
pico_rand
FreeRTOS-Kernel-Heap3
tinyusb_device
tinyusb_board
)

target_compile_options(snes_controllers_to_usb PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra>
-fstack-usage
-Wno-psabi
)

target_include_directories(snes_controllers_to_usb PRIVATE
${CMAKE_SOURCE_DIR}/include
)

target_compile_features(snes_controllers_to_usb PRIVATE
cxx_std_23
)

pico_set_printf_implementation(snes_controllers_to_usb compiler)
pico_set_stdio_implementation(snes_controllers_to_usb compiler)

set_property(TARGET snes_controllers_to_usb PROPERTY CXX_STANDARD 23)

if (DEFINED HOSTNAME)
add_compile_definitions(CYW43_HOST_NAME=\"${HOSTNAME}\")
endif()

pico_add_extra_outputs(snes_controllers_to_usb)
61 changes: 61 additions & 0 deletions firmware/FreeRTOS_Kernel_import.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This is a copy of <FREERTOS_KERNEL_PATH>/portable/ThirdParty/GCC/RP2040/FREERTOS_KERNEL_import.cmake

# This can be dropped into an external project to help locate the FreeRTOS kernel
# It should be include()ed prior to project(). Alternatively this file may
# or the CMakeLists.txt in this directory may be included or added via add_subdirectory
# respectively.

if (DEFINED ENV{FREERTOS_KERNEL_PATH} AND (NOT FREERTOS_KERNEL_PATH))
set(FREERTOS_KERNEL_PATH $ENV{FREERTOS_KERNEL_PATH})
message("Using FREERTOS_KERNEL_PATH from environment ('${FREERTOS_KERNEL_PATH}')")
endif ()

set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/GCC/RP2040")
# undo the above
set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../..")

if (NOT FREERTOS_KERNEL_PATH)
# check if we are inside the FreeRTOS kernel tree (i.e. this file has been included directly)
get_filename_component(_ACTUAL_PATH ${CMAKE_CURRENT_LIST_DIR} REALPATH)
get_filename_component(_POSSIBLE_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH} REALPATH)
if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH)
endif()
if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH)
message("Setting FREERTOS_KERNEL_PATH to ${FREERTOS_KERNEL_PATH} based on location of FreeRTOS-Kernel-import.cmake")
elseif (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../FreeRTOS-Kernel")
set(FREERTOS_KERNEL_PATH ${PICO_SDK_PATH}/../FreeRTOS-Kernel)
message("Defaulting FREERTOS_KERNEL_PATH as sibling of PICO_SDK_PATH: ${FREERTOS_KERNEL_PATH}")
endif()
endif ()

if (NOT FREERTOS_KERNEL_PATH)
foreach(POSSIBLE_SUFFIX Source FreeRTOS-Kernel FreeRTOS/Source)
# check if FreeRTOS-Kernel exists under directory that included us
set(SEARCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
get_filename_component(_POSSIBLE_PATH ${SEARCH_ROOT}/${POSSIBLE_SUFFIX} REALPATH)
if (EXISTS ${_POSSIBLE_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt)
get_filename_component(FREERTOS_KERNEL_PATH ${_POSSIBLE_PATH} REALPATH)
message("Setting FREERTOS_KERNEL_PATH to '${FREERTOS_KERNEL_PATH}' found relative to enclosing project")
break()
endif()
endforeach()
endif()

if (NOT FREERTOS_KERNEL_PATH)
message(FATAL_ERROR "FreeRTOS location was not specified. Please set FREERTOS_KERNEL_PATH.")
endif()

set(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" CACHE PATH "Path to the FreeRTOS Kernel")

get_filename_component(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${FREERTOS_KERNEL_PATH})
message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' not found")
endif()
if (NOT EXISTS ${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt)
message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' does not contain an RP2040 port here: ${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}")
endif()
set(FREERTOS_KERNEL_PATH ${FREERTOS_KERNEL_PATH} CACHE PATH "Path to the FreeRTOS_KERNEL" FORCE)

add_subdirectory(${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH} FREERTOS_KERNEL)
9 changes: 9 additions & 0 deletions firmware/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This software is released under the following licenses:
- GPL v2 or later
- LGPL v2.1 or later

You should be able to find the text to the GPL v2, GPL v3, LGPL v2.1, and LGPL
v3.0 licenses in the root directory of this repository.

At the time of this writing all of the available licenses could be found on
https://www.gnu.org/licenses/licenses.html
Loading

0 comments on commit bcdc418

Please sign in to comment.