diff options
Diffstat (limited to 'keyboards/helix/local_drivers/serial.h')
-rw-r--r-- | keyboards/helix/local_drivers/serial.h | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/keyboards/helix/local_drivers/serial.h b/keyboards/helix/local_drivers/serial.h new file mode 100644 index 000000000..2e53928df --- /dev/null +++ b/keyboards/helix/local_drivers/serial.h | |||
@@ -0,0 +1,89 @@ | |||
1 | #ifndef SOFT_SERIAL_H | ||
2 | #define SOFT_SERIAL_H | ||
3 | |||
4 | #include <stdbool.h> | ||
5 | |||
6 | // ///////////////////////////////////////////////////////////////// | ||
7 | // Need Soft Serial defines in config.h | ||
8 | // ///////////////////////////////////////////////////////////////// | ||
9 | // ex. | ||
10 | // #define SOFT_SERIAL_PIN ?? // ?? = D0,D1,D2,D3,E6 | ||
11 | // OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5 | ||
12 | // // 1: about 137kbps (default) | ||
13 | // // 2: about 75kbps | ||
14 | // // 3: about 39kbps | ||
15 | // // 4: about 26kbps | ||
16 | // // 5: about 20kbps | ||
17 | // | ||
18 | // //// USE OLD API (compatible with let's split serial.c) | ||
19 | // ex. | ||
20 | // #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
21 | // #define SERIAL_MASTER_BUFFER_LENGTH 1 | ||
22 | // | ||
23 | // //// USE NEW API | ||
24 | // //// USE simple API (using signle-type transaction function) | ||
25 | // #define SERIAL_USE_SINGLE_TRANSACTION | ||
26 | // //// USE flexible API (using multi-type transaction function) | ||
27 | // #define SERIAL_USE_MULTI_TRANSACTION | ||
28 | // | ||
29 | // ///////////////////////////////////////////////////////////////// | ||
30 | |||
31 | |||
32 | //////////////// for backward compatibility //////////////////////////////// | ||
33 | #if !defined(SERIAL_USE_SINGLE_TRANSACTION) && !defined(SERIAL_USE_MULTI_TRANSACTION) | ||
34 | /* --- USE OLD API (compatible with let's split serial.c) */ | ||
35 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 | ||
36 | extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; | ||
37 | #endif | ||
38 | #if SERIAL_MASTER_BUFFER_LENGTH > 0 | ||
39 | extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; | ||
40 | #endif | ||
41 | |||
42 | void serial_master_init(void); | ||
43 | void serial_slave_init(void); | ||
44 | int serial_update_buffers(void); | ||
45 | |||
46 | #endif // end of USE OLD API | ||
47 | //////////////////////////////////////////////////////////////////////////// | ||
48 | |||
49 | // Soft Serial Transaction Descriptor | ||
50 | typedef struct _SSTD_t { | ||
51 | uint8_t *status; | ||
52 | uint8_t initiator2target_buffer_size; | ||
53 | uint8_t *initiator2target_buffer; | ||
54 | uint8_t target2initiator_buffer_size; | ||
55 | uint8_t *target2initiator_buffer; | ||
56 | } SSTD_t; | ||
57 | #define TID_LIMIT( table ) (sizeof(table) / sizeof(SSTD_t)) | ||
58 | |||
59 | // initiator is transaction start side | ||
60 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size); | ||
61 | // target is interrupt accept side | ||
62 | void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size); | ||
63 | |||
64 | // initiator resullt | ||
65 | #define TRANSACTION_END 0 | ||
66 | #define TRANSACTION_NO_RESPONSE 0x1 | ||
67 | #define TRANSACTION_DATA_ERROR 0x2 | ||
68 | #define TRANSACTION_TYPE_ERROR 0x4 | ||
69 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
70 | int soft_serial_transaction(void); | ||
71 | #else | ||
72 | int soft_serial_transaction(int sstd_index); | ||
73 | #endif | ||
74 | |||
75 | // target status | ||
76 | // *SSTD_t.status has | ||
77 | // initiator: | ||
78 | // TRANSACTION_END | ||
79 | // or TRANSACTION_NO_RESPONSE | ||
80 | // or TRANSACTION_DATA_ERROR | ||
81 | // target: | ||
82 | // TRANSACTION_DATA_ERROR | ||
83 | // or TRANSACTION_ACCEPTED | ||
84 | #define TRANSACTION_ACCEPTED 0x8 | ||
85 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
86 | int soft_serial_get_and_clean_status(int sstd_index); | ||
87 | #endif | ||
88 | |||
89 | #endif /* SOFT_SERIAL_H */ | ||