Problem
The Getting Started guide shows example code that doesn't compile with the recommended MicroZig version (0.15.0).
Steps to Reproduce
- Follow the getting started guide exactly as written
- Install MicroZig 0.15.0 as instructed:
zig fetch --save https://github.com/ZigEmbeddedGroup/microzig/releases/download/0.15.0/microzig.tar.gz
- Use the example code from the docs:
const pin_config = rp2xxx.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);
}
}
- Run
zig build
Expected Behavior
The code should compile and work as documented.
Actual Behavior
Compilation fails with:
src/main.zig:17:13: error: type 'void' does not support field access
pins.led.toggle();
~~~~^~~~
Root Cause
In MicroZig 0.15.0, the GlobalConfiguration.apply() function returns void, not a struct with named pin fields. The function signature is:
pub fn apply(comptime config: GlobalConfiguration) void {
So const pins = pin_config.apply() results in pins having type void, which doesn't support field access.
Environment
- Zig version: 0.15.2
- MicroZig version: 0.15.0 (as recommended in docs)
- Target: Raspberry Pi Pico (RP2040)
Suggested Fix
Either:
- Update the documentation to show code that works with 0.15.0 (using
gpio.num() directly), or
- Release a new version of MicroZig where
apply() returns a struct with named pins, and update the docs to recommend that version
Workaround
For anyone hitting this issue, here's working code for MicroZig 0.15.0:
const std = @import("std");
const microzig = @import("microzig");
const rp2xxx = microzig.hal;
const time = rp2xxx.time;
const gpio = rp2xxx.gpio;
pub fn main() !void {
const led = gpio.num(25);
led.set_function(.sio);
led.set_direction(.out);
while (true) {
led.toggle();
time.sleep_ms(250);
}
}
Problem
The Getting Started guide shows example code that doesn't compile with the recommended MicroZig version (0.15.0).
Steps to Reproduce
zig buildExpected Behavior
The code should compile and work as documented.
Actual Behavior
Compilation fails with:
Root Cause
In MicroZig 0.15.0, the
GlobalConfiguration.apply()function returnsvoid, not a struct with named pin fields. The function signature is:So
const pins = pin_config.apply()results inpinshaving typevoid, which doesn't support field access.Environment
Suggested Fix
Either:
gpio.num()directly), orapply()returns a struct with named pins, and update the docs to recommend that versionWorkaround
For anyone hitting this issue, here's working code for MicroZig 0.15.0: