Cross platform WhooHoo! (and license)

This commit is contained in:
Matthias Portzel 2024-02-17 10:33:48 -05:00
parent 07d668378e
commit 3dc231ad49
5 changed files with 53 additions and 23 deletions

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
VIRAL ROBOT LICENSE VERSION 1
(VRLv1)
This is not free or open source software. Neither the OSI or the FSF have or ever will endorse this license.
If you have received a copy of this source repository:
* You may learn from this code, and may apply the knowledge you gain from it without restriction.
* You may modify the code and run it on your personal computer without restriction.
* If you create a project deriving from this code, and reach the point that you are flashing or uploading to an external processor, you must make the whole source code of your project available under the terms of the Viral Robot License to anyone who is interested.

4
README
View File

@ -1,3 +1,5 @@
# Building
Build with `zig build`.
This creates `zig-out/firmware/pico_blinky.uf2` which can be uploaded to an RP2040.
This creates two main files:
* `zig-out/firmware/micromouse.uf2` which can be uploaded to an RP2040.
* `zig-out/bin/micromouse` which can be run on the host computer in simulation

View File

@ -11,10 +11,18 @@ pub fn build(b: *std.Build) void {
// The target will convey all necessary information on the chip,
// cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{
.name = "pico_blinky",
.name = "micromouse",
.target = rp2040.boards.raspberry_pi.pico,
.optimize = optimize,
.source_file = .{ .path = "src/blinky.zig" },
.source_file = .{ .path = "src/main.zig" },
});
// We also build a native executable for simulator testing
const exe = b.addExecutable(.{
.name = "micromouse",
.root_source_file = .{ .path = "src/main.zig" },
// Will be .target = b.host in 0.12
.target = b.standardTargetOptions(.{})
});
// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
@ -25,4 +33,7 @@ pub fn build(b: *std.Build) void {
// For debugging, we also always install the firmware as an ELF file
microzig.installFirmware(b, firmware, .{ .format = .elf });
// Install the native executable into zig-out/bin/
b.installArtifact(exe);
}

View File

@ -1,20 +0,0 @@
const std = @import("std");
const microzig = @import("microzig");
const rp2040 = microzig.hal;
const time = rp2040.time;
const pin_config = rp2040.pins.GlobalConfiguration{
.GPIO25 = .{
.name = "led",
.direction = .out,
},
};
pub fn main() !void {
const pins = pin_config.apply();
while (true) {
pins.led.toggle();
time.sleep_ms(250);
}
}

28
src/main.zig Normal file
View File

@ -0,0 +1,28 @@
const std = @import("std");
const builtin = @import("builtin");
const is_mouse = builtin.os.tag == .freestanding;
const microzig = @import("microzig");
const rp2040 = microzig.hal;
const time = rp2040.time;
const pin_config = rp2040.pins.GlobalConfiguration{
.GPIO25 = .{
.name = "led",
.direction = .out,
},
};
pub fn main() !void {
if (is_mouse) {
const pins = pin_config.apply();
while (true) {
pins.led.toggle();
time.sleep_ms(250);
}
}else {
std.debug.print("Hello", .{});
}
}