-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy patholed_text.si
More file actions
212 lines (174 loc) · 4.38 KB
/
oled_text.si
File metadata and controls
212 lines (174 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// SL 2020-08
// MIT license, see LICENSE_MIT in Silice repo root
// https://github.com/sylefeb/Silice
// vvvvvvvvvvvvv select screen driver below
$$ -- SSD1331=1
$$ -- SSD1351=1
$$ ST7789=1
// vvvvv adjust to your screen
$$ oled_width = 240
$$ oled_height = 240
// vvvvv set to false if the screen uses the CS pin
$$ st7789_no_cs = true
// vvvvv set to true to rotate view 90 degrees
$$ st7789_transpose = true
// -------------------------
$include('../common/oled.si')
$$if not ULX3S then
$$error('only tested on ULX3S, small changes likely required to main input/outputs for other boards')
$$end
// -------------------------
algorithm text_display(
input uint10 pix_x,
input uint10 pix_y,
output uint1 white,
output! uint12 letter_addr,
input uint6 letter,
) <autorun> {
// ---------- font
$include('../common/font.si')
$$if letter_w ~= 8 or letter_h ~= 8 then
error('expects a 8x8 font')
$$end
// ---------- text display
uint6 text_i = 0;
uint6 text_j = 0;
uint4 letter_i = 0;
uint5 letter_j = 0;
uint12 addr = 0;
// ---------- show time!
while (1) {
// text
letter_i = pix_x & 7;
text_i = pix_x >> 3;
letter_j = pix_y & 7;
text_j = pix_y >> 3;
if (text_i < 32 && text_j < 32) {
letter_addr = text_i + (text_j*$oled_width>>3$);
++:
addr = letter_i + ( letter_j << 3)
+ (letter << 6);
white = letters[ addr ];
} else {
white = 0;
}
}
}
// -------------------------
algorithm main(
$$if ULX3S then
output uint8 leds,
input uint7 btns,
output uint1 oled_clk,
output uint1 oled_mosi,
output uint1 oled_dc,
output uint1 oled_resn,
output uint1 oled_csn,
$$end
) {
oledio io;
oled display(
$$if ULX3S then
oled_clk :> oled_clk,
oled_mosi :> oled_mosi,
oled_dc :> oled_dc,
oled_resn :> oled_resn,
oled_csn :> oled_csn,
$$end
io <:> io
);
// Text buffer
simple_dualport_bram uint6 txt[$(oled_width*oled_height)>>6$] = uninitialized;
uint11 str_x = 0;
uint10 str_y = 0;
// ---------- string
uint8 str[] = " HELLO WORLD FROM FPGA # THIS IS WRITTEN IN SILICE# A LANGUAGE FOR FPGA DEVEL #FUN AND SIMPLE YET POWERFUL #";
// --------- print string
subroutine print_string(
reads str,
reads str_x,
readwrites str_y,
writes txt,
) {
uint10 col = 0;
uint8 lttr = 0;
uint6 offs = 0;
// print line
while (str[col] != 0) {
if (str[col] == 35) {
str_y = str_y + 1;
offs = 0;
} else {
switch (str[col]) {
case 32: {lttr = 36;}
case 45: {lttr = 37;}
default: {lttr = str[col] - 55;}
}
txt.addr1 = offs + str_x + (str_y*$oled_width>>3$);
txt.wdata1 = lttr[0,6];
offs = offs + 1;
}
col = col + 1;
}
return;
}
// --------- display
uint10 u = 0;
uint10 v = 0;
uint1 white = 0;
text_display text(
pix_x <: u,
pix_y <: v,
white :> white,
letter_addr :> txt.addr0,
letter <: txt.rdata0
);
uint16 frame = 0;
leds := frame[0,8];
// maintain low (pulses high when sending)
io.start_rect := 0;
io.next_pixel := 0;
txt.wenable1 := 1;
// fill buffer with spaces
{
uint11 next = 0;
txt.wdata1 = 36; // data to write
next = 0;
while (next < 1024) {
txt.addr1 = next; // address to write
next = next + 1; // next
}
}
// write text in buffer
str_y = 0;
() <- print_string <- ();
// wait for controller to be ready
while (io.ready == 0) { }
// setup draw window
io.x_start = 0;
io.x_end = $oled_width-1$;
io.y_start = 0;
io.y_end = $oled_height-1$;
io.start_rect = 1;
while (io.ready == 0) { }
while (1) {
// refresh (framebuffer style, even though the OLED
// screen could support random access ...
v = 0;
while (v < $oled_height$) {
u = 0;
while (u < $oled_width$) {
// wait for text module to refresh given new u,video_b
// (NOTE: a cycle could be saved by working one delayed)
++:
io.color = white ? 18h3ffff : 0;
io.next_pixel = 1;
while (io.ready == 0) { }
u = u + 1;
}
v = v + 1;
}
frame = frame + 1;
}
}
// -------------------------