aboutsummaryrefslogtreecommitdiff
path: root/keyboards/zinc
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/zinc')
-rw-r--r--keyboards/zinc/serial.c78
1 files changed, 63 insertions, 15 deletions
diff --git a/keyboards/zinc/serial.c b/keyboards/zinc/serial.c
index 830f86b55..325c29a3f 100644
--- a/keyboards/zinc/serial.c
+++ b/keyboards/zinc/serial.c
@@ -1,5 +1,10 @@
1/* 1/*
2 * WARNING: be careful changing this code, it is very timing dependent 2 * WARNING: be careful changing this code, it is very timing dependent
3 *
4 * 2018-10-28 checked
5 * avr-gcc 4.9.2
6 * avr-gcc 5.4.0
7 * avr-gcc 7.3.0
3 */ 8 */
4 9
5#ifndef F_CPU 10#ifndef F_CPU
@@ -65,6 +70,7 @@
65 #error serial.c now support ATmega32U4 only 70 #error serial.c now support ATmega32U4 only
66#endif 71#endif
67 72
73//////////////// for backward compatibility ////////////////////////////////
68#ifndef SERIAL_USE_MULTI_TRANSACTION 74#ifndef SERIAL_USE_MULTI_TRANSACTION
69/* --- USE Simple API (OLD API, compatible with let's split serial.c) */ 75/* --- USE Simple API (OLD API, compatible with let's split serial.c) */
70 #if SERIAL_SLAVE_BUFFER_LENGTH > 0 76 #if SERIAL_SLAVE_BUFFER_LENGTH > 0
@@ -106,7 +112,8 @@ int serial_update_buffers()
106 return result; 112 return result;
107} 113}
108 114
109#endif // Simple API (OLD API, compatible with let's split serial.c) 115#endif // end of Simple API (OLD API, compatible with let's split serial.c)
116////////////////////////////////////////////////////////////////////////////
110 117
111#define ALWAYS_INLINE __attribute__((always_inline)) 118#define ALWAYS_INLINE __attribute__((always_inline))
112#define NO_INLINE __attribute__((noinline)) 119#define NO_INLINE __attribute__((noinline))
@@ -136,38 +143,68 @@ int serial_update_buffers()
136// 5: about 20kbps 143// 5: about 20kbps
137#endif 144#endif
138 145
139#define TID_SEND_ADJUST 2 146#if __GNUC__ < 6
147 #define TID_SEND_ADJUST 14
148#else
149 #define TID_SEND_ADJUST 2
150#endif
140 151
141#if SELECT_SOFT_SERIAL_SPEED == 0 152#if SELECT_SOFT_SERIAL_SPEED == 0
142 // Very High speed 153 // Very High speed
143 #define SERIAL_DELAY 4 // micro sec 154 #define SERIAL_DELAY 4 // micro sec
144 #define READ_WRITE_START_ADJUST 33 // cycles 155 #if __GNUC__ < 6
145 #define READ_WRITE_WIDTH_ADJUST 6 // cycles 156 #define READ_WRITE_START_ADJUST 33 // cycles
157 #define READ_WRITE_WIDTH_ADJUST 3 // cycles
158 #else
159 #define READ_WRITE_START_ADJUST 34 // cycles
160 #define READ_WRITE_WIDTH_ADJUST 7 // cycles
161 #endif
146#elif SELECT_SOFT_SERIAL_SPEED == 1 162#elif SELECT_SOFT_SERIAL_SPEED == 1
147 // High speed 163 // High speed
148 #define SERIAL_DELAY 6 // micro sec 164 #define SERIAL_DELAY 6 // micro sec
149 #define READ_WRITE_START_ADJUST 30 // cycles 165 #if __GNUC__ < 6
150 #define READ_WRITE_WIDTH_ADJUST 7 // cycles 166 #define READ_WRITE_START_ADJUST 30 // cycles
167 #define READ_WRITE_WIDTH_ADJUST 3 // cycles
168 #else
169 #define READ_WRITE_START_ADJUST 33 // cycles
170 #define READ_WRITE_WIDTH_ADJUST 7 // cycles
171 #endif
151#elif SELECT_SOFT_SERIAL_SPEED == 2 172#elif SELECT_SOFT_SERIAL_SPEED == 2
152 // Middle speed 173 // Middle speed
153 #define SERIAL_DELAY 12 // micro sec 174 #define SERIAL_DELAY 12 // micro sec
154 #define READ_WRITE_START_ADJUST 30 // cycles 175 #define READ_WRITE_START_ADJUST 30 // cycles
155 #define READ_WRITE_WIDTH_ADJUST 7 // cycles 176 #if __GNUC__ < 6
177 #define READ_WRITE_WIDTH_ADJUST 3 // cycles
178 #else
179 #define READ_WRITE_WIDTH_ADJUST 7 // cycles
180 #endif
156#elif SELECT_SOFT_SERIAL_SPEED == 3 181#elif SELECT_SOFT_SERIAL_SPEED == 3
157 // Low speed 182 // Low speed
158 #define SERIAL_DELAY 24 // micro sec 183 #define SERIAL_DELAY 24 // micro sec
159 #define READ_WRITE_START_ADJUST 30 // cycles 184 #define READ_WRITE_START_ADJUST 30 // cycles
160 #define READ_WRITE_WIDTH_ADJUST 7 // cycles 185 #if __GNUC__ < 6
186 #define READ_WRITE_WIDTH_ADJUST 3 // cycles
187 #else
188 #define READ_WRITE_WIDTH_ADJUST 7 // cycles
189 #endif
161#elif SELECT_SOFT_SERIAL_SPEED == 4 190#elif SELECT_SOFT_SERIAL_SPEED == 4
162 // Very Low speed 191 // Very Low speed
163 #define SERIAL_DELAY 36 // micro sec 192 #define SERIAL_DELAY 36 // micro sec
164 #define READ_WRITE_START_ADJUST 30 // cycles 193 #define READ_WRITE_START_ADJUST 30 // cycles
165 #define READ_WRITE_WIDTH_ADJUST 7 // cycles 194 #if __GNUC__ < 6
195 #define READ_WRITE_WIDTH_ADJUST 3 // cycles
196 #else
197 #define READ_WRITE_WIDTH_ADJUST 7 // cycles
198 #endif
166#elif SELECT_SOFT_SERIAL_SPEED == 5 199#elif SELECT_SOFT_SERIAL_SPEED == 5
167 // Ultra Low speed 200 // Ultra Low speed
168 #define SERIAL_DELAY 48 // micro sec 201 #define SERIAL_DELAY 48 // micro sec
169 #define READ_WRITE_START_ADJUST 30 // cycles 202 #define READ_WRITE_START_ADJUST 30 // cycles
170 #define READ_WRITE_WIDTH_ADJUST 7 // cycles 203 #if __GNUC__ < 6
204 #define READ_WRITE_WIDTH_ADJUST 3 // cycles
205 #else
206 #define READ_WRITE_WIDTH_ADJUST 7 // cycles
207 #endif
171#else 208#else
172#error invalid SELECT_SOFT_SERIAL_SPEED value 209#error invalid SELECT_SOFT_SERIAL_SPEED value
173#endif /* SELECT_SOFT_SERIAL_SPEED */ 210#endif /* SELECT_SOFT_SERIAL_SPEED */
@@ -187,16 +224,19 @@ int serial_update_buffers()
187static SSTD_t *Transaction_table = NULL; 224static SSTD_t *Transaction_table = NULL;
188static uint8_t Transaction_table_size = 0; 225static uint8_t Transaction_table_size = 0;
189 226
227inline static void serial_delay(void) ALWAYS_INLINE;
190inline static 228inline static
191void serial_delay(void) { 229void serial_delay(void) {
192 _delay_us(SERIAL_DELAY); 230 _delay_us(SERIAL_DELAY);
193} 231}
194 232
233inline static void serial_delay_half1(void) ALWAYS_INLINE;
195inline static 234inline static
196void serial_delay_half1(void) { 235void serial_delay_half1(void) {
197 _delay_us(SERIAL_DELAY_HALF1); 236 _delay_us(SERIAL_DELAY_HALF1);
198} 237}
199 238
239inline static void serial_delay_half2(void) ALWAYS_INLINE;
200inline static 240inline static
201void serial_delay_half2(void) { 241void serial_delay_half2(void) {
202 _delay_us(SERIAL_DELAY_HALF2); 242 _delay_us(SERIAL_DELAY_HALF2);
@@ -216,6 +256,7 @@ void serial_input_with_pullup(void) {
216 SERIAL_PIN_PORT |= SERIAL_PIN_MASK; 256 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
217} 257}
218 258
259inline static uint8_t serial_read_pin(void) ALWAYS_INLINE;
219inline static 260inline static
220uint8_t serial_read_pin(void) { 261uint8_t serial_read_pin(void) {
221 return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK); 262 return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
@@ -270,7 +311,7 @@ void sync_recv(void) {
270} 311}
271 312
272// Used by the reciver to send a synchronization signal to the sender. 313// Used by the reciver to send a synchronization signal to the sender.
273static void sync_send(void)NO_INLINE; 314static void sync_send(void) NO_INLINE;
274static 315static
275void sync_send(void) { 316void sync_send(void) {
276 serial_low(); 317 serial_low();
@@ -536,7 +577,14 @@ int soft_serial_get_and_clean_status(int sstd_index) {
536#endif 577#endif
537 578
538// Helix serial.c history 579// Helix serial.c history
539// 2018-1-29 fork from let's split (#2308) 580// 2018-1-29 fork from let's split and add PD2, modify sync_recv() (#2308, bceffdefc)
540// 2018-6-28 bug fix master to slave comm (#3255) 581// 2018-6-28 bug fix master to slave comm and speed up (#3255, 1038bbef4)
541// 2018-8-11 improvements (#3608) 582// (adjusted with avr-gcc 4.9.2)
542// 2018-10-21 fix serial and RGB animation conflict (#4191) 583// 2018-7-13 remove USE_SERIAL_PD2 macro (#3374, f30d6dd78)
584// (adjusted with avr-gcc 4.9.2)
585// 2018-8-11 add support multi-type transaction (#3608, feb5e4aae)
586// (adjusted with avr-gcc 4.9.2)
587// 2018-10-21 fix serial and RGB animation conflict (#4191, 4665e4fff)
588// (adjusted with avr-gcc 7.3.0)
589// 2018-10-28 re-adjust compiler depend value of delay (#4269, 8517f8a66)
590// (adjusted with avr-gcc 5.4.0, 7.3.0)