mirror of
https://github.com/pine64/blisp.git
synced 2024-12-22 06:20:12 +00:00
Add libserialport + another improvements
This commit is contained in:
parent
019c7dd845
commit
fb70d7eea4
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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/
|
||||
|
@ -9,3 +9,24 @@ add_executable(blisp src/main.c src/cmd/write.c)
|
||||
|
||||
target_include_directories(blisp PRIVATE vendor/argtable3/src)
|
||||
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()
|
@ -21,6 +21,7 @@ cmd_write_args_init() {
|
||||
fprintf(stderr, "insufficient memory\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
|
15
src/main.c
15
src/main.c
@ -5,9 +5,11 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
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();
|
||||
|
1
vendor/libserialport
vendored
Submodule
1
vendor/libserialport
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 6f9b03e597ea7200eb616a4e410add3dd1690cb1
|
Loading…
Reference in New Issue
Block a user