From 6e48ce664e20ac5a43dd42f5e0706d6f813e3479 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Thu, 8 Feb 2024 22:49:40 -0500 Subject: [PATCH] c-with-rust: make cmake call cargo --- c-with-rust/CMakeLists.txt | 5 ++++- c-with-rust/blink.c | 3 +++ c-with-rust/build.sh | 3 --- c-with-rust/rblink/CMakeLists.txt | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 c-with-rust/rblink/CMakeLists.txt diff --git a/c-with-rust/CMakeLists.txt b/c-with-rust/CMakeLists.txt index 39aacea..8881ab8 100644 --- a/c-with-rust/CMakeLists.txt +++ b/c-with-rust/CMakeLists.txt @@ -15,11 +15,14 @@ add_executable( blink.c ) +add_subdirectory(rblink) +add_dependencies(blink rblink) + # pull in common dependencies target_link_libraries( blink pico_stdlib - /tmp/cargo-target/thumbv6m-none-eabi/release/librblink.a + ${CMAKE_CURRENT_BINARY_DIR}/rblink/librblink.a ) # create map/bin/hex file etc. diff --git a/c-with-rust/blink.c b/c-with-rust/blink.c index 8bff825..69bc508 100644 --- a/c-with-rust/blink.c +++ b/c-with-rust/blink.c @@ -51,6 +51,9 @@ int c_main() { gpio_put(LED_PIN, 0); sleep_ms(sleep); sleep = add_half(sleep); + if(sleep > 2000) { + reset_usb_boot(LED_PIN, 0); + } } } diff --git a/c-with-rust/build.sh b/c-with-rust/build.sh index 838e049..9f99bb1 100755 --- a/c-with-rust/build.sh +++ b/c-with-rust/build.sh @@ -5,9 +5,6 @@ set -euxo pipefail SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -cd "$SCRIPT_DIR"/rblink -CARGO_TARGET_DIR=/tmp/cargo-target cargo build --release --target thumbv6m-none-eabi - mkdir -p /tmp/8 cd /tmp/8 diff --git a/c-with-rust/rblink/CMakeLists.txt b/c-with-rust/rblink/CMakeLists.txt new file mode 100644 index 0000000..dd10d95 --- /dev/null +++ b/c-with-rust/rblink/CMakeLists.txt @@ -0,0 +1,20 @@ +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CARGO_CMD cargo build --target thumbv6m-none-eabi) + set(TARGET_DIR "debug") +else () + set(CARGO_CMD cargo build --release --target thumbv6m-none-eabi) + set(TARGET_DIR "release") +endif () + +set(RBLINK_A "${CMAKE_CURRENT_BINARY_DIR}/thumbv6m-none-eabi/${TARGET_DIR}/librblink.a") + +add_custom_target(rblink ALL + COMMENT "Compiling rblink module" + COMMAND CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} ${CARGO_CMD} + COMMAND cp ${RBLINK_A} ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +set_target_properties(rblink PROPERTIES LOCATION ${CMAKE_CURRENT_BINARY_DIR}) + +add_test(NAME rblink_test + COMMAND cargo test + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})