9 |
9 |
10 #include "QEI.h" |
10 #include "QEI.h" |
11 #include "Keypad.h" |
11 #include "Keypad.h" |
12 |
12 |
13 // Pins and device declarations |
13 // Pins and device declarations |
14 #if defined TARGET_NUCLEO_F446RE |
|
15 #include "def_f446re.h" |
|
16 #elif defined TARGET_HP34970_FP_F303RD |
|
17 #include "def_hp34970_fp.h" |
14 #include "def_hp34970_fp.h" |
18 #endif |
|
19 |
15 |
20 #include "platform/CircularBuffer.h" |
16 #include "platform/CircularBuffer.h" |
21 #include <USBSerial.h> |
|
22 |
17 |
23 Display *dsp; |
18 Display *dsp; |
24 volatile bool splashscreen; |
19 volatile bool splashscreen; |
25 HPSerial *hp; |
20 HPSerial *hp; |
26 Thread tdsp(osPriorityNormal, OS_STACK_SIZE, nullptr, "DSP"); |
21 Thread tdsp(osPriorityNormal, OS_STACK_SIZE, nullptr, "DSP"); |
109 uint8_t nchars; |
104 uint8_t nchars; |
110 char buffer[MAX_BUFF+1]; |
105 char buffer[MAX_BUFF+1]; |
111 |
106 |
112 void refresh_display(void); |
107 void refresh_display(void); |
113 |
108 |
114 void timeout_h() { |
|
115 #if defined(HAS_LED) |
|
116 led = !led; |
|
117 #endif |
|
118 } |
|
119 |
|
120 #ifdef DEBUG |
|
121 |
|
122 DigitalOut dbgpin(DBGPIN); |
|
123 inline void pulse(uint8_t count=1, bool stayup=false) |
|
124 { |
|
125 dbgpin = 0; |
|
126 wait_us(2); |
|
127 while (count--) |
|
128 { |
|
129 dbgpin = 1; |
|
130 wait_us(2); |
|
131 dbgpin = 0; |
|
132 wait_us(2); |
|
133 } |
|
134 if (stayup) |
|
135 dbgpin = 1; |
|
136 } |
|
137 #else |
|
138 inline void pulse(uint8_t count=1, bool stayup=false) |
|
139 {} |
|
140 #endif |
|
141 |
|
142 // callbacks & thread functions |
109 // callbacks & thread functions |
143 void reset(void); |
110 void reset(void); |
144 void reset_irq(void); |
111 void reset_irq(void); |
145 void qei_cb(int dir); |
112 void qei_cb(int dir); |
146 void end_splashscreen(void); |
113 void end_splashscreen(void); |
147 |
114 |
148 |
|
149 #if defined(HAVE_PC) |
115 #if defined(HAVE_PC) |
150 FileHandle *mbed::mbed_override_console(int fd) |
116 FileHandle *mbed::mbed_override_console(int fd) |
151 { |
117 { |
152 return static_cast<FileHandle*> (&pc); |
118 return static_cast<FileHandle*> (&pc); |
153 //return &pc; |
119 //return &pc; |
154 } |
120 } |
155 #endif |
121 #endif |
156 |
|
157 |
122 |
158 void setup() { |
123 void setup() { |
159 #if defined(HAVE_PC) |
124 #if defined(HAVE_PC) |
160 pc.connect(); |
125 pc.connect(); |
161 ThisThread::sleep_for(100ms); |
126 ThisThread::sleep_for(100ms); |
163 #endif |
128 #endif |
164 |
129 |
165 printf("\n\nSETUP\n"); |
130 printf("\n\nSETUP\n"); |
166 printf(" System Core Clock = %ld MHZ\r\n", SystemCoreClock/1000000); |
131 printf(" System Core Clock = %ld MHZ\r\n", SystemCoreClock/1000000); |
167 |
132 |
168 printf("Create USBSerial\n"); |
|
169 hp = NULL; |
133 hp = NULL; |
170 |
134 |
171 printf("Serial communication via UART4\r\n"); |
|
172 |
|
173 printf("Setup HP communication pins\r\n"); |
135 printf("Setup HP communication pins\r\n"); |
174 //printf(" HP_RX=%d\r\n", HP_RX); |
|
175 DigitalIn(HP_RX).mode(PullDown); |
136 DigitalIn(HP_RX).mode(PullDown); |
176 //printf(" HP_TX=%d\r\n", HP_TX); |
|
177 DigitalOut(HP_TX).write(1); |
137 DigitalOut(HP_TX).write(1); |
178 //printf(" HP_RST=%d\r\n", HP_RST); |
|
179 DigitalIn(HP_RST).mode(PullDown); |
138 DigitalIn(HP_RST).mode(PullDown); |
180 |
139 |
181 printf(" setup QEI pins\r\n"); |
140 printf(" setup QEI pins\r\n"); |
182 //printf(" ENC1=%d\r\n", KP_ENC1); |
|
183 DigitalIn(KP_ENC1).mode(PullDown); |
141 DigitalIn(KP_ENC1).mode(PullDown); |
184 //printf(" ENC2=%d\r\n", KP_ENC2); |
|
185 DigitalIn(KP_ENC2).mode(PullDown); |
142 DigitalIn(KP_ENC2).mode(PullDown); |
186 qenc.attach(&qei_cb); |
143 qenc.attach(&qei_cb); |
187 |
144 |
188 printf(" setup Keypad\r\n"); |
145 printf(" setup Keypad\r\n"); |
189 |
|
190 shift = false; |
146 shift = false; |
191 must_reset = false; |
147 must_reset = false; |
192 must_shutdown = false; |
148 must_shutdown = false; |
193 kpad = new Keypad(KP_NROWS, kp_rows, KP_NCOLS, kp_columns); |
149 kpad = new Keypad(KP_NROWS, kp_rows, KP_NCOLS, kp_columns); |
194 printf(" attach Keypad callbacks\r\n"); |
150 printf(" attach Keypad callbacks\r\n"); |
196 printf(" start Keypad\r\n"); |
152 printf(" start Keypad\r\n"); |
197 kpad->start(); |
153 kpad->start(); |
198 |
154 |
199 printf("Setup OLED display\r\n"); |
155 printf("Setup OLED display\r\n"); |
200 // init the LCD |
156 // init the LCD |
201 /* |
|
202 printf(" DSP_MOSI=%d\r\n", DSP_MOSI); |
|
203 printf(" DSP_MISO=%d\r\n", DSP_MISO); |
|
204 printf(" DSP_SCLK=%d\r\n", DSP_SCLK); |
|
205 printf(" DSP_CS=%d\r\n", DSP_CS); |
|
206 printf(" DSP_RST=%d\r\n", DSP_RST); |
|
207 printf(" DSP_DC=%d\r\n", DSP_DC); |
|
208 */ |
|
209 dsp = new Display(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, |
157 dsp = new Display(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, |
210 DSP_RST, DSP_DC, "SSD1322"); |
158 DSP_RST, DSP_DC, "SSD1322"); |
211 |
159 |
212 curchar = 0; |
160 curchar = 0; |
213 nchars = 0; |
161 nchars = 0; |
261 if (DigitalIn(HP_RST).read() == 0) { |
209 if (DigitalIn(HP_RST).read() == 0) { |
262 byescreen_timer.detach(); // cancel a "poweroff", if any |
210 byescreen_timer.detach(); // cancel a "poweroff", if any |
263 splashscreen_timer.detach(); // same for splashscreen |
211 splashscreen_timer.detach(); // same for splashscreen |
264 splashscreen = false; // in case it still on |
212 splashscreen = false; // in case it still on |
265 |
213 |
266 if (hp == NULL) { |
214 if (hp == NULL) { |
267 printf("setup HP communication handler\r\n"); |
215 printf("setup HP communication handler\r\n"); |
268 hp = new HPSerial(HP_TX, HP_RX); |
216 hp = new HPSerial(HP_TX, HP_RX); |
269 } else { |
217 } else { |
270 printf("Connection already initialized\n"); |
218 printf("reset existing connection\n"); |
271 } |
219 hp->reset(); |
272 |
220 } |
273 printf("!! RST !! (gstate=%d, state=%d)\r\n", |
221 dsp->power_on(); |
274 hp->gstate(), hp->state()); |
222 dsp->cls(); |
275 //printf("Value is ... %X\n", hp->search()); |
223 printf("Initiate startup sequence\n"); |
276 dsp->power_on(); |
224 if (last_key.keyevent == KEY_PRESSED) { |
277 dsp->cls(); |
225 printf(" with key pressed\n"); |
278 printf("Initiate startup sequence\n"); |
226 hp->send_startup_seq(kp_mapping[last_key.row][last_key.col]); |
279 if (last_key.keyevent == KEY_PRESSED) { |
227 } else { |
280 printf(" with key pressed\n"); |
228 hp->send_startup_seq(); |
281 hp->send_startup_seq(kp_mapping[last_key.row][last_key.col]); |
229 } |
282 } else { |
|
283 hp->send_startup_seq(); |
|
284 } |
|
285 } |
230 } |
286 else |
231 else |
287 { |
232 { |
288 printf("HP_RST is not LOW, skipping\n"); |
233 printf("HP_RST is not LOW, skipping\n"); |
289 } |
234 } |
441 byescreen_timer.attach(callback(&shutdown), 2s); |
384 byescreen_timer.attach(callback(&shutdown), 2s); |
442 } else { |
385 } else { |
443 // display related commands |
386 // display related commands |
444 dsp->show(cmd.cmd, cmd.value, cmd.size); |
387 dsp->show(cmd.cmd, cmd.value, cmd.size); |
445 } |
388 } |
446 #if defined(HAS_LED) |
|
447 led = 0; |
|
448 #endif |
|
449 } |
389 } |
450 } |
390 } |
451 //else |
391 //else |
452 ThisThread::sleep_for(1ms); |
392 ThisThread::sleep_for(1ms); |
453 } |
393 } |