14 DigitalOut lled(LED3); |
14 DigitalOut lled(LED3); |
15 |
15 |
16 #define RXTIMEOUT 50ms |
16 #define RXTIMEOUT 50ms |
17 #define STARTUPRETRY 0.5 |
17 #define STARTUPRETRY 0.5 |
18 |
18 |
19 const uint8_t startup_seq[] = { |
19 uint8_t startup_seq[] = { |
20 0x33, |
20 0x33, |
21 0x02, |
21 0x02, |
22 0x00, |
22 0x00, |
|
23 0x00, // to be replaced by the actual keycode, if any |
23 }; |
24 }; |
24 |
25 |
25 HPSerial::statemethod HPSerial::state_table[NUM_STATES] = { |
26 HPSerial::statemethod HPSerial::state_table[NUM_STATES] = { |
26 &HPSerial::do_state_initial, |
27 &HPSerial::do_state_initial, |
27 &HPSerial::do_state_command, |
28 &HPSerial::do_state_command, |
40 serial.baud(187500); |
41 serial.baud(187500); |
41 cur_state = STATE_IDLE; |
42 cur_state = STATE_IDLE; |
42 serial.attach(callback(this, &HPSerial::rxIrq), SerialBase::RxIrq); |
43 serial.attach(callback(this, &HPSerial::rxIrq), SerialBase::RxIrq); |
43 } |
44 } |
44 |
45 |
45 void HPSerial::startup(void) { |
46 void HPSerial::startup(uint8_t keycode) { |
|
47 if (keycode != 0xFF) { |
|
48 startup_sed[2] = 0xFF; |
|
49 startup_sed[3] = keycode; |
|
50 } |
|
51 |
46 cur_gstate = GSTATE_STARTING; |
52 cur_gstate = GSTATE_STARTING; |
47 set_timer(10ms); // launch the startup in 10ms |
53 set_timer(10ms); // launch the startup in 10ms |
48 } |
54 } |
49 |
55 |
50 void HPSerial::_startup(void) |
56 void HPSerial::_startup(void) |
51 { |
57 { |
52 cur_gstate = GSTATE_STARTING; |
58 cur_gstate = GSTATE_STARTING; |
53 tr_data.size = sizeof(startup_seq); |
|
54 tr_data.cmd = 0xFF; |
59 tr_data.cmd = 0xFF; |
55 tr_data.pos = 0; |
60 tr_data.pos = 0; |
|
61 |
|
62 if (startup_seq[2] == 0xFF) |
|
63 tr_data.size = 4; |
|
64 else |
|
65 tr_data.size = 3; // sizeof(startup_seq); |
56 for(uint8_t i=0; i<tr_data.size; i++) |
66 for(uint8_t i=0; i<tr_data.size; i++) |
57 tr_data.payload[i] = startup_seq[i]; |
67 tr_data.payload[i] = startup_seq[i]; |
|
68 |
58 cur_state = do_state_sending(); |
69 cur_state = do_state_sending(); |
59 } |
|
60 |
|
61 void HPSerial::send(const uint8_t *buf, uint8_t size) |
|
62 { |
|
63 // tx_data-> |
|
64 //send(startup, sizeof(startup)/sizeof(startup[0])); |
|
65 } |
70 } |
66 |
71 |
67 void HPSerial::sendkey(uint8_t keycode) |
72 void HPSerial::sendkey(uint8_t keycode) |
68 { |
73 { |
69 tr_data.size = 2; |
74 tr_data.size = 2; |