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

Start migrating to protobuf board configs #970

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ add_compile_options(-Wall
include(compile_proto.cmake)
compile_proto()

include(patch_board_config.cmake)
patch_board_config()

#pull in tinyUSB
set(PICO_TINYUSB_PATH "${CMAKE_CURRENT_LIST_DIR}/lib/tinyusb")

Expand Down Expand Up @@ -204,7 +207,6 @@ src/storagemanager.cpp
src/system.cpp
src/usbdriver.cpp
src/usbhostmanager.cpp
src/config_legacy.cpp
src/config_utils.cpp
src/configs/webconfig.cpp
src/addons/analog.cpp
Expand Down
25 changes: 25 additions & 0 deletions compile_proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ function (compile_proto)
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 --disable-pip-version-check install gp2040ce-binary-tools
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(PYTHON_GENERATOR ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/protoc)
set(PROTO_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto)
set(PROTO_OUTPUT_DIR ${PROTO_OUTPUT_DIR} PARENT_SCOPE)

Expand All @@ -41,4 +43,27 @@ function (compile_proto)
OUTPUT ${PROTO_OUTPUT_DIR}/config.pb.c ${PROTO_OUTPUT_DIR}/config.pb.h ${PROTO_OUTPUT_DIR}/enums.pb.c ${PROTO_OUTPUT_DIR}/enums.pb.h
COMMENT "Compiling enums.proto and config.proto"
)

add_custom_command(
DEPENDS ${VENV_FILE} ${PYTHON_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 ${PYTHON_GENERATOR}
--python_out ${PROTO_OUTPUT_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
-I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto
${CMAKE_SOURCE_DIR}/proto/enums.proto
COMMAND ${VENV_BIN_DIR}/python ${PYTHON_GENERATOR}
--python_out ${PROTO_OUTPUT_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
-I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto
${CMAKE_SOURCE_DIR}/proto/config.proto
COMMAND ${VENV_BIN_DIR}/python ${PYTHON_GENERATOR}
--python_out ${PROTO_OUTPUT_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
-I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto
${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto
OUTPUT ${PROTO_OUTPUT_DIR}/config_pb2.py ${PROTO_OUTPUT_DIR}/enums_pb2.py ${PROTO_OUTPUT_DIR}/nanopb_pb2.py
COMMENT "Compiling config_pb2.py, enums_pb2.py, and nanopb_pb2.py Python modules"
)
endfunction()
3 changes: 3 additions & 0 deletions configs/ARCController/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/BentoBox/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/Blank/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/FightboardV3/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/FightboardV3Mirrored/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/FlatboxRev4/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/FlatboxRev5/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/FlatboxRev5RGB/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/FlatboxRev5Southpaw/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/FlatboxRev5USBPassthrough/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/Granola/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/Haute42COSMOX/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/KB2040/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/KeyboardConverter/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/Liatris/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/MavercadeRev1/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/MavercadeRev2/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/MiSTercadeV2/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/OSUMGP-RP2040/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/OpenCore0/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/OpenCore0WASD/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/PXPGamepad/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/Pico/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/PicoAnn/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/PicoFightingBoard/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/PicoW/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/RP2040AdvancedBreakoutBoard/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/RP2040MiniBreakoutBoard/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/RanaTadpole/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ReflexCtrlGenesis6/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ReflexCtrlNES/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ReflexCtrlSNES/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ReflexCtrlSaturn/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ReflexCtrlVB/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ReflexEncodeV1.2/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ReflexEncodeV2.0/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/SGFDevices/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/SparkFunProMicro/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/Stress/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/WaveshareZero/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ZeroRhythm/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
3 changes: 3 additions & 0 deletions configs/ergoSHIFTRev2/board-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"boardVersion": "v0.7.8"
}
5 changes: 0 additions & 5 deletions headers/build_info.h

This file was deleted.

1 change: 0 additions & 1 deletion headers/config_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace ConfigUtils {

std::string toJSON(const Config& config);
bool fromJSON(Config& config, const char* data, size_t dataLen);
bool fromLegacyStorage(Config& config);
}

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

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

set(PROTO_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto)

add_custom_target(
PatchBoardConfig ALL
DEPENDS ${PROJECT_NAME} ${PROTO_OUTPUT_DIR}/config_pb2.py ${PROTO_OUTPUT_DIR}/enums_pb2.py ${PROTO_OUTPUT_DIR}/nanopb_pb2.py
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
# something in the protobuf compiler doesn't like the multiple paths,
# so we'll copy all the .proto files into one location
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROTO_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto ${PROTO_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/proto/enums.proto ${PROTO_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/proto/config.proto ${PROTO_OUTPUT_DIR}
COMMAND ${VENV_BIN_DIR}/concatenate
-P ${PROTO_OUTPUT_DIR}
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin
--json-board-config-filename ./configs/${GP2040_BOARDCONFIG}/board-config.json
--backup
--new-filename ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2
COMMAND ${VENV_BIN_DIR}/summarize-gp2040ce
-P ${PROTO_OUTPUT_DIR}
--filename ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2
COMMENT "Patching binary with board config"
)
endfunction()
4 changes: 2 additions & 2 deletions proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import "enums.proto";
message GamepadOptions
{
optional InputMode inputMode = 1;
optional DpadMode dpadMode = 2;
optional SOCDMode socdMode = 3;
optional DpadMode dpadMode = 2 [default = DPAD_MODE_DIGITAL];
optional SOCDMode socdMode = 3 [default = SOCD_MODE_NEUTRAL];
optional bool invertXAxis = 4;
optional bool invertYAxis = 5;
optional bool switchTpShareForDs4 = 6;
Expand Down
Loading
Loading