This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates raspberrypi-pico example readme.
- Loading branch information
Felix "xq" Queißner
committed
Sep 23, 2023
1 parent
3879307
commit fac4648
Showing
3 changed files
with
79 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,58 @@ | ||
const std = @import("std"); | ||
const rp2040 = @import("rp2040"); | ||
|
||
const available_targets = [_]TargetDesc{ | ||
.{ .name = "pico", .target = rp2040.boards.raspberry_pi.pico }, | ||
.{ .name = "rp2040-eth", .target = rp2040.boards.waveshare.rp2040_eth }, | ||
.{ .name = "rp2040-plus-4m", .target = rp2040.boards.waveshare.rp2040_plus_4m }, | ||
.{ .name = "rp2040-plus-16m", .target = rp2040.boards.waveshare.rp2040_plus_16m }, | ||
.{ .name = "rp2040-matrix", .target = rp2040.boards.waveshare.rp2040_matrix }, | ||
}; | ||
const available_examples = [_]Example{ | ||
.{ .name = "pico_adc", .target = rp2040.boards.raspberry_pi.pico, .file = "src/adc.zig" }, | ||
.{ .name = "pico_blinky", .target = rp2040.boards.raspberry_pi.pico, .file = "src/blinky.zig" }, | ||
// TODO: Fix multicore hal! .{ .name = "pico", .target = rp2040.boards.raspberry_pi.pico , .file = "src/blinky_core1.zig" }, | ||
.{ .name = "pico_flash-program", .target = rp2040.boards.raspberry_pi.pico, .file = "src/flash_program.zig" }, | ||
.{ .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{ | ||
"src/adc.zig", | ||
"src/blinky.zig", | ||
// TODO: Fix multicore hal! "src/blinky_core1.zig", | ||
"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", | ||
// .{ .name = "rp2040-eth", .target = rp2040.boards.waveshare.rp2040_eth }, | ||
// .{ .name = "rp2040-plus-4m", .target = rp2040.boards.waveshare.rp2040_plus_4m }, | ||
// .{ .name = "rp2040-plus-16m", .target = rp2040.boards.waveshare.rp2040_plus_16m }, | ||
// .{ .name = "rp2040-matrix", .target = rp2040.boards.waveshare.rp2040_matrix }, | ||
}; | ||
|
||
pub fn build(b: *std.Build) void { | ||
const microzig = @import("microzig").init(b, "microzig"); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
for (available_targets) |target| { | ||
for (available_examples) |example| { | ||
// `addFirmware` basically works like addExecutable, but takes a | ||
// `microzig.Target` for target instead of a `std.zig.CrossTarget`. | ||
// | ||
// The target will convey all necessary information on the chip, | ||
// cpu and potentially the board as well. | ||
const firmware = microzig.addFirmware(b, .{ | ||
.name = b.fmt("{s}-{s}", .{ std.fs.path.stem(example), target.name }), | ||
.target = target.target, | ||
.optimize = optimize, | ||
.source_file = .{ .path = example }, | ||
}); | ||
for (available_examples) |example| { | ||
// `addFirmware` basically works like addExecutable, but takes a | ||
// `microzig.Target` for target instead of a `std.zig.CrossTarget`. | ||
// | ||
// The target will convey all necessary information on the chip, | ||
// cpu and potentially the board as well. | ||
const firmware = microzig.addFirmware(b, .{ | ||
.name = example.name, | ||
.target = example.target, | ||
.optimize = optimize, | ||
.source_file = .{ .path = example.file }, | ||
}); | ||
|
||
// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()` | ||
// and allows installing the firmware as a typical firmware file. | ||
// | ||
// This will also install into `$prefix/firmware` instead of `$prefix/bin`. | ||
microzig.installFirmware(b, firmware, .{}); | ||
// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()` | ||
// and allows installing the firmware as a typical firmware file. | ||
// | ||
// This will also install into `$prefix/firmware` instead of `$prefix/bin`. | ||
microzig.installFirmware(b, firmware, .{}); | ||
|
||
// For debugging, we also always install the firmware as an ELF file | ||
microzig.installFirmware(b, firmware, .{ .format = .elf }); | ||
} | ||
// For debugging, we also always install the firmware as an ELF file | ||
microzig.installFirmware(b, firmware, .{ .format = .elf }); | ||
} | ||
} | ||
|
||
const TargetDesc = struct { | ||
const Example = struct { | ||
target: @import("microzig").Target, | ||
name: []const u8, | ||
file: []const u8, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters