~repos /rp2350

#zig#raspberry-pi

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

code to drive rp2350


9f7e5aa2 pyrossh

7 months ago
get zig example working
Files changed (4) hide show
  1. build.zig +2 -3
  2. readme.md +5 -0
  3. src/aa.zig +18 -18
  4. src/main.zig +14 -12
build.zig CHANGED
@@ -11,8 +11,8 @@ pub fn build(b: *std.Build) void {
11
11
  const mb = MicroBuild.init(b, mz_dep) orelse return;
12
12
 
13
13
  const firmware = mb.add_firmware(.{
14
- .name = "pico_blinky",
14
+ .name = "rp2350",
15
- .target = mb.ports.rp2xxx.boards.raspberrypi.pico,
15
+ .target = mb.ports.rp2xxx.boards.raspberrypi.pico2_arm,
16
16
  .optimize = optimize,
17
17
  .root_source_file = b.path("src/main.zig"),
18
18
  });
@@ -20,5 +20,4 @@ pub fn build(b: *std.Build) void {
20
20
  // We call this twice to demonstrate that the default binary output for
21
21
  // RP2040 is UF2, but we can also output other formats easily
22
22
  mb.install_firmware(firmware, .{});
23
- mb.install_firmware(firmware, .{ .format = .elf });
24
23
  }
readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # RP2350 Dev Board
2
+
3
+ ## Run
4
+ 1. `zig build`
5
+ 2. `picotool load -x zig-out/firmware/rp2350.uf2 -f`
src/aa.zig CHANGED
@@ -1,24 +1,6 @@
1
1
  const std = @import("std");
2
2
  const stdout = std.io.getStdOut().writer();
3
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
- for (0..10) |j| {
18
- std.debug.print("{d}\n", .{j});
19
- }
20
- }
21
-
22
4
  pub const User = struct {
23
5
  power: u64,
24
6
  name: []const u8,
@@ -73,3 +55,21 @@ const Timestamp = union(TimestampType) {
73
55
  };
74
56
 
75
57
  const user = User{ .name = "Goku" };
58
+
59
+ pub fn main() !void {
60
+ var i: usize = 1;
61
+ while (i <= 16) : (i += 1) {
62
+ if (i % 15 == 0) {
63
+ try stdout.writeAll("ZiggZagg\n");
64
+ } else if (i % 3 == 0) {
65
+ try stdout.writeAll("Zigg\n");
66
+ } else if (i % 5 == 0) {
67
+ try stdout.writeAll("Zagg\n");
68
+ } else {
69
+ try stdout.print("{d}\n", .{i});
70
+ }
71
+ }
72
+ for (0..10) |j| {
73
+ std.debug.print("{d}\n", .{j});
74
+ }
75
+ }
src/main.zig CHANGED
@@ -2,23 +2,25 @@ const std = @import("std");
2
2
  const microzig = @import("microzig");
3
3
  const rp2xxx = microzig.hal;
4
4
  const time = rp2xxx.time;
5
+ const gpio = rp2xxx.gpio;
5
6
 
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();
7
+ const ssr = gpio.num(0);
8
+ const button = gpio.num(1);
15
9
 
16
10
  pub fn main() !void {
11
+ ssr.set_function(.sio);
12
+ ssr.set_direction(.out);
13
+ button.set_function(.sio);
14
+ button.set_direction(.in);
17
- pin_config.apply();
15
+ button.set_pull(.up);
18
- pin_config.apply();
19
16
 
20
17
  while (true) {
21
- pins.led.toggle();
18
+ const a = button.read();
19
+ if (a == 0) {
20
+ ssr.put(1);
21
+ } else {
22
+ ssr.put(0);
23
+ }
22
24
  time.sleep_ms(250);
23
25
  }
24
26
  }