diff --git a/examples/raspberrypi/rp2xxx/build.zig b/examples/raspberrypi/rp2xxx/build.zig index d76f1a782..a064b3949 100644 --- a/examples/raspberrypi/rp2xxx/build.zig +++ b/examples/raspberrypi/rp2xxx/build.zig @@ -16,15 +16,19 @@ pub fn build(b: *std.Build) void { const specific_examples: []const Example = &.{ // RaspberryPi Boards: + .{ .target = raspberrypi.pico, .name = "pico_board_blinky", .file = "src/board_blinky.zig" }, .{ .target = raspberrypi.pico, .name = "pico_flash-program", .file = "src/rp2040_only/flash_program.zig" }, .{ .target = raspberrypi.pico, .name = "pico_flash-id", .file = "src/rp2040_only/flash_id.zig" }, .{ .target = raspberrypi.pico, .name = "pico_random", .file = "src/rp2040_only/random.zig" }, .{ .target = raspberrypi.pico, .name = "pico_rtc", .file = "src/rp2040_only/rtc.zig" }, - .{ .target = raspberrypi.pico, .name = "pico_multicore", .file = "src/rp2040_only/blinky_core1.zig" }, + .{ .target = raspberrypi.pico, .name = "pico_multicore", .file = "src/blinky_core1.zig" }, .{ .target = raspberrypi.pico, .name = "pico_hd44780", .file = "src/rp2040_only/hd44780.zig" }, .{ .target = raspberrypi.pico, .name = "pico_pcf8574", .file = "src/rp2040_only/pcf8574.zig" }, .{ .target = raspberrypi.pico, .name = "pico_i2c_slave", .file = "src/rp2040_only/i2c_slave.zig" }, + .{ .target = raspberrypi.pico2_arm, .name = "pico2_arm_multicore", .file = "src/blinky_core1.zig" }, + .{ .target = raspberrypi.pico2_arm, .name = "pico2_arm_board_blinky", .file = "src/board_blinky.zig" }, + .{ .target = raspberrypi.pico_flashless, .name = "pico_flashless_blinky", .file = "src/blinky.zig" }, .{ .target = raspberrypi.pico_flashless, .name = "pico_flashless_flash-program", .file = "src/rp2040_only/flash_program.zig" }, @@ -39,6 +43,11 @@ pub fn build(b: *std.Build) void { .{ .target = raspberrypi.pico2_arm, .name = "pico2_arm_always_on_timer", .file = "src/rp2350_only/always_on_timer.zig" }, .{ .target = raspberrypi.pico2_riscv, .name = "pico2_riscv_always_on_timer", .file = "src/rp2350_only/always_on_timer.zig" }, + // Adafruit boards + .{ .target = mb.ports.rp2xxx.boards.adafruit.feather_rp2350, .name = "adafruit_feather_rp2350_blinky", .file = "src/board_blinky.zig" }, + .{ .target = mb.ports.rp2xxx.boards.adafruit.feather_rp2350, .name = "adafruit_feather_rp2350_multicore", .file = "src/blinky_core1.zig" }, + .{ .target = mb.ports.rp2xxx.boards.adafruit.metro_rp2350, .name = "adafruit_metro_rp2350_blinky", .file = "src/board_blinky.zig" }, + // WaveShare Boards: .{ .target = mb.ports.rp2xxx.boards.waveshare.rp2040_matrix, .name = "rp2040_matrix_tiles", .file = "src/rp2040_only/tiles.zig" }, // .{ .target = "board:waveshare/rp2040_eth", .name = "rp2040-eth" }, diff --git a/examples/raspberrypi/rp2xxx/src/allocator.zig b/examples/raspberrypi/rp2xxx/src/allocator.zig index 99642987a..6962373d7 100644 --- a/examples/raspberrypi/rp2xxx/src/allocator.zig +++ b/examples/raspberrypi/rp2xxx/src/allocator.zig @@ -28,8 +28,6 @@ const pin_config = hal.pins.GlobalConfiguration{ }, }; -const pins = pin_config.pins(); - // ---- UART Configuration -------------------------------- const baud_rate = 115200; @@ -46,7 +44,7 @@ pub fn main() !void { // --- Set up GPIO ------------------------------- - pin_config.apply(); + _ = pin_config.apply(); // --- Set up UART ------------------------------- diff --git a/examples/raspberrypi/rp2xxx/src/blinky.zig b/examples/raspberrypi/rp2xxx/src/blinky.zig index cce93a0e1..a6b937cd6 100644 --- a/examples/raspberrypi/rp2xxx/src/blinky.zig +++ b/examples/raspberrypi/rp2xxx/src/blinky.zig @@ -10,10 +10,8 @@ const pin_config: rp2xxx.pins.GlobalConfiguration = .{ }, }; -const pins = pin_config.pins(); - pub fn main() !void { - pin_config.apply(); + const pins = pin_config.apply(); while (true) { pins.led.toggle(); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/blinky_core1.zig b/examples/raspberrypi/rp2xxx/src/blinky_core1.zig similarity index 50% rename from examples/raspberrypi/rp2xxx/src/rp2040_only/blinky_core1.zig rename to examples/raspberrypi/rp2xxx/src/blinky_core1.zig index 23e43b5d8..10755ed37 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/blinky_core1.zig +++ b/examples/raspberrypi/rp2xxx/src/blinky_core1.zig @@ -2,24 +2,31 @@ const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; +const board = microzig.board; const gpio = rp2xxx.gpio; const time = rp2xxx.time; const multicore = rp2xxx.multicore; -const led = gpio.num(25); +const pins = board.pin_config.pins(); fn core1() void { while (true) { - led.put(1); - time.sleep_ms(250); - led.put(0); - time.sleep_ms(250); + pins.led.put(1); + time.sleep_ms(100); + pins.led.put(0); + time.sleep_ms(100); } } pub fn main() !void { - led.set_function(.sio); - led.set_direction(.out); + _ = board.pin_config.apply(); + + // Blink a few time on core0 + pins.led.put(1); + time.sleep_ms(250); + pins.led.put(0); + time.sleep_ms(250); + multicore.launch_core1(core1); while (true) { diff --git a/examples/raspberrypi/rp2xxx/src/board_blinky.zig b/examples/raspberrypi/rp2xxx/src/board_blinky.zig new file mode 100644 index 000000000..770a42614 --- /dev/null +++ b/examples/raspberrypi/rp2xxx/src/board_blinky.zig @@ -0,0 +1,13 @@ +const std = @import("std"); +const microzig = @import("microzig"); +const rp2xxx = microzig.hal; +const board = microzig.board; + +pub fn main() !void { + const pins = board.pin_config.apply(); + + while (true) { + pins.led.toggle(); + rp2xxx.time.sleep_ms(250); + } +} diff --git a/examples/raspberrypi/rp2xxx/src/ds18b20.zig b/examples/raspberrypi/rp2xxx/src/ds18b20.zig index a35000106..d24ed073a 100644 --- a/examples/raspberrypi/rp2xxx/src/ds18b20.zig +++ b/examples/raspberrypi/rp2xxx/src/ds18b20.zig @@ -18,10 +18,8 @@ const pin_config: rp2xxx.pins.GlobalConfiguration = .{ }, }; -const pins = pin_config.pins(); - pub fn main() !void { - pin_config.apply(); + const pins = pin_config.apply(); var ds18b20_gpio = rp2xxx.drivers.GPIO_Device.init(pins.ds18b20); const clock_device = rp2xxx.drivers.clock_device(); diff --git a/examples/raspberrypi/rp2xxx/src/mlx90640.zig b/examples/raspberrypi/rp2xxx/src/mlx90640.zig index 8da4f9700..5740759e2 100644 --- a/examples/raspberrypi/rp2xxx/src/mlx90640.zig +++ b/examples/raspberrypi/rp2xxx/src/mlx90640.zig @@ -76,7 +76,7 @@ fn init() !void { i2c0.apply(i2c.Config{ .clock_config = rp2xxx.clock_config }); rp2xxx.uart.init_logger(uart); - pin_config.apply(); + _ = pin_config.apply(); std.log.info("Hello from mlx90640", .{}); diff --git a/examples/raspberrypi/rp2xxx/src/pwm.zig b/examples/raspberrypi/rp2xxx/src/pwm.zig index 8e37971cc..aea051ef4 100644 --- a/examples/raspberrypi/rp2xxx/src/pwm.zig +++ b/examples/raspberrypi/rp2xxx/src/pwm.zig @@ -11,10 +11,8 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ .GPIO25 = .{ .name = "led", .function = .PWM4_B }, }; -const pins = pin_config.pins(); - pub fn main() !void { - pin_config.apply(); + const pins = pin_config.apply(); pins.led.slice().set_wrap(100); pins.led.slice().enable(); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_slave.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_slave.zig index 326b60d7f..4f5f998b0 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_slave.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_slave.zig @@ -38,7 +38,7 @@ pub fn main() !void { }); rp2xxx.uart.init_logger(uart); - pin_config.apply(); + _ = pin_config.apply(); std.log.info("Hello from i2c_slave.", .{}); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig index d5aa50274..0d5f815fb 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig @@ -33,7 +33,7 @@ fn rtc_isr() callconv(.c) void { } pub fn main() !void { - const pins = pin_config.pins(); + const pins = pin_config.apply(); // Configure initial datetime for RTC rp2xxx.rtc.set_datetime(.{ diff --git a/examples/raspberrypi/rp2xxx/src/rp2350_only/always_on_timer.zig b/examples/raspberrypi/rp2xxx/src/rp2350_only/always_on_timer.zig index 82337f0a1..2980b3582 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2350_only/always_on_timer.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2350_only/always_on_timer.zig @@ -16,8 +16,6 @@ const pin_config = hal.pins.GlobalConfiguration{ .GPIO0 = .{ .name = "gpio0", .function = .UART0_TX }, }; -const pins = pin_config.pins(); - pub const microzig_options = microzig.Options{ .log_level = .debug, .logFn = uart.log, @@ -27,7 +25,7 @@ pub fn main() !void { var buffer: [128]u8 = undefined; var len: usize = 0; - pin_config.apply(); + _ = pin_config.apply(); uart0.apply(.{ .clock_config = hal.clock_config, diff --git a/examples/raspberrypi/rp2xxx/src/rp2350_only/random_data.zig b/examples/raspberrypi/rp2xxx/src/rp2350_only/random_data.zig index 5e7f9bcb9..80142241d 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2350_only/random_data.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2350_only/random_data.zig @@ -15,15 +15,13 @@ const pin_config = hal.pins.GlobalConfiguration{ .GPIO0 = .{ .name = "gpio0", .function = .UART0_TX }, }; -const pins = pin_config.pins(); - pub const microzig_options = microzig.Options{ .log_level = .debug, .logFn = uart.log, }; pub fn main() !void { - pin_config.apply(); + _ = pin_config.apply(); uart0.apply(.{ .clock_config = hal.clock_config, diff --git a/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig b/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig index 95a63b552..975b74c98 100644 --- a/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig +++ b/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig @@ -10,10 +10,8 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ .direction = .out, }, }; -const pins = pin_config.pins(); - pub fn main() !void { - pin_config.apply(); + const pins = pin_config.apply(); // Set up different blinking behavior if this reset was due to a WD trip const wd_reset: bool = if (watchdog.caused_reboot()) |_| diff --git a/port/raspberrypi/rp2xxx/build.zig b/port/raspberrypi/rp2xxx/build.zig index 727454df5..4036e74a4 100644 --- a/port/raspberrypi/rp2xxx/build.zig +++ b/port/raspberrypi/rp2xxx/build.zig @@ -11,6 +11,7 @@ chips: struct { boards: struct { adafruit: struct { + feather_rp2350: *const microzig.Target, metro_rp2350: *const microzig.Target, }, raspberrypi: struct { @@ -167,6 +168,13 @@ pub fn init(dep: *std.Build.Dependency) Self { }, .boards = .{ .adafruit = .{ + .feather_rp2350 = chip_rp2350_arm.derive(.{ + .board = .{ + .name = "Adafruit Faether RP2350", + .url = "https://www.adafruit.com/product/6000", + .root_source_file = b.path("src/boards/adafruit_feather_rp2350.zig"), + }, + }), .metro_rp2350 = chip_rp2350_arm.derive(.{ .board = .{ .name = "Adafruit Metro RP2350", diff --git a/port/raspberrypi/rp2xxx/src/boards/adafruit_feather_rp2350.zig b/port/raspberrypi/rp2xxx/src/boards/adafruit_feather_rp2350.zig new file mode 100644 index 000000000..fc7562e3e --- /dev/null +++ b/port/raspberrypi/rp2xxx/src/boards/adafruit_feather_rp2350.zig @@ -0,0 +1,12 @@ +pub const xosc_freq = 12_000_000; + +const microzig = @import("microzig"); +const hal = microzig.hal; +const pins = hal.pins; + +pub const pin_config = pins.GlobalConfiguration{ + .GPIO7 = .{ + .name = "led", + .function = .SIO, + }, +}; diff --git a/port/raspberrypi/rp2xxx/src/boards/adafruit_metro_rp2350.zig b/port/raspberrypi/rp2xxx/src/boards/adafruit_metro_rp2350.zig index 88eef65f2..8088ea119 100644 --- a/port/raspberrypi/rp2xxx/src/boards/adafruit_metro_rp2350.zig +++ b/port/raspberrypi/rp2xxx/src/boards/adafruit_metro_rp2350.zig @@ -9,184 +9,184 @@ const hal = microzig.hal; const pins = hal.pins; pub const pin_config = pins.GlobalConfiguration{ - .GPIO12 = .{ - .name = "hstx_d2p", - .function = .HSTX, - }, - - .GPIO13 = .{ - .name = "hstx_d2n", - .function = .HSTX, - }, - - .GPIO14 = .{ - .name = "hstx_ckp", - .function = .HSTX, - }, - - .GPIO15 = .{ - .name = "hstx_ckn", - .function = .HSTX, - }, - - .GPIO16 = .{ - .name = "hstx_d1p", - .function = .HSTX, - }, - - .GPIO17 = .{ - .name = "hstx_d1n", - .function = .HSTX, - }, - - .GPIO18 = .{ - .name = "hstx_d0p", - .function = .HSTX, - }, - - .GPIO19 = .{ - .name = "hstx_d0n", - .function = .HSTX, - }, - - .GPIO20 = .{ - .name = "sda", - .function = .I2C0, - }, - - .GPIO21 = .{ - .name = "scl", - .function = .I2C0, - }, + // .GPIO12 = .{ + // .name = "hstx_d2p", + // .function = .HSTX, + // }, + // + // .GPIO13 = .{ + // .name = "hstx_d2n", + // .function = .HSTX, + // }, + // + // .GPIO14 = .{ + // .name = "hstx_ckp", + // .function = .HSTX, + // }, + // + // .GPIO15 = .{ + // .name = "hstx_ckn", + // .function = .HSTX, + // }, + // + // .GPIO16 = .{ + // .name = "hstx_d1p", + // .function = .HSTX, + // }, + // + // .GPIO17 = .{ + // .name = "hstx_d1n", + // .function = .HSTX, + // }, + // + // .GPIO18 = .{ + // .name = "hstx_d0p", + // .function = .HSTX, + // }, + // + // .GPIO19 = .{ + // .name = "hstx_d0n", + // .function = .HSTX, + // }, + // + // .GPIO20 = .{ + // .name = "sda", + // .function = .I2C0_SDA, + // }, + // + // .GPIO21 = .{ + // .name = "scl", + // .function = .I2C0_SCL, + // }, .GPIO23 = .{ - .name = "red_led", - .function = .SIO, - .direction = .out, - }, - - .GPIO24 = .{ - .name = "boot_button", - .function = .SIO, - .direction = .in, - }, - - .GPIO25 = .{ - .name = "neo_pixel", - .function = .SIO, - .direction = .out, - }, - - .GPIO26 = .{ - .name = "hstx_d26", - .function = .SIO, - }, - - .GPIO27 = .{ - .name = "hstx_d27", - .function = .SIO, - }, - - .GPIO28 = .{ - .name = "miso", - .function = .SPI0, - }, - - .GPIO29 = .{ - .name = "usb_host_power", + .name = "led", .function = .SIO, .direction = .out, }, - .GPIO30 = .{ - .name = "mosi", - .function = .SPI0, - }, - - .GPIO31 = .{ - .name = "sck", - .function = .SPI0, - }, - - .GPIO32 = .{ - .name = "usb_host_data_plus", - }, - - .GPIO33 = .{ - .name = "usb_host_data_minus", - }, - - .GPIO34 = .{ - .name = "sd_sck", - .function = .SPI1, - .direction = .out, - }, - - .GPIO35 = .{ - .name = "sd_miso", - .function = .SPI1, - .direction = .in, - }, - - .GPIO36 = .{ - .name = "sd_mosi", - .function = .SPI1, - .direction = .out, - }, - - .GPIO37 = .{ - .name = "sd_data1", - .direction = .out, - }, - - .GPIO38 = .{ - .name = "sd_data2", - .direction = .out, - }, - - .GPIO39 = .{ - .name = "sd_cs", - .function = .SPI1, - .direction = .out, - }, - - .GPIO40 = .{ - .name = "sd_cd", - }, - - .GPIO41 = .{ - .name = "A0", - .function = .ADC1, - }, - - .GPIO42 = .{ - .name = "A1", - .function = .ADC2, - }, - - .GPIO43 = .{ - .name = "A2", - .function = .ADC3, - }, - - .GPIO44 = .{ - .name = "A3", - .function = .ADC4, - }, - - .GPIO45 = .{ - .name = "A4", - .function = .ADC5, - }, - - .GPIO46 = .{ - .name = "A5", - .function = .ADC6, - }, - - .GPIO47 = .{ - .name = "QMI_CS1", - .function = .PIO2, - .direction = .out, - }, + // .GPIO24 = .{ + // .name = "boot_button", + // .function = .SIO, + // .direction = .in, + // }, + // + // .GPIO25 = .{ + // .name = "neo_pixel", + // .function = .SIO, + // .direction = .out, + // }, + // + // .GPIO26 = .{ + // .name = "hstx_d26", + // .function = .SIO, + // }, + // + // .GPIO27 = .{ + // .name = "hstx_d27", + // .function = .SIO, + // }, + // + // .GPIO28 = .{ + // .name = "miso", + // .function = .SPI1_RX, + // }, + // + // .GPIO29 = .{ + // .name = "usb_host_power", + // .function = .SIO, + // .direction = .out, + // }, + // + // .GPIO30 = .{ + // .name = "sck", + // .function = .SPI1_SCK, + // }, + // + // .GPIO31 = .{ + // .name = "mosi", + // .function = .SPI1_TX, + // }, + // + // .GPIO32 = .{ + // .name = "usb_host_data_plus", + // }, + // + // .GPIO33 = .{ + // .name = "usb_host_data_minus", + // }, + // + // .GPIO34 = .{ + // .name = "sd_sck", + // .function = .SPI0_SCK, + // .direction = .out, + // }, + // + // .GPIO35 = .{ + // .name = "sd_mosi", + // .function = .SPI0_TX, + // .direction = .out, + // }, + // + // .GPIO36 = .{ + // .name = "sd_miso", + // .function = .SPI0_RX, + // .direction = .in, + // }, + // + // .GPIO37 = .{ + // .name = "sd_data1", + // .direction = .out, + // }, + // + // .GPIO38 = .{ + // .name = "sd_data2", + // .direction = .out, + // }, + // + // .GPIO39 = .{ + // .name = "sd_cs", + // .function = .SIO, + // .direction = .out, + // }, + // + // .GPIO40 = .{ + // .name = "sd_cd", + // }, + // + // .GPIO41 = .{ + // .name = "A0", + // .function = .ADC1, + // }, + // + // .GPIO42 = .{ + // .name = "A1", + // .function = .ADC2, + // }, + // + // .GPIO43 = .{ + // .name = "A2", + // .function = .ADC3, + // }, + // + // .GPIO44 = .{ + // .name = "A3", + // .function = .ADC4, + // }, + // + // .GPIO45 = .{ + // .name = "A4", + // .function = .ADC5, + // }, + // + // .GPIO46 = .{ + // .name = "A5", + // .function = .ADC6, + // }, + // + // .GPIO47 = .{ + // .name = "QMI_CS1", + // .function = .PIO2, + // .direction = .out, + // }, }; diff --git a/port/raspberrypi/rp2xxx/src/boards/raspberry_pi_pico.zig b/port/raspberrypi/rp2xxx/src/boards/raspberry_pi_pico.zig index f46cbfc25..1ea66fcb7 100644 --- a/port/raspberrypi/rp2xxx/src/boards/raspberry_pi_pico.zig +++ b/port/raspberrypi/rp2xxx/src/boards/raspberry_pi_pico.zig @@ -1,7 +1,18 @@ pub const xosc_freq = 12_000_000; +const microzig = @import("microzig"); +const hal = microzig.hal; +const pins = hal.pins; + pub const bootrom = @import("shared/rp2040_bootrom.zig"); comptime { _ = bootrom; } + +pub const pin_config = pins.GlobalConfiguration{ + .GPIO25 = .{ + .name = "led", + .function = .SIO, + }, +}; diff --git a/port/raspberrypi/rp2xxx/src/boards/raspberry_pi_pico2.zig b/port/raspberrypi/rp2xxx/src/boards/raspberry_pi_pico2.zig index aa428ccb3..9ed9464af 100644 --- a/port/raspberrypi/rp2xxx/src/boards/raspberry_pi_pico2.zig +++ b/port/raspberrypi/rp2xxx/src/boards/raspberry_pi_pico2.zig @@ -1 +1,12 @@ pub const xosc_freq = 12_000_000; + +const microzig = @import("microzig"); +const hal = microzig.hal; +const pins = hal.pins; + +pub const pin_config = pins.GlobalConfiguration{ + .GPIO25 = .{ + .name = "led", + .function = .SIO, + }, +}; diff --git a/port/raspberrypi/rp2xxx/src/hal/pins.zig b/port/raspberrypi/rp2xxx/src/hal/pins.zig index 2c25dc0f8..e1a82c0e8 100644 --- a/port/raspberrypi/rp2xxx/src/hal/pins.zig +++ b/port/raspberrypi/rp2xxx/src/hal/pins.zig @@ -814,25 +814,28 @@ pub const GlobalConfiguration = struct { var ret: self.PinsType() = undefined; inline for (@typeInfo(GlobalConfiguration).@"struct".fields) |field| { if (@field(self, field.name)) |pin_config| { - 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{ - .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) { - .ADC0 => 0, - .ADC1 => 1, - .ADC2 => 2, - .ADC3 => 3, - .ADC4 => 4, - .ADC5 => 5, - .ADC6 => 6, - .ADC7 => 7, - else => unreachable, - })); + const cname = pin_config.name orelse field.name; + if (@hasField(self.PinsType(), cname)) { + if (pin_config.function == .SIO) { + @field(ret, cname) = gpio.num(@intFromEnum(@field(Pin, field.name))); + } else if (pin_config.function.is_pwm()) { + @field(ret, cname) = pwm.Pwm{ + .slice_number = pin_config.function.pwm_slice(), + .channel = pin_config.function.pwm_channel(), + }; + } else if (pin_config.function.is_adc()) { + @field(ret, cname) = @as(adc.Input, @enumFromInt(switch (pin_config.function) { + .ADC0 => 0, + .ADC1 => 1, + .ADC2 => 2, + .ADC3 => 3, + .ADC4 => 4, + .ADC5 => 5, + .ADC6 => 6, + .ADC7 => 7, + else => unreachable, + })); + } } } } @@ -840,7 +843,7 @@ pub const GlobalConfiguration = struct { return ret; } - pub fn apply(comptime config: GlobalConfiguration) void { + pub fn apply(comptime config: GlobalConfiguration) config.PinsType() { comptime var input_gpios: u48 = 0; comptime var output_gpios: u48 = 0; comptime var has_adc = false; @@ -963,5 +966,7 @@ pub const GlobalConfiguration = struct { // Set other ADC features using functions in `hal.adc`. adc.set_enabled(true); } + + return config.pins(); } }; diff --git a/website/content/docs/getting-started.smd b/website/content/docs/getting-started.smd index af481271f..d52ba8917 100644 --- a/website/content/docs/getting-started.smd +++ b/website/content/docs/getting-started.smd @@ -76,10 +76,8 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ }, }; -const pins = pin_config.pins(); - pub fn main() !void { - pin_config.apply(); + const pins = pin_config.apply(); while (true) { pins.led.toggle();