aboutsummaryrefslogtreecommitdiff
path: root/doc/langref/packed_struct_mmio.zig
diff options
context:
space:
mode:
Diffstat (limited to 'doc/langref/packed_struct_mmio.zig')
-rw-r--r--doc/langref/packed_struct_mmio.zig17
1 files changed, 10 insertions, 7 deletions
diff --git a/doc/langref/packed_struct_mmio.zig b/doc/langref/packed_struct_mmio.zig
index 79236a76ea..18b57f83b2 100644
--- a/doc/langref/packed_struct_mmio.zig
+++ b/doc/langref/packed_struct_mmio.zig
@@ -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