-
-
Save metajack/9c62566415f8ceaf095d677e59cdcca1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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