Skip to content

Getting Started documentation doesn't work with MicroZig 0.15.0 #860

@Jdad5150

Description

@Jdad5150

Problem

The Getting Started guide shows example code that doesn't compile with the recommended MicroZig version (0.15.0).

Steps to Reproduce

  1. Follow the getting started guide exactly as written
  2. Install MicroZig 0.15.0 as instructed:
    zig fetch --save https://github.com/ZigEmbeddedGroup/microzig/releases/download/0.15.0/microzig.tar.gz
    
  3. 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);
        }
    }
  4. 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:

  1. Update the documentation to show code that works with 0.15.0 (using gpio.num() directly), or
  2. 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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions