sylveos

Toy Operating System
Log | Files | Refs

gpio.zig (940B)


      1 const std = @import("std");
      2 const shared = @import("shared");
      3 const pi = @import("pi");
      4 
      5 const gpio = pi.devices.gpio;
      6 const uart = pi.devices.mini_uart;
      7 
      8 pub fn gpio_rising_edge(pin: *const u8) void {
      9     uart.writer.print("pin {d} is high\n", .{pin.*}) catch {};
     10 }
     11 
     12 pub fn gpio_falling_edge(pin: *const u8) void {
     13     uart.writer.print("pin {d} is low\n", .{pin.*}) catch {};
     14 }
     15 
     16 pub fn main() !void {
     17     try gpio.fn_sel(9, .input);
     18     try gpio.fn_sel(10, .output);
     19     try gpio.write(10, true);
     20 
     21     try uart.writer.print("enabling interrupts\n", .{});
     22 
     23     try gpio.enable_interrupts();
     24 
     25     try gpio.rising_edge_interrupt(9, true);
     26     try gpio.falling_edge_interrupt(9, true);
     27 
     28     try gpio.ev.listen(.PinRisingEdge, &gpio_rising_edge);
     29     try gpio.ev.listen(.PinFallingEdge, &gpio_falling_edge);
     30 
     31     try uart.writer.print("waiting for interrupts\n", .{});
     32 
     33     // Wait around so we can listen for interrupts
     34     while (true) {}
     35 }