-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I don't get why the delay is off by a factor of 32. None of the prescaling factors are even 32, it goes 8, 64, 256, 1024. Where does 32 come from? Why is it not in Arduino's code? I have a 16 MHz crystal. What the heck man? Oh well.
- Loading branch information
1 parent
7e22531
commit 625deb9
Showing
3 changed files
with
63 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
const std = @import("std"); | ||
const gpio = @import("gpio.zig"); | ||
const pins = @import("pins.zig"); | ||
const time = @import("time.zig"); | ||
|
||
pub fn main() void { | ||
// This baud should match what you pass in build | ||
time.init(); | ||
// Onboard LED | ||
gpio.pinMode(pins.led_builtin, .out); | ||
// Wired LED | ||
gpio.pinMode(8, .out); | ||
// Button | ||
gpio.pinMode(3, .in); | ||
|
||
while (true) { | ||
gpio.toggle(pins.led_builtin); | ||
if (gpio.digitalRead(3) == .low) { | ||
gpio.digitalWrite(8, .low); | ||
} else { | ||
gpio.digitalWrite(8, .high); | ||
} | ||
time.delay(1000); | ||
} | ||
} | ||
|
||
// Hard code a busy wait. Will add delays eventually. | ||
var i: u32 = 0; | ||
while (i < 100000) : (i += 1) { | ||
// For some reason need to nop the busy wait | ||
asm volatile ("nop"); | ||
// Interrupt stuff in root for timer | ||
pub const interrupts = struct { | ||
pub fn TIMER0_OVF() void { | ||
// Dunno if we need locals like in Arduino standard library to keep in | ||
// registers. But I'll do it anyway | ||
var m = time.timer0_millis; | ||
var f = time.timer0_fract; | ||
|
||
m += time.millis_inc; | ||
f += time.fract_inc; | ||
if (f >= time.fract_max) { | ||
f -= time.fract_max; | ||
m += 1; | ||
} | ||
|
||
time.timer0_fract = f; | ||
time.timer0_millis = m; | ||
time.timer0_overflow_count += 1; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters