diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-10-05 12:44:04 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-10-05 12:44:04 -0400 |
commit | e7b04608254c414d0e770acde071b651ea1472cf (patch) | |
tree | ca2e1d387fc70613054f75ee90d6a6a8cd760351 /src/main.zig | |
parent | f529a3b0f8ee24229997e995021a2ee8cb25f065 (diff) |
toggle gpio
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index de602dd..0fe4497 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,8 +3,44 @@ //! is to delete this file and start with root.zig instead. //const std = @import("std"); +const gpio = packed struct { + moder: u32, + otyper: u32, + ospeedr: u32, + pupdr: u32, + idr: u32, + odr: u32, + bsrr: u32, + lckr: u32, + afrl: u32, + afrh: u32, + brr: u32, + ascr: u32, +}; + +const cpu = struct { + pub fn interrupt_disable() void { + asm volatile("cpsid i"); + } + + pub fn interrupt_enable() void { + asm volatile("cpsie i"); + } +}; + +const gpioa: *gpio = @ptrFromInt(0x48000000); +const rcc: *[39]u32 = @ptrFromInt(0x40021000); + export fn _start() callconv(.C) noreturn { - while (true) {} + cpu.interrupt_disable(); + + rcc[19] |= 1; // gpioaen + gpioa.moder &= ~@as(u32, 0x3 << (5 * 2)); + gpioa.moder |= (1 << (5 * 2)); + + while (true) { + gpioa.odr ^= (1 << 5); + } } export fn fault_handler() callconv(.C) void { |