Skip to content

Convert buffer to slice so user doesn't need unsafe #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ pub trait FlashAlgorithm: Sized + 'static {
/// # Arguments
///
/// * `address` - The start address of the flash page to program.
/// * `size` - Specifies the size of the data buffer.
/// * `data` - The data to be written to the page.
fn program_page(&mut self, address: u32, size: u32, data: *const u8) -> Result<(), ErrorCode>;
fn program_page(&mut self, address: u32, data: &[u8]) -> Result<(), ErrorCode>;
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -140,7 +139,8 @@ macro_rules! algorithm {
return 1;
}
let this = &mut *_ALGO_INSTANCE.as_mut_ptr();
match <$type as FlashAlgorithm>::program_page(this, addr, size, data) {
let data_slice: &[u8] = unsafe { core::slice::from_raw_parts(data, size as usize) };
match <$type as FlashAlgorithm>::program_page(this, addr, data_slice) {
Ok(()) => 0,
Err(e) => e.get(),
}
Expand Down