parent
f1e25c9837
commit
43ef1f29d8
@ -1,27 +1,29 @@
|
||||
use super::ffi;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct PointerData {
|
||||
pub ptr: *const u8,
|
||||
pub len: u32,
|
||||
}
|
||||
|
||||
pub fn get_translations_blob() -> &'static [u8] {
|
||||
// SAFETY: Returned slice is valid and immutable until a call to `erase()` and/or `set_blob()`.
|
||||
// Caller is responsible for disposing of all references to the slice before touching
|
||||
// the flash contents.
|
||||
pub unsafe fn get_blob<'a>() -> &'a [u8] {
|
||||
let mut len: u32 = 0;
|
||||
let ptr = unsafe { ffi::translations_read(&mut len, 0) };
|
||||
if ptr.is_null() {
|
||||
fatal_error!("Translations read failed", "");
|
||||
}
|
||||
// SAFETY: The pointer is always valid.
|
||||
unsafe { core::slice::from_raw_parts(ptr, len as usize) }
|
||||
}
|
||||
|
||||
pub fn get_pointer_with_offset(offset: u16, len: u16) -> PointerData {
|
||||
let ptr = unsafe { ffi::translations_read(&mut 0, offset.into()) };
|
||||
if ptr.is_null() {
|
||||
fatal_error!("Translations read failed", "");
|
||||
}
|
||||
PointerData {
|
||||
ptr,
|
||||
len: len.into(),
|
||||
}
|
||||
// SAFETY: This call invalidates the reference to the blob returned by `get_blob()`.
|
||||
pub unsafe fn erase() {
|
||||
unsafe { ffi::translations_erase() };
|
||||
}
|
||||
|
||||
pub fn area_bytesize() -> usize {
|
||||
// SAFETY: Safe, no side effects.
|
||||
unsafe { ffi::translations_area_bytesize() as usize }
|
||||
}
|
||||
|
||||
// SAFETY: This call may invalidate the reference to the blob returned by `get_blob()`.
|
||||
pub unsafe fn write(data: &[u8], offset: usize) {
|
||||
unsafe { ffi::translations_write(data.as_ptr(), offset as u32, data.len() as u32) };
|
||||
}
|
||||
|
Loading…
Reference in new issue