diff --git a/examples/raspberrypi/rp2xxx/build.zig b/examples/raspberrypi/rp2xxx/build.zig index 2453bbe9..4558a732 100644 --- a/examples/raspberrypi/rp2xxx/build.zig +++ b/examples/raspberrypi/rp2xxx/build.zig @@ -13,15 +13,10 @@ pub fn build(b: *std.Build) void { const rp2040_only_examples: []const Example = &.{ // RaspberryPi Boards: - .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_adc", .file = "src/rp2040_only/adc.zig" }, .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_flash-program", .file = "src/rp2040_only/flash_program.zig" }, .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_flash-id", .file = "src/rp2040_only/flash_id.zig" }, - .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_i2c-bus-scan", .file = "src/rp2040_only/i2c_bus_scan.zig" }, - .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_pwm", .file = "src/rp2040_only/pwm.zig" }, .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_random", .file = "src/rp2040_only/random.zig" }, .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_rtc", .file = "src/rp2040_only/rtc.zig" }, - .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_uart-echo", .file = "src/rp2040_only/uart_echo.zig" }, - .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_uart-log", .file = "src/rp2040_only/uart_log.zig" }, .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_usb-hid", .file = "src/rp2040_only/usb_hid.zig" }, .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_multicore", .file = "src/rp2040_only/blinky_core1.zig" }, .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_hd44780", .file = "src/rp2040_only/hd44780.zig" }, @@ -39,6 +34,11 @@ pub fn build(b: *std.Build) void { }; const chip_agnostic_examples: []const ChipAgnosticExample = &.{ + .{ .name = "adc", .file = "src/adc.zig" }, + .{ .name = "i2c-bus-scan", .file = "src/i2c_bus_scan.zig" }, + .{ .name = "pwm", .file = "src/pwm.zig" }, + .{ .name = "uart-echo", .file = "src/uart_echo.zig" }, + .{ .name = "uart-log", .file = "src/uart_log.zig" }, .{ .name = "spi-master", .file = "src/spi_master.zig" }, .{ .name = "spi-slave", .file = "src/spi_slave.zig" }, .{ .name = "squarewave", .file = "src/squarewave.zig" }, diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/adc.zig b/examples/raspberrypi/rp2xxx/src/adc.zig similarity index 73% rename from examples/raspberrypi/rp2xxx/src/rp2040_only/adc.zig rename to examples/raspberrypi/rp2xxx/src/adc.zig index 728ef66a..9e122c35 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/adc.zig +++ b/examples/raspberrypi/rp2xxx/src/adc.zig @@ -6,12 +6,10 @@ const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; const adc = rp2xxx.adc; const time = rp2xxx.time; -const chip = rp2xxx.compatibility.chip; const uart = rp2xxx.uart.instance.num(0); const baud_rate = 115200; const uart_tx_pin = gpio.num(0); -const uart_rx_pin = gpio.num(1); pub const microzig_options = .{ .logFn = rp2xxx.uart.logFn, @@ -22,14 +20,7 @@ pub fn main() void { .temp_sensor_enabled = true, }); - switch (chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_second); - }, - } + uart_tx_pin.set_function(.uart); uart.apply(.{ .baud_rate = baud_rate, diff --git a/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig b/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig index dcb79a41..9b5b7613 100644 --- a/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig +++ b/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig @@ -4,8 +4,6 @@ const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; const time = rp2xxx.time; const clocks = rp2xxx.clocks; -const GlobalConfig = clocks.config.Global; -const Pin = rp2xxx.gpio.Pin; /// The HAL provides a convenvience function for detecting which of the RP2XXX /// family you're currently compiling for. diff --git a/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig b/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig index 4af2e09b..b9e21168 100644 --- a/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig +++ b/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig @@ -4,7 +4,6 @@ const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; const time = rp2xxx.time; const clocks = rp2xxx.clocks; -const GlobalConfig = clocks.config.Global; const Pin = rp2xxx.gpio.Pin; const gpout0_pin = gpio.num(21); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_bus_scan.zig b/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig similarity index 83% rename from examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_bus_scan.zig rename to examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig index d95793a5..7f8d4dee 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_bus_scan.zig +++ b/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig @@ -21,13 +21,8 @@ const uart_rx_pin = gpio.num(1); const i2c0 = i2c.instance.num(0); pub fn main() !void { - switch (chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_second); - }, + inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { + pin.set_function(.uart); } uart.apply(.{ diff --git a/examples/raspberrypi/rp2xxx/src/interrupts.zig b/examples/raspberrypi/rp2xxx/src/interrupts.zig index f445d804..9cc35622 100644 --- a/examples/raspberrypi/rp2xxx/src/interrupts.zig +++ b/examples/raspberrypi/rp2xxx/src/interrupts.zig @@ -7,7 +7,6 @@ const led = rp2xxx.gpio.num(25); const uart = rp2xxx.uart.instance.num(0); const baud_rate = 115200; const uart_tx_pin = rp2xxx.gpio.num(0); -const uart_rx_pin = rp2xxx.gpio.num(1); pub const microzig_options = .{ .log_level = .debug, @@ -48,14 +47,7 @@ pub fn set_alarm(us: u32) void { pub fn main() !void { // init uart logging - switch (rp2xxx.compatibility.chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_first); - }, - } + uart_tx_pin.set_function(.uart); uart.apply(.{ .baud_rate = baud_rate, diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/pwm.zig b/examples/raspberrypi/rp2xxx/src/pwm.zig similarity index 100% rename from examples/raspberrypi/rp2xxx/src/rp2040_only/pwm.zig rename to examples/raspberrypi/rp2xxx/src/pwm.zig diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/flash_id.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/flash_id.zig index 9f153deb..03b13315 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/flash_id.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/flash_id.zig @@ -5,7 +5,6 @@ const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; const flash = rp2xxx.flash; -const chip = rp2xxx.compatibility.chip; const uart = rp2xxx.uart.instance.num(0); const baud_rate = 115200; @@ -24,13 +23,8 @@ pub const std_options = struct { }; pub fn main() !void { - switch (chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_second); - }, + inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { + pin.set_function(.uart); } uart.apply(.{ diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/flash_program.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/flash_program.zig index f78c4368..18cc5cc1 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/flash_program.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/flash_program.zig @@ -6,7 +6,6 @@ const flash = rp2xxx.flash; const time = rp2xxx.time; const gpio = rp2xxx.gpio; const clocks = rp2xxx.clocks; -const chip = rp2xxx.compatibility.chip; const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); @@ -33,13 +32,8 @@ pub fn main() !void { led.set_direction(.out); led.put(1); - switch (chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_second); - }, + inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { + pin.set_function(.uart); } uart.apply(.{ diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig index eb946595..0e1426e0 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig @@ -9,7 +9,6 @@ const time = rp2xxx.time; const gpio = rp2xxx.gpio; const clocks = rp2xxx.clocks; const rand = rp2xxx.rand; -const chip = rp2xxx.compatibility.chip; const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); @@ -33,13 +32,8 @@ pub fn main() !void { led.set_direction(.out); led.put(1); - switch (chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_second); - }, + inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { + pin.set_function(.uart); } uart.apply(.{ diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/uart_echo.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/uart_echo.zig deleted file mode 100644 index b0a45b44..00000000 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/uart_echo.zig +++ /dev/null @@ -1,41 +0,0 @@ -const std = @import("std"); -const microzig = @import("microzig"); -const time = microzig.drivers.time; - -const rp2040 = microzig.hal; -const uart = rp2040.uart; -const gpio = rp2040.gpio; -const clocks = rp2040.clocks; - -const echo_uart = uart.instance.num(0); -const baud_rate = 115200; -const uart_tx_pin = gpio.num(0); -const uart_rx_pin = gpio.num(1); - -pub fn main() !void { - inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - } - - echo_uart.apply(.{ - .baud_rate = baud_rate, - .clock_config = rp2040.clock_config, - //.parity = .none, - //.stop_bits = .one, - //.flow_control = .none - }); - - var data: [1]u8 = .{0}; - while (true) { - //read one byte, timeout disabled - echo_uart.read_blocking(&data, null) catch { - echo_uart.clear_errors(); //You need to clear UART errors before making a new transaction - continue; - }; - - //tries to write one byte with 100ms timeout - echo_uart.write_blocking(&data, time.Duration.from_ms(100)) catch { - echo_uart.clear_errors(); - }; - } -} diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/usb_hid.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/usb_hid.zig index df78f932..35acb23b 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/usb_hid.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/usb_hid.zig @@ -7,7 +7,6 @@ const time = rp2xxx.time; const gpio = rp2xxx.gpio; const clocks = rp2xxx.clocks; const usb = rp2xxx.usb; -const chip = rp2xxx.compatibility.chip; const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); @@ -71,13 +70,8 @@ pub fn main() !void { led.set_direction(.out); led.put(1); - switch (chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_second); - }, + inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { + pin.set_function(.uart); } uart.apply(.{ diff --git a/examples/raspberrypi/rp2xxx/src/spi_slave.zig b/examples/raspberrypi/rp2xxx/src/spi_slave.zig index 8d208476..b271ce6c 100644 --- a/examples/raspberrypi/rp2xxx/src/spi_slave.zig +++ b/examples/raspberrypi/rp2xxx/src/spi_slave.zig @@ -35,10 +35,7 @@ pub fn main() !void { pin.set_function(.spi); } - switch (chip) { - .RP2040 => uart_tx_pin.set_function(.uart), - .RP2350 => uart_tx_pin.set_function(.uart_first), - } + uart_tx_pin.set_function(.uart); uart.apply(.{ .baud_rate = uart_baud_rate, .clock_config = rp2xxx.clock_config, diff --git a/examples/raspberrypi/rp2xxx/src/uart_echo.zig b/examples/raspberrypi/rp2xxx/src/uart_echo.zig new file mode 100644 index 00000000..35a7cea1 --- /dev/null +++ b/examples/raspberrypi/rp2xxx/src/uart_echo.zig @@ -0,0 +1,45 @@ +const std = @import("std"); +const microzig = @import("microzig"); +const time = microzig.drivers.time; + +const rp2xxx = microzig.hal; +const gpio = rp2xxx.gpio; +const clocks = rp2xxx.clocks; + +const led = gpio.num(25); +const uart = rp2xxx.uart.instance.num(0); +const baud_rate = 115200; +const uart_tx_pin = gpio.num(0); +const uart_rx_pin = gpio.num(1); + +pub fn main() !void { + led.set_function(.sio); + led.set_direction(.out); + led.put(1); + inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { + pin.set_function(.uart); + } + + uart.apply(.{ + .baud_rate = baud_rate, + .clock_config = rp2xxx.clock_config, + }); + + var data: [1]u8 = .{0}; + while (true) { + // Read one byte, timeout disabled + uart.read_blocking(&data, null) catch { + // You need to clear UART errors before making a new transaction + uart.clear_errors(); + continue; + }; + + //tries to write one byte with 100ms timeout + uart.write_blocking(&data, time.Duration.from_ms(100)) catch { + uart.clear_errors(); + }; + // Toggle the led every time we think we've received a character so we + // know something is going on. + led.toggle(); + } +} diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/uart_log.zig b/examples/raspberrypi/rp2xxx/src/uart_log.zig similarity index 74% rename from examples/raspberrypi/rp2xxx/src/rp2040_only/uart_log.zig rename to examples/raspberrypi/rp2xxx/src/uart_log.zig index d8dbcc30..aa3c1646 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/uart_log.zig +++ b/examples/raspberrypi/rp2xxx/src/uart_log.zig @@ -5,13 +5,11 @@ const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; const clocks = rp2xxx.clocks; -const chip = rp2xxx.compatibility.chip; const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); const baud_rate = 115200; const uart_tx_pin = gpio.num(0); -const uart_rx_pin = gpio.num(1); pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { std.log.err("panic: {s}", .{message}); @@ -29,14 +27,7 @@ pub fn main() !void { led.set_direction(.out); led.put(1); - switch (chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_second); - }, - } + uart_tx_pin.set_function(.uart); uart.apply(.{ .baud_rate = baud_rate, diff --git a/examples/raspberrypi/rp2xxx/src/usb_cdc.zig b/examples/raspberrypi/rp2xxx/src/usb_cdc.zig index 984aa14f..4c6bf046 100644 --- a/examples/raspberrypi/rp2xxx/src/usb_cdc.zig +++ b/examples/raspberrypi/rp2xxx/src/usb_cdc.zig @@ -7,7 +7,6 @@ const time = rp2xxx.time; const gpio = rp2xxx.gpio; const clocks = rp2xxx.clocks; const usb = rp2xxx.usb; -const chip = rp2xxx.compatibility.chip; const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); @@ -69,13 +68,8 @@ pub fn main() !void { led.set_direction(.out); led.put(1); - switch (chip) { - .RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart); - }, - .RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { - pin.set_function(.uart_second); - }, + inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { + pin.set_function(.uart); } uart.apply(.{ diff --git a/port/raspberrypi/rp2xxx/src/hal/gpio.zig b/port/raspberrypi/rp2xxx/src/hal/gpio.zig index 8118770f..48b43c1b 100644 --- a/port/raspberrypi/rp2xxx/src/hal/gpio.zig +++ b/port/raspberrypi/rp2xxx/src/hal/gpio.zig @@ -31,8 +31,7 @@ pub const Function = .RP2350 => enum(u5) { hstx = 0, spi, - // TODO: Not in love with this naming - uart_first, + uart, i2c, pwm, sio, @@ -41,7 +40,7 @@ pub const Function = pio2, gpck, usb, - uart_second, + uart_alt, disabled = 0x1f, }, }; diff --git a/port/raspberrypi/rp2xxx/src/hal/i2c.zig b/port/raspberrypi/rp2xxx/src/hal/i2c.zig index b2a67b80..5f3e641a 100644 --- a/port/raspberrypi/rp2xxx/src/hal/i2c.zig +++ b/port/raspberrypi/rp2xxx/src/hal/i2c.zig @@ -109,8 +109,8 @@ fn translate_baudrate(baud_rate: u32, freq_in: u32) ConfigError!TimingRegisterVa // that means the input clock frequency is too low (not granular enough). // This also serves as a nice sanity check that we're still in spec no matter // the baud rate. - const scl_low_ns = (1_000_000_000 / freq_in) * scl_lcnt_with_additions; - const scl_high_ns = (1_000_000_000 / freq_in) * scl_hcnt_with_additions; + const scl_low_ns = (1_000_000_000.0 / @as(f64, @floatFromInt(freq_in))) * @as(f64, @floatFromInt(scl_lcnt_with_additions)); + const scl_high_ns = (1_000_000_000.0 / @as(f64, @floatFromInt(freq_in))) * @as(f64, @floatFromInt(scl_hcnt_with_additions)); switch (baud_rate) { 1...100_000 => { const i2c_normal_scl_low_min_ns = 4700; @@ -171,16 +171,22 @@ fn translate_baudrate(baud_rate: u32, freq_in: u32) ConfigError!TimingRegisterVa if ((sda_tx_hold_count > scl_lcnt - 2) or (sda_tx_hold_count > std.math.maxInt(u16))) return ConfigError.HoldCountViolation; return .{ - .scl_hcnt = @as(u16, @intCast(scl_hcnt)), - .scl_lcnt = @as(u16, @intCast(scl_lcnt)), - .sda_tx_hold_count = @as(u16, @intCast(sda_tx_hold_count)), + .scl_hcnt = @intCast(scl_hcnt), + .scl_lcnt = @intCast(scl_lcnt), + .sda_tx_hold_count = @intCast(sda_tx_hold_count), .spklen = spklen, }; } test "i2c.translate_baudrate" { - try std.testing.expectEqualDeep(TimingRegisterValues{ .scl_hcnt = 486, .scl_lcnt = 749, .sda_tx_hold_count = 38, .spklen = 7 }, translate_baudrate(100_000, 125_000_000)); - try std.testing.expectEqualDeep(TimingRegisterValues{ .scl_hcnt = 112, .scl_lcnt = 186, .sda_tx_hold_count = 38, .spklen = 7 }, translate_baudrate(400_000, 125_000_000)); + try std.testing.expectEqualDeep( + TimingRegisterValues{ .scl_hcnt = 486, .scl_lcnt = 749, .sda_tx_hold_count = 38, .spklen = 7 }, + translate_baudrate(100_000, 125_000_000), + ); + try std.testing.expectEqualDeep( + TimingRegisterValues{ .scl_hcnt = 112, .scl_lcnt = 186, .sda_tx_hold_count = 38, .spklen = 7 }, + translate_baudrate(400_000, 125_000_000), + ); try std.testing.expectError(ConfigError.UnsupportedBaudRate, translate_baudrate(0, 125_000_000)); // Taken directly from Table 450 to confirm our calculations match the datasheet's expectations try std.testing.expectError(ConfigError.InputFreqTooLow, translate_baudrate(100_000, 2_600_000)); diff --git a/port/raspberrypi/rp2xxx/src/hal/pins.zig b/port/raspberrypi/rp2xxx/src/hal/pins.zig index 7c8eeb92..0dd0340b 100644 --- a/port/raspberrypi/rp2xxx/src/hal/pins.zig +++ b/port/raspberrypi/rp2xxx/src/hal/pins.zig @@ -76,6 +76,7 @@ pub const Function = enum { PIO0, PIO1, + // TODO: PIO2 for RP2350 SPI0_RX, SPI0_CSn, @@ -426,12 +427,12 @@ pub const GlobalConfiguration = struct { if (pin_config.function == .SIO) { @field(ret, pin_config.name orelse field.name) = gpio.num(@intFromEnum(@field(Pin, field.name))); } else if (pin_config.function.is_pwm()) { - @field(ret, pin_config.name orelse field.name) = pwm.Pwm { + @field(ret, pin_config.name orelse field.name) = pwm.Pwm{ .slice_number = pin_config.function.pwm_slice(), .channel = pin_config.function.pwm_channel(), }; } else if (pin_config.function.is_adc()) { - @field(ret, pin_config.name orelse field.name) = @as(adc.Input, @enumFromInt(switch(pin_config.function) { + @field(ret, pin_config.name orelse field.name) = @as(adc.Input, @enumFromInt(switch (pin_config.function) { .ADC0 => 0, .ADC1 => 1, .ADC2 => 2, @@ -495,8 +496,10 @@ pub const GlobalConfiguration = struct { // i2c, // pio0, // pio1, + // pio2 (rp2350 only) // gpck, // usb, + // uart_alt (rp2350 only) // @"null" = 0x1f, if (func == .SIO) { @@ -509,6 +512,7 @@ pub const GlobalConfiguration = struct { pin.set_pull(.disabled); pin.set_input_enabled(false); } else if (comptime func.is_uart_tx() or func.is_uart_rx()) { + // TODO: Handle pins that can be used with an alternate uart function pin.set_function(.uart); } else if (comptime func.is_spi()) { pin.set_function(.spi);