-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
50 lines (38 loc) · 1.58 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const std = @import("std");
const microzig = @import("microzig/src/main.zig");
pub fn build(b: *std.build.Builder) !void {
const backing = .{
.board = microzig.boards.arduino_uno,
// if you don't have one of the boards, but do have one of the
// "supported" chips:
// .chip = microzig.chips.atmega328p,
};
var exe = microzig.addEmbeddedExecutable(
b,
"arduzig",
"src/main.zig",
backing,
.{
.optimize = .ReleaseSmall,
},
);
exe.install();
const port = b.option([]const u8, "port", "Port Arduino is connected to (default: /dev/ttyACM0)") orelse "/dev/ttyACM0";
const bin_path = b.getInstallPath(exe.inner.install_step.?.dest_dir, exe.inner.out_filename);
const flash = try std.fmt.allocPrint(b.allocator, "flash:w:{s}:e", .{bin_path});
defer b.allocator.free(flash);
// Assume avrdude installed
const upload_command = b.addSystemCommand(&.{ "avrdude", "-c", "arduino", "-P", port, "-b", "115200", "-p", "atmega328p", "-U", flash });
upload_command.step.dependOn(b.getInstallStep());
const upload_step = b.step("upload", "Upload binary to Arduino");
upload_step.dependOn(&upload_command.step);
const monitor = b.step("serial", "Serial output monitor");
const baud = b.option([]const u8, "baud", "Baud rate for the serial monitor") orelse "115200";
const screen = b.addSystemCommand(&.{
"screen",
port,
baud,
});
// You don't have to upload in order to attach the serial monitor
monitor.dependOn(&screen.step);
}