langref: packed struct documentation

This commit is contained in:
kj4tmp@gmail.com
2024-10-18 00:52:56 -07:00
committed by Andrew Kelley
parent ae38fc6a50
commit a8621731ec
2 changed files with 34 additions and 13 deletions

View File

@@ -0,0 +1,16 @@
pub const GPIORegister = packed struct(u8) {
GPIO0: bool,
GPIO1: bool,
GPIO2: bool,
GPIO3: bool,
_reserved: u4 = 0,
};
/// Write a new state to the memory-mapped IO.
pub fn writeToGPIO(new_states: GPIORegister) void {
const gpio_register_address = 0x0123;
const raw_ptr: *align(1) volatile GPIORegister = @ptrFromInt(gpio_register_address);
raw_ptr.* = new_states;
}
// syntax