-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HAL and demos for verifying hardware subsystems
- Loading branch information
Showing
26 changed files
with
3,056 additions
and
25 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! This is firmware for the SYCL badge. | ||
//! | ||
//! The badge image | ||
//! For normal operation, the default app will run. Pressing select will go to | ||
//! the main menu. The default app will display the SYCL logo, users will be | ||
//! able to change the default app. | ||
//! | ||
//! Apps will have the option to to save state to non-volatile memory. This | ||
//! will prompt the user. The user will either exit without saving, save and | ||
//! exit, or cancel. | ||
//! | ||
//! TODO: | ||
//! - USB mass drive | ||
//! - USB CDC logging | ||
const std = @import("std"); | ||
|
||
const microzig = @import("microzig"); | ||
const board = microzig.board; | ||
const hal = microzig.hal; | ||
const usb = hal.usb; | ||
|
||
const peripherals = microzig.chip.peripherals; | ||
const MCLK = peripherals.MCLK; | ||
|
||
const led_pin = board.D13; | ||
const backlight = board.TFT_LITE; | ||
const @"D+" = board.@"D+"; | ||
const @"D-" = board.@"D-"; | ||
|
||
pub fn main() !void { | ||
// Initialize clocks | ||
MCLK.AHBMASK.modify(.{ .USB_ = 1 }); | ||
MCLK.APBBMASK.modify(.{ .USB_ = 1 }); | ||
|
||
// Initialize pins | ||
led_pin.set_dir(.out); | ||
backlight.set_dir(.out); | ||
@"D+".set_mux(.H); | ||
@"D-".set_mux(.H); | ||
|
||
backlight.write(.low); | ||
|
||
const period = 200000; | ||
while (true) { | ||
delay_count(period); | ||
led_pin.write(.high); | ||
delay_count(period); | ||
led_pin.write(.low); | ||
} | ||
} | ||
|
||
fn delay_count(count: u32) void { | ||
var i: u32 = 0; | ||
while (i < count) : (i += 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
const hal = microzig.hal; | ||
const gclk = hal.gclk; | ||
const timer = hal.timer; | ||
|
||
const spkr_en_pin = microzig.board.SPKR_EN; | ||
const analog_out_pin = microzig.board.A0; | ||
const led_pin = microzig.board.D13; | ||
|
||
pub fn main() !void { | ||
spkr_en_pin.set_dir(.out); | ||
analog_out_pin.set_dir(.out); | ||
led_pin.set_dir(.out); | ||
|
||
analog_out_pin.write(.low); | ||
spkr_en_pin.write(.high); | ||
|
||
gclk.enable_generator(.GCLK1, .DFLL, .{ | ||
.divsel = .DIV1, | ||
.div = 48, | ||
}); | ||
|
||
timer.init(); | ||
while (true) { | ||
led_pin.toggle(); | ||
analog_out_pin.toggle(); | ||
timer.delay_us(std.time.us_per_ms); | ||
} | ||
} | ||
|
||
fn delay_count(count: u32) void { | ||
var i: u32 = 0; | ||
while (i < count) : (i += 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const microzig = @import("microzig"); | ||
|
||
const led_pin = microzig.board.D13; | ||
|
||
pub fn main() !void { | ||
// Initialize pins | ||
led_pin.set_dir(.out); | ||
|
||
const period = 200000; | ||
while (true) { | ||
delay_count(period); | ||
led_pin.write(.high); | ||
delay_count(period); | ||
led_pin.write(.low); | ||
} | ||
} | ||
|
||
fn delay_count(count: u32) void { | ||
var i: u32 = 0; | ||
while (i < count) : (i += 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
const hal = microzig.hal; | ||
const timer = hal.timer; | ||
const gclk = hal.gclk; | ||
|
||
const led_pin = microzig.board.D13; | ||
|
||
pub fn main() !void { | ||
// Initialize pins | ||
led_pin.set_dir(.out); | ||
|
||
gclk.enable_generator(.GCLK1, .DFLL, .{ | ||
.divsel = .DIV1, | ||
.div = 48, | ||
}); | ||
|
||
timer.init(); | ||
while (true) { | ||
led_pin.toggle(); | ||
timer.delay_us(1 * std.time.us_per_s); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
const board = microzig.board; | ||
|
||
// pins | ||
const Buttons = board.Buttons; | ||
const led_pin = board.D13; | ||
|
||
const Symbol = enum { | ||
dot, | ||
dash, | ||
|
||
fn blink(symbol: Symbol, pin: microzig.hal.port.Pin) void { | ||
pin.write(.high); | ||
delay_count(switch (symbol) { | ||
.dot => unit_period_count, | ||
.dash => 3 * unit_period_count, | ||
}); | ||
pin.write(.low); | ||
delay_count(unit_period_count); | ||
} | ||
}; | ||
|
||
const unit_period_count = 200000; | ||
|
||
const Mapping = struct { | ||
character: u8, | ||
symbols: []const Symbol, | ||
}; | ||
|
||
const alphabet = [_]Mapping{ | ||
.{ .character = 'a', .symbols = &.{ .dot, .dash } }, // A: .- | ||
.{ .character = 'b', .symbols = &.{ .dash, .dot, .dot, .dot } }, // B: -... | ||
.{ .character = 'c', .symbols = &.{ .dash, .dot, .dash, .dot } }, // C: -.-. | ||
.{ .character = 'd', .symbols = &.{ .dash, .dot, .dot } }, // D: -.. | ||
.{ .character = 'e', .symbols = &.{.dot} }, // E: . | ||
.{ .character = 'f', .symbols = &.{ .dot, .dot, .dash, .dot } }, // F: ..-. | ||
.{ .character = 'g', .symbols = &.{ .dash, .dash, .dot } }, // G: --. | ||
.{ .character = 'h', .symbols = &.{ .dot, .dot, .dot, .dot } }, // H: .... | ||
.{ .character = 'i', .symbols = &.{ .dot, .dot } }, // I: .. | ||
.{ .character = 'j', .symbols = &.{ .dot, .dash, .dash, .dash } }, // J: .--- | ||
.{ .character = 'k', .symbols = &.{ .dash, .dot, .dash } }, // K: -.- | ||
.{ .character = 'l', .symbols = &.{ .dot, .dash, .dot, .dot } }, // L: .-.. | ||
.{ .character = 'm', .symbols = &.{ .dash, .dash } }, // M: -- | ||
.{ .character = 'n', .symbols = &.{ .dash, .dot } }, // N: -. | ||
.{ .character = 'o', .symbols = &.{ .dash, .dash, .dash } }, // O: --- | ||
.{ .character = 'p', .symbols = &.{ .dot, .dash, .dash, .dot } }, // P: .--. | ||
.{ .character = 'q', .symbols = &.{ .dash, .dash, .dot, .dash } }, // Q: --.- | ||
.{ .character = 'r', .symbols = &.{ .dot, .dash, .dot } }, // R: .-. | ||
.{ .character = 's', .symbols = &.{ .dot, .dot, .dot } }, // S: ... | ||
.{ .character = 't', .symbols = &.{.dash} }, // T: - | ||
.{ .character = 'u', .symbols = &.{ .dot, .dot, .dash } }, // U: ..- | ||
.{ .character = 'v', .symbols = &.{ .dot, .dot, .dot, .dash } }, // V: ...- | ||
.{ .character = 'w', .symbols = &.{ .dot, .dash, .dash } }, // W: .-- | ||
.{ .character = 'x', .symbols = &.{ .dash, .dot, .dot, .dash } }, // X: -..- | ||
.{ .character = 'y', .symbols = &.{ .dash, .dot, .dash, .dash } }, // Y: -.-- | ||
.{ .character = 'z', .symbols = &.{ .dash, .dash, .dot, .dot } }, // Z: --.. | ||
}; | ||
|
||
fn get_symbols(character: u8) []const Symbol { | ||
return for (alphabet) |entry| { | ||
if (entry.character == character) | ||
break entry.symbols; | ||
} else unreachable; | ||
} | ||
|
||
pub fn main() !void { | ||
Buttons.configure(); | ||
// Use morse code to convey which button is currently pressed | ||
led_pin.set_dir(.out); | ||
|
||
while (true) { | ||
const message: []const u8 = blk: { | ||
const buttons = Buttons.read_from_port(); | ||
inline for (@typeInfo(Buttons).Struct.fields) |field| { | ||
if (@field(buttons, field.name) == 1) | ||
break :blk field.name; | ||
} | ||
|
||
continue; | ||
}; | ||
|
||
for (message) |character| { | ||
const symbols = get_symbols(character); | ||
for (symbols) |symbol| symbol.blink(led_pin); | ||
|
||
// there's supposed to be 3, but we already wait one period after every symbol | ||
delay_count(2 * unit_period_count); | ||
} | ||
|
||
delay_count(5 * unit_period_count); | ||
} | ||
} | ||
|
||
fn delay_count(count: u32) void { | ||
var i: u32 = 0; | ||
while (i < count) : (i += 1) {} | ||
} |
Oops, something went wrong.