Skip to content

Commit

Permalink
Merge pull request #85 from Ragarnoy/fix-unsafe-pointer
Browse files Browse the repository at this point in the history
Mark `AccComplex::from_ptr` as `unsafe`
  • Loading branch information
Ragarnoy authored Oct 27, 2024
2 parents 1d54532 + fd481e0 commit 93dbea1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.80"

[dependencies]
a121-sys = { version = "0.4", features = ["distance", "presence"] }
Expand All @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 32 additions & 13 deletions examples/xe125-nightly/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/xe125-nightly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 5 additions & 1 deletion examples/xe125-nightly/src/bin/distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 7 additions & 4 deletions src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ impl AccComplex {
Self::default()
}

pub fn from_ptr(ptr: *const acc_int16_complex_t) -> Self {
Self {
inner: unsafe { *ptr },
}
/// 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: *ptr }
}

/// Returns a mutable pointer to the inner `acc_int16_complex_t` struct.
Expand Down
2 changes: 1 addition & 1 deletion src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Drop for Processing {

impl From<acc_processing_result_t> 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,
Expand Down

0 comments on commit 93dbea1

Please sign in to comment.