66E7AVNYU4BJ3O2B2BW2JLPQQJSPBHWLTRWSG7RNRSL62WVCLR2AC const std = @import("std");const microzig = @import("microzig");const rp2xxx = microzig.hal;const time = rp2xxx.time;const pwm = rp2xxx.pwm;const LOW = 0;const HIGH = 100;const WRAP = 100;const SLEEP_MS = 100;// Compile-time pin configurationconst pin_config = rp2xxx.pins.GlobalConfiguration{.GPIO16 = .{ .function = .PWM0_A },.GPIO17 = .{ .function = .PWM0_B },.GPIO18 = .{ .function = .PWM1_A },.GPIO19 = .{ .function = .PWM1_B },.GPIO20 = .{ .function = .PWM2_A },.GPIO21 = .{ .function = .PWM2_B },.GPIO22 = .{ .function = .PWM3_A },.GPIO26 = .{ .function = .PWM5_A },.GPIO27 = .{ .function = .PWM5_B },.GPIO28 = .{ .function = .PWM6_A },};const pins = pin_config.pins();const duties = &[10 + 20]u10{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 512 + 256, 512, 256 + 128, 256, 128, 64, 32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };pub fn main() !void {pin_config.apply();inline for (std.meta.fields(@TypeOf(pins))) |field| {const slice = @field(pins, field.name).slice();slice.set_wrap(WRAP);slice.enable();}// This is the manual way// rp2xxx.gpio.num(28).set_function(.pwm);// const pwm6a = pwm.Pwm{// .slice_number = 6,// .channel = .a,// };// pwm6a.slice().set_wrap(WRAP);// pwm6a.slice().enable();// while (true) {// pwm6a.set_level(25);// time.sleep_ms(SLEEP_MS * 10);// pwm6a.set_level(100);// time.sleep_ms(SLEEP_MS * 10);// }while (true) {for (0..20) |i| {inline for (std.meta.fields(@TypeOf(pins)), 0..) |field, counter| {const val = map(isize, duties[i + counter], 0, 1024, LOW, HIGH);@field(pins, field.name).set_level(@intCast(val));}time.sleep_ms(SLEEP_MS);}for (0..20) |i| {inline for (&.{ "28", "27", "26", "22", "21", "20", "19", "18", "17", "16" }, 0..) |io, counter| {const val = map(isize, duties[i + counter], 0, 1024, LOW, HIGH);_ = @field(pins, "GPIO" ++ io).set_level(@intCast(val));}time.sleep_ms(SLEEP_MS);}}}fn map(comptime T: type, value: T, fromLow: T, fromHigh: T, toLow: T, toHigh: T) T {return @divTrunc((value - fromLow) * (toHigh - toLow), (fromHigh - fromLow)) + toLow;}
const std = @import("std");const microzig = @import("microzig");const rp2xxx = microzig.hal;const time = rp2xxx.time;const LOW = 0;const HIGH = 100;const WRAP = 100;const SLEEP_MS = 10;// Compile-time pin configurationconst pin_config = rp2xxx.pins.GlobalConfiguration{.GPIO17 = .{.name = "led",.function = .PWM0_B,},};const pins = pin_config.pins();pub fn main() !void {pin_config.apply();pins.led.slice().set_wrap(WRAP);pins.led.slice().enable();// duty cycle = level/wrap * 100var invert: bool = true;while (true) {for (LOW..HIGH) |i| {pins.led.set_level(@truncate(i));time.sleep_ms(SLEEP_MS);}pins.led.set_inverted(invert);invert = !invert;}}
const std = @import("std");const microzig = @import("microzig");const rp2xxx = microzig.hal;const time = rp2xxx.time;const LOW = 0;const HIGH = 1;const BOUNCE_DELAY = 20;// Compile-time pin configurationconst pin_config = rp2xxx.pins.GlobalConfiguration{.GPIO15 = .{.name = "red_led",.direction = .out,},.GPIO16 = .{.name = "blue_led",.direction = .out,},.GPIO17 = .{.name = "green_led",.direction = .out,},.GPIO13 = .{.name = "button",.direction = .in,},};var ledState: bool = false;const pins = pin_config.pins();pub fn main() !void {pin_config.apply();while (true) {if (pins.button.read() == HIGH) {// button pressed, let's wait a bittime.sleep_ms(BOUNCE_DELAY);if (pins.button.read() == LOW) {// still pressed, so toggle itpins.red_led.toggle();}// wait until the button releasewhile (pins.button.read() == LOW) {// just to avoid optimizationpins.green_led.put(HIGH);}pins.green_led.put(LOW);}}// while (true) {// if (pins.button.read() == LOW) {// time.sleep_ms(BOUNCE_DELAY);// if (pins.button.read() == LOW) {// reverseGPIO();// }// while (pins.button.read() == LOW) {// // zig optimizez away the loop in ReleaseSmall// // if nothing happens here :-(// // pins.green_led.put(HIGH);// }// // pins.green_led.put(LOW);// }// if (ledState) {// pins.red_led.put(HIGH);// pins.blue_led.put(LOW);// } else {// pins.red_led.put(LOW);// pins.blue_led.put(HIGH);// }// }}fn reverseGPIO() void {ledState = !ledState;// pins.led.put(@intFromBool(ledState));}
const pr41 = mb.add_firmware(.{.name = "pr41",.target = mb.ports.rp2xxx.boards.raspberrypi.pico,.optimize = .ReleaseSmall,.root_source_file = b.path("src/pr41.zig"),});mb.install_firmware(pr41, .{});const pr42 = mb.add_firmware(.{.name = "pr42",.target = mb.ports.rp2xxx.boards.raspberrypi.pico,.optimize = .ReleaseSmall,.root_source_file = b.path("src/pr42.zig"),});mb.install_firmware(pr42, .{});