Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed Apr 27, 2024
1 parent 4c45680 commit c4b9cc4
Show file tree
Hide file tree
Showing 16 changed files with 22,003 additions and 322 deletions.
67 changes: 57 additions & 10 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub const sycl_badge_2024 = MicroZig.Target{
.name = "SYCL Badge 2024",
.root_source_file = .{ .cwd_relative = "src/board.zig" },
},
.linker_script = .{ .cwd_relative = "src/badge/samd51j19a_self.ld" },
};

pub fn build(b: *Build) void {
Expand Down Expand Up @@ -51,6 +52,36 @@ pub fn build(b: *Build) void {

const watch_step = b.step("watch", "");
watch_step.dependOn(&zeroman_cart.watch_run_cmd.step);
//var dep: std.Build.Dependency = .{ .builder = b };
//const cart = add_cart(&dep, b, .{
// .name = "sample",
// .optimize = optimize,
// .root_source_file = .{ .path = "samples/feature_test.zig" },
//});

//const watch_step = b.step("watch", "");
//watch_step.dependOn(&cart.watch_run_cmd.step);

//const modified_memory_regions = b.allocator.dupe(MicroZig.MemoryRegion, py_badge.chip.memory_regions) catch @panic("out of memory");
//for (modified_memory_regions) |*memory_region| {
// if (memory_region.kind != .ram) continue;
// memory_region.offset += 0x19A0;
// memory_region.length -= 0x19A0;
// break;
//}
//var modified_py_badge = py_badge;
//modified_py_badge.chip.memory_regions = modified_memory_regions;

//const fw = mz.add_firmware(b, .{
// .name = "pybadge-io",
// .target = modified_py_badge,
// .optimize = optimize,
// .source_file = .{ .path = "src/main.zig" },
//});
//fw.artifact.step.dependOn(&fw_options.step);
//fw.modules.app.addImport("options", fw_options.createModule());x
//mz.install_firmware(b, fw, .{});
//mz.install_firmware(b, fw, .{ .format = .{ .uf2 = .SAMD51 } });

const badge = mz.add_firmware(b, .{
.name = "badge",
Expand All @@ -66,19 +97,24 @@ pub fn build(b: *Build) void {
"usb_cdc",
"usb_storage",
"buttons",
"lcd",
//"lcd",
"audio",
"light_sensor",
"neopixels",
"qspi",
"qa",
}) |name| {
const mvp = mz.add_firmware(b, .{
.name = std.fmt.comptimePrint("badge.demo.{s}", .{name}),
.target = sycl_badge_2024,
.optimize = optimize,
.root_source_file = .{ .path = std.fmt.comptimePrint("src/badge/demos/{s}.zig", .{name}) },
});
mvp.artifact.image_base = 0x4000;
mz.install_firmware(b, mvp, .{});
mz.install_firmware(b, mvp, .{
.format = .{ .uf2 = .SAMD51 },
});
}

const font_export_step = b.step("generate-font.ts", "convert src/font.zig to simulator/src/font.ts");
Expand Down Expand Up @@ -157,15 +193,26 @@ pub fn add_cart(

const watch_run_cmd = b.addRunArtifact(watch);
watch_run_cmd.step.dependOn(b.getInstallStep());

watch_run_cmd.addArgs(&.{
"serve",
b.graph.zig_exe,
"--zig-out-bin-dir",
b.pathJoin(&.{ b.install_path, "bin" }),
"--input-dir",
options.root_source_file.dirname().getPath(b),
});
//const watch = d.builder.addExecutable(.{
// .name = "watch",
// .root_source_file = .{ .path = "src/watch/main.zig" },
// .target = b.resolveTargetQuery(.{}),
// .optimize = options.optimize,
//});
//watch.root_module.addImport("ws", d.builder.dependency("ws", .{}).module("websocket"));
//watch.root_module.addImport("mime", d.builder.dependency("mime", .{}).module("mime"));

//const watch_run_cmd = b.addRunArtifact(watch);
//watch_run_cmd.step.dependOn(b.getInstallStep());

//watch_run_cmd.addArgs(&.{
// "serve",
// b.graph.zig_exe,
// "--zig-out-bin-dir",
// b.pathJoin(&.{ b.install_path, "bin" }),
// "--input-dir",
// options.root_source_file.dirname().getPath(b),
//});

const cart: *Cart = b.allocator.create(Cart) catch @panic("out of memory");
cart.* = .{
Expand Down
83 changes: 83 additions & 0 deletions build/image_to_splash.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const std = @import("std");
const img = @import("img");

const Arguments = struct {
output_path: ?[]const u8 = null,
};

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();

var arena = std.heap.ArenaAllocator.init(gpa.allocator());
defer arena.deinit();

const allocator = arena.allocator();
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);

var input_file_arg: ?[]const u8 = null;
var output_file_arg: ?[]const u8 = null;

{
var i: u32 = 1;
while (i < args.len) : (i += 1) {
if (std.mem.eql(u8, args[i], "-o")) {
if (i + 1 >= args.len)
return error.MissingOutputFileArg;

output_file_arg = args[i + 1];
i += 1;
} else {
input_file_arg = args[i];
}
}
}

const input_file_path = input_file_arg orelse unreachable;
const output_file_path = output_file_arg orelse unreachable;

var image = try img.Image.fromFilePath(allocator, input_file_path);
defer image.deinit();

if (image.width != 160 or image.height != 128) {
std.log.err("Image must be 160x128 but it is {}x{}!!!", .{ image.width, image.height });
}

const output_file = try std.fs.cwd().createFile(output_file_path, .{});
defer output_file.close();

const writer = output_file.writer();
try writer.print(
\\const microzig = @import("microzig");
\\const board = microzig.board;
\\const lcd = board.lcd;
\\
\\pub const data = [{}]lcd.Color16 {{
\\
, .{image.height * image.width});
switch (image.pixelFormat()) {
.rgba32 => {
for (image.pixels.rgba32) |pixel| {
const lcd_pixel = img.color.Rgb565.fromU32Rgba(pixel.toU32Rgba());
try writer.print(
\\ .{{ .b = {}, .g = {}, .r = {} }},
\\
, .{
lcd_pixel.b,
lcd_pixel.g,
lcd_pixel.r,
});
}
},
else => {
std.log.err("TODO: {}", .{image.pixelFormat()});
return error.TodoPixelFormat;
},
}

try writer.writeAll(
\\};
\\
);
}
22 changes: 22 additions & 0 deletions build/utils.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const std = @import("std");
const Build = std.Build;
const LazyPath = Build.LazyPath;

const img = @import("img");

pub fn add_static_screen(b: *Build, image_file: []const u8) *Build.Step.Options {
return add_static_screen_impl(b, image_file) catch unreachable;
}

pub fn add_static_screen_impl(b: *Build, image_file: []const u8) !*Build.Step.Options {
const options = b.addOptions();

const image = img.Image.fromFilePath(b.allocator, image_file);
defer image.deinit();

//const data = &.{};

//options.addOptionPath("data", data);

return options;
}
Loading

0 comments on commit c4b9cc4

Please sign in to comment.