From fb70d7eea45fdefd401d3a9510ca7fc226d0b34d Mon Sep 17 00:00:00 2001 From: Marek Kraus Date: Mon, 12 Sep 2022 13:14:55 +0200 Subject: [PATCH] Add libserialport + another improvements --- .gitmodules | 3 +++ CMakeLists.txt | 23 ++++++++++++++++++++++- src/cmd/write.c | 1 + src/main.c | 15 +++++++++------ vendor/libserialport | 1 + 5 files changed, 36 insertions(+), 7 deletions(-) create mode 160000 vendor/libserialport diff --git a/.gitmodules b/.gitmodules index 7b360dc..ee3db22 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendor/argtable3"] path = vendor/argtable3 url = https://github.com/argtable/argtable3 +[submodule "vendor/libserialport"] + path = vendor/libserialport + url = https://github.com/sigrokproject/libserialport/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d28e2e..f7edcd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,4 +8,25 @@ add_subdirectory(vendor/argtable3) add_executable(blisp src/main.c src/cmd/write.c) target_include_directories(blisp PRIVATE vendor/argtable3/src) -target_link_libraries(blisp PRIVATE argtable3) \ No newline at end of file +target_link_libraries(blisp PRIVATE argtable3) + +target_sources(blisp PRIVATE + ${CMAKE_SOURCE_DIR}/vendor/libserialport/serialport.c + ${CMAKE_SOURCE_DIR}/vendor/libserialport/timing.c) + +if(WIN32) + target_link_libraries(blisp PRIVATE Setupapi.lib) + target_compile_definitions(blisp PRIVATE LIBSERIALPORT_MSBUILD) + target_sources(blisp PRIVATE + ${CMAKE_SOURCE_DIR}/vendor/libserialport/windows.c) +elseif(UNIX AND NOT APPLE) + target_sources(blisp PRIVATE + ${CMAKE_SOURCE_DIR}/vendor/libserialport/linux.c + ${CMAKE_SOURCE_DIR}/vendor/libserialport/linux_termios.c) + target_compile_definitions(blisp PRIVATE + LIBSERIALPORT_ATBUILD + "SP_API=__attribute__((visibility(\"default\")))" + "SP_PRIV=__attribute__((visibility(\"hidden\")))") + target_include_directories(blisp PRIVATE ${CMAKE_SOURCE_DIR}/vendor/libserialport) + write_file(${CMAKE_SOURCE_DIR}/vendor/libserialport/config.h "// bypass errors.") +endif() \ No newline at end of file diff --git a/src/cmd/write.c b/src/cmd/write.c index 3c93385..3b941fa 100644 --- a/src/cmd/write.c +++ b/src/cmd/write.c @@ -21,6 +21,7 @@ cmd_write_args_init() { fprintf(stderr, "insufficient memory\n"); return -1; } + return 0; } uint8_t diff --git a/src/main.c b/src/main.c index f521df1..182cec3 100644 --- a/src/main.c +++ b/src/main.c @@ -5,9 +5,11 @@ #include struct cmd* cmds[] = { - &cmd_write, + &cmd_write }; +static uint8_t cmds_count = sizeof(cmds) / sizeof(cmds[0]); + static struct arg_lit* help; static struct arg_lit* version; static struct arg_end* end; @@ -22,11 +24,12 @@ int8_t args_init() { fprintf(stderr, "insufficient memory\n"); return -1; } + return 0; } void print_help() { puts("Usage:"); - for (uint8_t i = 0; cmds[i] != NULL; i++) { + for (uint8_t i = 0; i < cmds_count; i++) { fputs("\tblisp", stdout); cmds[i]->args_print_syntax(); } @@ -62,7 +65,7 @@ main(int argc, char** argv) { goto exit; } - for (uint8_t i = 0; cmds[i] != NULL; i++) { + for (uint8_t i = 0; i < cmds_count; i++) { if (cmds[i]->args_init() != 0) { exit_code = -1; goto exit; @@ -74,7 +77,7 @@ main(int argc, char** argv) { } uint8_t command_found = false; - for (uint8_t i = 0; cmds[i] != NULL; i++) { + for (uint8_t i = 0; i < cmds_count; i++) { if (cmds[i]->args_parse_exec(argc, argv)) { command_found = true; break; @@ -82,11 +85,11 @@ main(int argc, char** argv) { } if (!command_found) { - + print_help(); } exit: - for (uint8_t i = 0; cmds[i] != NULL; i++) { + for (uint8_t i = 0; i < cmds_count; i++) { cmds[i]->args_free(); } args_free(); diff --git a/vendor/libserialport b/vendor/libserialport new file mode 160000 index 0000000..6f9b03e --- /dev/null +++ b/vendor/libserialport @@ -0,0 +1 @@ +Subproject commit 6f9b03e597ea7200eb616a4e410add3dd1690cb1