src/main.cpp

Mon, 11 Mar 2024 15:35:36 +0100

author
David Douard <david.douard@sdf3.org>
date
Mon, 11 Mar 2024 15:35:36 +0100
changeset 71
d193c24a078a
parent 69
516acbbce05a
permissions
-rw-r--r--

Add links to sr.ht repos and add an image in the README file

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
21
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
3 #include <mbed.h>
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
4 #include <rtos.h>
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
5 #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
6
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents: 4
diff changeset
7 #include "hp34comm.h"
37
07e8ca2bdf6d Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents: 36
diff changeset
8 #include "display.h"
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
10 #include "QEI.h"
18
4fd621551d55 [full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents: 17
diff changeset
11 #include "Keypad.h"
4fd621551d55 [full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents: 17
diff changeset
12
32
bc1d6ecbb0cc Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents: 28
diff changeset
13 // Pins and device declarations
bc1d6ecbb0cc Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents: 28
diff changeset
14 #include "def_hp34970_fp.h"
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
15
32
bc1d6ecbb0cc Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents: 28
diff changeset
16 #include "platform/CircularBuffer.h"
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17
37
07e8ca2bdf6d Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents: 36
diff changeset
18 Display *dsp;
07e8ca2bdf6d Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents: 36
diff changeset
19 volatile bool splashscreen;
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
20 HPSerial *hp;
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
21 Thread tdsp(osPriorityNormal, OS_STACK_SIZE, nullptr, "DSP");
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
22 Ticker dsp_refresh;
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
23 Timeout rst_delay;
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
24 Timeout splashscreen_timer;
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
25 Timeout byescreen_timer;
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
26 InterruptIn rst(HP_RST);
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
27
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
28 QEI qenc(KP_ENC1, KP_ENC2, NC, 16);
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
29 volatile uint8_t knob;
35
b2dca6b935bb Indent src/main.cpp with 2-ws
David Douard <david.douard@sdf3.org>
parents: 34
diff changeset
30 bool shift; // true when kp is shifted, cleared by command 0x01 from Unit
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
31 bool must_reset;
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
32 bool must_shutdown;
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
33
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
34 typedef enum {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
35 KEY_NONE=0,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
36 KEY_PRESSED,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
37 KEY_RELEASED
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
38 } key_event_t;
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
39
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
40 typedef struct keycode {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
41 uint8_t row;
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
42 uint8_t col;
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
43 key_event_t keyevent;
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
44 } keycode_t;
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
45
32
bc1d6ecbb0cc Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents: 28
diff changeset
46
bc1d6ecbb0cc Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents: 28
diff changeset
47 #define KEY_BUF_SIZE 10
bc1d6ecbb0cc Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents: 28
diff changeset
48 CircularBuffer<keycode_t, KEY_BUF_SIZE> key_buf;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents: 4
diff changeset
49
34
94ab7ff42a1b Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents: 32
diff changeset
50 #define KP_NROWS 4
94ab7ff42a1b Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents: 32
diff changeset
51 #define KP_NCOLS 5
94ab7ff42a1b Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents: 32
diff changeset
52 DigitalIn kp_rows[KP_NROWS] = {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
53 KP_R0,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
54 KP_R1,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
55 KP_R2,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
56 KP_R3
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
57 };
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
58
34
94ab7ff42a1b Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents: 32
diff changeset
59 DigitalOut kp_columns[KP_NCOLS] = {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
60 KP_C0, KP_C1,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
61 KP_C2, KP_C3,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
62 KP_C4
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
63 };
18
4fd621551d55 [full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents: 17
diff changeset
64
36
a6c7292742a0 Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents: 35
diff changeset
65 /* key mapping
a6c7292742a0 Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents: 35
diff changeset
66 RxC code name
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
67 0x2 0x00 View
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
68 0x1 0x01 Mon
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
69 3x3 0x02 Sto/Rcl
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
70 0x0 0x03 Scan
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
71 1x2 0x04 Alarm
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
72 1x1 0x05 Mx+B
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
73 1x0 0x06 Measure
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
74 2x0 0x07 Interval
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
75 3x2 0x08 Card Reset
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
76 3x1 0x09 Close
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
77 3x0 0x0A Open
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
78 0x3 0x0B Read
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
79 2x3 0x0C Shift
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
80 1x3 0x0D Write
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
81 0x4 0x0E Left
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
82 1x4 0x0F Right
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
83 2x2 0x10 Advanced
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
84 2x1 0x11 Step
34
94ab7ff42a1b Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents: 32
diff changeset
85 */
94ab7ff42a1b Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents: 32
diff changeset
86
36
a6c7292742a0 Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents: 35
diff changeset
87 uint8_t kp_mapping[KP_NROWS][KP_NCOLS] = {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
88 {0x03, 0x01, 0x00, 0x0B, 0x0E},
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
89 {0x06, 0x05, 0x04, 0x0D, 0x0F},
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
90 {0x07, 0x11, 0x10, 0x0C, 0xFF},
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
91 {0x0A, 0x09, 0x08, 0x02, 0xFF}
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
92 };
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
93
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
94 #define KC_SHIFT 0x0C
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
95
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
96 void kp_cb(uint8_t row, uint8_t col);
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
97 void kr_cb(uint8_t row, uint8_t col);
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
98
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
99 Keypad *kpad;
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
100 keycode_t last_key = {0, 0, KEY_NONE};
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
101
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
102 uint8_t curchar;
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 23
diff changeset
103 //uint8_t curcmd;
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
104 uint8_t nchars;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
105 char buffer[MAX_BUFF+1];
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
106
37
07e8ca2bdf6d Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents: 36
diff changeset
107 void refresh_display(void);
07e8ca2bdf6d Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents: 36
diff changeset
108
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
109 // callbacks & thread functions
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
110 void reset(void);
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
111 void reset_irq(void);
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
112 void qei_cb(int dir);
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
113 void end_splashscreen(void);
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
114
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
115 #if defined(HAVE_PC)
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
116 FileHandle *mbed::mbed_override_console(int fd)
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
117 {
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
118 return static_cast<FileHandle*> (&pc);
64
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
119 //return &pc;
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
120 }
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
121 #endif
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
122
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
123 void setup() {
64
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
124 #if defined(HAVE_PC)
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
125 pc.connect();
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
126 ThisThread::sleep_for(100ms);
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
127 //pc.printf("SERIAL CONNECTION\r\n");
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
128 #endif
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
129
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
130 printf("\n\nSETUP\n");
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
131 printf(" System Core Clock = %ld MHZ\r\n", SystemCoreClock/1000000);
21
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
132
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
133 hp = NULL;
64
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
134
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
135 printf("Setup HP communication pins\r\n");
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
136 DigitalIn(HP_RX).mode(PullDown);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
137 DigitalOut(HP_TX).write(1);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
138 DigitalIn(HP_RST).mode(PullDown);
21
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
139
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
140 printf(" setup QEI pins\r\n");
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
141 DigitalIn(KP_ENC1).mode(PullDown);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
142 DigitalIn(KP_ENC2).mode(PullDown);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
143 qenc.attach(&qei_cb);
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
144
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
145 printf(" setup Keypad\r\n");
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
146 shift = false;
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
147 must_reset = false;
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
148 must_shutdown = false;
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
149 kpad = new Keypad(KP_NROWS, kp_rows, KP_NCOLS, kp_columns);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
150 printf(" attach Keypad callbacks\r\n");
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
151 kpad->attach(&kp_cb, &kr_cb);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
152 printf(" start Keypad\r\n");
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
153 kpad->start();
21
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
154
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
155 printf("Setup OLED display\r\n");
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
156 // init the LCD
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
157 dsp = new Display(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
158 DSP_RST, DSP_DC, "SSD1322");
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
159
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
160 curchar = 0;
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
161 nchars = 0;
7
5cf4034ba4e0 attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents: 5
diff changeset
162
54
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
163 //for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i)
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
164 // memset(table[i].buffer, 0, MAX_BUFF+1);
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
165
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
166 printf(" display splash screen\r\n");
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
167 dsp->show_splashscreen();
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
168
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
169 printf("Starting LCD thread\r\n");
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
170 // does not compile...
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
171 // dsp_refresh.attach(callback(dsp, &Display::copy_to_lcd), 50ms);
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
172 tdsp.start(&refresh_display);
22
2f51221af82d more stuff
David Douard <david.douard@logilab.fr>
parents: 21
diff changeset
173
48
fc55f6eaa8bc Remove print statements
David Douard <david.douard@sdf3.org>
parents: 44
diff changeset
174 printf("Attach timers\r\n");
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
175 splashscreen = true;
62
55e3b4441b11 Stop splashscreen after 5s
David Douard <david.douard@sdfa3.org>
parents: 57
diff changeset
176 splashscreen_timer.attach(callback(&end_splashscreen), 5s);
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
177 rst.fall(&reset_irq);
64
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
178 printf("SETUP DONE\r\n");
21
David Douard <david.douard@logilab.fr>
parents: 19
diff changeset
179
64
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
180 if (rst.read() == 0)
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
181 // in case we reset the FP while the unit is running
69
516acbbce05a Possibly fix the 'reset FP while running' case
David Douard <david.douard@sdfa3.org>
parents: 68
diff changeset
182 hp = new HPSerial(HP_TX, HP_RX);
516acbbce05a Possibly fix the 'reset FP while running' case
David Douard <david.douard@sdfa3.org>
parents: 68
diff changeset
183 //reset();
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
184 }
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
185
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
186 void end_splashscreen(void)
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
187 {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
188 splashscreen = false;
63
f71f6c0af3cd Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents: 62
diff changeset
189 // wait for the reset irq from the CPU board
f71f6c0af3cd Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents: 62
diff changeset
190 must_shutdown = true;
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
191 }
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
192
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
193
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
194 void reset_irq_tmr(void)
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
195 {
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
196 must_reset = true;
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
197 }
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
198
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
199
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
200 void reset_irq(void)
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
201 {
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
202 //must_reset = true;
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
203 rst_delay.attach(callback(&reset_irq_tmr), 600ms);
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
204 //NVIC_SystemReset();
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
205 }
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
206
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
207 void reset(void)
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
208 {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
209 // this should be called as a result of the HP_RST pin going LO
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
210 printf("Reset connection to the main unit\n");
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
211 if (DigitalIn(HP_RST).read() == 0) {
57
cce151e4bf3d Small fixes in main
David Douard <david.douard@sdf3.org>
parents: 54
diff changeset
212 byescreen_timer.detach(); // cancel a "poweroff", if any
63
f71f6c0af3cd Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents: 62
diff changeset
213 splashscreen_timer.detach(); // same for splashscreen
62
55e3b4441b11 Stop splashscreen after 5s
David Douard <david.douard@sdfa3.org>
parents: 57
diff changeset
214 splashscreen = false; // in case it still on
57
cce151e4bf3d Small fixes in main
David Douard <david.douard@sdf3.org>
parents: 54
diff changeset
215
65
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
216 if (hp == NULL) {
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
217 printf("setup HP communication handler\r\n");
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
218 hp = new HPSerial(HP_TX, HP_RX);
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
219 } else {
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
220 printf("reset existing connection\n");
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
221 hp->reset();
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
222 }
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
223 dsp->power_on();
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
224 dsp->cls();
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
225
65
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
226 printf("Initiate startup sequence\n");
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
227 if (last_key.keyevent == KEY_PRESSED) {
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
228 printf(" with key pressed\n");
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
229 hp->send_startup_seq(kp_mapping[last_key.row][last_key.col]);
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
230 } else {
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
231 hp->send_startup_seq();
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
232 }
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
233 }
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
234 else
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
235 {
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
236 printf("HP_RST is not LOW, skipping\n");
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
237 }
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
238 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
239
37
07e8ca2bdf6d Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents: 36
diff changeset
240 void refresh_display(void) {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
241 while(1) { //!must_shutdown) {
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
242 dsp->copy_to_lcd();
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
243 ThisThread::sleep_for(50ms);
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
244 }
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
245 }
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
246
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
247 void shutdown(void)
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
248 {
64
897330ee6e9d Make USBSerial work -- at last
David Douard <david.douard@sdfa3.org>
parents: 63
diff changeset
249 // TODO: implement low-power-mode stuff
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
250 must_shutdown = true;
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
251 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
252
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
253 void mainloop()
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
254 { // run over and over
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
255 keycode_t key = {0, 0, KEY_NONE};
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
256 uint8_t keycode; // actual sent value to the CPU
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
257 HPSerial::CMD cmd;
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
258 unsigned int nkeys = 0;
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
259 unsigned int err[8];
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
260 for (uint8_t i=0; i<8; i++)
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
261 err[i] = 0;
32
bc1d6ecbb0cc Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents: 28
diff changeset
262
65
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
263 printf("Start the main loop\n");
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
264 while(1) {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
265 if (must_reset) {
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
266 must_reset = false;
63
f71f6c0af3cd Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents: 62
diff changeset
267 must_shutdown = false; // just in case...
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
268 reset();
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
269 }
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
270 else if (must_shutdown) {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
271 must_shutdown = false;
63
f71f6c0af3cd Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents: 62
diff changeset
272 dsp->cls();
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
273 dsp->power_off();
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
274 }
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
275 else {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
276 if (knob != 0)
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
277 {
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
278 if (hp != NULL)
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
279 {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
280 printf("KEY[%d] %s%X\n", nkeys++, knob<0x0F ? "0" : "", knob);
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
281 hp->sendkey(knob);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
282 }
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
283 else
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
284 {
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
285 dsp->locate(70, 0);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
286 dsp->printf("Knob = %X ", knob);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
287 dsp->copy_to_lcd();
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
288 }
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
289 knob = 0;
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
290 }
34
94ab7ff42a1b Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents: 32
diff changeset
291
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
292 if (!key_buf.empty())
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
293 {
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
294 key_buf.pop(key);
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
295 keycode = kp_mapping[key.row][key.col];
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
296
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
297 if ((keycode == KC_SHIFT) && (key.keyevent == KEY_PRESSED))
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
298 {
57
cce151e4bf3d Small fixes in main
David Douard <david.douard@sdf3.org>
parents: 54
diff changeset
299 // toggle the shift indicator
cce151e4bf3d Small fixes in main
David Douard <david.douard@sdf3.org>
parents: 54
diff changeset
300 if (shift)
cce151e4bf3d Small fixes in main
David Douard <david.douard@sdf3.org>
parents: 54
diff changeset
301 shift = false;
cce151e4bf3d Small fixes in main
David Douard <david.douard@sdf3.org>
parents: 54
diff changeset
302 else
65
d9c5eaf85fab Fix SHIFT and code cleanup
David Douard <david.douard@sdfa3.org>
parents: 64
diff changeset
303 shift = true;
57
cce151e4bf3d Small fixes in main
David Douard <david.douard@sdf3.org>
parents: 54
diff changeset
304 dsp->set_flag_status(0x0E, shift);
54
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
305 dsp->draw_flag(0x0E);
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
306 }
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
307
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
308 if (hp != NULL) {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
309 if ((shift) && (keycode != KC_SHIFT))
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
310 {
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
311 keycode |= 0x20; // bit 5: key shifted
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
312 shift = false;
54
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
313 dsp->set_flag_status(0x0E, false);
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
314 }
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
315 if (key.keyevent == KEY_RELEASED)
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
316 keycode |= 0x40; // bit 6: key relased
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
317 printf("KEY[%d] %s%X\n", nkeys++, keycode<0x0F ? "0" : "", keycode);
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
318 hp->sendkey(keycode);
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
319 }
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
320 else
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
321 {
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
322 dsp->locate(140, 0);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
323 dsp->printf("KC: %dx%d[0x%s%X] %s",
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
324 key.row, key.col,
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
325 kp_mapping[key.row][key.col] <= 0x0F ? "0" : "",
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
326 kp_mapping[key.row][key.col],
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
327 key.keyevent==KEY_PRESSED ? "PRE" : "REL");
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
328 dsp->copy_to_lcd();
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
329 }
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
330 }
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
331
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
332 if ((hp != NULL) && (hp->cmd_available()))
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
333 {
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
334 if (hp->pop(cmd))
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
335 {
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
336 for (uint8_t i=0; i<7; i++)
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
337 if (hp->nerrors(i) > err[i]) {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
338 printf("ERR: %X/%X/%X/%X/%X/%X/%X\n",
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
339 hp->nerrors(0),
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
340 hp->nerrors(1),
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
341 hp->nerrors(2),
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
342 hp->nerrors(3),
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
343 hp->nerrors(4),
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
344 hp->nerrors(5),
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
345 hp->nerrors(6)
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
346 );
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
347 break;
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
348 }
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
349 for (uint8_t i=0; i<7; i++)
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
350 err[i] = hp->nerrors(i);
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
351
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
352 printf("CMD[%d] %s%X", (int)cmd.id, cmd.cmd<0x10 ? "0" : "", cmd.cmd);
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
353
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
354 // 0x00: main display
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
355 // 0x0C: channel display
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
356 if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C))
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
357 printf(": '%s'\n", cmd.value);
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
358 else {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
359 printf(": ");
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
360 for (uint8_t i=0; i<cmd.size; i++)
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
361 printf("%s%X ", cmd.value[i] < 0x10 ? "0" : "", cmd.value[i]);
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
362 printf("\n");
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
363 }
36
a6c7292742a0 Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents: 35
diff changeset
364
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
365 if (cmd.cmd == 0x01) {
36
a6c7292742a0 Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents: 35
diff changeset
366 // clear a flag
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
367 if (cmd.value[0] == 0x0E) {
36
a6c7292742a0 Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents: 35
diff changeset
368 // clear the Shift flag
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
369 shift = false;
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
370 }
54
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
371 dsp->set_flag_status(cmd.value[0], false);
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
372 dsp->draw_flag(cmd.value[0]);
52
098124b730eb Add support for 0x08 and 0x09 command codes (display a flag dimm/bright)
David Douard <david.douard@sdf3.org>
parents: 49
diff changeset
373 } else if (cmd.cmd == 0x08) {
098124b730eb Add support for 0x08 and 0x09 command codes (display a flag dimm/bright)
David Douard <david.douard@sdf3.org>
parents: 49
diff changeset
374 // set a flag dimmed
54
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
375 dsp->set_flag_status(cmd.value[0], true);
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
376 dsp->set_flag_dim(cmd.value[0], true);
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
377 dsp->draw_flag(cmd.value[0]);
52
098124b730eb Add support for 0x08 and 0x09 command codes (display a flag dimm/bright)
David Douard <david.douard@sdf3.org>
parents: 49
diff changeset
378 } else if (cmd.cmd == 0x09) {
098124b730eb Add support for 0x08 and 0x09 command codes (display a flag dimm/bright)
David Douard <david.douard@sdf3.org>
parents: 49
diff changeset
379 // set a flag bright
54
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
380 dsp->set_flag_status(cmd.value[0], true);
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
381 dsp->set_flag_dim(cmd.value[0], false);
f6774bd0d570 Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents: 53
diff changeset
382 dsp->draw_flag(cmd.value[0]);
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
383 } else if (cmd.cmd == 0x86) {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
384 // shutdown
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
385 dsp->show_byescreen();
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
386 byescreen_timer.attach(callback(&shutdown), 2s);
62
55e3b4441b11 Stop splashscreen after 5s
David Douard <david.douard@sdfa3.org>
parents: 57
diff changeset
387 } else {
36
a6c7292742a0 Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents: 35
diff changeset
388 // display related commands
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
389 dsp->show(cmd.cmd, cmd.value, cmd.size);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
390 }
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
391 }
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
392 }
68
a0f97359f266 Revert to soft reset on RST irq
David Douard <david.douard@sdfa3.org>
parents: 65
diff changeset
393 }
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
394 //else
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
395 ThisThread::sleep_for(1ms);
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
396 }
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
397 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
398
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
399
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
400 void qei_cb(int dir)
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
401 {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
402 if(dir == 1) // turn right
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
403 knob = 0x80;
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
404 else // turn left
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
405 knob = 0x81; // 83?
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
406 }
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
407
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
408 void kp_cb(uint8_t row, uint8_t col)
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
409 {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
410 last_key.row = row;
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
411 last_key.col = col;
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
412 last_key.keyevent = KEY_PRESSED;
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
413 if(!key_buf.full())
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
414 key_buf.push(last_key);
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
415 }
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
416
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
417 void kr_cb(uint8_t row, uint8_t col)
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
418 {
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
419 last_key.row = row;
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
420 last_key.col = col;
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
421 last_key.keyevent = KEY_RELEASED;
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
422 if(!key_buf.full())
44
b3c3d54d2c7c Many improvements
David Douard <david.douard@sdf3.org>
parents: 38
diff changeset
423 key_buf.push(last_key);
19
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
424 }
a52d60613cf7 Stuff...
David Douard <david.douard@logilab.fr>
parents: 18
diff changeset
425
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
426 int main()
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
427 {
38
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
428 setup();
ffef9bbb345d kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents: 37
diff changeset
429 mainloop();
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
430 }

mercurial