Updates raspberrypi-pico example readme.

wch-ch32v003
Felix "xq" Queißner 1 year ago
parent 38793077e8
commit fac4648f5c

@ -0,0 +1,31 @@
# Examples for the BSP `raspberrypi-rp2040`
- [adc](src/adc.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
This example takes periodic samples of the temperature sensor and prints it to the UART using the stdlib logging facility.
- [blinky](src/blinky.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Blinks the LED on the board.
- [blinky core1](src/blinky_core1.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Blinks the LED on the board using the second CPU.
- [flash program](src/flash_program.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Writes and reads data into the flash.
- [gpio clk](src/gpio_clk.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Enables a `CLKOUT` mode on GPIO0.
- [i2c bus scan](src/i2c_bus_scan.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Prints all I²C devices on UART0 (Pin 0,1) attached to I²C on SCL=GPIO4, SDA=GPIO5.
- [pwm](src/pwm.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Slowly blinks the LED on the Pico with a smooth blinking using PWM.
- [random](src/random.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Showcases how to use the internal random generator.
- [spi master](src/spi_master.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Showcases how to use the SPI host controller.
- [squarewave](src/squarewave.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Showcases how to use the PIO to emit a basic square wave.
- [uart](src/uart.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Showcases how to use the UART together with `std.log`.
- [usb device](src/usb_device.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
A really basic example for a raw USB device. You can use the Python 3 script [`scripts/usb_device_loopback.py`](scripts/usb_device_loopback.py) to test the USB device.
- [usb hid](src/usb_hid.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
A really basic example how to implement a USB HID device. You can use the Python 3 script [`scripts/hid_test.py`](scripts/hid_test.py) to test the HID device.
- [ws2812](src/ws2812.zig) on [RaspberryPi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/)
Showcases how to control one WS2812 LED attached to GPIO23.

@ -1,36 +1,32 @@
const std = @import("std"); const std = @import("std");
const rp2040 = @import("rp2040"); const rp2040 = @import("rp2040");
const available_targets = [_]TargetDesc{ const available_examples = [_]Example{
.{ .name = "pico", .target = rp2040.boards.raspberry_pi.pico }, .{ .name = "pico_adc", .target = rp2040.boards.raspberry_pi.pico, .file = "src/adc.zig" },
.{ .name = "rp2040-eth", .target = rp2040.boards.waveshare.rp2040_eth }, .{ .name = "pico_blinky", .target = rp2040.boards.raspberry_pi.pico, .file = "src/blinky.zig" },
.{ .name = "rp2040-plus-4m", .target = rp2040.boards.waveshare.rp2040_plus_4m }, // TODO: Fix multicore hal! .{ .name = "pico", .target = rp2040.boards.raspberry_pi.pico , .file = "src/blinky_core1.zig" },
.{ .name = "rp2040-plus-16m", .target = rp2040.boards.waveshare.rp2040_plus_16m }, .{ .name = "pico_flash-program", .target = rp2040.boards.raspberry_pi.pico, .file = "src/flash_program.zig" },
.{ .name = "rp2040-matrix", .target = rp2040.boards.waveshare.rp2040_matrix }, .{ .name = "pico_gpio-clk", .target = rp2040.boards.raspberry_pi.pico, .file = "src/gpio_clk.zig" },
}; .{ .name = "pico_i2c-bus-scan", .target = rp2040.boards.raspberry_pi.pico, .file = "src/i2c_bus_scan.zig" },
.{ .name = "pico_pwm", .target = rp2040.boards.raspberry_pi.pico, .file = "src/pwm.zig" },
.{ .name = "pico_random", .target = rp2040.boards.raspberry_pi.pico, .file = "src/random.zig" },
.{ .name = "pico_spi-master", .target = rp2040.boards.raspberry_pi.pico, .file = "src/spi_master.zig" },
.{ .name = "pico_squarewave", .target = rp2040.boards.raspberry_pi.pico, .file = "src/squarewave.zig" },
.{ .name = "pico_uart", .target = rp2040.boards.raspberry_pi.pico, .file = "src/uart.zig" },
.{ .name = "pico_usb-device", .target = rp2040.boards.raspberry_pi.pico, .file = "src/usb_device.zig" },
.{ .name = "pico_usb-hid", .target = rp2040.boards.raspberry_pi.pico, .file = "src/usb_hid.zig" },
.{ .name = "pico_ws2812", .target = rp2040.boards.raspberry_pi.pico, .file = "src/ws2812.zig" },
const available_examples = [_][]const u8{ // .{ .name = "rp2040-eth", .target = rp2040.boards.waveshare.rp2040_eth },
"src/adc.zig", // .{ .name = "rp2040-plus-4m", .target = rp2040.boards.waveshare.rp2040_plus_4m },
"src/blinky.zig", // .{ .name = "rp2040-plus-16m", .target = rp2040.boards.waveshare.rp2040_plus_16m },
// TODO: Fix multicore hal! "src/blinky_core1.zig", // .{ .name = "rp2040-matrix", .target = rp2040.boards.waveshare.rp2040_matrix },
"src/flash_program.zig",
"src/gpio_clk.zig",
"src/i2c_bus_scan.zig",
"src/pwm.zig",
"src/random.zig",
"src/spi_master.zig",
"src/squarewave.zig",
"src/uart.zig",
"src/usb_device.zig",
"src/usb_hid.zig",
"src/ws2812.zig",
}; };
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const microzig = @import("microzig").init(b, "microzig"); const microzig = @import("microzig").init(b, "microzig");
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
for (available_targets) |target| {
for (available_examples) |example| { for (available_examples) |example| {
// `addFirmware` basically works like addExecutable, but takes a // `addFirmware` basically works like addExecutable, but takes a
// `microzig.Target` for target instead of a `std.zig.CrossTarget`. // `microzig.Target` for target instead of a `std.zig.CrossTarget`.
@ -38,10 +34,10 @@ pub fn build(b: *std.Build) void {
// The target will convey all necessary information on the chip, // The target will convey all necessary information on the chip,
// cpu and potentially the board as well. // cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{ const firmware = microzig.addFirmware(b, .{
.name = b.fmt("{s}-{s}", .{ std.fs.path.stem(example), target.name }), .name = example.name,
.target = target.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.source_file = .{ .path = example }, .source_file = .{ .path = example.file },
}); });
// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()` // `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
@ -53,10 +49,10 @@ pub fn build(b: *std.Build) void {
// For debugging, we also always install the firmware as an ELF file // For debugging, we also always install the firmware as an ELF file
microzig.installFirmware(b, firmware, .{ .format = .elf }); microzig.installFirmware(b, firmware, .{ .format = .elf });
} }
}
} }
const TargetDesc = struct { const Example = struct {
target: @import("microzig").Target, target: @import("microzig").Target,
name: []const u8, name: []const u8,
file: []const u8,
}; };

@ -14,10 +14,16 @@ const pin_config = rp2040.pins.GlobalConfiguration{
pub fn main() !void { pub fn main() !void {
const pins = pin_config.apply(); const pins = pin_config.apply();
pins.led.slice().set_wrap(100); pins.led.slice().set_wrap(100);
pins.led.set_level(10);
pins.led.slice().enable(); pins.led.slice().enable();
while (true) { while (true) {
time.sleep_ms(250); for (0..101) |level| {
pins.led.set_level(@truncate(level));
time.sleep_ms(10);
}
for (1..100) |level| {
pins.led.set_level(@truncate(100 - level));
time.sleep_ms(10);
}
} }
} }

Loading…
Cancel
Save