langref: reword some packed struct text and example
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
pub const GPIORegister = packed struct(u8) {
|
||||
pub const GpioRegister = packed struct(u8) {
|
||||
GPIO0: bool,
|
||||
GPIO1: bool,
|
||||
GPIO2: bool,
|
||||
GPIO3: bool,
|
||||
_reserved: u4 = 0,
|
||||
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;
|
||||
const gpio: *volatile GpioRegister = @ptrFromInt(0x0123);
|
||||
|
||||
pub fn writeToGpio(new_states: GpioRegister) void {
|
||||
// Example of what not to do:
|
||||
// BAD! gpio.GPIO0 = true; BAD!
|
||||
|
||||
// Instead, do this:
|
||||
gpio.* = new_states;
|
||||
}
|
||||
|
||||
// syntax
|
||||
|
||||
Reference in New Issue
Block a user