From 9186848a68adb19ff21bc8ab291685b62f6e9427 Mon Sep 17 00:00:00 2001 From: Grazfather Date: Wed, 15 Jan 2025 20:16:42 -0500 Subject: [PATCH] cleanup --- examples/raspberrypi/rp2xxx/build.zig | 53 ++++++++++--------- .../rp2xxx/src/hal/pio/assembler.zig | 2 - .../hal/pio/assembler/comparison_tests.zig | 13 ----- .../src/hal/pio/assembler/tokenizer.zig | 15 ++++-- 4 files changed, 38 insertions(+), 45 deletions(-) diff --git a/examples/raspberrypi/rp2xxx/build.zig b/examples/raspberrypi/rp2xxx/build.zig index 25aeeb56..e26f3d85 100644 --- a/examples/raspberrypi/rp2xxx/build.zig +++ b/examples/raspberrypi/rp2xxx/build.zig @@ -13,38 +13,41 @@ 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_spi-host", .file = "src/rp2040_only/spi_host.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_usb-cdc", .file = "src/rp2040_only/usb_cdc.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" }, - // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_pcf8574", .file = "src/rp2040_only/pcf8574.zig" }, - // - // // WaveShare Boards: - // .{ .target = mb.ports.rp2xxx.boards.waveshare.rp2040_matrix, .name = "rp2040-matrix_tiles", .file = "src/rp2040_only/tiles.zig" }, + .{ .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_spi-host", .file = "src/rp2040_only/spi_host.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_usb-cdc", .file = "src/rp2040_only/usb_cdc.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" }, + .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_pcf8574", .file = "src/rp2040_only/pcf8574.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" }, // .{ .target = "board:waveshare/rp2040_plus_4m", .name = "rp2040-plus-4m" }, // .{ .target = "board:waveshare/rp2040_plus_16m", .name = "rp2040-plus-16m" }, }; - const rp2350_only_examples: []const Example = &.{}; + const rp2350_only_examples: []const Example = &.{ + // TODO: No RP2350 feature specific examples to show off yet + }; const chip_agnostic_examples: []const ChipAgnosticExample = &.{ - // .{ .name = "ws2812", .file = "src/ws2812.zig" }, - // .{ .name = "blinky", .file = "src/blinky.zig" }, - // .{ .name = "gpio-clock-output", .file = "src/gpio_clock_output.zig" }, - // .{ .name = "changing-system-clocks", .file = "src/changing_system_clocks.zig" }, - // .{ .name = "custom-clock-config", .file = "src/custom_clock_config.zig" }, - // .{ .name = "watchdog-timer", .file = "src/watchdog_timer.zig" }, + .{ .name = "squarewave", .file = "src/squarewave.zig" }, + .{ .name = "ws2812", .file = "src/ws2812.zig" }, + .{ .name = "blinky", .file = "src/blinky.zig" }, + .{ .name = "gpio-clock-output", .file = "src/gpio_clock_output.zig" }, + .{ .name = "changing-system-clocks", .file = "src/changing_system_clocks.zig" }, + .{ .name = "custom-clock-config", .file = "src/custom_clock_config.zig" }, + .{ .name = "watchdog-timer", .file = "src/watchdog_timer.zig" }, }; var available_examples = std.ArrayList(Example).init(b.allocator); diff --git a/port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig b/port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig index 34229c9e..1f11a610 100644 --- a/port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig +++ b/port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig @@ -100,9 +100,7 @@ fn format_compile_error(comptime message: []const u8, comptime source: []const u var line_it = std.mem.tokenize(u8, source, "\n\r"); while (line_it.next()) |line| : (line_num += 1) { line_str = line_str ++ "\n" ++ line; - // If the line iterator is overlapping the provided index, then we are on the correct line if (line_it.index >= index) { - // Calculate the column column = line.len - (line_it.index - index); line_str = line; break; diff --git a/port/raspberrypi/rp2xxx/src/hal/pio/assembler/comparison_tests.zig b/port/raspberrypi/rp2xxx/src/hal/pio/assembler/comparison_tests.zig index cc99263e..dea3b96d 100644 --- a/port/raspberrypi/rp2xxx/src/hal/pio/assembler/comparison_tests.zig +++ b/port/raspberrypi/rp2xxx/src/hal/pio/assembler/comparison_tests.zig @@ -41,19 +41,6 @@ fn pio_comparison(comptime source: []const u8) !void { } fn pio_comparison_chip(comptime chip: Chip, comptime source: []const u8) !void { - // comptime var diags: ?assembler.Diagnostics = null; - // const output = comptime blk: { - // const v = assembler.assemble_impl(chip, source, &diags, .{}) catch |err| { - // @compileLog("err {}", err); - // if (diags != null) { - // std.log.debug("diag {}", .{diags}); - // @compileLog("Diag", diags); - // } - // // I want to return an error here but this is comptime? - // break :blk err; - // }; - // break :blk v; - // }; const output = comptime assembler.assemble(chip, source, .{}); try std.testing.expect(output.programs.len > 0); diff --git a/port/raspberrypi/rp2xxx/src/hal/pio/assembler/tokenizer.zig b/port/raspberrypi/rp2xxx/src/hal/pio/assembler/tokenizer.zig index d53a24e3..27a45ff7 100644 --- a/port/raspberrypi/rp2xxx/src/hal/pio/assembler/tokenizer.zig +++ b/port/raspberrypi/rp2xxx/src/hal/pio/assembler/tokenizer.zig @@ -953,9 +953,6 @@ pub fn Tokenizer(chip: Chip) type { }; }, .RP2350 => { - // This doesn't work: idx_mode's type only exists at comptime, - // even though this is a comptime-only switch :/ - // Hardcoding the type const IdxMode = Token(chip).Instruction.Irq.IdxMode; const idx_mode: IdxMode = if (try self.peek_arg(diags)) |result| blk: { const idxmode_lower = try lowercase_bounded(256, result.str); @@ -969,7 +966,6 @@ pub fn Tokenizer(chip: Chip) type { self.consume_peek(result); break :blk .next; } else { - // Not specified: direct break :blk .direct; } } else .direct; @@ -2144,7 +2140,6 @@ test "tokenize.instr.irq" { test "tokenize.instr.irq.rel" { const tokens = try bounded_tokenize(.RP2040, "irq set 2 rel"); - // TODO: rp2350 support try expect_instr_irq(.RP2040, .{ .clear = false, .wait = false, @@ -2153,6 +2148,16 @@ test "tokenize.instr.irq.rel" { }, tokens.get(0)); } +test "tokenize.instr.irq.relnext" { + const tokens = try bounded_tokenize(.RP2350, "irq set 2 next"); + try expect_instr_irq(.RP2350, .{ + .clear = false, + .wait = false, + .num = 2, + .idxmode = @intFromEnum(Token(.RP2350).Instruction.Irq.IdxMode.next), + }, tokens.get(0)); +} + test "tokenize.instr.set" { inline for (.{ "pins",