From 193ce99c1888cc9c373aac1aa4f7c307d643bd1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20=22xq=22=20Quei=C3=9Fner?= Date: Tue, 19 Sep 2023 10:05:33 +0200 Subject: [PATCH] Bootstrap code --- .gitattributes | 1 + .github/workflows/build.yml | 26 ++++++++++++++++++++++++++ .gitignore | 3 +++ build.zig | 19 +++++++++++++++++++ build.zig.zon | 14 ++++++++++++++ ezpkg.sh | 5 +++++ shell.nix | 8 ++++++++ src/blinky.zig | 20 ++++++++++++++++++++ 8 files changed, 96 insertions(+) create mode 100644 .gitattributes create mode 100644 .github/workflows/build.yml create mode 100644 .gitignore create mode 100644 build.zig create mode 100644 build.zig.zon create mode 100755 ezpkg.sh create mode 100644 shell.nix create mode 100644 src/blinky.zig diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0cb064a --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.zig text=auto eol=lf diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..59cf509 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,26 @@ +name: Build +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: '0 0 * * *' + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-latest, linux-latest] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Zig + uses: goto-bus-stop/setup-zig@v2 + with: + version: 0.11.0 + + - name: Build examples + run: zig build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eacd52b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +zig-cache/ +dev-scripts/ +zig-out diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..cac966e --- /dev/null +++ b/build.zig @@ -0,0 +1,19 @@ +const std = @import("std"); +const microzig = @import("microzig"); +const rp2040 = @import("rp2040"); + +pub fn build(b: *std.Build) void { + const optimize = b.standardOptimizeOption(.{}); + + const firmware = microzig.addFirmware(b, .{ + .name = "blinky", + .target = rp2040.chips.rp2040, + .optimize = optimize, + .source_file = .{ .path = "src/blinky.zig" }, + }); + + microzig.installFirmware(firmware, .{ + + .format = .uf2, // .dfu, .bin, .hex, .elf, … + }); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..d661193 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,14 @@ +.{ + .name = "microzig-examples", + .version = "0.1.0", + .dependencies = .{ + .microzig = .{ + .url = "https://github.com/ZigEmbeddedGroup/microzig/archive/f0a6aa9ce1829df91f2d7f160bbc6f5bc41a3c80.tar.gz", + .hash = "12203f8cb7803a82dff1310ab0917055c0055bc7385f1321bbaf0de998b26a00b44d", + }, + .rp2040 = .{ + .url = "https://github.com/ZigEmbeddedGroup/raspberrypi-rp2040/archive/2a0c0ff2814a716a163822211c2686d84801a97a.tar.gz", + .hash = "12208735720ddf172a28943f1b17375f7b16370140be9c458f1482076025e465c3b0", + }, + }, +} diff --git a/ezpkg.sh b/ezpkg.sh new file mode 100755 index 0000000..b1f61da --- /dev/null +++ b/ezpkg.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +exec ezpkg \ + microzig=/home/felix/projects/zeg/microzig \ + rp2040=/home/felix/projects/zeg/device-support-package/rp2040 \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..3c88ea0 --- /dev/null +++ b/shell.nix @@ -0,0 +1,8 @@ +{pkgs ? import {}}: +pkgs.mkShell { + nativeBuildInputs = [ + pkgs.zig_0_11_0 + pkgs.picotool + ]; + buildInputs = []; +} diff --git a/src/blinky.zig b/src/blinky.zig new file mode 100644 index 0000000..5632fe3 --- /dev/null +++ b/src/blinky.zig @@ -0,0 +1,20 @@ +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); + } +}