diff options
Diffstat (limited to 'quantum/split_common/serial.c')
-rw-r--r-- | quantum/split_common/serial.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/quantum/split_common/serial.c b/quantum/split_common/serial.c index 1315377a3..322ab8030 100644 --- a/quantum/split_common/serial.c +++ b/quantum/split_common/serial.c | |||
@@ -29,36 +29,32 @@ | |||
29 | #endif | 29 | #endif |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin) & 0xF), \ | ||
33 | PORTx_ADDRESS(pin) |= _BV((pin) & 0xF)) | ||
34 | #define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin) & 0xF)) | ||
35 | #define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin) & 0xF)) | ||
36 | #define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin) & 0xF)) | ||
37 | #define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin) & 0xF))) | ||
38 | |||
32 | #if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3 | 39 | #if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3 |
33 | #define SERIAL_PIN_DDR DDRD | ||
34 | #define SERIAL_PIN_PORT PORTD | ||
35 | #define SERIAL_PIN_INPUT PIND | ||
36 | #if SOFT_SERIAL_PIN == D0 | 40 | #if SOFT_SERIAL_PIN == D0 |
37 | #define SERIAL_PIN_MASK _BV(PD0) | ||
38 | #define EIMSK_BIT _BV(INT0) | 41 | #define EIMSK_BIT _BV(INT0) |
39 | #define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01))) | 42 | #define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01))) |
40 | #define SERIAL_PIN_INTERRUPT INT0_vect | 43 | #define SERIAL_PIN_INTERRUPT INT0_vect |
41 | #elif SOFT_SERIAL_PIN == D1 | 44 | #elif SOFT_SERIAL_PIN == D1 |
42 | #define SERIAL_PIN_MASK _BV(PD1) | ||
43 | #define EIMSK_BIT _BV(INT1) | 45 | #define EIMSK_BIT _BV(INT1) |
44 | #define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11))) | 46 | #define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11))) |
45 | #define SERIAL_PIN_INTERRUPT INT1_vect | 47 | #define SERIAL_PIN_INTERRUPT INT1_vect |
46 | #elif SOFT_SERIAL_PIN == D2 | 48 | #elif SOFT_SERIAL_PIN == D2 |
47 | #define SERIAL_PIN_MASK _BV(PD2) | ||
48 | #define EIMSK_BIT _BV(INT2) | 49 | #define EIMSK_BIT _BV(INT2) |
49 | #define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21))) | 50 | #define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21))) |
50 | #define SERIAL_PIN_INTERRUPT INT2_vect | 51 | #define SERIAL_PIN_INTERRUPT INT2_vect |
51 | #elif SOFT_SERIAL_PIN == D3 | 52 | #elif SOFT_SERIAL_PIN == D3 |
52 | #define SERIAL_PIN_MASK _BV(PD3) | ||
53 | #define EIMSK_BIT _BV(INT3) | 53 | #define EIMSK_BIT _BV(INT3) |
54 | #define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31))) | 54 | #define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31))) |
55 | #define SERIAL_PIN_INTERRUPT INT3_vect | 55 | #define SERIAL_PIN_INTERRUPT INT3_vect |
56 | #endif | 56 | #endif |
57 | #elif SOFT_SERIAL_PIN == E6 | 57 | #elif SOFT_SERIAL_PIN == E6 |
58 | #define SERIAL_PIN_DDR DDRE | ||
59 | #define SERIAL_PIN_PORT PORTE | ||
60 | #define SERIAL_PIN_INPUT PINE | ||
61 | #define SERIAL_PIN_MASK _BV(PE6) | ||
62 | #define EIMSK_BIT _BV(INT6) | 58 | #define EIMSK_BIT _BV(INT6) |
63 | #define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61))) | 59 | #define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61))) |
64 | #define SERIAL_PIN_INTERRUPT INT6_vect | 60 | #define SERIAL_PIN_INTERRUPT INT6_vect |
@@ -200,33 +196,32 @@ void serial_delay_half2(void) { | |||
200 | inline static void serial_output(void) ALWAYS_INLINE; | 196 | inline static void serial_output(void) ALWAYS_INLINE; |
201 | inline static | 197 | inline static |
202 | void serial_output(void) { | 198 | void serial_output(void) { |
203 | SERIAL_PIN_DDR |= SERIAL_PIN_MASK; | 199 | setPinOutput(SOFT_SERIAL_PIN); |
204 | } | 200 | } |
205 | 201 | ||
206 | // make the serial pin an input with pull-up resistor | 202 | // make the serial pin an input with pull-up resistor |
207 | inline static void serial_input_with_pullup(void) ALWAYS_INLINE; | 203 | inline static void serial_input_with_pullup(void) ALWAYS_INLINE; |
208 | inline static | 204 | inline static |
209 | void serial_input_with_pullup(void) { | 205 | void serial_input_with_pullup(void) { |
210 | SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK; | 206 | setPinInputHigh(SOFT_SERIAL_PIN); |
211 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | ||
212 | } | 207 | } |
213 | 208 | ||
214 | inline static uint8_t serial_read_pin(void) ALWAYS_INLINE; | 209 | inline static uint8_t serial_read_pin(void) ALWAYS_INLINE; |
215 | inline static | 210 | inline static |
216 | uint8_t serial_read_pin(void) { | 211 | uint8_t serial_read_pin(void) { |
217 | return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK); | 212 | return !! readPin(SOFT_SERIAL_PIN); |
218 | } | 213 | } |
219 | 214 | ||
220 | inline static void serial_low(void) ALWAYS_INLINE; | 215 | inline static void serial_low(void) ALWAYS_INLINE; |
221 | inline static | 216 | inline static |
222 | void serial_low(void) { | 217 | void serial_low(void) { |
223 | SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; | 218 | writePinLow(SOFT_SERIAL_PIN); |
224 | } | 219 | } |
225 | 220 | ||
226 | inline static void serial_high(void) ALWAYS_INLINE; | 221 | inline static void serial_high(void) ALWAYS_INLINE; |
227 | inline static | 222 | inline static |
228 | void serial_high(void) { | 223 | void serial_high(void) { |
229 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | 224 | writePinHigh(SOFT_SERIAL_PIN); |
230 | } | 225 | } |
231 | 226 | ||
232 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) | 227 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) |
@@ -245,7 +240,7 @@ void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size) | |||
245 | 240 | ||
246 | // Enable INT0-INT3,INT6 | 241 | // Enable INT0-INT3,INT6 |
247 | EIMSK |= EIMSK_BIT; | 242 | EIMSK |= EIMSK_BIT; |
248 | #if SERIAL_PIN_MASK == _BV(PE6) | 243 | #if SOFT_SERIAL_PIN == E6 |
249 | // Trigger on falling edge of INT6 | 244 | // Trigger on falling edge of INT6 |
250 | EICRB &= EICRx_BIT; | 245 | EICRB &= EICRx_BIT; |
251 | #else | 246 | #else |