736f723f pyrossh

tag: v0.0.2tag: v0.0.1

v0.0.2 v0.0.1

8 months ago
get openocd working
build.zig CHANGED
@@ -20,4 +20,5 @@ 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 });
23
24
  }
{src → docs}/aa.zig RENAMED
File without changes
kaluma-rp2-pico2-w-1.2.0.uf2 → docs/kaluma-rp2-pico2-w-1.2.0.uf2 RENAMED
File without changes
main.js → docs/main.js RENAMED
File without changes
docs/openocd.tar.gz ADDED
Binary file
readme.md CHANGED
@@ -1,10 +1,31 @@
1
1
  # RP2350 Dev Board
2
2
 
3
+ ## Setup
4
+ 1. `brew install zig open-ocd arm-none-eabi-gdb`
5
+
6
+ If open-ocd doesn't work build from source,
7
+
8
+ `brew remove open-ocd`
9
+ `brew install pkg-config autoconf automake texinfo libfdti hidpi jimtcl`
10
+ `untar docs/openocd.tar.gz`
11
+ `./boostrap`
12
+ `./configure --enable-target=rp2350 --enable-interface=jtag`
13
+ `make`
14
+ `sudo make install`
15
+
3
16
  ## Run
4
17
  1. `zig build`
5
18
  2. `picotool load -x zig-out/firmware/rp2350.uf2 -f`
6
19
 
7
20
 
21
+ # Start OCD Server
22
+
23
+ `sudo openocd -s tcl -f interface/cmsis-dap.cfg -f target/rp2350.cfg -c "adapter speed 5000"sudo openocd -s tcl -f interface/cmsis-dap.cfg -f target/rp2350.cfg -c "adapter speed 5000"`
24
+
25
+ # Flash OCD Program
26
+
27
+ `sudo openocd -f interface/cmsis-dap.cfg -f target/rp2350.cfg -c "adapter speed 5000" -c "program zig-out/firmware/rp2350.elf verify reset exit"`
28
+
8
29
  ```c
9
30
  // Flash allocation map 4MB for pico 2W
10
31
  //
src/main.zig CHANGED
@@ -5,14 +5,20 @@ const time = rp2xxx.time;
5
5
  const gpio = rp2xxx.gpio;
6
6
  const SPI0 = rp2xxx.spi.instance.SPI0;
7
7
 
8
+ const uart = rp2xxx.uart.instance.num(0);
9
+ const uart_baud_rate = 115200;
10
+ const uart_tx_pin = gpio.num(0);
11
+ const uart_rx_pin = gpio.num(1);
12
+
8
- const ssr = gpio.num(0);
13
+ const ssr = gpio.num(26);
9
- const button = gpio.num(1);
14
+ const button = gpio.num(27);
10
15
  const miso = gpio.num(16);
11
16
  const csn = gpio.num(17);
12
17
  const sck = gpio.num(18);
13
18
  const mosi = gpio.num(19);
14
19
  const dc = gpio.num(20);
15
20
  const rst = gpio.num(21);
21
+
16
22
  // spi = SPI(0, 40_000_000, sck=Pin(18), mosi=Pin(19), miso=Pin(16))
17
23
  // display = Display(spi, gamma=False, bgr=False, dc=Pin(20), cs=Pin(17), rst=Pin(21))
18
24
  // display.clear(color565(64, 0, 255))
@@ -24,6 +30,17 @@ const Command = struct {
24
30
  delay_ms: ?u32 = null,
25
31
  };
26
32
 
33
+ // const initDisplayCommands = [
34
+ // Command(code: 0x01, data: [], delay_ms: 150),
35
+ // Command(code: 0x01, data: [], delay_ms: 150),
36
+ // Command(code: 0x01, data: [], delay_ms: 150),
37
+ // Command(code: 0x01, data: [], delay_ms: 150),
38
+ // Command(code: 0x01, data: [], delay_ms: 150),
39
+ // Command(code: 0x01, data: [], delay_ms: 150),
40
+ // Command(code: 0x01, data: [], delay_ms: 150),
41
+ // Command(code: 0x01, data: [], delay_ms: 150),
42
+ //]
43
+
27
44
  const initDisplayCommands: []const Command = &.{
28
45
  .{ .code = 0x01, .data = &.{}, .delay_ms = 150 }, // Software reset
29
46
  // .{ .code = 0xEF, .data = &.{ 0x03, 0x80, 0x02 } },
@@ -81,6 +98,77 @@ fn block(x0: u16, y0: u16, x1: u16, y1: u16, data: []const u8) void {
81
98
  send(Command{ .code = 0x2C, .data = data });
82
99
  }
83
100
 
101
+ fn draw_pixel(x: u16, y: u16, color: u16) void {
102
+ block(x, y, x, y, &.{color});
103
+ }
104
+
105
+ // def draw_circle(self, x0, y0, r, color):
106
+ // """Draw a circle.
107
+
108
+ // Args:
109
+ // x0 (int): X coordinate of center point.
110
+ // y0 (int): Y coordinate of center point.
111
+ // r (int): Radius.
112
+ // color (int): RGB565 color value.
113
+ // """
114
+ // f = 1 - r
115
+ // dx = 1
116
+ // dy = -r - r
117
+ // x = 0
118
+ // y = r
119
+ // self.draw_pixel(x0, y0 + r, color)
120
+ // self.draw_pixel(x0, y0 - r, color)
121
+ // self.draw_pixel(x0 + r, y0, color)
122
+ // self.draw_pixel(x0 - r, y0, color)
123
+ // while x < y:
124
+ // if f >= 0:
125
+ // y -= 1
126
+ // dy += 2
127
+ // f += dy
128
+ // x += 1
129
+ // dx += 2
130
+ // f += dx
131
+ // self.draw_pixel(x0 + x, y0 + y, color)
132
+ // self.draw_pixel(x0 - x, y0 + y, color)
133
+ // self.draw_pixel(x0 + x, y0 - y, color)
134
+ // self.draw_pixel(x0 - x, y0 - y, color)
135
+ // self.draw_pixel(x0 + y, y0 + x, color)
136
+ // self.draw_pixel(x0 - y, y0 + x, color)
137
+ // self.draw_pixel(x0 + y, y0 - x, color)
138
+ // self.draw_pixel(x0 - y, y0 - x, color)
139
+
140
+ // def draw_image(self, path, x=0, y=0, w=320, h=240):
141
+ // """Draw image from flash.
142
+
143
+ // Args:
144
+ // path (string): Image file path.
145
+ // x (int): X coordinate of image left. Default is 0.
146
+ // y (int): Y coordinate of image top. Default is 0.
147
+ // w (int): Width of image. Default is 320.
148
+ // h (int): Height of image. Default is 240.
149
+ // """
150
+ // x2 = x + w - 1
151
+ // y2 = y + h - 1
152
+ // if self.is_off_grid(x, y, x2, y2):
153
+ // return
154
+ // with open(path, "rb") as f:
155
+ // chunk_height = 1024 // w
156
+ // chunk_count, remainder = divmod(h, chunk_height)
157
+ // chunk_size = chunk_height * w * 2
158
+ // chunk_y = y
159
+ // if chunk_count:
160
+ // for c in range(0, chunk_count):
161
+ // buf = f.read(chunk_size)
162
+ // self.block(x, chunk_y,
163
+ // x2, chunk_y + chunk_height - 1,
164
+ // buf)
165
+ // chunk_y += chunk_height
166
+ // if remainder:
167
+ // buf = f.read(remainder * w * 2)
168
+ // self.block(x, chunk_y,
169
+ // x2, chunk_y + remainder - 1,
170
+ // buf)
171
+
84
172
  fn color565(r: u32, g: u32, b: u32) u16 {
85
173
  return (r & 0xF8) << 8 | (g & 0xFC) << 3 | b >> 3;
86
174
  }
@@ -111,6 +199,12 @@ pub fn main() !void {
111
199
  inline for (&.{ miso, mosi, sck }) |pin| {
112
200
  pin.set_function(.spi);
113
201
  }
202
+ uart_tx_pin.set_function(.uart);
203
+ uart_rx_pin.set_function(.uart);
204
+ uart.apply(.{
205
+ .baud_rate = uart_baud_rate,
206
+ .clock_config = rp2xxx.clock_config,
207
+ });
114
208
  ssr.set_function(.sio);
115
209
  ssr.set_direction(.out);
116
210
  csn.set_function(.sio);
@@ -155,17 +249,16 @@ pub fn main() !void {
155
249
  }
156
250
  }
157
251
 
158
- // const expect = std.testing.expect;
252
+ const expect = std.testing.expect;
159
253
 
160
- // fn data2(v: u8) u8 {
254
+ fn data2(v: u8) u8 {
161
- // return v;
255
+ return v;
162
- // }
256
+ }
163
-
164
- // test "truncate u16 to u6" {
165
- // const a: u16 = 320;
166
- // try expect(data2(@truncate(a)) == 64);
167
- // try expect(320 & 0xFF == 64);
168
- // try expect(320 >> 8 == 1);
169
257
 
258
+ test "truncate u16 to u6" {
259
+ const a: u16 = 320;
260
+ try expect(data2(@truncate(a)) == 64);
261
+ try expect(320 & 0xFF == 64);
262
+ try expect(320 >> 8 == 1);
170
- // try expect(data2(@intCast(a >> 8)) == 1);
263
+ try expect(data2(@intCast(a >> 8)) == 1);
171
- // }
264
+ }