forked from grahamwhaley/DSPham
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcd.cpp
393 lines (336 loc) · 6.85 KB
/
lcd.cpp
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// SPDX-License-Identifier: GNU General Public License v3.0 or later
#include <arm_math.h>
#include "lcd.h"
#include "global.h"
#include "morseDecode.h"
#include "k4icy.h"
#include "tf3lj_dec.h"
rgb_lcd lcd;
//Min volume - '1' char 0x00
uint8_t custom0[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b10000,
0b00000
};
//volume - '2' char 0x01
uint8_t custom1[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b01000,
0b11000,
0b00000
};
//volume - '3' char 0x02
uint8_t custom2[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00100,
0b01100,
0b11100,
0b00000
};
//volume - '4' char 0x03
uint8_t custom3[8] = {
0b00000,
0b00000,
0b00000,
0b00010,
0b00110,
0b01110,
0b11110,
0b00000
};
//Max volume - '5' char 0x04
uint8_t custom4[8] = {
0b00000,
0b00000,
0b00001,
0b00011,
0b00111,
0b01111,
0b11111,
0b00000
};
//Noise blanker symbol char 0x05
uint8_t custom5[8] = {
0b00000,
0b00100,
0b01100,
0b10101,
0b00110,
0b00100,
0b00000,
0b00000
};
//Autonotch filter char 0x06
uint8_t custom6[8] = {
0b00000,
0b10001,
0b01010,
0b01010,
0b01110,
0b00100,
0b00100,
0b00000
};
//Morse tune - character 0x07 - note, dynaically updated!!!
// blanck char for when we are turned off
uint8_t morsecharblank[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
// '<<'
uint8_t morsechar0[8] = {
0b00000,
0b00101,
0b01010,
0b10100,
0b01010,
0b00101,
0b00000,
0b00000
};
// '<'
uint8_t morsechar1[8] = {
0b00000,
0b00001,
0b00010,
0b00100,
0b00010,
0b00001,
0b00000,
0b00000
};
// '><'
uint8_t morsechar2[8] = {
0b00000,
0b10001,
0b01010,
0b00100,
0b01010,
0b10001,
0b00000,
0b00000
};
// '>'
uint8_t morsechar3[8] = {
0b00000,
0b00100,
0b00010,
0b00001,
0b00010,
0b00100,
0b00000,
0b00000
};
// '>>'
uint8_t morsechar4[8] = {
0b00000,
0b10100,
0b01010,
0b00101,
0b01010,
0b10100,
0b00000,
0b00000
};
//Defaults should be over-written by eeprom loading.
uint8_t lcd_colourR = 32;
uint8_t lcd_colourG = 32;
uint8_t lcd_colourB = 32;
void lcd_setcolour(void) {
lcd.setRGB(lcd_colourR, lcd_colourG, lcd_colourB);
}
void lcd_setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd_setcolour();
lcd.createChar(0, custom0);
lcd.createChar(1, custom1);
lcd.createChar(2, custom2);
lcd.createChar(3, custom3);
lcd.createChar(4, custom4);
lcd.createChar(5, custom5);
lcd.createChar(6, custom6);
lcd.createChar(7, morsecharblank); //Default blank - off
}
void updateDisplay(void)
{
char buf[17];
int invol;
/* Sequence goes something like:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0|1|2|3|4|5|6|7|8|9|0|1|2|3|4|5|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|v|F|N|N|A| |NR | |C P U| |W |
|o|i|B|o|G| | | | | | | | | |P |
|l|l|l|t|C| | | | | | | | | |M |
|u|t|a|c| | | | | | | | | | | | |
|m|e|n|h| | | | | | | | | | | | |
|e|r|k| | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
CPU is updated in the main loop.
*/
//Input volume (peak) bar graph - 5 'special' chars, from 0x00-0x04
//Bump by '10%', as we'd like to show 90+% as a full whack clipping
invol = (char)(((input_peak_acc+0.5)/10.0)*4.0);
if (invol > 4) invol = 4;
//Special case - we cannot write character '0x00' using a string write!
//So, substitute here for a non-zero placeholder, and write it singly at the
// end if we need....
if (invol == 0 ) buf[0] = ' ';
else buf[0] = invol;
//And then, if we clipped on input, overwrite with a *splat* char to try and make
// it visually obvious.
if (input_peak_clipped) buf[0] = '!';
if (nr_mode != NR_MODE_COMPLETE_BYPASS ) {
//Filter mode
switch (current_filter_mode) {
case 0: //passthrough (no filter)
buf[1] = 0x7E; //right arrow
break;
case 1: //SSB
buf[1] = 'S';
break;
case 2: //CW
buf[1] = 'C';
break;
case 3: //AM
buf[1] = 'A';
break;
case 4: //FM
buf[1] = 'F';
break;
default:
buf[1] = '#';
break;
}
//Noise blanker
if (nb_enabled) buf[2] = 0x05;
else buf[2] = '-';
//Auto notch filter
if (xanr_notch) buf[3] = 0x06;
else buf[3] = '-';
//AGC
switch(agc_mode) {
case AGC_MODE_OFF:
buf[4] = '-';
break;
case AGC_MODE_TRACK:
buf[4] = 'T';
break;
case AGC_MODE_SG5K:
buf[4] = '5';
break;
default:
buf[4] = '#';
break;
}
//Spacer
buf[5] = ' ';
} else {
//Full bypass mode!
buf[1] = '#';
buf[2] = '#';
buf[3] = '#';
buf[4] = '#';
buf[5] = '#';
}
//Noise reduction
switch(nr_mode) {
case NR_MODE_COMPLETE_BYPASS: //Complete audio processing bypass
buf[6] = 'B';
buf[7] = 'Y';
buf[8] = 'P';
break;
case NR_MODE_OFF: //off
buf[6] = 'O';
buf[7] = 'f';
buf[8] = 'f';
break;
case NR_MODE_LMS: //LMS
buf[6] = 'L';
buf[7] = 'M';
buf[8] = 'S';
break;
case NR_MODE_KIM: //Kim
buf[6] = 'K';
buf[7] = 'i';
buf[8] = 'm';
break;
case NR_MODE_FNR: //fnr
buf[6] = 'f';
buf[7] = 'n';
buf[8] = 'r';
break;
case NR_MODE_FNRA: //fnrA
buf[6] = 'f';
buf[7] = 'n';
buf[8] = 'A';
break;
case NR_MODE_SPECTRAL: //Spectral
buf[6] = 'S';
buf[7] = 'p';
buf[8] = 'c';
break;
case NR_MODE_LLMS: //Leaky LMS
buf[6] = 'L';
buf[7] = 'L';
buf[8] = 'M';
break;
default: //Unknown
buf[6] = '#';
buf[7] = '#';
buf[8] = '#';
break;
}
//Spacer
buf[9] = ' ';
//CPU date lives in buf[10-12] - is filled out (overwritten) in main loop.
buf[10] = ' ';
buf[11] = ' ';
buf[12] = ' ';
//Decoder speeds and things
if (decoder_mode == DECODER_MORSE) {
buf[13] = 0x07; //The special morse tuning char
sprintf(&buf[14], "%2d", morseWPM() );
} else
if (decoder_mode == DECODER_MORSE_K4ICY) {
buf[13] = 0x07; //The special morse tuning char
sprintf(&buf[14], "%2d", k4icy_getWPM() );
} else
if (decoder_mode == DECODER_MORSE_TF3LJ) {
buf[13] = 0x07; //The special morse tuning char
sprintf(&buf[14], "%2d", tf3lj_getWPM() );
} else {
//spacer
buf[13] = ' ';
buf[14] = '-';
buf[15] = '-';
}
//And finally print it out
buf[16]='\0';
lcd.setCursor(0, 1);
lcd.print(buf);
//And do we need to write the input volume by hand??
if (invol == 0 ) {
lcd.setCursor(0, 1);
lcd.print((char)invol);
}
}