Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add arduino uno board #89

Merged
merged 4 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn build(b: *std.build.Builder) !void {
const BuildConfig = struct { name: []const u8, backing: Backing, supports_uart_test: bool = true };
const all_backings = [_]BuildConfig{
BuildConfig{ .name = "boards.arduino_nano", .backing = Backing{ .board = boards.arduino_nano } },
BuildConfig{ .name = "boards.arduino_uno", .backing = Backing{ .board = boards.arduino_uno } },
BuildConfig{ .name = "boards.mbed_lpc1768", .backing = Backing{ .board = boards.mbed_lpc1768 } },
BuildConfig{ .name = "chips.atmega328p", .backing = Backing{ .chip = chips.atmega328p } },
BuildConfig{ .name = "chips.lpc1768", .backing = Backing{ .chip = chips.lpc1768 } },
Expand Down
6 changes: 6 additions & 0 deletions src/modules/boards.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub const arduino_nano = Board{
.chip = chips.atmega328p,
};

pub const arduino_uno = Board{
.name = "Arduino Uno",
.path = root_path ++ "boards/arduino-uno/arduino-uno.zig",
.chip = chips.atmega328p,
};

pub const mbed_lpc1768 = Board{
.name = "mbed LPC1768",
.path = root_path ++ "boards/mbed-lpc1768/mbed-lpc1768.zig",
Expand Down
32 changes: 32 additions & 0 deletions src/modules/boards/arduino-uno/arduino-uno.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pub const chip = @import("chip");

pub const clock_frequencies = .{
.cpu = 16_000_000,
};

pub const pin_map = .{
// Port D
.D0 = "PD0",
.D1 = "PD1",
.D2 = "PD2",
.D3 = "PD3",
.D4 = "PD4",
.D5 = "PD5",
.D6 = "PD6",
.D7 = "PD7",
// Port B
.D8 = "PB0",
.D9 = "PB1",
.D10 = "PB2",
.D11 = "PB3",
.D12 = "PB4",
// LED_BUILTIN
.D13 = "PB5",
// Port C (Analog)
.A0 = "PC0",
.A1 = "PC1",
.A2 = "PC2",
.A3 = "PC3",
.A4 = "PC4",
.A5 = "PC5",
};
2 changes: 1 addition & 1 deletion src/modules/chips/atmega328p/atmega328p.zig
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn Uart(comptime index: usize, comptime pins: micro.uart.Pins) type {
const pclk = micro.clock.get().cpu;
const divider = ((pclk + (8 * baud_rate)) / (16 * baud_rate)) - 1;

return std.math.cast(u12, divider) catch return error.UnsupportedBaudRate;
return std.math.cast(u12, divider) orelse return error.UnsupportedBaudRate;
}

fn computeBaudRate(divider: u12) u32 {
Expand Down
1 change: 1 addition & 0 deletions tests/blinky.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const micro = @import("microzig");
const led_pin = if (micro.config.has_board)
switch (micro.config.board_name) {
.@"Arduino Nano" => micro.Pin("D13"),
.@"Arduino Uno" => micro.Pin("D13"),
.@"mbed LPC1768" => micro.Pin("LED-1"),
.@"STM32F3DISCOVERY" => micro.Pin("LD3"),
.@"STM32F4DISCOVERY" => micro.Pin("LD5"),
Expand Down
5 changes: 5 additions & 0 deletions tests/uart-sync.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const cfg = if (micro.config.has_board)
.uart_idx = 1,
.pins = .{ .tx = null, .rx = null },
},
.@"Arduino Uno" => .{
.led_pin = micro.Pin("D13"),
.uart_idx = 0,
.pins = .{},
},
else => @compileError("unknown board"),
}
else switch (micro.config.chip_name) {
Expand Down