diff options
Diffstat (limited to 'keyboards/helix/rev2/split_scomm.c')
-rw-r--r-- | keyboards/helix/rev2/split_scomm.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c new file mode 100644 index 000000000..9719eb22e --- /dev/null +++ b/keyboards/helix/rev2/split_scomm.c | |||
@@ -0,0 +1,73 @@ | |||
1 | #ifdef USE_SERIAL | ||
2 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
3 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
4 | |||
5 | #include <stdbool.h> | ||
6 | #include <stdint.h> | ||
7 | #include <stddef.h> | ||
8 | #include <split_scomm.h> | ||
9 | #include "serial.h" | ||
10 | #ifdef SERIAL_DEBUG_MODE | ||
11 | #include <avr/io.h> | ||
12 | #endif | ||
13 | |||
14 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
15 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
16 | uint8_t volatile status_com = 0; | ||
17 | uint8_t volatile status1 = 0; | ||
18 | uint8_t slave_buffer_change_count = 0; | ||
19 | uint8_t s_change_old = 0xff; | ||
20 | |||
21 | SSTD_t transactions[] = { | ||
22 | #define GET_SLAVE_STATUS 0 | ||
23 | /* master buffer not changed, only recive slave_buffer_change_count */ | ||
24 | { (uint8_t *)&status_com, | ||
25 | 0, NULL, | ||
26 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
27 | }, | ||
28 | #define PUT_MASTER_GET_SLAVE_STATUS 1 | ||
29 | /* master buffer changed need send, and recive slave_buffer_change_count */ | ||
30 | { (uint8_t *)&status_com, | ||
31 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
32 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
33 | }, | ||
34 | #define GET_SLAVE_BUFFER 2 | ||
35 | /* recive serial_slave_buffer */ | ||
36 | { (uint8_t *)&status1, | ||
37 | 0, NULL, | ||
38 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
39 | } | ||
40 | }; | ||
41 | |||
42 | void serial_master_init(void) | ||
43 | { | ||
44 | soft_serial_initiator_init(transactions); | ||
45 | } | ||
46 | |||
47 | void serial_slave_init(void) | ||
48 | { | ||
49 | soft_serial_target_init(transactions); | ||
50 | } | ||
51 | |||
52 | // 0 => no error | ||
53 | // 1 => slave did not respond | ||
54 | // 2 => checksum error | ||
55 | int serial_update_buffers(int master_update) | ||
56 | { | ||
57 | int status; | ||
58 | static int need_retry = 0; | ||
59 | if( s_change_old != slave_buffer_change_count ) { | ||
60 | status = soft_serial_transaction(GET_SLAVE_BUFFER); | ||
61 | if( status == TRANSACTION_END ) | ||
62 | s_change_old = slave_buffer_change_count; | ||
63 | } | ||
64 | if( !master_update && !need_retry) | ||
65 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
66 | else | ||
67 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
68 | need_retry = ( status == TRANSACTION_END ) ? 0 : 1; | ||
69 | return status; | ||
70 | } | ||
71 | |||
72 | #endif // SERIAL_USE_MULTI_TRANSACTION | ||
73 | #endif /* USE_SERIAL */ | ||