diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-05 16:32:46 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-05 16:32:46 +0200 |
commit | d9093e3245f9619850cea391adcad1a12164d38e (patch) | |
tree | a28c8acd5735de423ee142afe29d218df23b873e | |
parent | 36a8f66aeee73e82f28b040ca304e55034f05644 (diff) |
the large library cleanup
-rw-r--r-- | .gitmodules | 4 | ||||
-rw-r--r-- | client/CMakeLists.txt | 8 | ||||
l--------- | client/compile_commands.json | 1 | ||||
-rw-r--r-- | client/i2c.cpp | 4 | ||||
-rw-r--r-- | i2ctcp/include.cmake | 19 | ||||
l--------- | i2ctcp/lib | 1 | ||||
-rw-r--r-- | lib/i2ctcp/CMakeLists.txt | 14 | ||||
-rw-r--r-- | lib/i2ctcp/i2ctcpv1.c (renamed from i2ctcp/i2ctcpv1.c) | 0 | ||||
-rw-r--r-- | lib/i2ctcp/i2ctcpv1.h (renamed from i2ctcp/i2ctcpv1.h) | 0 | ||||
-rw-r--r-- | lib/i2ctcp/makefile | 4 | ||||
-rw-r--r-- | lib/i2ctcp/readme.md (renamed from i2ctcp/readme.md) | 0 | ||||
-rw-r--r-- | lib/mpack/CMakeLists.txt | 26 | ||||
-rw-r--r-- | lib/mpack/makefile | 4 | ||||
m--------- | lib/mpack/src (renamed from lib/mpack) | 0 | ||||
-rw-r--r-- | lib/pbdrv/CMakeLists.txt | 40 | ||||
-rw-r--r-- | lib/pbdrv/drv/arduino/mod.cpp (renamed from shared/pb/drv/arduino/mod.cpp) | 0 | ||||
-rw-r--r-- | lib/pbdrv/drv/arduino/mod.h (renamed from shared/pb/drv/arduino/mod.h) | 2 | ||||
-rw-r--r-- | lib/pbdrv/makefile | 4 | ||||
-rw-r--r-- | lib/pbdrv/mod/main.h (renamed from shared/pb/mod/main.h) | 8 | ||||
-rw-r--r-- | lib/pbdrv/pb-mod.c (renamed from shared/pb/moddrv.c) | 5 | ||||
-rw-r--r-- | lib/pbdrv/pb-mod.h (renamed from shared/pb/moddrv.h) | 10 | ||||
-rw-r--r-- | lib/pbdrv/pb-read.c | 3 | ||||
-rw-r--r-- | lib/pbdrv/pb-read.h | 2 | ||||
-rw-r--r-- | lib/pbdrv/pb-types.h (renamed from shared/pb/types.h) | 1 | ||||
-rw-r--r-- | lib/pbdrv/pb-write.c | 1 | ||||
-rw-r--r-- | lib/pbdrv/pb-write.h | 3 | ||||
-rw-r--r-- | lib/pbdrv/pb.h (renamed from shared/pb/bus.h) | 2 | ||||
-rw-r--r-- | lib/pbdrv/spec.adoc (renamed from shared/pb/spec.adoc) | 0 | ||||
-rw-r--r-- | main/CMakeLists.txt | 3 | ||||
l--------- | main/compile_commands.json | 1 | ||||
-rw-r--r-- | puzzle/dummy/CMakeLists.txt | 2 | ||||
-rw-r--r-- | puzzle/dummy/main.cpp | 7 | ||||
-rw-r--r-- | shared/pb.cmake | 20 | ||||
-rw-r--r-- | test/CMakeLists.txt | 7 |
34 files changed, 134 insertions, 72 deletions
diff --git a/.gitmodules b/.gitmodules index 6313925..9ff7e96 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,8 +13,8 @@ url = https://github.com/FreeRTOS/FreeRTOS-Kernel branch = V11.1.0 shallow = true -[submodule "lib/mpack"] - path = lib/mpack +[submodule "lib/mpack/src"] + path = lib/mpack/src url = https://github.com/ludocode/mpack branch = v1.1.1 shallow = true diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index b1cfbaf..7d492b0 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -8,10 +8,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_BUILD_TYPE Debug) add_compile_definitions(DEBUG) -project(puzzlebox_client C CXX) +project(pbc C CXX) -include(../i2ctcp/include.cmake) -include(../shared/pb.cmake) +add_subdirectory(lib/mpack) +add_subdirectory(lib/i2ctcp) +add_subdirectory(lib/pbdrv) add_executable(pbc main.cpp @@ -27,5 +28,6 @@ target_link_libraries(pbc i2ctcp mpack readline # this is such a common library that I did not bother adding it as a submodule + pbdrv ) diff --git a/client/compile_commands.json b/client/compile_commands.json deleted file mode 120000 index 25eb4b2..0000000 --- a/client/compile_commands.json +++ /dev/null @@ -1 +0,0 @@ -build/compile_commands.json
\ No newline at end of file diff --git a/client/i2c.cpp b/client/i2c.cpp index 951f654..4dbc724 100644 --- a/client/i2c.cpp +++ b/client/i2c.cpp @@ -5,8 +5,8 @@ #include "sock.h" #include "xxd.h" -#include "pb/bus.h" -#include "pb/types.h" +#include "pb.h" +#include "pb-types.h" // #include "pb/mod/main.h" diff --git a/i2ctcp/include.cmake b/i2ctcp/include.cmake deleted file mode 100644 index b61b2a4..0000000 --- a/i2ctcp/include.cmake +++ /dev/null @@ -1,19 +0,0 @@ -include_directories(${CMAKE_CURRENT_LIST_DIR}) -add_library(i2ctcp STATIC - ${CMAKE_CURRENT_LIST_DIR}/i2ctcpv1.c - ) - -# mpack -include_directories(${CMAKE_CURRENT_LIST_DIR}/lib/mpack/src/mpack) -add_library(mpack STATIC - ${CMAKE_CURRENT_LIST_DIR}/lib/mpack/src/mpack/mpack-common.c - ${CMAKE_CURRENT_LIST_DIR}/lib/mpack/src/mpack/mpack-expect.c - ${CMAKE_CURRENT_LIST_DIR}/lib/mpack/src/mpack/mpack-node.c - ${CMAKE_CURRENT_LIST_DIR}/lib/mpack/src/mpack/mpack-platform.c - ${CMAKE_CURRENT_LIST_DIR}/lib/mpack/src/mpack/mpack-reader.c - ${CMAKE_CURRENT_LIST_DIR}/lib/mpack/src/mpack/mpack-writer.c - ) - -# causes some wild crashes, please leave off -add_compile_definitions(MPACK_READ_TRACKING=0) - diff --git a/i2ctcp/lib b/i2ctcp/lib deleted file mode 120000 index dc598c5..0000000 --- a/i2ctcp/lib +++ /dev/null @@ -1 +0,0 @@ -../lib
\ No newline at end of file diff --git a/lib/i2ctcp/CMakeLists.txt b/lib/i2ctcp/CMakeLists.txt new file mode 100644 index 0000000..b47b1d7 --- /dev/null +++ b/lib/i2ctcp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.29) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +project(i2ctcp C CXX) + +add_subdirectory(../mpack ${CMAKE_CURRENT_BINARY_DIR}/mpack) + +add_library(i2ctcp STATIC ./i2ctcpv1.c) +target_link_libraries(i2ctcp mpack) +target_include_directories(i2ctcp SYSTEM INTERFACE .) + diff --git a/i2ctcp/i2ctcpv1.c b/lib/i2ctcp/i2ctcpv1.c index 944df3a..944df3a 100644 --- a/i2ctcp/i2ctcpv1.c +++ b/lib/i2ctcp/i2ctcpv1.c diff --git a/i2ctcp/i2ctcpv1.h b/lib/i2ctcp/i2ctcpv1.h index 799b668..799b668 100644 --- a/i2ctcp/i2ctcpv1.h +++ b/lib/i2ctcp/i2ctcpv1.h diff --git a/lib/i2ctcp/makefile b/lib/i2ctcp/makefile new file mode 100644 index 0000000..5ca3fd1 --- /dev/null +++ b/lib/i2ctcp/makefile @@ -0,0 +1,4 @@ +TARGET = $(BUILD_DIR)/libi2ctcp.a + +include ../../lazy.mk + diff --git a/i2ctcp/readme.md b/lib/i2ctcp/readme.md index d5bfe6d..d5bfe6d 100644 --- a/i2ctcp/readme.md +++ b/lib/i2ctcp/readme.md diff --git a/lib/mpack/CMakeLists.txt b/lib/mpack/CMakeLists.txt new file mode 100644 index 0000000..0a904b0 --- /dev/null +++ b/lib/mpack/CMakeLists.txt @@ -0,0 +1,26 @@ +if(TARGET mpack) + return() +endif() + +cmake_minimum_required(VERSION 3.29) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +project(mpack C) + +add_library(mpack STATIC + src/src/mpack/mpack-common.c + src/src/mpack/mpack-expect.c + src/src/mpack/mpack-node.c + src/src/mpack/mpack-platform.c + src/src/mpack/mpack-reader.c + src/src/mpack/mpack-writer.c + ) +target_include_directories(mpack SYSTEM INTERFACE + src/src/mpack + ) + +# causes some wild crashes, please leave off +add_compile_definitions(MPACK_READ_TRACKING=0) + diff --git a/lib/mpack/makefile b/lib/mpack/makefile new file mode 100644 index 0000000..e96794a --- /dev/null +++ b/lib/mpack/makefile @@ -0,0 +1,4 @@ +TARGET = $(BUILD_DIR)/libmpack.a + +include ../../lazy.mk + diff --git a/lib/mpack b/lib/mpack/src -Subproject 79d3fcd3e04338b06e82d01a62f4aa98c7bad5f +Subproject 79d3fcd3e04338b06e82d01a62f4aa98c7bad5f diff --git a/lib/pbdrv/CMakeLists.txt b/lib/pbdrv/CMakeLists.txt new file mode 100644 index 0000000..08894cc --- /dev/null +++ b/lib/pbdrv/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.29) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +# enable debug features +set(CMAKE_BUILD_TYPE Debug) +add_compile_definitions(DEBUG) + +project(pbdrv C CXX) + +if(DEFINED ARDUINO) + set(PBDRV_ARDUINO true) +endif() + +include_directories(.) +add_library(pbdrv STATIC + pb-read.c + pb-write.c + ) +target_include_directories(pbdrv SYSTEM INTERFACE .) + +list(APPEND PBDRV_SRCS pb-mod.c) + +if(PBDRV_ARDUINO) + list(APPEND PBDRV_SRCS drv/arduino/mod.cpp) +endif() + +add_library(pbdrv-mod STATIC ${PBDRV_SRCS}) +target_link_libraries(pbdrv-mod pbdrv) +# add_dependencies(pbdrv-mod pbdrv) + +if(PBDRV_ARDUINO) + target_link_arduino_libraries(pbdrv-mod + core + Wire + ) +endif() + diff --git a/shared/pb/drv/arduino/mod.cpp b/lib/pbdrv/drv/arduino/mod.cpp index c7bbe45..c7bbe45 100644 --- a/shared/pb/drv/arduino/mod.cpp +++ b/lib/pbdrv/drv/arduino/mod.cpp diff --git a/shared/pb/drv/arduino/mod.h b/lib/pbdrv/drv/arduino/mod.h index e2e3b6d..e545d9b 100644 --- a/shared/pb/drv/arduino/mod.h +++ b/lib/pbdrv/drv/arduino/mod.h @@ -1,6 +1,6 @@ #pragma once -#include "../../moddrv.h" +#include "../../pb-mod.h" #ifdef __cplusplus extern "C" { diff --git a/lib/pbdrv/makefile b/lib/pbdrv/makefile new file mode 100644 index 0000000..c87d1af --- /dev/null +++ b/lib/pbdrv/makefile @@ -0,0 +1,4 @@ +TARGET = $(BUILD_DIR)/libpbdrv.a + +include ../../lazy.mk + diff --git a/shared/pb/mod/main.h b/lib/pbdrv/mod/main.h index 56ccd3d..535ce06 100644 --- a/shared/pb/mod/main.h +++ b/lib/pbdrv/mod/main.h @@ -2,12 +2,12 @@ #include "../types.h" -typedef struct __packed { - const uint8_t addr; - const enum pb_state state; +typedef struct { + const i2c_addr_t mod_addr; + const pb_global_state_t mod_state; } pb_mod_main_mod_t; -enum __packed { +enum { PB_MOD_MAIN_ADDR_MODS = 0x01, //!< connected puzzle modules }; diff --git a/shared/pb/moddrv.c b/lib/pbdrv/pb-mod.c index b17b7ac..740f2a5 100644 --- a/shared/pb/moddrv.c +++ b/lib/pbdrv/pb-mod.c @@ -1,5 +1,5 @@ -#include "types.h" -#include "moddrv.h" +#include "pb-types.h" +#include "pb.h" //! fallback module name __weak const char * PBDRV_MOD_NAME = "???"; @@ -23,3 +23,4 @@ __weak void pbdrv_i2c_recv(const uint8_t * buf, size_t sz) { } __weak void pbdrv_hook_main_state_update(pb_global_state_t state) { } + diff --git a/shared/pb/moddrv.h b/lib/pbdrv/pb-mod.h index b48f4db..fa290bf 100644 --- a/shared/pb/moddrv.h +++ b/lib/pbdrv/pb-mod.h @@ -14,15 +14,17 @@ #include <stddef.h> #include <stdbool.h> -#include "types.h" - -extern const char * PBDRV_MOD_NAME; -extern const i2c_addr_t PBDRV_MOD_ADDR; +#include "pb-types.h" #ifdef __cplusplus extern "C" { #endif +//! puzzle module name (optional, default = "???") +extern const char * PBDRV_MOD_NAME; +//! puzzle module bus address (required) +extern const i2c_addr_t PBDRV_MOD_ADDR; + void pbdrv_i2c_recv(const uint8_t * buf, size_t sz); void pbdrv_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz); diff --git a/lib/pbdrv/pb-read.c b/lib/pbdrv/pb-read.c new file mode 100644 index 0000000..843420d --- /dev/null +++ b/lib/pbdrv/pb-read.c @@ -0,0 +1,3 @@ +#include "pb-read.h" + + diff --git a/lib/pbdrv/pb-read.h b/lib/pbdrv/pb-read.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/lib/pbdrv/pb-read.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/shared/pb/types.h b/lib/pbdrv/pb-types.h index 186066b..3c1314f 100644 --- a/shared/pb/types.h +++ b/lib/pbdrv/pb-types.h @@ -1,5 +1,6 @@ #pragma once #include <stdint.h> +#include <stddef.h> #ifdef __cplusplus extern "C" { diff --git a/lib/pbdrv/pb-write.c b/lib/pbdrv/pb-write.c new file mode 100644 index 0000000..65a2932 --- /dev/null +++ b/lib/pbdrv/pb-write.c @@ -0,0 +1 @@ +#include "pb-write.h" diff --git a/lib/pbdrv/pb-write.h b/lib/pbdrv/pb-write.h new file mode 100644 index 0000000..45dcbb0 --- /dev/null +++ b/lib/pbdrv/pb-write.h @@ -0,0 +1,3 @@ +#pragma once + + diff --git a/shared/pb/bus.h b/lib/pbdrv/pb.h index 6f464c3..e37d785 100644 --- a/shared/pb/bus.h +++ b/lib/pbdrv/pb.h @@ -14,5 +14,5 @@ // #define BUSADDR_MOD_AUTOMATION 0 // main controller -#define BUSADDR_MAIN 0x00 +#define BUSADDR_MOD_MAIN 0x00 diff --git a/shared/pb/spec.adoc b/lib/pbdrv/spec.adoc index 3172e84..3172e84 100644 --- a/shared/pb/spec.adoc +++ b/lib/pbdrv/spec.adoc diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 6390d7c..70cd901 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -7,7 +7,8 @@ set(PICO_BOARD pico_w) include(lib/pico-sdk/pico_sdk_init.cmake) include(lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) -include(../i2ctcp/include.cmake) +add_subdirectory(lib/mpack) +add_subdirectory(lib/i2ctcp) project(puzzlebox_main C CXX ASM) diff --git a/main/compile_commands.json b/main/compile_commands.json deleted file mode 120000 index 25eb4b2..0000000 --- a/main/compile_commands.json +++ /dev/null @@ -1 +0,0 @@ -build/compile_commands.json
\ No newline at end of file diff --git a/puzzle/dummy/CMakeLists.txt b/puzzle/dummy/CMakeLists.txt index acc567c..435a2ad 100644 --- a/puzzle/dummy/CMakeLists.txt +++ b/puzzle/dummy/CMakeLists.txt @@ -14,7 +14,7 @@ set(ARDUINO_BOARD "Arduino Uno [avr.uno]") project(pb_mod_dummy C CXX) -include(../../shared/pb.cmake) +add_subdirectory(lib/pbdrv) add_executable(main main.cpp diff --git a/puzzle/dummy/main.cpp b/puzzle/dummy/main.cpp index edcc587..1c79441 100644 --- a/puzzle/dummy/main.cpp +++ b/puzzle/dummy/main.cpp @@ -1,7 +1,7 @@ #include <Arduino.h> #include <Wire.h> -#include "pb/drv/arduino/mod.h" +#include "drv/arduino/mod.h" const char * PBDRV_MOD_NAME = "dummy"; const i2c_addr_t PBDRV_MOD_ADDR = 0x20; @@ -10,8 +10,5 @@ void setup() { pbdrv_setup(); } -void loop() { - pbdrv_i2c_send(0x00, (uint8_t *) "hoi", 3); - delay(100); -} +void loop() { } diff --git a/shared/pb.cmake b/shared/pb.cmake deleted file mode 100644 index 71a28cb..0000000 --- a/shared/pb.cmake +++ /dev/null @@ -1,20 +0,0 @@ -if(DEFINED ARDUINO) - set(PBDRV_ARDUINO true) -endif() - -include_directories(${CMAKE_CURRENT_LIST_DIR}) - -list(APPEND PBDRV_SRCS "${CMAKE_CURRENT_LIST_DIR}/pb/moddrv.c") - -if(PBDRV_ARDUINO) - list(APPEND PBDRV_SRCS "${CMAKE_CURRENT_LIST_DIR}/pb/drv/arduino/mod.cpp") -endif() - -add_library(pbdrv-mod STATIC ${PBDRV_SRCS}) - -if(PBDRV_ARDUINO) - target_link_arduino_libraries(pbdrv-mod - core - Wire - ) -endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e139c34..818c533 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,21 +6,20 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) project(pbtest C CXX ASM) -include(../i2ctcp/include.cmake) -include(../shared/pb.cmake) - add_executable(test ExampleTest.cpp i2ctcp/main.cpp ) -# enable_testing() add_subdirectory(lib/googletest) +add_subdirectory(lib/pbdrv) +add_subdirectory(lib/i2ctcp) # target_include_directories(tests PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_link_libraries(test gtest_main i2ctcp mpack + pbdrv ) |