src/main.cpp

Tue, 13 Sep 2016 21:32:48 +0200

author
David Douard <david.douard@logilab.fr>
date
Tue, 13 Sep 2016 21:32:48 +0200
changeset 4
219766126afb
parent 3
a3233abe730e
child 5
f1c85c2500f2
permissions
-rw-r--r--

another attempt using a more complete support of the protocol and async serial stuff

1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 #include "stdio.h"
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
2
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 #include "mbed.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 #include "string"
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
5 #include "CircularBuffer.h"
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
6
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
7 #include "Terminal6x8.h"
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
8 #include "Mono19x27.h"
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
9 #include "Mono15x22.h"
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 #include "Arial12x12.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
12 #include "SSD1322.h"
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
14 Serial pc(USBTX, USBRX);
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
15
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
16 //BufferedSerial hp(NC, PA_1, 64, 0); // serial4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
17 #define HP_SERIAL_TX PC_7 // serial6 RX
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
18 #define HP_SERIAL_RX PA_1 // serial4 RX
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
20 SSD1322 dsp(SPI_8, 10000000, PB_15, PB_14, PB_13, PB_12, D11, D12, "SSD1322", 256, 64);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
22 #define BUF_SIZE 32
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
23 #define MAX_BUFF 15
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
24 #define MAX_ERRS 10
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 uint8_t curchar;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 uint8_t cmd;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 uint8_t nchars;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 char buffer[MAX_BUFF+1];
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 typedef struct _DSP
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 uint8_t cmd;
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
33 uint8_t color;
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
34 uint8_t bgcolor;
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
35 uint8_t x0;
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 uint8_t y0;
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
37 uint8_t fmt; // 0=>ascii, 1=>hex, 2=>bits, 3=>flags
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38 uint8_t maxsize;
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
39 uint8_t width;
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 const unsigned char* font;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41 char buffer[MAX_BUFF+1];
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42 } DSP;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
44 static DSP table[] =
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 {
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
46 { 0x00, 0xF, 0x0, 0, 0, 0, MAX_BUFF, 245, Mono19x27}, // main display
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
47 { 0x0C, 0xF, 0x0,204, 38, 0, 3, 45, Mono15x22}, // channels display
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
48 { 0x01, 0xF, 0x0, 0, 0, 4, MAX_BUFF, 0, Terminal6x8},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
49 { 0x02, 0xF, 0x0, 0, 0, 4, MAX_BUFF, 0, Terminal6x8},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
50 { 0x0A, 0xF, 0x0, 0, 57, 2, 4, 0, Terminal6x8},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
51 { 0x0A, 0xF, 0x0, 0, 0, 3, 4, 0, Terminal6x8}, // flags
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
52 { 0xFF, 0xF, 0x0, 0, 0, 4, MAX_BUFF, 0, Terminal6x8},
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
53 };
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
54
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
55 // 9x10
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
56 const unsigned char icon_alarm[] __attribute__((aligned (2))) =
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
57 {
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
58 0x1c, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
59 0x3e, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
60 0x7f, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
61 0x7f, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
62 0x7f, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
63 0x7f, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
64 0x7f, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
65 0x7f, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
66 0xff, 0x80,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
67 0x10, 0x0
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
68 };
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
69
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
70 const unsigned char icon_curve[] __attribute__((aligned (2))) =
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
71 {
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
72 0x80, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
73 0x80, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
74 0x80, 0x80,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
75 0x81, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
76 0x9e, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
77 0xa0, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
78 0xc0, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
79 0x80, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
80 0x80, 0x0,
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
81 0xff, 0x80
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
82 };
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
83
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
84 typedef struct _FLAG
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
85 {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
86 uint8_t flag;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
87 uint8_t x;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
88 uint8_t y;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
89 const char* msg;
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
90 const unsigned char* icon;
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
91 } FLAG;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
92
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
93 static const FLAG flags[] =
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
94 {
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
95 //{ 0x00, 160, 30, "Alarm"}, // for the 'alarm' box
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
96 { 0x00, 246, 0, NULL, icon_alarm}, // F1.1
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
97 { 0x01, 246, 11, NULL, icon_curve}, // F1.2
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
98 { 0x03, 204, 30, "Channel"}, // F1.4
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
99 { 0x14, 68, 44, "4W"}, // F2.5
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
100 { 0x33, 40, 44, "VIEW"}, // F4.4
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
101 { 0x34, 0, 30, "MON"}, // F4.5
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
102 { 0x36, 0, 44, "CONFIG"}, // F4.7
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
103
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
104 { 0xFF, 0, 0, "SCAN"}, // F4.6 or F4.3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
105 { 0xFF, 0, 0, "*"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
106 { 0xFF, 0, 0, "ADRS"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
107 { 0xFF, 0, 0, "RMT"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
108 { 0xFF, 0, 0, "ERROR"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
109 { 0xFF, 0, 0, "EXT"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
110 { 0xFF, 0, 0, "ONCE"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
111 { 0xFF, 0, 0, "AUTO"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
112 { 0xFF, 0, 0, "MEM"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
113 { 0xFF, 0, 0, "LAST"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
114 { 0xFF, 0, 0, "MIN"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
115 { 0xFF, 0, 0, "MAX"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
116 { 0xFF, 0, 0, "AVG"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
117 { 0xFF, 0, 0, "OC"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
118
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
119 { 0xFF, 0, 0, "H"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
120 { 0xFF, 0, 0, "1"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
121 { 0xFF, 0, 0, "2"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
122 { 0xFF, 0, 0, "3"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
123 { 0xFF, 0, 0, "4"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
124 { 0xFF, 0, 0, "L"},
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
125
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
126 };
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
127
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
128
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
129 #ifdef DEBUG
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
130 #define DBGPIN PC_0
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
131
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
132 DigitalOut dbgpin(DBGPIN);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
133 inline void DebugPulse(uint8_t count=1)
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
134 {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
135 while (count--)
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
136 {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
137 dbgpin = 1;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
138 dbgpin = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
139 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
140 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
141 #else
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
142 inline void DebugPulse(uint8_t count=1)
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
143 {}
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
144 #endif
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
145
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
146
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
147
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
148 /***** HP 34970A communication class ***/
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
149
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
150 class HPSerial {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
151
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
152 public:
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
153 enum TrState {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
154 Idle = 0,
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
155 Tx,
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
156 Rx,
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
157 };
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
158 typedef struct _CMD
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
159 {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
160 TrState direction;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
161 uint8_t cmd;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
162 uint8_t size;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
163 char value[MAX_BUFF+1];
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
164 unsigned long id;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
165 } CMD;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
166
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
167
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
168
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
169 HPSerial(): ncmd(0), serial_tx(NC, HP_SERIAL_TX), serial_rx(NC, HP_SERIAL_RX) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
170 pc.printf("HPSerial init\n");
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
171 for(uint8_t i=0; i<MAX_ERRS; i++)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
172 errs[i] = 0;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
173 reset();
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
174
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
175 serial_tx.baud(187500);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
176 serial_tx.attach(this, &HPSerial::txIrq, Serial::RxIrq); //sic!
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
177
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
178 serial_rx.baud(187500);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
179 serial_rx.attach(this, &HPSerial::rxIrq, Serial::RxIrq);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
180 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
181
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
182 bool cmd_available(void) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
183 return !cmdbuf.empty();
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
184 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
185
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
186 bool pop(CMD& cmd) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
187 return cmdbuf.pop(cmd);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
188 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
189
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
190 bool cmd_buf_full(void) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
191 return cmdbuf.full();
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
192 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
193
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
194 unsigned int nerrors(uint8_t errorno) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
195 return errs[errorno];
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
196 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
197
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
198
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
199
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
200 private:
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
201 void reset(uint8_t errorno=0xFF) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
202 head = 0;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
203 tx_state = Idle;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
204 tx_cmd = 0xFF;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
205 tx_ack = false;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
206 tx_len = 0xFF;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
207 memset(buf, 0, BUF_SIZE);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
208 if (errorno != 0xFF)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
209 errs[errorno]++;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
210 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
211
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
212 void handleAck(uint8_t val) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
213 if (tx_ack == true)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
214 reset(0);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
215
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
216 else
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
217 if (tx_cmd == 0xFF) // still at the beginning of a packet, expect 0x99 as ack
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
218 if (val == 0x99)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
219 tx_ack = true;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
220 else
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
221 reset(1);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
222
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
223 else // expect 0x00 as ack
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
224 if (val == 0x00)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
225 tx_ack = true;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
226 else
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
227 reset(2);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
228 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
229
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
230 void pushCmd(TrState direction, uint8_t cmd, uint8_t size, char *payload) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
231 CMD val;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
232 uint8_t i;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
233 val.id = ncmd++;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
234 val.direction = direction;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
235 val.cmd = cmd;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
236 val.size = size;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
237 for(i=0; i<size; i++)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
238 val.value[i] = payload[i];
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
239 val.value[i] = 0x00;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
240 cmdbuf.push(val);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
241 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
242
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
243 void handleChar(uint8_t val) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
244 if (tx_ack == false)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
245 reset(3);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
246 else // remaining of the state machine
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
247 if (tx_cmd == 0xFF) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
248 // begin of transmission, expect a cmd
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
249 tx_cmd = val;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
250 tx_ack = false;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
251 tx_len = 0xFF;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
252 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
253 else if (tx_len == 0xFF) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
254 // got a cmd, expect a payload size
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
255 tx_len = val;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
256 tx_ack = false;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
257 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
258 else if (tx_len > 0) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
259 // a payload char
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
260 buf[head++] = val;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
261 tx_len--;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
262 tx_ack = false;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
263 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
264 else {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
265 uint8_t cur_state = tx_state;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
266 pushCmd(tx_state, tx_cmd, head, buf);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
267 reset();
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
268
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
269 if (val != 0x55) { // not an end of transmission
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
270 // should be another cmd I think
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
271 tx_cmd = val;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
272 tx_state = cur_state;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
273 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
274 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
275 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
276
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
277
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
278 void rxIrq(void) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
279 uint8_t val;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
280 if(serial_rx.readable()) { // no reason why we would end here without this condition, but hey
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
281 val = serial_rx.getc();
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
282
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
283 if (tx_state == Idle)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
284 if (val == 0x66) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
285 // no transmission in progress, expect a start of transmission
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
286 tx_state = Rx;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
287 tx_ack = false;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
288 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
289 else
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
290 reset(4);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
291
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
292 else if (tx_state == Tx) // manage the acks
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
293 handleAck(val);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
294
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
295 else
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
296 handleChar(val);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
297 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
298 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
299
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
300 void txIrq(void) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
301 uint8_t val;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
302 if(serial_tx.readable()) { // no reason why we would end here without this condition, but hey
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
303 val = serial_tx.getc();
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
304
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
305 if (tx_state == Idle)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
306 if (val == 0x66) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
307 // no transmission in progress, expect a start of transmission
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
308 tx_state = Tx;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
309 tx_ack = false;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
310 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
311 else
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
312 reset(5);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
313
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
314 else if (tx_state == Rx) // manage the acks
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
315 handleAck(val);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
316
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
317 else
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
318 handleChar(val);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
319 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
320 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
321
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
322 private:
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
323 RawSerial serial_tx;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
324 RawSerial serial_rx;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
325 uint8_t buf[BUF_SIZE];
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
326 uint8_t head;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
327 uint8_t tx_state;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
328 uint8_t tx_cmd;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
329 uint8_t tx_len;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
330 bool tx_ack;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
331 CircularBuffer<CMD, 32> cmdbuf;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
332 unsigned long ncmd;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
333 unsigned int errs[MAX_ERRS];
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
334 };
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
335
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
336
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
337 HPSerial hp;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
338 Ticker dsp_refresher;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
339 volatile bool must_refresh;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
340
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
341 void copy_to_lcd(void);
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
342 void test_dsp();
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
343
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
344 void setup() {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
345 // init the LCD
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
346
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
347 //dsp.set_orientation(3);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
348 pc.baud (115200);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
349 pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
350 (float)SystemCoreClock/1000000);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
351
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
352 // myLCD.set_font((unsigned char*) Terminal6x8);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
353 // myLCD.claim(stdout); // send stdout to the LCD display
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
354 // myLCD.claim(stderr); // send stderr to the LCD display
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
355 dsp.background(Black); // set background to black
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
356 dsp.foreground(0xF);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
357 dsp.cls();
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
358 dsp.locate(0, 0);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
359 dsp.set_font(Mono19x27);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
360
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
361 cmd = 0xFF;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
362 curchar = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
363 nchars = 0;
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
364
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
365
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
366 dsp.printf("HP34970A");
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
367 dsp.set_font(Terminal6x8);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
368 for(uint8_t i=0; i<4; i++) {
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
369 dsp.locate(160, i*8);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
370 dsp.printf("Lg %d", i+1);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
371 dsp.locate(208, (3-i)*8);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
372 dsp.printf("Lg %d", i+1);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
373 }
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
374 dsp.copy_to_lcd();
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
375 wait(2);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
376 dsp.cls();
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
377
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
378 dsp_refresher.attach(&copy_to_lcd, 0.1);
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
379 test_dsp();
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
380 wait(2);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
381 dsp.cls();
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
382
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
383 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
384
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
385 void copy_to_lcd(void) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
386 if (must_refresh)
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
387 dsp.copy_to_lcd();
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
388 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
389
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
390 void show(uint8_t cmd, char *txt, uint8_t nchar=0) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
391 uint8_t i, len;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
392 uint16_t bgcolor, fgcolor;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
393 char *oldv;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
394
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
395 must_refresh = false;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
396
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
397 len = MAX_BUFF;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
398
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
399 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
400 if (table[i].cmd == cmd) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
401 bgcolor = table[i].bgcolor;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
402 fgcolor = table[i].color;
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
403 dsp.background(bgcolor);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
404 dsp.foreground(fgcolor);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
405 dsp.locate(table[i].x0, table[i].y0);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
406 dsp.set_font((unsigned char*) table[i].font);
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
407 oldv = table[i].buffer;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
408
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
409 switch (table[i].fmt) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
410 case 0: //ascii
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
411 if (table[i].width > 0)
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
412 dsp.fillrect(table[i].x0, table[i].y0, table[i].x0 + table[i].width, table[i].y0 + table[i].font[2], bgcolor);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
413 dsp.printf(txt);
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
414 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
415 case 1: // hex
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
416 for (uint8_t j=0;; j++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
417 if (txt[j] == 0x00)
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
418 break;
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
419 dsp.printf("%02X ", txt[j]);
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
420 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
421 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
422 dsp.printf(" ");
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
423 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
424 case 2: // binary
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
425 dsp.foreground(fgcolor);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
426 dsp.printf(" [");
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
427 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
428 if (j>0) {
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
429 dsp.foreground(fgcolor);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
430 dsp.printf(" | ");
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
431 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
432 for (uint8_t k=0; k<8; k++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
433 if (txt[j] & (1 << (7-k)))
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
434 dsp.foreground(fgcolor);
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
435 else
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
436 dsp.foreground(bgcolor);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
437 dsp.printf("%d", (8-k));
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
438 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
439 }
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
440 dsp.foreground(fgcolor);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
441 dsp.printf("]");
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
442 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
443 case 3: // flags
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
444 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
445 for (uint8_t k=0; k<8; k++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
446 if ((txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
447
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
448 if (txt[j] & (1 << k))
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
449 dsp.foreground(fgcolor);
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
450 else
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
451 dsp.foreground(bgcolor);
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
452 for (uint8_t l=0;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
453 l<(sizeof(flags)/sizeof(flags[0])); ++l) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
454 if (flags[l].flag == ((j<<4) + k)) {
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
455 if (flags[l].msg != NULL) { // a string
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
456 dsp.locate(flags[l].x, flags[l].y);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
457 dsp.printf(flags[l].msg);}
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
458 else { // an icon
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
459 Bitmap_s pic = {9, 10, 2, flags[l].icon};
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
460 dsp.Bitmap_BW(pic, flags[l].x, flags[l].y);
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
461 }
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
462 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
463 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
464 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
465 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
466 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
467 oldv[j] = txt[j];
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
468 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
469 break;
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
470 case 4: //ignore
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
471 break;
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
472 }
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
473 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
474 }
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
475 must_refresh = true;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
476 //dsp.copy_to_lcd();
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
477 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
478
3
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
479 void test_dsp()
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
480 {
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
481 show(0x00, "8g8g8g8g8g8g8", 13); // main dsp
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
482 show(0x0C, "888", 3); // channel dsp
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
483 show(0x0A, "\xFF\xFF\xFF\xFF", 4); // flags
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
484 }
a3233abe730e beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents: 2
diff changeset
485
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
486
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
487 void loop() { // run over and over
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
488 if (hp.cmd_available())
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
489 {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
490 HPSerial::CMD cmd;
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
491 if (hp.pop(cmd))
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
492 {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
493 pc.printf("CMD[%s:%d %d/%d/%d/%d/%d/%d] %X\n", (cmd.direction==HPSerial::Rx)?"Rx":"Tx", cmd.id,
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
494 hp.nerrors(0),
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
495 hp.nerrors(1),
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
496 hp.nerrors(2),
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
497 hp.nerrors(3),
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
498 hp.nerrors(4),
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
499 hp.nerrors(5),
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
500 cmd.cmd);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
501
4
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
502 if (cmd.direction == HPSerial::Rx) {
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
503 if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C))
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
504 pc.printf(" data=%s\n", cmd.value);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
505 show(cmd.cmd, cmd.value, cmd.size);
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
506
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
507 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
508 }
219766126afb another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents: 3
diff changeset
509 }
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
510 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
511
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
512 int main()
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
513 {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
514 setup();
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
515 while(1)
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
516 loop();
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
517 }

mercurial