diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-18 15:39:03 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-18 15:39:03 +0200 |
commit | 1e54994000d1c26e9cbd724b76da5ceb273f9cbb (patch) | |
tree | 3c3fb7fab24a7d91438d22555daecc60d7962c30 | |
parent | 573ee2dd6790c00c9e0f709f222bc2a68f015d6d (diff) |
i2c reply kinda working
-rw-r--r-- | lib/pbdrv/drv/arduino/mod.cpp | 4 | ||||
-rw-r--r-- | lib/pbdrv/mpack-config.h | 12 | ||||
-rw-r--r-- | lib/pbdrv/pb-msg.c | 13 | ||||
-rw-r--r-- | lib/pbdrv/pb-types.h | 3 | ||||
-rw-r--r-- | puzzle/dummy/CMakeLists.txt | 1 | ||||
-rw-r--r-- | puzzle/dummy/FreeRTOSConfig.h | 2 | ||||
-rw-r--r-- | puzzle/dummy/main.cpp | 20 | ||||
-rw-r--r-- | puzzle/dummy/mod.c | 5 |
8 files changed, 24 insertions, 36 deletions
diff --git a/lib/pbdrv/drv/arduino/mod.cpp b/lib/pbdrv/drv/arduino/mod.cpp index 328c3c7..9130334 100644 --- a/lib/pbdrv/drv/arduino/mod.cpp +++ b/lib/pbdrv/drv/arduino/mod.cpp @@ -82,7 +82,3 @@ int main(void) { * puzzle modules are likely not using USB. */ -void pb_null_err(const char * from) { - Serial.println(from); -} - diff --git a/lib/pbdrv/mpack-config.h b/lib/pbdrv/mpack-config.h index 7e7d0b2..f040698 100644 --- a/lib/pbdrv/mpack-config.h +++ b/lib/pbdrv/mpack-config.h @@ -11,11 +11,11 @@ #define MPACK_REALLOC pb_realloc // more reasonable buffer size (all messages are small) -#define MPACK_BUFFER_SIZE 80 -#define MPACK_STACK_SIZE 80 -#define MPACK_PAGE_SIZE 80 +#define MPACK_BUFFER_SIZE 256 +#define MPACK_STACK_SIZE MPACK_BUFFER_SIZE +#define MPACK_PAGE_SIZE MPACK_BUFFER_SIZE -// // disable unused features (causes errors?) -// #define MPACK_NODE 0 -// #define MPACK_BUILDER 0 +// disable unused features (causes errors?) +#define MPACK_NODE 0 +#define MPACK_BUILDER 0 diff --git a/lib/pbdrv/pb-msg.c b/lib/pbdrv/pb-msg.c index ab3f5b2..8cf020c 100644 --- a/lib/pbdrv/pb-msg.c +++ b/lib/pbdrv/pb-msg.c @@ -3,17 +3,26 @@ #include "pb-msg.h" #include "pb-serial.h" #include "pb-mem.h" +#include "mpack-config.h" pb_buf_t pb_msg_write(const pb_msg_t * msg) { pb_buf_t buf = { 0 }; if (msg == NULL) return buf; + buf.data = pb_malloc(MPACK_BUFFER_SIZE); + if (buf.data == NULL) return buf; + mpack_writer_t writer; - mpack_writer_init_growable(&writer, &buf.data, &buf.size); + mpack_writer_init(&writer, buf.data, buf.size); pb_ser_w(&writer, msg); - mpack_writer_destroy(&writer); + buf.size = mpack_writer_buffer_used(&writer); + if (mpack_writer_destroy(&writer) != mpack_ok) { + pb_free(buf.data); + buf.data = NULL; + buf.size = 0; + } return buf; } diff --git a/lib/pbdrv/pb-types.h b/lib/pbdrv/pb-types.h index fab9028..4d085f9 100644 --- a/lib/pbdrv/pb-types.h +++ b/lib/pbdrv/pb-types.h @@ -75,9 +75,6 @@ typedef struct { size_t _magic_size; //!< [META] size of \p magic } pb_cmd_magic_t; -// DEBUG: remove -void pb_null_err(const char * from); - #ifdef __cplusplus } #endif diff --git a/puzzle/dummy/CMakeLists.txt b/puzzle/dummy/CMakeLists.txt index 0d5e1bd..6acc4c8 100644 --- a/puzzle/dummy/CMakeLists.txt +++ b/puzzle/dummy/CMakeLists.txt @@ -33,6 +33,7 @@ add_subdirectory(lib/FreeRTOS-Kernel) add_executable(main main.cpp + mod.c ) target_link_libraries(main diff --git a/puzzle/dummy/FreeRTOSConfig.h b/puzzle/dummy/FreeRTOSConfig.h index f398db9..1cfdd71 100644 --- a/puzzle/dummy/FreeRTOSConfig.h +++ b/puzzle/dummy/FreeRTOSConfig.h @@ -20,7 +20,7 @@ // #define configTOTAL_HEAP_SIZE (1024) #define configTOTAL_HEAP_SIZE (7 * 1024) #define configCHECK_FOR_STACK_OVERFLOW 0 -#define configUSE_MALLOC_FAILED_HOOK 1 +#define configUSE_MALLOC_FAILED_HOOK 0 #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 #define configGENERATE_RUN_TIME_STATS 0 #define configUSE_TRACE_FACILITY 0 diff --git a/puzzle/dummy/main.cpp b/puzzle/dummy/main.cpp index 217ce94..41d8993 100644 --- a/puzzle/dummy/main.cpp +++ b/puzzle/dummy/main.cpp @@ -3,24 +3,8 @@ #include <FreeRTOS.h> #include <task.h> -#include "pb-mod.h" -#include "pb-route.h" -#include "pb-send.h" - -const char * PB_MOD_NAME = "dummy"; -const i2c_addr_t PB_MOD_ADDR = 0x69; - void setup() { Serial.begin(115200); - - pb_buf_t buf = pb_send_magic_res(); - Serial.print("response bytes:"); - for (size_t i = 0; i < buf.size; i++) { - Serial.print(" "); - Serial.print(buf.data[i]); - } - Serial.print("\r\n"); - pb_buf_free(&buf); } void loop() { @@ -28,7 +12,3 @@ void loop() { vTaskDelay(1000 / portTICK_PERIOD_MS); } -void vApplicationMallocFailedHook(void) { - Serial.println("malloc failed!"); -} - diff --git a/puzzle/dummy/mod.c b/puzzle/dummy/mod.c new file mode 100644 index 0000000..018ea68 --- /dev/null +++ b/puzzle/dummy/mod.c @@ -0,0 +1,5 @@ +#include "pb-mod.h" + +const char * PB_MOD_NAME = "dummy"; +const i2c_addr_t PB_MOD_ADDR = 0x69; + |