Sun, 01 Nov 2020 22:10:10 +0100
SSD1322: add power off/on methods
5 | 1 | #ifndef HP34COMM_H |
2 | #define HP34COMM_H | |
3 | ||
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
21
diff
changeset
|
4 | #include <mbed.h> |
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
21
diff
changeset
|
5 | #include <CircularBuffer.h> |
5 | 6 | |
7 | /***** HP 34970A communication class ***/ | |
8 | ||
9 | #define MAX_ERRS 10 | |
8 | 10 | #define MAX_BUFF 16 |
11 | #define BUF_SIZE 16 | |
5 | 12 | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
13 | |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
14 | |
5 | 15 | class HPSerial { |
16 | ||
17 | public: | |
18 | typedef struct _CMD | |
19 | { | |
20 | uint8_t cmd; | |
21 | uint8_t size; | |
22 | char value[MAX_BUFF+1]; | |
23 | unsigned long id; | |
24 | } CMD; | |
21 | 25 | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
26 | HPSerial(PinName tx, PinName rx); |
19 | 27 | |
5 | 28 | bool cmd_available(void); |
29 | bool pop(CMD& cmd); | |
30 | bool cmd_buf_full(void); | |
31 | unsigned int nerrors(uint8_t errorno); | |
21 | 32 | |
39
63c6a720cb97
hp34comm: add support for boot keycode
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
33 | void startup(uint8_t keycode=0xFF); |
19 | 34 | void sendkey(uint8_t keycode); |
21 | 35 | |
5 | 36 | private: |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
37 | void pushCmd(uint8_t cmd, uint8_t size, char *payload); |
5 | 38 | void rxIrq(void); |
39 | void timeout(void); | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
40 | void set_timer(Kernel::Clock::duration_u32 v=0ms) { |
19 | 41 | timeouter.detach(); |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
42 | if (v > 0ms) |
19 | 43 | timeouter.attach(callback(this, &HPSerial::timeout), v); |
44 | } | |
5 | 45 | |
46 | private: | |
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
21
diff
changeset
|
47 | UnbufferedSerial serial; |
5 | 48 | uint8_t buf[BUF_SIZE]; |
49 | uint8_t head; | |
50 | CircularBuffer<CMD, 32> cmdbuf; | |
51 | unsigned long ncmd; | |
52 | unsigned int errs[MAX_ERRS]; | |
53 | Ticker timeouter; | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
54 | |
19 | 55 | public: |
56 | // global state machine | |
57 | typedef enum { | |
58 | GSTATE_STARTING, | |
59 | GSTATE_IDLE, | |
60 | GSTATE_TX, | |
61 | GSTATE_RX, | |
62 | NUM_GSTATES} gstate_t; | |
63 | gstate_t gstate() {return cur_gstate;}; | |
64 | /* gstate_t do_start(); */ | |
65 | /* gstate_t do_send(); */ | |
66 | /* gstate_t do_receive(); */ | |
21 | 67 | |
19 | 68 | /* typedef gstate_t(HPSerial::*gstatemethod)(); */ |
69 | /* statemethod const gstate_table[NUM_GSTATES] = { */ | |
70 | /* &HPSerial::do_start, */ | |
71 | /* &HPSerial::do_send, */ | |
72 | /* &HPSerial::do_receive, */ | |
73 | /* }; */ | |
21 | 74 | |
19 | 75 | /* gstate_t run_gstate(gstate_t cur_state); */ |
76 | private: | |
77 | gstate_t cur_gstate; | |
21 | 78 | |
19 | 79 | public: |
80 | // transmission state machine | |
81 | typedef enum { | |
82 | STATE_IDLE, | |
83 | STATE_COMMAND, | |
84 | STATE_PAYLOAD_SIZE, | |
85 | STATE_PAYLOAD, | |
86 | STATE_SENDING, | |
87 | STATE_EOT, | |
88 | NUM_STATES} state_t; | |
89 | state_t state() {return cur_state;}; | |
21 | 90 | |
19 | 91 | private: |
92 | typedef struct state_data { | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
93 | uint8_t cmd; |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
94 | uint8_t size; |
19 | 95 | uint8_t pos; |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
96 | char payload[MAX_BUFF]; |
19 | 97 | } state_data_t; |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
98 | |
19 | 99 | void _startup(void); |
100 | state_t do_state_initial(uint8_t c=0x00); | |
101 | state_t do_state_command(uint8_t c); | |
102 | state_t do_state_payload_size(uint8_t c); | |
103 | state_t do_state_payload(uint8_t c); | |
104 | state_t do_state_sending(uint8_t c=0x00); | |
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
21
diff
changeset
|
105 | state_t do_state_eot(uint8_t c=0x55); |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
106 | |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
107 | void send_ack(uint8_t c); |
21 | 108 | |
19 | 109 | typedef state_t(HPSerial::*statemethod)(uint8_t c); |
21 | 110 | static statemethod state_table[NUM_STATES]; |
19 | 111 | state_t run_state(state_t cur_state, uint8_t c); |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
112 | |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
113 | state_t cur_state; |
19 | 114 | state_data_t tr_data; |
5 | 115 | }; |
116 | ||
19 | 117 | |
5 | 118 | #endif |