376c0f5e
—
pyrossh 7 months ago
initial display
- docs/connecting-to-the-internet-with-pico-w.pdf +0 -0
- docs/getting-started-with-pico.pdf +0 -0
- docs/hardware-design-with-rp2350.pdf +0 -0
- docs/pico2w.png +0 -0
- docs/raspberry-pi-pico-c-sdk.pdf +0 -0
- docs/rp2350-datasheet.pdf +0 -0
- docs/rp2350-product-brief.pdf +0 -0
- readme.md +27 -1
- src/main.zig +129 -0
docs/connecting-to-the-internet-with-pico-w.pdf
ADDED
|
Binary file
|
docs/getting-started-with-pico.pdf
ADDED
|
Binary file
|
docs/hardware-design-with-rp2350.pdf
ADDED
|
Binary file
|
docs/pico2w.png
ADDED
|
Binary file
|
docs/raspberry-pi-pico-c-sdk.pdf
ADDED
|
Binary file
|
docs/rp2350-datasheet.pdf
ADDED
|
Binary file
|
docs/rp2350-product-brief.pdf
ADDED
|
Binary file
|
readme.md
CHANGED
|
@@ -2,4 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
## Run
|
|
4
4
|
1. `zig build`
|
|
5
|
-
2. `picotool load -x zig-out/firmware/rp2350.uf2 -f`
|
|
5
|
+
2. `picotool load -x zig-out/firmware/rp2350.uf2 -f`
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
```c
|
|
9
|
+
// Flash allocation map 4MB for pico 2W
|
|
10
|
+
//
|
|
11
|
+
// |------------------------------------------------|
|
|
12
|
+
// | A | B | C | D |
|
|
13
|
+
// |----------------|---|-----------|---------------|
|
|
14
|
+
// | 1024K |64K| 1472K | 1536K |
|
|
15
|
+
// |------------------------------------------------|
|
|
16
|
+
// |----------- flash.c -----------|
|
|
17
|
+
|
|
18
|
+
// |------ 1MB -----|------------- 3MB -------------|
|
|
19
|
+
// |---------------------- 4MB ---------------------|
|
|
20
|
+
//
|
|
21
|
+
// - A : binary (firmware)
|
|
22
|
+
// - B : storage (key-value database)
|
|
23
|
+
// - C : user program (js)
|
|
24
|
+
// - D : file system (lfs)
|
|
25
|
+
// (Total : 4MB)
|
|
26
|
+
|
|
27
|
+
// file system on flash (1024K)
|
|
28
|
+
// - sector base : 400
|
|
29
|
+
// - sector count : 384
|
|
30
|
+
// - use block device : new Flash(400, 384)
|
|
31
|
+
```
|
src/main.zig
CHANGED
|
@@ -3,17 +3,146 @@ const microzig = @import("microzig");
|
|
|
3
3
|
const rp2xxx = microzig.hal;
|
|
4
4
|
const time = rp2xxx.time;
|
|
5
5
|
const gpio = rp2xxx.gpio;
|
|
6
|
+
const SPI0 = rp2xxx.spi.instance.SPI0;
|
|
6
7
|
|
|
7
8
|
const ssr = gpio.num(0);
|
|
8
9
|
const button = gpio.num(1);
|
|
10
|
+
const miso = gpio.num(16);
|
|
11
|
+
const csn = gpio.num(17);
|
|
12
|
+
const sck = gpio.num(18);
|
|
13
|
+
const mosi = gpio.num(19);
|
|
14
|
+
const dc = gpio.num(20);
|
|
15
|
+
const rst = gpio.num(21);
|
|
16
|
+
// spi = SPI(0, 40_000_000, sck=Pin(18), mosi=Pin(19), miso=Pin(16))
|
|
17
|
+
// display = Display(spi, gamma=False, bgr=False, dc=Pin(20), cs=Pin(17), rst=Pin(21))
|
|
18
|
+
// display.clear(color565(64, 0, 255))
|
|
19
|
+
// sleep(1)
|
|
20
|
+
|
|
21
|
+
const Command = struct {
|
|
22
|
+
code: u8,
|
|
23
|
+
data: []const u8,
|
|
24
|
+
delay_ms: ?u32 = null,
|
|
25
|
+
};
|
|
26
|
+
// MIRROR_ROTATE = { # MADCTL configurations for rotation and mirroring
|
|
27
|
+
// (False, 0): 0x80, # 1000 0000
|
|
28
|
+
// (False, 90): 0xE0, # 1110 0000
|
|
29
|
+
// (False, 180): 0x40, # 0100 0000
|
|
30
|
+
// (False, 270): 0x20, # 0010 0000
|
|
31
|
+
// (True, 0): 0xC0, # 1100 0000
|
|
32
|
+
// (True, 90): 0x60, # 0110 0000
|
|
33
|
+
// (True, 180): 0x00, # 0000 0000
|
|
34
|
+
// (True, 270): 0xA0, # 1010 0000
|
|
35
|
+
// }
|
|
36
|
+
// self.write_cmd(self.MADCTL, self.rotation) # Memory access ctrl
|
|
37
|
+
|
|
38
|
+
const initDisplayCommands: []const Command = &.{
|
|
39
|
+
Command{ .code = 0x01, .data = &.{}, .delay_ms = 150 }, // Software reset
|
|
40
|
+
Command{ .code = 0xEF, .data = &.{ 0x03, 0x80, 0x02 } },
|
|
41
|
+
Command{ .code = 0xCF, .data = &.{ 0x00, 0xC1, 0x30 } }, // Pwr ctrl B
|
|
42
|
+
Command{ .code = 0xED, .data = &.{ 0x64, 0x03, 0x12, 0x81 } }, // # Pwr on seq. ctrl
|
|
43
|
+
Command{ .code = 0xE8, .data = &.{ 0x85, 0x00, 0x78 } }, // Driver timing ctrl A
|
|
44
|
+
Command{ .code = 0xCB, .data = &.{ 0x39, 0x2C, 0x00, 0x34, 0x02 } }, // Pwr ctrl A
|
|
45
|
+
Command{ .code = 0xF7, .data = &.{0x20} }, // Pump ratio control
|
|
46
|
+
Command{ .code = 0xEA, .data = &.{ 0x00, 0x00 } }, // Driver timing ctrl B
|
|
47
|
+
Command{ .code = 0xC0, .data = &.{0x23} }, // Pwr ctrl 1
|
|
48
|
+
Command{ .code = 0xC1, .data = &.{0x10} }, // Pwr ctrl 2
|
|
49
|
+
Command{ .code = 0xC5, .data = &.{ 0x3E, 0x28 } }, // VCM control1
|
|
50
|
+
Command{ .code = 0xC7, .data = &.{0x86} }, // VCM control2
|
|
51
|
+
Command{ .code = 0x36, .data = &.{0x48} }, // Memory Access Control
|
|
52
|
+
Command{ .code = 0x37, .data = &.{0x00} }, // Vertical scroll zero
|
|
53
|
+
Command{ .code = 0x3A, .data = &.{0x55} }, // COLMOD: Pixel Format Set
|
|
54
|
+
Command{ .code = 0xB1, .data = &.{ 0x00, 0x18 } }, // Frame Rate Control (In Normal Mode/Full Colors)
|
|
55
|
+
Command{ .code = 0xB6, .data = &.{ 0x08, 0x82, 0x27 } }, // Display Function Control
|
|
56
|
+
Command{ .code = 0xF2, .data = &.{0x00} }, // 3Gamma Function Disable
|
|
57
|
+
Command{ .code = 0x26, .data = &.{0x01} }, // Gamma curve selected
|
|
58
|
+
// Command{ .code = 0xE0, .data = &.{ 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00 } }, // Set Gamma Positive Gamma Correction
|
|
59
|
+
// Command{ .code = 0xE1, .data = &.{ 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F } }, // Set Gamma Negative Gamma Correction
|
|
60
|
+
Command{ .code = 0x11, .data = &.{}, .delay_ms = 150 }, // Exit Sleep/Sleep Out
|
|
61
|
+
Command{ .code = 0x29, .data = &.{}, .delay_ms = 150 }, // Display on
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
fn send(self: Command) void {
|
|
65
|
+
dc.put(0);
|
|
66
|
+
csn.put(0);
|
|
67
|
+
SPI0.write_blocking(u8, &.{self.code});
|
|
68
|
+
csn.put(1);
|
|
69
|
+
if (self.data.len > 0) {
|
|
70
|
+
sendData(self.data);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
fn sendData(data: []const u8) void {
|
|
75
|
+
dc.put(1);
|
|
76
|
+
csn.put(0);
|
|
77
|
+
SPI0.write_blocking(u8, data);
|
|
78
|
+
csn.put(1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Write a block of data to display.
|
|
82
|
+
//
|
|
83
|
+
// Args:
|
|
84
|
+
// x0 (int): Starting X position.
|
|
85
|
+
// y0 (int): Starting Y position.
|
|
86
|
+
// x1 (int): Ending X position.
|
|
87
|
+
// y1 (int): Ending Y position.
|
|
88
|
+
// data (bytes): Data buffer to write.
|
|
89
|
+
fn block(x0: u8, y0: u8, x1: u8, y1: u8) void {
|
|
90
|
+
send(Command{ .code = 0x2A, .data = &.{ x0 >> 8, x0 & 0xFF, x1 >> 8, x1 & 0xFF } }); // Column address set
|
|
91
|
+
send(Command{ .code = 0x2B, .data = &.{ y0 >> 8, y0 & 0xFF, y1 >> 8, y1 & 0xFF } }); // Page address set
|
|
92
|
+
send(Command{ .code = 0x2C, .data = &{} }); // Memory write
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fn clear() void {
|
|
96
|
+
var buffer: [][]u16 = &.{};
|
|
97
|
+
for (0..320 - 1) |i| {
|
|
98
|
+
buffer[i] = &.{};
|
|
99
|
+
for (0..240 - 1) |j| {
|
|
100
|
+
buffer[i][j] = 0xFFFF;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
block(0, 0, 320 - 1, 240 - 1, &.{});
|
|
104
|
+
dc.put(1);
|
|
105
|
+
csn.put(0);
|
|
106
|
+
SPI0.writev_blocking(u16, buffer);
|
|
107
|
+
csn.put(1);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
fn hardware_reset() void {
|
|
111
|
+
rst.put(0);
|
|
112
|
+
time.sleep_ms(50);
|
|
113
|
+
rst.put(1);
|
|
114
|
+
time.sleep_ms(50);
|
|
115
|
+
}
|
|
9
116
|
|
|
10
117
|
pub fn main() !void {
|
|
118
|
+
inline for (&.{ csn, mosi, sck }) |pin| {
|
|
119
|
+
pin.set_function(.spi);
|
|
120
|
+
}
|
|
11
121
|
ssr.set_function(.sio);
|
|
12
122
|
ssr.set_direction(.out);
|
|
123
|
+
csn.set_function(.sio);
|
|
124
|
+
csn.set_direction(.out);
|
|
125
|
+
csn.put(1);
|
|
126
|
+
dc.set_function(.sio);
|
|
127
|
+
dc.set_direction(.out);
|
|
128
|
+
dc.put(0);
|
|
129
|
+
rst.set_function(.sio);
|
|
130
|
+
rst.set_direction(.out);
|
|
131
|
+
rst.put(1);
|
|
13
132
|
button.set_function(.sio);
|
|
14
133
|
button.set_direction(.in);
|
|
15
134
|
button.set_pull(.up);
|
|
16
135
|
|
|
136
|
+
try SPI0.apply(.{ .clock_config = rp2xxx.clock_config });
|
|
137
|
+
|
|
138
|
+
hardware_reset();
|
|
139
|
+
for (initDisplayCommands) |cmd| {
|
|
140
|
+
send(cmd);
|
|
141
|
+
if (cmd.delay_ms) |delay_ms| {
|
|
142
|
+
time.sleep_ms(delay_ms);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
17
146
|
while (true) {
|
|
18
147
|
const a = button.read();
|
|
19
148
|
if (a == 0) {
|