Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fightingbox committed Aug 4, 2023
0 parents commit 7660e20
Show file tree
Hide file tree
Showing 1,082 changed files with 110,695 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
221 changes: 221 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
cmake_minimum_required(VERSION 3.13)
include(CMakePrintHelpers)



set(ENV{GP2040_BOARDCONFIG} PicoFightingBoard)
# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)

if (PICO_SDK_VERSION_STRING VERSION_LESS "1.5.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.5.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()

# Uncomment the next line for an unomptimized build for debugging. Use in conjunction with the Debug build type.
# set(PICO_DEOPTIMIZED_DEBUG 1)

project(GP2040-CE LANGUAGES C CXX ASM VERSION 0.7.3)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

if(DEFINED ENV{GP2040_BOARDCONFIG})
set(GP2040_BOARDCONFIG $ENV{GP2040_BOARDCONFIG})
elseif(NOT DEFINED GP2040_BOARDCONFIG)
set(GP2040_BOARDCONFIG Pico)
endif()

if(DEFINED ENV{SKIP_SUBMODULES})
set(SKIP_SUBMODULES $ENV{SKIP_SUBMODULES})
elseif(NOT DEFINED SKIP_SUBMODULES)
set(SKIP_SUBMODULES FALSE)
endif()

if(DEFINED ENV{SKIP_WEBBUILD})
set(SKIP_WEBBUILD $ENV{SKIP_WEBBUILD})
elseif(NOT DEFINED SKIP_WEBBUILD)
set(SKIP_WEBBUILD FALSE)
endif()


if(SKIP_SUBMODULES)
cmake_print_variables(SKIP_SUBMODULES)
else()
find_package(Git)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
else()
message("Submodules updated")
endif()
endif()
endif()

if(SKIP_WEBBUILD)
cmake_print_variables(SKIP_WEBBUILD)
else()
message(STATUS "Not Skipping WebBuild")
include(${CMAKE_SOURCE_DIR}/modules/FindNodeJS.cmake)
include(${CMAKE_SOURCE_DIR}/modules/FindNPM.cmake)
if(NODEJS_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/www")
if(NPM_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/www/package.json")
execute_process(COMMAND ${NPM_EXECUTABLE} ci
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/www
RESULT_VARIABLE NPM_CI_RESULT)
if(NOT NPM_CI_RESULT EQUAL "0")
message(FATAL_ERROR "npm ci failed with ${NPM_CI_RESULT}")
endif()
execute_process(COMMAND ${NPM_EXECUTABLE} run build
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/www
RESULT_VARIABLE NPM_BUILD_RESULT)
if(NOT NPM_BUILD_RESULT EQUAL "0")
message(FATAL_ERROR "npm run build failed with ${NPM_BUILD_RESULT}")
endif()
endif()
endif()
endif()


set(PICO_BOARD_HEADER_DIRS ${CMAKE_SOURCE_DIR}/configs/${GP2040_BOARDCONFIG})
include(FetchContent)
FetchContent_Declare(ArduinoJson
GIT_REPOSITORY https://github.com/bblanchon/ArduinoJson.git
GIT_TAG v6.21.2
)
FetchContent_MakeAvailable(ArduinoJson)

if(DEFINED ENV{PICO_PIO_USB_PATH})
message(STATUS "Found custom Pico-PIO-USB path, using it.")
set(PICO_PIO_USB_PATH $ENV{PICO_PIO_USB_PATH})
elseif(NOT DEFINED PICO_PIO_USB_PATH)
message(STATUS "Using default Pico-PIO-USB.")
set(PICO_PIO_USB_PATH ${CMAKE_SOURCE_DIR}/lib/pico_pio_usb)
endif()

include(compile_proto.cmake)
compile_proto()

# initialize the Raspberry Pi Pico SDK
pico_sdk_init()

# Remove unused code and data
add_compile_options(-fdata-sections -ffunction-sections)
add_link_options(-Wl,--gc-sections)

add_subdirectory(lib)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Activate some compiler / linker options to aid us with diagnosing stack space issues in Debug builds
add_compile_options(-fstack-usage -Wstack-usage=500)
add_compile_definitions(PICO_USE_STACK_GUARDS=1)
endif()

# We want a larger stack of 4kb per core instead of the default 2kb
add_compile_definitions(PICO_STACK_SIZE=0x1000)

add_executable(${PROJECT_NAME}
src/main.cpp
src/gp2040.cpp
src/gp2040aux.cpp
src/gamepad.cpp
src/addonmanager.cpp
src/configmanager.cpp
src/storagemanager.cpp
src/system.cpp
src/config_legacy.cpp
src/config_utils.cpp
src/configs/webconfig.cpp
src/addons/analog.cpp
src/addons/board_led.cpp
src/addons/bootsel_button.cpp
src/addons/focus_mode.cpp
src/addons/buzzerspeaker.cpp
src/addons/dualdirectional.cpp
src/addons/extra_button.cpp
src/addons/keyboard_host.cpp
src/addons/i2canalog1219.cpp
src/addons/jslider.cpp
src/addons/i2cdisplay.cpp
src/addons/neopicoleds.cpp
src/addons/playernum.cpp
src/addons/playerleds.cpp
src/addons/ps4mode.cpp
src/addons/reverse.cpp
src/addons/turbo.cpp
src/addons/slider_socd.cpp
src/addons/wiiext.cpp
src/addons/snes_input.cpp
src/gamepad/GamepadDebouncer.cpp
src/gamepad/GamepadDescriptors.cpp
src/addons/tilt.cpp
${PROTO_OUTPUT_DIR}/enums.pb.c
${PROTO_OUTPUT_DIR}/config.pb.c
)

set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG})

pico_set_program_name(GP2040-CE "GP2040-CE")
pico_set_program_version(GP2040-CE "0.7.3")

target_link_libraries(${PROJECT_NAME}
pico_stdlib
pico_bootsel_via_double_reset
tinyusb_host
tinyusb_pico_pio_usb
AnimationStation
CRC32
FlashPROM
ADS1219
PlayerLEDs
NeoPico
OneBitDisplay
ArduinoJson
rndis
hardware_adc
WiiExtension
SNESpad
pico_mbedtls
TinyUSB_Gamepad
nanopb
)

target_include_directories(${PROJECT_NAME} PUBLIC
headers
headers/addons
headers/configs
headers/gamepad
configs/${GP2040_BOARDCONFIG}
${PROTO_OUTPUT_DIR}
)

target_compile_definitions(${PROJECT_NAME} PUBLIC
PICO_XOSC_STARTUP_DELAY_MULTIPLIER=64
)

target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
)

pico_add_extra_outputs(${PROJECT_NAME})

add_compile_options(-Wall
-Wtype-limits
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that aren't called
-Wno-maybe-uninitialized
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2
${CMAKE_CURRENT_LIST_DIR}/README.md
DESTINATION .
)

if (NOT (DEFINED ENV(CI)) AND (EXISTS ${CMAKE_SOURCE_DIR}/modules/Custom.cmake))
message(STATUS "Found custom script.")
include(${CMAKE_SOURCE_DIR}/modules/Custom.cmake)
endif()
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Jason Skuby (mytechtoybox.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Flatbox-LED
Based on the [GP2040-CE](https://github.com/OpenStickCommunity/GP2040-CE) Flatbox Rev4

Add the colorful LEDs and the OLED display, perfect hardware change beased on the [Flatbox](https://github.com/jfedor2/flatbox) design by [jfedor2](https://github.com/jfedor2) powered by an RP2040 MCU.

![Flatbox-LED](pictures/4.jpg)

![Flatbox-LED](pictures/5.jpg)

![Flatbox-LED](pictures/6.png)



52 changes: 52 additions & 0 deletions compile_proto.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function (compile_proto)
find_package(Python3 REQUIRED COMPONENTS Interpreter)

set(VENV ${CMAKE_CURRENT_BINARY_DIR}/venv)
set(VENV_FILE ${VENV}/environment.txt)
if(CMAKE_HOST_WIN32)
set(VENV_BIN_DIR ${VENV}/Scripts)
else()
set(VENV_BIN_DIR ${VENV}/bin)
endif()

add_custom_command(
DEPENDS ${CMAKE_SOURCE_DIR}/lib/nanopb/extra/requirements.txt
COMMAND ${Python3_EXECUTABLE} -m venv ${VENV}
COMMAND ${VENV_BIN_DIR}/pip --disable-pip-version-check install -r ${CMAKE_SOURCE_DIR}/lib/nanopb/extra/requirements.txt
COMMAND ${VENV_BIN_DIR}/pip freeze > ${VENV_FILE}
OUTPUT ${VENV_FILE}
COMMENT "Setting up Python Virtual Environment"
)

set(NANOPB_GENERATOR ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/nanopb_generator.py)
set(PROTO_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto)
set(PROTO_OUTPUT_DIR ${PROTO_OUTPUT_DIR} PARENT_SCOPE)

add_custom_command(
DEPENDS ${VENV_FILE} ${NANOPB_GENERATOR} ${CMAKE_SOURCE_DIR}/proto/enums.proto ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROTO_OUTPUT_DIR}
COMMAND ${VENV_BIN_DIR}/python ${NANOPB_GENERATOR}
-q
-D ${PROTO_OUTPUT_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
-I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto
${CMAKE_SOURCE_DIR}/proto/enums.proto
OUTPUT ${PROTO_OUTPUT_DIR}/enums.pb.c ${PROTO_OUTPUT_DIR}/enums.pb.h
COMMENT "Compiling enums.proto"
)

add_custom_command(
DEPENDS ${VENV_FILE} ${NANOPB_GENERATOR} ${CMAKE_SOURCE_DIR}/proto/enums.proto ${CMAKE_SOURCE_DIR}/proto/config.proto ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROTO_OUTPUT_DIR}
COMMAND ${VENV_BIN_DIR}/python ${NANOPB_GENERATOR}
-q
-D ${PROTO_OUTPUT_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
-I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto
${CMAKE_SOURCE_DIR}/proto/config.proto
OUTPUT ${PROTO_OUTPUT_DIR}/config.pb.c ${PROTO_OUTPUT_DIR}/config.pb.h
COMMENT "Compiling config.proto"
)
endfunction()
Loading

0 comments on commit 7660e20

Please sign in to comment.