diff --git a/crates/api-desc/CHANGELOG.md b/crates/api-desc/CHANGELOG.md index 6aaf7be3..0c4a5d11 100644 --- a/crates/api-desc/CHANGELOG.md +++ b/crates/api-desc/CHANGELOG.md @@ -16,6 +16,7 @@ ### Patch +- Use `*const void` instead of `*const u8` for opaque data - Update dependencies - Fix lints diff --git a/crates/api-desc/src/button.rs b/crates/api-desc/src/button.rs index 4e5e7933..ac31bf9f 100644 --- a/crates/api-desc/src/button.rs +++ b/crates/api-desc/src/button.rs @@ -46,10 +46,10 @@ pub(crate) fn new() -> Item { /// Function called on button events. /// /// The function takes its opaque `data` and the new button `state` as arguments. - handler_func: fn { data: *const u8, state: usize }, + handler_func: fn { data: *const void, state: usize }, /// The opaque data to use when calling the handler function. - handler_data: *const u8, + handler_data: *const void, } -> {} }, item! { diff --git a/crates/api-desc/src/clock.rs b/crates/api-desc/src/clock.rs index 96fbecbe..44297624 100644 --- a/crates/api-desc/src/clock.rs +++ b/crates/api-desc/src/clock.rs @@ -34,10 +34,10 @@ pub(crate) fn new() -> Item { /// Allocates a timer (initially stopped). fn allocate "ta" { /// Function called when the timer triggers. - handler_func: fn { data: *const u8 }, + handler_func: fn { data: *const void }, /// The opaque data to use when calling the handler function. - handler_data: *const u8, + handler_data: *const void, } -> { /// Identifier for this timer. id: usize, diff --git a/crates/api-desc/src/macros.rs b/crates/api-desc/src/macros.rs index f88baaac..4a931807 100644 --- a/crates/api-desc/src/macros.rs +++ b/crates/api-desc/src/macros.rs @@ -29,7 +29,7 @@ macro_rules! type_ { }; (*const $($type:tt)*) => (type_!(*false $($type)*)); (*mut $($type:tt)*) => (type_!(*true $($type)*)); - (*$mut:tt u8) => (Type::Pointer { mutable: $mut, type_: None }); + (*$mut:tt void) => (Type::Pointer { mutable: $mut, type_: None }); (*$mut:tt $($type:tt)*) => { Type::Pointer { mutable: $mut, type_: Some(Box::new(type_!($($type)*))) } }; diff --git a/crates/api-desc/src/radio/ble.rs b/crates/api-desc/src/radio/ble.rs index 1507e5f7..bb0a20a1 100644 --- a/crates/api-desc/src/radio/ble.rs +++ b/crates/api-desc/src/radio/ble.rs @@ -60,10 +60,10 @@ pub(crate) fn new() -> Item { /// Function called on radio events. /// /// The function takes its opaque `data` as argument. - handler_func: fn { data: *mut u8 }, + handler_func: fn { data: *const void }, /// The opaque data to use when calling the handler function. - handler_data: *mut u8, + handler_data: *const void, } -> {} }, item! { diff --git a/crates/api-desc/src/uart.rs b/crates/api-desc/src/uart.rs index f6bb934c..6abe5c49 100644 --- a/crates/api-desc/src/uart.rs +++ b/crates/api-desc/src/uart.rs @@ -80,10 +80,10 @@ pub(crate) fn new() -> Item { event: usize, /// Function pointer of the closure to call on events. - handler_func: fn { data: *const u8 }, + handler_func: fn { data: *const void }, /// Opaque data of the closure to call on events. - handler_data: *const u8, + handler_data: *const void, } -> {} }, item! { diff --git a/crates/api-desc/src/usb/serial.rs b/crates/api-desc/src/usb/serial.rs index 3450be3a..af594928 100644 --- a/crates/api-desc/src/usb/serial.rs +++ b/crates/api-desc/src/usb/serial.rs @@ -63,8 +63,8 @@ pub(crate) fn new() -> Item { /// It is possible that the callback is spuriously called. fn register "use" { event: usize, - handler_func: fn { data: *const u8 }, - handler_data: *const u8, + handler_func: fn { data: *const void }, + handler_data: *const void, } -> {} }, item! { diff --git a/crates/prelude/CHANGELOG.md b/crates/prelude/CHANGELOG.md index 2b9233ea..fbc0d8a9 100644 --- a/crates/prelude/CHANGELOG.md +++ b/crates/prelude/CHANGELOG.md @@ -113,4 +113,4 @@ ## 0.1.0 - + diff --git a/crates/prelude/src/radio/ble.rs b/crates/prelude/src/radio/ble.rs index e78be502..ec31e4cc 100644 --- a/crates/prelude/src/radio/ble.rs +++ b/crates/prelude/src/radio/ble.rs @@ -57,7 +57,7 @@ impl Listener { let event = event as u32; let handler_func = Self::call; let handler = Box::into_raw(Box::new(handler)); - let handler_data = handler as *mut u8; + let handler_data = handler as *const u8; unsafe { api::register(api::register::Params { event, handler_func, handler_data }) }; Listener { handler } } @@ -78,8 +78,8 @@ impl Listener { core::mem::forget(self); } - extern "C" fn call(data: *mut u8) { - let handler = unsafe { &mut *(data as *mut H) }; + extern "C" fn call(data: *const u8) { + let handler = unsafe { &*(data as *const H) }; handler.event(Event::Advertisement); } }