From f11962e39936e7d95b6c8d139aad1e31fc2b6b3c Mon Sep 17 00:00:00 2001 From: Ragarnoy Date: Wed, 23 Oct 2024 20:45:39 +0200 Subject: [PATCH 1/6] Mark `AccComplex::from_ptr` as `unsafe` Fixes #84 Mark the `AccComplex::from_ptr` function as `unsafe`. * Add a safety comment to the `AccComplex::from_ptr` function explaining the potential risk of dereferencing a raw pointer. * Update the function signature to indicate it is unsafe. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Ragarnoy/a121-rs/issues/84?shareId=XXXX-XXXX-XXXX-XXXX). --- src/num.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/num.rs b/src/num.rs index 2a68f20..b63a848 100644 --- a/src/num.rs +++ b/src/num.rs @@ -14,9 +14,14 @@ impl AccComplex { Self::default() } - pub fn from_ptr(ptr: *const acc_int16_complex_t) -> Self { + /// Creates a new `AccComplex` instance from a raw pointer. + /// + /// # Safety + /// This function is unsafe because it dereferences a raw pointer. + /// The caller must ensure that the pointer is valid and points to a properly initialized `acc_int16_complex_t` struct. + pub unsafe fn from_ptr(ptr: *const acc_int16_complex_t) -> Self { Self { - inner: unsafe { *ptr }, + inner: *ptr, } } From 3806657dbe195b42dd994bda687d954cfc2b8f1e Mon Sep 17 00:00:00 2001 From: ragarnoy Date: Wed, 23 Oct 2024 21:07:23 +0200 Subject: [PATCH 2/6] Formatting --- src/num.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/num.rs b/src/num.rs index b63a848..61c84a9 100644 --- a/src/num.rs +++ b/src/num.rs @@ -20,9 +20,7 @@ impl AccComplex { /// This function is unsafe because it dereferences a raw pointer. /// The caller must ensure that the pointer is valid and points to a properly initialized `acc_int16_complex_t` struct. pub unsafe fn from_ptr(ptr: *const acc_int16_complex_t) -> Self { - Self { - inner: *ptr, - } + Self { inner: *ptr } } /// Returns a mutable pointer to the inner `acc_int16_complex_t` struct. From 282a0ee0ff5ed9b130fed71f3aa05fbcc4f92f1b Mon Sep 17 00:00:00 2001 From: ragarnoy Date: Sun, 27 Oct 2024 17:48:46 +0100 Subject: [PATCH 3/6] Update Cargo dependencies and improve safety checks --- .github/workflows/check.yml | 2 +- examples/xe125-nightly/Cargo.lock | 45 +++++++++++++++------- examples/xe125-nightly/Cargo.toml | 8 ++-- examples/xe125-nightly/src/bin/distance.rs | 6 ++- src/processing.rs | 2 +- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4326ca2..ceb577e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -133,7 +133,7 @@ jobs: # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability strategy: matrix: - msrv: ["1.77"] + msrv: ["1.80"] target: [thumbv7em-none-eabihf] name: ubuntu / ${{ matrix.msrv }} steps: diff --git a/examples/xe125-nightly/Cargo.lock b/examples/xe125-nightly/Cargo.lock index f4f5b11..37ebd15 100644 --- a/examples/xe125-nightly/Cargo.lock +++ b/examples/xe125-nightly/Cargo.lock @@ -1,10 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "a121-rs" -version = "0.1.2" +version = "0.1.3" dependencies = [ "a121-sys", "bindgen", @@ -306,11 +306,29 @@ dependencies = [ "nb 1.1.0", ] +[[package]] +name = "embassy-embedded-hal" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5794414bc20e0d750f145bc0e82366b19dd078e9e075e8331fb8dd069a1cb6a2" +dependencies = [ + "defmt", + "embassy-futures", + "embassy-sync 0.6.0", + "embassy-time", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "embedded-storage", + "embedded-storage-async", + "nb 1.1.0", +] + [[package]] name = "embassy-executor" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec648daedd2143466eff4b3e8002024f9f6c1de4ab7666bb679688752624c925" +checksum = "0fd0a2386252214d31d22400730e28e9c6bc62b346df62802e30a0bb3677e43b" dependencies = [ "cortex-m", "critical-section", @@ -323,9 +341,9 @@ dependencies = [ [[package]] name = "embassy-executor-macros" -version = "0.4.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad454accf80050e9cf7a51e994132ba0e56286b31f9317b68703897c328c59b5" +checksum = "c853e6bcad2d1c0811f4de404cef87363a1fa2535430cf76824c163cf75689ba" dependencies = [ "darling", "proc-macro2", @@ -375,7 +393,7 @@ dependencies = [ "critical-section", "defmt", "document-features", - "embassy-embedded-hal", + "embassy-embedded-hal 0.1.0", "embassy-futures", "embassy-hal-internal", "embassy-net-driver", @@ -432,9 +450,9 @@ dependencies = [ [[package]] name = "embassy-time" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "274c019608a9004aed3cafc871e2a3c87ce9351d537dcaab4cc5db184d4a04b1" +checksum = "158080d48f824fad101d7b2fae2d83ac39e3f7a6fa01811034f7ab8ffc6e7309" dependencies = [ "cfg-if", "critical-section", @@ -504,14 +522,15 @@ dependencies = [ [[package]] name = "embedded-hal-bus" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b4e6ede84339ebdb418cd986e6320a34b017cdf99b5cc3efceec6450b06886" +checksum = "0d3980bf28e8577db59fe2bdb3df868a419469d2cecb363644eea2b6f7797669" dependencies = [ "critical-section", "defmt", "embedded-hal 1.0.0", "embedded-hal-async", + "portable-atomic", ] [[package]] @@ -1275,10 +1294,10 @@ dependencies = [ "cortex-m-rt", "defmt", "defmt-rtt", - "embassy-embedded-hal", + "embassy-embedded-hal 0.2.0", "embassy-executor", "embassy-stm32", - "embassy-sync 0.5.0", + "embassy-sync 0.6.0", "embassy-time", "embedded-hal 1.0.0", "embedded-hal-bus", diff --git a/examples/xe125-nightly/Cargo.toml b/examples/xe125-nightly/Cargo.toml index ccbabbb..cc069ff 100644 --- a/examples/xe125-nightly/Cargo.toml +++ b/examples/xe125-nightly/Cargo.toml @@ -19,12 +19,12 @@ defmt = "0.3" defmt-rtt = "0.4" embedded-hal = "1.0.0" -embassy-executor = { version = "0.5.0", features = [ "task-arena-size-20480", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers" ] } +embassy-executor = { version = "0.6.1", features = [ "task-arena-size-20480", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers" ] } embassy-time = { version = "0.3.0", features = [ "defmt", "tick-hz-32_768" ]} embassy-stm32 = { version = "0.1.0", features = [ "defmt", "unstable-pac", "stm32l431cb", "memory-x", "time-driver-any", "exti", "chrono"] } -embassy-sync = "0.5" -embassy-embedded-hal = { version = "0.1", features = ["defmt"] } -embedded-hal-bus = { version = "0.1.0", features = ["defmt-03"] } +embassy-sync = "0.6.0" +embassy-embedded-hal = { version = "0.2.0", features = ["defmt"] } +embedded-hal-bus = { version = "0.2.0", features = ["defmt-03"] } libc = { version = "0.2", default-features = false } talc = { version = "4.4", default-features = false, features = ["lock_api"] } diff --git a/examples/xe125-nightly/src/bin/distance.rs b/examples/xe125-nightly/src/bin/distance.rs index 7b7ee26..2aa45ef 100644 --- a/examples/xe125-nightly/src/bin/distance.rs +++ b/examples/xe125-nightly/src/bin/distance.rs @@ -43,7 +43,11 @@ async fn main(_spawner: Spawner) { ); let exclusive_device = ExclusiveDevice::new(spi, cs_pin, Delay); - unsafe { SPI_DEVICE = Some(RefCell::new(SpiAdapter::new(exclusive_device))) }; + unsafe { + SPI_DEVICE = Some(RefCell::new(SpiAdapter::new( + exclusive_device.expect("SPI device init failed!"), + ))) + }; let spi_mut_ref = unsafe { SPI_DEVICE.as_mut().unwrap() }; debug!("RSS Version: {}", rss_version()); diff --git a/src/processing.rs b/src/processing.rs index 5a663a9..1c5de4f 100644 --- a/src/processing.rs +++ b/src/processing.rs @@ -87,7 +87,7 @@ impl Drop for Processing { impl From for ProcessingResult { fn from(result: acc_processing_result_t) -> Self { - let frame = AccComplex::from_ptr(result.frame); + let frame = unsafe { AccComplex::from_ptr(result.frame) }; Self { inner: result, frame, From 2181e9cf0aa76f5ea1a3625f57e659a58766853e Mon Sep 17 00:00:00 2001 From: ragarnoy Date: Sun, 27 Oct 2024 18:04:26 +0100 Subject: [PATCH 4/6] Update README with status and bump versions --- Cargo.toml | 6 +++--- README.md | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee99a35..3279a45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ categories = ["embedded", "no-std"] readme = "README.md" license = "MIT" edition = "2021" -version = "0.1.3" -rust-version = "1.77" +version = "0.1.4" +rust-version = "1.81" [dependencies] a121-sys = { version = "0.4", features = ["distance", "presence"] } @@ -25,7 +25,7 @@ num = { version = "0.4", default-features = false } libm = { version = "0.2.8", default-features = false, optional = true } [build-dependencies] -bindgen = "0.69" +bindgen = "0.70" cc = "1.0" [features] diff --git a/README.md b/README.md index cb295cd..d1f48ff 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ _a121-rs_ is a Rust library providing a high-level abstraction for interfacing w _a121-rs_ aims to simplify the development process for applications requiring accurate distance measurements and presence detection, leveraging the unique capabilities of the A121 radar sensor. +## Status + +Being maintained but definitely looking for assistance + ## Features _a121-rs_ comes with a host of features designed to make working with the A121 sensor as straightforward as possible: From 71c1e22f395e885d7467bef3d6899ef958be65c4 Mon Sep 17 00:00:00 2001 From: ragarnoy Date: Sun, 27 Oct 2024 18:04:26 +0100 Subject: [PATCH 5/6] Update README with status and bump versions --- Cargo.toml | 6 +++--- README.md | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee99a35..3279a45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ categories = ["embedded", "no-std"] readme = "README.md" license = "MIT" edition = "2021" -version = "0.1.3" -rust-version = "1.77" +version = "0.1.4" +rust-version = "1.81" [dependencies] a121-sys = { version = "0.4", features = ["distance", "presence"] } @@ -25,7 +25,7 @@ num = { version = "0.4", default-features = false } libm = { version = "0.2.8", default-features = false, optional = true } [build-dependencies] -bindgen = "0.69" +bindgen = "0.70" cc = "1.0" [features] diff --git a/README.md b/README.md index cb295cd..d1f48ff 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ _a121-rs_ is a Rust library providing a high-level abstraction for interfacing w _a121-rs_ aims to simplify the development process for applications requiring accurate distance measurements and presence detection, leveraging the unique capabilities of the A121 radar sensor. +## Status + +Being maintained but definitely looking for assistance + ## Features _a121-rs_ comes with a host of features designed to make working with the A121 sensor as straightforward as possible: From 64feb134f08a847e5750ffc4a06154987ad64717 Mon Sep 17 00:00:00 2001 From: ragarnoy Date: Sun, 27 Oct 2024 18:07:11 +0100 Subject: [PATCH 6/6] Update README with status and bump versions --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3279a45..d3968c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" license = "MIT" edition = "2021" version = "0.1.4" -rust-version = "1.81" +rust-version = "1.80" [dependencies] a121-sys = { version = "0.4", features = ["distance", "presence"] }