Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

All the examples #4

Merged
merged 13 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
dir:
- all-platforms
- raspberrypi-rp2040
- espressif-esp
- nxp-lpc
- microchip-atmega
- gigadevice-gd32
- nordic-nrf5x
- stmicro-stm32
os:
- windows-latest
- macos-latest
- ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -21,4 +34,5 @@ jobs:
version: 0.11.0

- name: Build examples
working-directory: ${{ matrix.dir }}
run: zig build
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
zig-cache/
dev-scripts/
zig-out
zig-out/

ezpkg.sh

.vscode

.envrc
shell.nix
84 changes: 84 additions & 0 deletions all-platforms/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const std = @import("std");
const rp2040 = @import("rp2040");
const stm32 = @import("stm32");
const lpc = @import("lpc");
const gd32 = @import("gd32");
const nrf5x = @import("nrf5x");
const esp = @import("esp");
const atmega = @import("atmega");

const available_targets = [_]TargetDesc{
// RP2040
.{ .name = "pico", .target = rp2040.boards.raspberry_pi.pico },
.{ .name = "rp2040-eth", .target = rp2040.boards.waveshare.rp2040_eth },
.{ .name = "rp2040-plus-4m", .target = rp2040.boards.waveshare.rp2040_plus_4m },
.{ .name = "rp2040-plus-16m", .target = rp2040.boards.waveshare.rp2040_plus_16m },
.{ .name = "rp2040-matrix", .target = rp2040.boards.waveshare.rp2040_matrix },

// STM32
.{ .name = "stm32f103x8", .target = stm32.chips.stm32f103x8 },
.{ .name = "stm32f303vc", .target = stm32.chips.stm32f303vc },
.{ .name = "stm32f407vg", .target = stm32.chips.stm32f407vg },
.{ .name = "stm32f429zit6u", .target = stm32.chips.stm32f429zit6u },
.{ .name = "stm32f3discovery", .target = stm32.boards.stm32f3discovery },
.{ .name = "stm32f4discovery", .target = stm32.boards.stm32f4discovery },
.{ .name = "stm3240geval", .target = stm32.boards.stm3240geval },
.{ .name = "stm32f429idiscovery", .target = stm32.boards.stm32f429idiscovery },

// NXP LPC
.{ .name = "lpc176x5x", .target = lpc.chips.lpc176x5x },
.{ .name = "mbed-lpc1768", .target = lpc.boards.mbed.lpc1768 },

// GigaDevice GD32
.{ .name = "gd32vf103xb", .target = gd32.chips.gd32vf103xb },
.{ .name = "gd32vf103x8", .target = gd32.chips.gd32vf103x8 },
.{ .name = "sipeed-longan_nano", .target = gd32.boards.sipeed.longan_nano },

// Nordic Nrf5x
.{ .name = "nrf52832", .target = nrf5x.chips.nrf52832 },
.{ .name = "nrf52840", .target = nrf5x.chips.nrf52840 },
.{ .name = "nrf52840-dongle", .target = nrf5x.boards.nordic.nRF52840_Dongle }, // TODO: Add support for DFU files!

// RISC-V Espressif ESP
.{ .name = "esp32-c3", .target = esp.chips.esp32_c3 }, // TODO: Add support for Espressif Update Binaries

// Microchip ATmega
// TODO: Fix compiler bugs
// - https://github.com/ziglang/zig/issues/17219
// .{ .name = "atmega328p", .target = atmega.chips.atmega328p },
// .{ .name = "arduino-nano", .target = atmega.boards.arduino.nano },
// .{ .name = "arduino-uno-rev3", .target = atmega.boards.arduino.uno_rev3 },
};

pub fn build(b: *std.Build) void {
const microzig = @import("microzig").init(b, "microzig");
const optimize = b.standardOptimizeOption(.{});

for (available_targets) |dest| {
// `addFirmware` basically works like addExecutable, but takes a
// `microzig.Target` for target instead of a `std.zig.CrossTarget`.
//
// The target will convey all necessary information on the chip,
// cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{
.name = b.fmt("empty-{s}", .{dest.name}),
.target = dest.target,
.optimize = optimize,
.source_file = .{ .path = "src/empty.zig" },
});

// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
// and allows installing the firmware as a typical firmware file.
//
// This will also install into `$prefix/firmware` instead of `$prefix/bin`.
microzig.installFirmware(b, firmware, .{});

// For debugging, we also always install the firmware as an ELF file
microzig.installFirmware(b, firmware, .{ .format = .elf });
}
}

const TargetDesc = struct {
target: @import("microzig").Target,
name: []const u8,
};
2 changes: 1 addition & 1 deletion build.zig.zon → all-platforms/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig-examples",
.name = "microzig-all-platforms-examples",
.version = "0.1.0",
.dependencies = .{
.microzig = .{
Expand Down
File renamed without changes.
File renamed without changes.
84 changes: 0 additions & 84 deletions build.zig

This file was deleted.

4 changes: 4 additions & 0 deletions espressif-esp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Examples for the BSP `espressif-esp`

- [Blinky](src/blinky.zig) on [ESP32-C3-32S-Kit](https://www.waveshare.com/wiki/ESP-C3-32S-Kit)
Showcases how to do a simple RGB cycling.
45 changes: 45 additions & 0 deletions espressif-esp/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const std = @import("std");
const esp = @import("esp");

const available_targets = [_]TargetDesc{
.{ .name = "esp32-c3", .target = esp.chips.esp32_c3 },
};

const available_examples = [_][]const u8{
"src/blinky.zig",
};

pub fn build(b: *std.Build) void {
const microzig = @import("microzig").init(b, "microzig");
const optimize = b.standardOptimizeOption(.{});

for (available_targets) |target| {
for (available_examples) |example| {
// `addFirmware` basically works like addExecutable, but takes a
// `microzig.Target` for target instead of a `std.zig.CrossTarget`.
//
// The target will convey all necessary information on the chip,
// cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{
.name = b.fmt("{s}-{s}", .{ std.fs.path.stem(example), target.name }),
.target = target.target,
.optimize = optimize,
.source_file = .{ .path = example },
});

// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
// and allows installing the firmware as a typical firmware file.
//
// This will also install into `$prefix/firmware` instead of `$prefix/bin`.
microzig.installFirmware(b, firmware, .{});

// For debugging, we also always install the firmware as an ELF file
microzig.installFirmware(b, firmware, .{ .format = .elf });
}
}
}

const TargetDesc = struct {
target: @import("microzig").Target,
name: []const u8,
};
14 changes: 14 additions & 0 deletions espressif-esp/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.{
.name = "microzig-espressif-esp-examples",
.version = "0.1.0",
.dependencies = .{
.microzig = .{
.url = "https://github.com/ZigEmbeddedGroup/microzig/archive/c6c9ec4516f57638e751141085c9d76120990312.tar.gz",
.hash = "1220af58bdaa721b8189f3a7adfda660517dd354463463388e96d69fe4ceccf80b92",
},
.esp = .{
.url = "https://github.com/ZigEmbeddedGroup/espressif-esp/archive/59b8ca028915c0d6224ec88dbf4db19afbb559c0.tar.gz",
.hash = "1220f6e5f22416fdc63442cd8869fcaa35f9abf30d878ea3d80073176677dc6f8a65",
},
},
}
90 changes: 90 additions & 0 deletions espressif-esp/src/blinky.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const std = @import("std");
const microzig = @import("microzig");
const peripherals = microzig.chip.peripherals;
const TIMG0 = peripherals.TIMG0;
const RTC_CNTL = peripherals.RTC_CNTL;
const INTERRUPT_CORE0 = peripherals.INTERRUPT_CORE0;
const GPIO = peripherals.GPIO;
const IO_MUX = peripherals.IO_MUX;

const dogfood: u32 = 0x50D83AA1;
const super_dogfood: u32 = 0x8F1D312A;

const LED_R_PIN = 3; // GPIO
const LED_G_PIN = 4; // GPIO
const LED_B_PIN = 5; // GPIO

const led_pins = [_]u32{
LED_R_PIN,
LED_G_PIN,
LED_B_PIN,
};

pub fn main() !void {
// Feed and disable watchdog 0
TIMG0.WDTWPROTECT.raw = dogfood;
TIMG0.WDTCONFIG0.raw = 0;
TIMG0.WDTWPROTECT.raw = 0;

// Feed and disable rtc watchdog
RTC_CNTL.WDTWPROTECT.raw = dogfood;
RTC_CNTL.WDTCONFIG0.raw = 0;
RTC_CNTL.WDTWPROTECT.raw = 0;

// Feed and disable rtc super watchdog
RTC_CNTL.SWD_WPROTECT.raw = super_dogfood;
RTC_CNTL.SWD_CONF.modify(.{ .SWD_DISABLE = 1 });
RTC_CNTL.SWD_WPROTECT.raw = 0;

// Disable all interrupts
INTERRUPT_CORE0.CPU_INT_ENABLE.raw = 0;

GPIO.ENABLE.modify(.{
.DATA = (1 << LED_R_PIN) |
(1 << LED_G_PIN) |
(1 << LED_B_PIN),
});

for (led_pins) |pin| {
IO_MUX.GPIO[pin].modify(.{
.MCU_OE = 1, // 1: output enabled
.SLP_SEL = 0, // Set to 1 to put the pin in sleep mode. (R/W)
.MCU_WPD = 0, // 0: internal pull-down disabled. (R/W)
.MCU_WPU = 0, // 0: internal pull-up disabled. (R/W)
.MCU_IE = 0, // 0: input disabled. (R/W)
.FUN_WPD = 0, // 0: internal pull-down disabled. (R/W)
.FUN_WPU = 0, // 0: internal pull-up disabled. (R/W)
.FUN_IE = 0, // 0: input disabled. (R/W)
.FUN_DRV = 3, // Select the drive strength of the pin. 0: ~5 mA; 1: ~ 10 mA; 2: ~ 20 mA; 3: ~40mA. (R/W)
.MCU_SEL = 1, // 1: GPIO
.FILTER_EN = 0, // 0: Filter disabled. (R/W)
});

GPIO.FUNC_OUT_SEL_CFG[pin].write(.{
// If a value 128 is written to this field, bit n of GPIO_OUT_REG and GPIO_ENABLE_REG will be selected as the output value and output enable. (R/W)
.OUT_SEL = 0x80,

.INV_SEL = 0x00, // 0: Do not invert the output value
.OEN_SEL = 0x01, // 1: Force the output enable signal to be sourced from bit n of GPIO_ENABLE_REG. (R/W)
.OEN_INV_SEL = 0x00, // 0: Do not invert the output enable signal

.padding = 0,
});
}

microzig.hal.uart.write(0, "Hello from Zig!\r\n");

while (true) {
GPIO.OUT.modify(.{ .DATA_ORIG = (1 << LED_R_PIN) });
microzig.hal.uart.write(0, "R");
microzig.core.experimental.debug.busy_sleep(100_000);

GPIO.OUT.modify(.{ .DATA_ORIG = (1 << LED_G_PIN) });
microzig.hal.uart.write(0, "G");
microzig.core.experimental.debug.busy_sleep(100_000);

GPIO.OUT.modify(.{ .DATA_ORIG = (1 << LED_B_PIN) });
microzig.hal.uart.write(0, "B");
microzig.core.experimental.debug.busy_sleep(100_000);
}
}
13 changes: 0 additions & 13 deletions ezpkg.sh

This file was deleted.

Loading
Loading