~repos /rp2350

#zig#raspberry-pi

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

code to drive rp2350


3ab0b514 pyrossh

7 months ago
get build working
Files changed (6) hide show
  1. .gitignore +2 -1
  2. aa.zig +0 -17
  3. blinky.zig +0 -22
  4. build.zig +3 -122
  5. build.zig.zon +4 -56
  6. src/aa.zig +75 -0
.gitignore CHANGED
@@ -1 +1,2 @@
1
- .zig-cache
1
+ .zig-cache
2
+ zig-out
aa.zig DELETED
@@ -1,17 +0,0 @@
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 DELETED
@@ -1,22 +0,0 @@
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 CHANGED
@@ -6,13 +6,14 @@ const MicroBuild = microzig.MicroBuild(.{
6
6
  });
7
7
 
8
8
  pub fn build(b: *std.Build) void {
9
+ const optimize = b.standardOptimizeOption(.{});
9
10
  const mz_dep = b.dependency("microzig", .{});
10
11
  const mb = MicroBuild.init(b, mz_dep) orelse return;
11
12
 
12
13
  const firmware = mb.add_firmware(.{
13
- .name = "blinky",
14
+ .name = "pico_blinky",
14
15
  .target = mb.ports.rp2xxx.boards.raspberrypi.pico,
15
- .optimize = .ReleaseSmall,
16
+ .optimize = optimize,
16
17
  .root_source_file = b.path("src/main.zig"),
17
18
  });
18
19
 
@@ -21,123 +22,3 @@ pub fn build(b: *std.Build) void {
21
22
  mb.install_firmware(firmware, .{});
22
23
  mb.install_firmware(firmware, .{ .format = .elf });
23
24
  }
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 CHANGED
@@ -1,69 +1,17 @@
1
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,
2
+ .name = .rp2350,
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
3
  .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.
4
+ .fingerprint = 0xf61d745fc6e28443,
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
5
  .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
6
  .dependencies = .{
39
7
  .microzig = .{
40
- .url = "https://microzig.tech/downloads/microzig/0.13.2/microzig.tar.gz",
8
+ .url = "git+https://github.com/ZigEmbeddedGroup/microzig.git#36c2517dd56d675fcd64a2d6e8fc8e7a053a0f15",
41
- .hash = "microzig-0.13.2-AAAAAEAoCACJtVQID09BdlBX63hCLqdwobnQC5A_1QfO",
9
+ .hash = "microzig-0.14.0-D20YSUoZagN9r5VoCh6qtb1ljAIFSAG19ED5EiqiVhvk",
42
10
  },
43
11
  },
44
12
  .paths = .{
45
13
  "build.zig",
46
14
  "build.zig.zon",
47
15
  "src",
48
- // For example...
49
- //"LICENSE",
50
- //"README.md",
51
16
  },
52
17
  }
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
- // }
src/aa.zig ADDED
@@ -0,0 +1,75 @@
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
+ for (0..10) |j| {
18
+ std.debug.print("{d}\n", .{j});
19
+ }
20
+ }
21
+
22
+ pub const User = struct {
23
+ power: u64,
24
+ name: []const u8,
25
+
26
+ pub const SUPER_POWER = 9000;
27
+
28
+ pub fn diagnose(self: User) void {
29
+ if (self.power >= SUPER_POWER) {
30
+ std.debug.print("it's over {d}!!!", .{SUPER_POWER});
31
+ }
32
+ }
33
+ };
34
+
35
+ const Stage = enum {
36
+ validate,
37
+ awaiting_confirmation,
38
+ confirmed,
39
+ err,
40
+
41
+ fn isComplete(self: Stage) bool {
42
+ return self == .confirmed or self == .err;
43
+ }
44
+ };
45
+
46
+ const TimestampType = enum {
47
+ unix,
48
+ datetime,
49
+ };
50
+
51
+ const Timestamp = union(TimestampType) {
52
+ unix: i32,
53
+ datetime: DateTime,
54
+
55
+ const DateTime = struct {
56
+ year: u16,
57
+ month: u8,
58
+ day: u8,
59
+ hour: u8,
60
+ minute: u8,
61
+ second: u8,
62
+ };
63
+
64
+ fn seconds(self: Timestamp) u16 {
65
+ switch (self) {
66
+ .datetime => |dt| return dt.second,
67
+ .unix => |ts| {
68
+ const seconds_since_midnight: i32 = @rem(ts, 86400);
69
+ return @intCast(@rem(seconds_since_midnight, 60));
70
+ },
71
+ }
72
+ }
73
+ };
74
+
75
+ const user = User{ .name = "Goku" };