rp2350

#zig#raspberry-pi

git clone https://git.pyrossh.dev/rp2350

code to drive rp2350


6a7717e — pyrossh 2025-04-18T21:06:22+05:30
initial commit

Generated files not shown: eda/package-lock.json

Files changed (14) hide show
  1. .gitignore +1 -0
  2. aa.zig +17 -0
  3. blinky.zig +22 -0
  4. build.zig +143 -0
  5. build.zig.zon +69 -0
  6. eda/.gitignore +26 -0
  7. eda/.npmrc +1 -0
  8. eda/index.tsx +10 -0
  9. eda/manual-edits.json +13 -0
  10. eda/package.json +18 -0
  11. eda/tsconfig.json +20 -0
  12. kaluma-rp2-pico2-w-1.2.0.uf2 +0 -0
  13. main.js +13 -0
  14. src/main.zig +24 -0
.gitignore ADDED
@@ -0,0 +1 @@
1
+ .zig-cache
aa.zig ADDED
@@ -0,0 +1,17 @@
1
+ const std = @import("std");
2
+ const stdout = std.io.getStdOut().writer();
3
+
4
+ pub fn main() !void {
5
+ var i: usize = 1;
6
+ while (i <= 16) : (i += 1) {
7
+ if (i % 15 == 0) {
8
+ try stdout.writeAll("ZiggZagg\n");
9
+ } else if (i % 3 == 0) {
10
+ try stdout.writeAll("Zigg\n");
11
+ } else if (i % 5 == 0) {
12
+ try stdout.writeAll("Zagg\n");
13
+ } else {
14
+ try stdout.print("{d}\n", .{i});
15
+ }
16
+ }
17
+ }
blinky.zig ADDED
@@ -0,0 +1,22 @@
1
+ const std = @import("std");
2
+ const microzig = @import("microzig");
3
+ const rp2xxx = microzig.hal;
4
+ const time = rp2xxx.time;
5
+
6
+ const pin_config = rp2xxx.pins.GlobalConfiguration{
7
+ .GPIO25 = .{
8
+ .name = "led",
9
+ .direction = .out,
10
+ },
11
+ };
12
+
13
+ const pins = pin_config.pins();
14
+
15
+ pub fn main() !void {
16
+ pin_config.apply();
17
+
18
+ while (true) {
19
+ pins.led.toggle();
20
+ time.sleep_ms(250);
21
+ }
22
+ }
build.zig ADDED
@@ -0,0 +1,143 @@
1
+ const std = @import("std");
2
+ const microzig = @import("microzig");
3
+
4
+ const MicroBuild = microzig.MicroBuild(.{
5
+ .rp2xxx = true,
6
+ });
7
+
8
+ pub fn build(b: *std.Build) void {
9
+ const mz_dep = b.dependency("microzig", .{});
10
+ const mb = MicroBuild.init(b, mz_dep) orelse return;
11
+
12
+ const firmware = mb.add_firmware(.{
13
+ .name = "blinky",
14
+ .target = mb.ports.rp2xxx.boards.raspberrypi.pico,
15
+ .optimize = .ReleaseSmall,
16
+ .root_source_file = b.path("src/main.zig"),
17
+ });
18
+
19
+ // We call this twice to demonstrate that the default binary output for
20
+ // RP2040 is UF2, but we can also output other formats easily
21
+ mb.install_firmware(firmware, .{});
22
+ mb.install_firmware(firmware, .{ .format = .elf });
23
+ }
24
+
25
+ // const std = @import("std");
26
+ // const microzig = @import("microzig");
27
+
28
+ // const MicroBuild = microzig.MicroBuild(.{
29
+ // .rp2xxx = true,
30
+ // });
31
+
32
+ // pub fn build(b: *std.Build) void {
33
+ // const optimize = b.standardOptimizeOption(.{});
34
+ // const maybe_example = b.option([]const u8, "example", "only build matching examples");
35
+
36
+ // const mz_dep = b.dependency("microzig", .{});
37
+ // const mb = MicroBuild.init(b, mz_dep) orelse return;
38
+
39
+ // const rp2040_only_examples: []const Example = &.{
40
+ // // RaspberryPi Boards:
41
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_flash-program", .file = "src/rp2040_only/flash_program.zig" },
42
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_flash-id", .file = "src/rp2040_only/flash_id.zig" },
43
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_random", .file = "src/rp2040_only/random.zig" },
44
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_rtc", .file = "src/rp2040_only/rtc.zig" },
45
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_usb-hid", .file = "src/rp2040_only/usb_hid.zig" },
46
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_multicore", .file = "src/rp2040_only/blinky_core1.zig" },
47
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_hd44780", .file = "src/rp2040_only/hd44780.zig" },
48
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_pcf8574", .file = "src/rp2040_only/pcf8574.zig" },
49
+ // .{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_i2c_slave", .file = "src/rp2040_only/i2c_slave.zig" },
50
+
51
+ // // WaveShare Boards:
52
+ // .{ .target = mb.ports.rp2xxx.boards.waveshare.rp2040_matrix, .name = "rp2040-matrix_tiles", .file = "src/rp2040_only/tiles.zig" },
53
+ // // .{ .target = "board:waveshare/rp2040_eth", .name = "rp2040-eth" },
54
+ // // .{ .target = "board:waveshare/rp2040_plus_4m", .name = "rp2040-plus-4m" },
55
+ // // .{ .target = "board:waveshare/rp2040_plus_16m", .name = "rp2040-plus-16m" },
56
+ // };
57
+
58
+ // const rp2350_only_examples: []const Example = &.{
59
+ // // TODO: No RP2350 feature specific examples to show off yet
60
+ // };
61
+
62
+ // const chip_agnostic_examples: []const ChipAgnosticExample = &.{
63
+ // .{ .name = "adc", .file = "src/adc.zig" },
64
+ // .{ .name = "i2c-bus-scan", .file = "src/i2c_bus_scan.zig" },
65
+ // .{ .name = "pwm", .file = "src/pwm.zig" },
66
+ // .{ .name = "uart-echo", .file = "src/uart_echo.zig" },
67
+ // .{ .name = "uart-log", .file = "src/uart_log.zig" },
68
+ // .{ .name = "spi-master", .file = "src/spi_master.zig" },
69
+ // .{ .name = "spi-slave", .file = "src/spi_slave.zig" },
70
+ // .{ .name = "squarewave", .file = "src/squarewave.zig" },
71
+ // .{ .name = "ws2812", .file = "src/ws2812.zig" },
72
+ // .{ .name = "blinky", .file = "src/blinky.zig" },
73
+ // .{ .name = "gpio-clock-output", .file = "src/gpio_clock_output.zig" },
74
+ // .{ .name = "changing-system-clocks", .file = "src/changing_system_clocks.zig" },
75
+ // .{ .name = "custom-clock-config", .file = "src/custom_clock_config.zig" },
76
+ // .{ .name = "watchdog-timer", .file = "src/watchdog_timer.zig" },
77
+ // .{ .name = "interrupts", .file = "src/interrupts.zig" },
78
+ // .{ .name = "stepper", .file = "src/stepper.zig" },
79
+ // .{ .name = "usb-cdc", .file = "src/usb_cdc.zig" },
80
+ // };
81
+
82
+ // var available_examples = std.ArrayList(Example).init(b.allocator);
83
+ // available_examples.appendSlice(rp2040_only_examples) catch @panic("out of memory");
84
+ // available_examples.appendSlice(rp2350_only_examples) catch @panic("out of memory");
85
+ // for (chip_agnostic_examples) |example| {
86
+ // available_examples.append(.{
87
+ // .target = mb.ports.rp2xxx.boards.raspberrypi.pico,
88
+ // .name = b.fmt("pico_{s}", .{example.name}),
89
+ // .file = example.file,
90
+ // }) catch @panic("out of memory");
91
+
92
+ // available_examples.append(.{
93
+ // .target = mb.ports.rp2xxx.boards.raspberrypi.pico2_arm,
94
+ // .name = b.fmt("pico2_arm_{s}", .{example.name}),
95
+ // .file = example.file,
96
+ // }) catch @panic("out of memory");
97
+
98
+ // available_examples.append(.{
99
+ // .target = mb.ports.rp2xxx.boards.raspberrypi.pico2_riscv,
100
+ // .name = b.fmt("pico2_riscv_{s}", .{example.name}),
101
+ // .file = example.file,
102
+ // }) catch @panic("out of memory");
103
+ // }
104
+
105
+ // for (available_examples.items) |example| {
106
+ // // If we specify example, only select the ones that match
107
+ // if (maybe_example) |selected_example|
108
+ // if (!std.mem.containsAtLeast(u8, example.name, 1, selected_example))
109
+ // continue;
110
+
111
+ // // `add_firmware` basically works like addExecutable, but takes a
112
+ // // `microzig.Target` for target instead of a `std.zig.CrossTarget`.
113
+ // //
114
+ // // The target will convey all necessary information on the chip,
115
+ // // cpu and potentially the board as well.
116
+ // const firmware = mb.add_firmware(.{
117
+ // .name = example.name,
118
+ // .target = example.target,
119
+ // .optimize = optimize,
120
+ // .root_source_file = b.path(example.file),
121
+ // });
122
+
123
+ // // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`
124
+ // // and allows installing the firmware as a typical firmware file.
125
+ // //
126
+ // // This will also install into `$prefix/firmware` instead of `$prefix/bin`.
127
+ // mb.install_firmware(firmware, .{});
128
+
129
+ // // For debugging, we also always install the firmware as an ELF file
130
+ // mb.install_firmware(firmware, .{ .format = .elf });
131
+ // }
132
+ // }
133
+
134
+ // const Example = struct {
135
+ // target: *const microzig.Target,
136
+ // name: []const u8,
137
+ // file: []const u8,
138
+ // };
139
+
140
+ // const ChipAgnosticExample = struct {
141
+ // name: []const u8,
142
+ // file: []const u8,
143
+ // };
build.zig.zon ADDED
@@ -0,0 +1,69 @@
1
+ .{
2
+ // This is the default name used by packages depending on this one. For
3
+ // example, when a user runs `zig fetch --save <url>`, this field is used
4
+ // as the key in the `dependencies` table. Although the user can choose a
5
+ // different name, most users will stick with this provided value.
6
+ //
7
+ // It is redundant to include "zig" in this name because it is already
8
+ // within the Zig package namespace.
9
+ .name = .rp2040,
10
+
11
+ // This is a [Semantic Version](https://semver.org/).
12
+ // In a future version of Zig it will be used for package deduplication.
13
+ .version = "0.0.0",
14
+
15
+ // Together with name, this represents a globally unique package
16
+ // identifier. This field is generated by the Zig toolchain when the
17
+ // package is first created, and then *never changes*. This allows
18
+ // unambiguous detection of one package being an updated version of
19
+ // another.
20
+ //
21
+ // When forking a Zig project, this id should be regenerated (delete the
22
+ // field and run `zig build`) if the upstream project is still maintained.
23
+ // Otherwise, the fork is *hostile*, attempting to take control over the
24
+ // original project's identity. Thus it is recommended to leave the comment
25
+ // on the following line intact, so that it shows up in code reviews that
26
+ // modify the field.
27
+ .fingerprint = 0xed40fb47bc802c59, // Changing this has security and trust implications.
28
+
29
+ // Tracks the earliest Zig version that the package considers to be a
30
+ // supported use case.
31
+ .minimum_zig_version = "0.14.0",
32
+
33
+ // This field is optional.
34
+ // Each dependency must either provide a `url` and `hash`, or a `path`.
35
+ // `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
36
+ // Once all dependencies are fetched, `zig build` no longer requires
37
+ // internet connectivity.
38
+ .dependencies = .{
39
+ .microzig = .{
40
+ .url = "https://microzig.tech/downloads/microzig/0.13.2/microzig.tar.gz",
41
+ .hash = "microzig-0.13.2-AAAAAEAoCACJtVQID09BdlBX63hCLqdwobnQC5A_1QfO",
42
+ },
43
+ },
44
+ .paths = .{
45
+ "build.zig",
46
+ "build.zig.zon",
47
+ "src",
48
+ // For example...
49
+ //"LICENSE",
50
+ //"README.md",
51
+ },
52
+ }
53
+
54
+ // .{
55
+ // .name = .examples_raspberrypi_rp2xxx,
56
+ // .fingerprint = 0xffa4bfa151162a57,
57
+ // .version = "0.0.0",
58
+ // .dependencies = .{
59
+ // .microzig = .{ .path = "../../.." },
60
+ // },
61
+ // .paths = .{
62
+ // "LICENSE",
63
+ // "README.md",
64
+ // "build.zig",
65
+ // "build.zig.zon",
66
+ // "src",
67
+ // "scripts",
68
+ // },
69
+ // }
eda/.gitignore ADDED
@@ -0,0 +1,26 @@
1
+ # Dependencies
2
+ node_modules/
3
+
4
+ # Build output
5
+ dist/
6
+ build/
7
+
8
+ # Environment variables
9
+ .env
10
+ .env.local
11
+ .env.*.local
12
+
13
+ # IDE files
14
+ .vscode/
15
+ .idea/
16
+ *.swp
17
+ *.swo
18
+
19
+ # OS files
20
+ .DS_Store
21
+ Thumbs.db
22
+
23
+ # Debug logs
24
+ npm-debug.log*
25
+ yarn-debug.log*
26
+ yarn-error.log*
eda/.npmrc ADDED
@@ -0,0 +1 @@
1
+ @tsci:registry=https://npm.tscircuit.com
eda/index.tsx ADDED
@@ -0,0 +1,10 @@
1
+ export default () => (
2
+ <board width="20mm" height="20mm" schTraceAutoLabelEnabled schAutoLayoutEnabled>
3
+ <resistor name="R1" resistance="1k" footprint="0402" />
4
+ <capacitor name="C1" capacitance="1000pF" footprint="0402" />
5
+ <resistor name="R2" resistance="2k" footprint="0402" />
6
+ <capacitor name="C2" capacitance="1000pF" footprint="0402" />
7
+ <trace from=".R1 > .pin1" to=".C1 > .pin1" />
8
+ <trace from=".R2 > .pin1" to=".C2 > .pin2" />
9
+ </board>
10
+ );
eda/manual-edits.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "schematic_placements": [],
3
+ "pcb_placements": [
4
+ {
5
+ "selector": "C2",
6
+ "center": {
7
+ "x": -8.023810013025601,
8
+ "y": 6.234023579882503
9
+ },
10
+ "relative_to": "group_center"
11
+ }
12
+ ]
13
+ }
eda/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "tss",
3
+ "version": "1.0.0",
4
+ "description": "A TSCircuit project",
5
+ "main": "index.tsx",
6
+ "keywords": [
7
+ "tscircuit",
8
+ "electronics"
9
+ ],
10
+ "scripts": {
11
+ "dev": "tsci dev",
12
+ "build": "tsci build"
13
+ },
14
+ "devDependencies": {
15
+ "@tscircuit/core": "^0.0.359",
16
+ "@types/react": "^19.0.12"
17
+ }
18
+ }
eda/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "module": "ESNext",
5
+ "jsx": "react-jsx",
6
+ "outDir": "dist",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "moduleResolution": "node",
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "sourceMap": true,
14
+ "allowSyntheticDefaultImports": true,
15
+ "experimentalDecorators": true,
16
+ "types": [
17
+ "@tscircuit/core"
18
+ ]
19
+ }
20
+ }
kaluma-rp2-pico2-w-1.2.0.uf2 ADDED
Binary file
main.js ADDED
@@ -0,0 +1,13 @@
1
+ pinMode(0, OUTPUT);
2
+ pinMode(1, INPUT_PULLUP);
3
+ pinMode(26, INPUT)
4
+
5
+ attachInterrupt(1, (pin, mode) => {
6
+ console.log(analogRead(26));
7
+ if (digitalRead(1) === LOW) {
8
+ digitalWrite(0, HIGH)
9
+ }
10
+ if (digitalRead(1) === HIGH) {
11
+ digitalWrite(0, LOW)
12
+ }
13
+ }, CHANGE);
src/main.zig ADDED
@@ -0,0 +1,24 @@
1
+ const std = @import("std");
2
+ const microzig = @import("microzig");
3
+ const rp2xxx = microzig.hal;
4
+ const time = rp2xxx.time;
5
+
6
+ // Compile-time pin configuration
7
+ const pin_config = rp2xxx.pins.GlobalConfiguration{
8
+ .GPIO25 = .{
9
+ .name = "led",
10
+ .direction = .out,
11
+ },
12
+ };
13
+
14
+ const pins = pin_config.pins();
15
+
16
+ pub fn main() !void {
17
+ pin_config.apply();
18
+ pin_config.apply();
19
+
20
+ while (true) {
21
+ pins.led.toggle();
22
+ time.sleep_ms(250);
23
+ }
24
+ }