From 3b129e1ca5ce7317e29f50cb1beaf67ce6281122 Mon Sep 17 00:00:00 2001 From: Matt Knight Date: Tue, 28 Feb 2023 01:32:34 -0800 Subject: [PATCH] Update microzig (#26) * update microzig * update to new api --------- Co-authored-by: mattnite --- build.zig | 45 ++++++++++++++++++++++----------------------- deps/microzig | 2 +- examples/adc.zig | 4 +++- examples/uart.zig | 6 ++++-- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/build.zig b/build.zig index a0ed86c..5da87f7 100644 --- a/build.zig +++ b/build.zig @@ -2,11 +2,12 @@ const std = @import("std"); const Builder = std.build.Builder; const Pkg = std.build.Pkg; const comptimePrint = std.fmt.comptimePrint; +const FileSource = std.build.FileSource; pub const microzig = @import("deps/microzig/build.zig"); -const chips = @import("src/chips.zig"); -const boards = @import("src/boards.zig"); +pub const chips = @import("src/chips.zig"); +pub const boards = @import("src/boards.zig"); const linkerscript_path = root() ++ "rp2040.ld"; @@ -14,24 +15,23 @@ pub const BuildOptions = struct { optimize: std.builtin.OptimizeMode, }; +pub const PicoExecutableOptions = struct { + name: []const u8, + source_file: FileSource, + optimize: std.builtin.OptimizeMode = .Debug, +}; + pub fn addPiPicoExecutable( builder: *Builder, - name: []const u8, - source: []const u8, - options: BuildOptions, + opts: PicoExecutableOptions, ) *microzig.EmbeddedExecutable { - const ret = microzig.addEmbeddedExecutable( - builder, - name, - source, - .{ .board = boards.raspberry_pi_pico }, - .{ - .optimize = options.optimize, - }, - ); - ret.inner.setLinkerScriptPath(.{ .path = linkerscript_path }); - - return ret; + return microzig.addEmbeddedExecutable(builder, .{ + .name = opts.name, + .source_file = opts.source_file, + .backing = .{ .board = boards.raspberry_pi_pico }, + .optimize = opts.optimize, + .linkerscript_source_file = .{ .path = linkerscript_path }, + }); } // this build script is mostly for testing and verification of this @@ -61,12 +61,11 @@ pub const Examples = struct { inline for (@typeInfo(Examples).Struct.fields) |field| { const path = comptime root() ++ "examples/" ++ field.name ++ ".zig"; - @field(ret, field.name) = addPiPicoExecutable( - b, - field.name, - path, - .{ .optimize = optimize }, - ); + @field(ret, field.name) = addPiPicoExecutable(b, .{ + .name = field.name, + .source_file = .{ .path = path }, + .optimize = optimize, + }); } return ret; diff --git a/deps/microzig b/deps/microzig index 11214ed..b6fc3ab 160000 --- a/deps/microzig +++ b/deps/microzig @@ -1 +1 @@ -Subproject commit 11214ed8ba05e380a516beef3f3f594571a1c732 +Subproject commit b6fc3abbf7a91cb0cdafc7843ac7e6c26042ff84 diff --git a/examples/adc.zig b/examples/adc.zig index 9800e91..5d8f0c3 100644 --- a/examples/adc.zig +++ b/examples/adc.zig @@ -12,7 +12,9 @@ const baud_rate = 115200; const uart_tx_pin = 0; const uart_rx_pin = 1; -pub const log = rp2040.uart.log; +pub const std_options = struct { + pub const logFn = rp2040.uart.log; +}; pub fn init() void { rp2040.clock_config.apply(); diff --git a/examples/uart.zig b/examples/uart.zig index 6eb0864..57cf1c4 100644 --- a/examples/uart.zig +++ b/examples/uart.zig @@ -18,8 +18,10 @@ pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noretu while (true) {} } -pub const log_level = .debug; -pub const log = rp2040.uart.log; +pub const std_options = struct { + pub const log_level = .debug; + pub const logFn = rp2040.uart.log; +}; pub fn main() !void { gpio.reset();