Skip to content

Instantly share code, notes, and snippets.

@metajack
Created July 13, 2021 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metajack/9c62566415f8ceaf095d677e59cdcca1 to your computer and use it in GitHub Desktop.
Save metajack/9c62566415f8ceaf095d677e59cdcca1 to your computer and use it in GitHub Desktop.
#[derive(Debug)]
#[repr(C, packed)]
struct LedState {
on: u16,
off: u16,
}
#[derive(Debug)]
#[repr(C, packed)]
struct LedArray {
reg_addr: u8,
leds: [LedState; 16],
}
#[link_section = ".sram1_bss"]
static mut LED_BUFFER: MaybeUninit<LedArray> = MaybeUninit::uninit();
fn main() -> ! {
// ...
unsafe {
LED_BUFFER.as_mut_ptr().write(LedArray {
reg_addr: 0x06,
leds: [
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0xfff },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0x100 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0 },
LedState { on: 0, off: 0xfff },
LedState { on: 0, off: 0 },
],
});
}
let led_bytes: &LedArray = unsafe { &*LED_BUFFER.as_ptr() };
rprintln!("len = {:?}", led_bytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment