Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rp2350: Fix GlobalConfig for uart, rename func to match rp2040 #403

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions examples/raspberrypi/rp2xxx/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(.{
Expand Down
10 changes: 1 addition & 9 deletions examples/raspberrypi/rp2xxx/src/interrupts.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/flash_id.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(.{
Expand Down
10 changes: 2 additions & 8 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/flash_program.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(.{
Expand Down
10 changes: 2 additions & 8 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(.{
Expand Down
41 changes: 0 additions & 41 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/uart_echo.zig

This file was deleted.

10 changes: 2 additions & 8 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/usb_hid.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(.{
Expand Down
5 changes: 1 addition & 4 deletions examples/raspberrypi/rp2xxx/src/spi_slave.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 45 additions & 0 deletions examples/raspberrypi/rp2xxx/src/uart_echo.zig
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions examples/raspberrypi/rp2xxx/src/usb_cdc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(.{
Expand Down
5 changes: 2 additions & 3 deletions port/raspberrypi/rp2xxx/src/hal/gpio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,7 +40,7 @@ pub const Function =
pio2,
gpck,
usb,
uart_second,
uart_alt,
disabled = 0x1f,
},
};
Expand Down
Loading
Loading