diff options
| author | Takeshi ISHII <2170248+mtei@users.noreply.github.com> | 2019-08-22 09:10:47 +0900 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-08-21 17:10:47 -0700 |
| commit | 1c5b0cbbeb049b1ce3fb2da6a81fbf83dd9a3ea7 (patch) | |
| tree | daeafd91c08b5631e6e4429fbbd8f895b2855a86 /quantum | |
| parent | b62e160a8950f451b08f1fee0109e60a58c5ddaa (diff) | |
| download | qmk_firmware-1c5b0cbbeb049b1ce3fb2da6a81fbf83dd9a3ea7.tar.gz qmk_firmware-1c5b0cbbeb049b1ce3fb2da6a81fbf83dd9a3ea7.zip | |
AVR GPIO macro defines more readable (#5937)
* A little easier to read the definition of the GPIO control macro for AVR.
No change in build result.
* Changed to not use GNU statement expression extension.
No change in build result.
* Modified split_common/serial.c to use qmk_firmware standard GPIO control macro.
No change in build result.
* fix PE6 -> E6
* remove some space
* add some comment to config_common.h
* Changed split_common/serial.c to use a newer version of qmk_firmware standard GPIO control macro.
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/config_common.h | 10 | ||||
| -rw-r--r-- | quantum/quantum.h | 15 | ||||
| -rw-r--r-- | quantum/split_common/serial.c | 31 |
3 files changed, 30 insertions, 26 deletions
diff --git a/quantum/config_common.h b/quantum/config_common.h index bc4d9ec1a..ae72701da 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h | |||
| @@ -132,6 +132,16 @@ | |||
| 132 | #define F7 PINDEF(F, 7) | 132 | #define F7 PINDEF(F, 7) |
| 133 | #endif | 133 | #endif |
| 134 | 134 | ||
| 135 | #ifndef __ASSEMBLER__ | ||
| 136 | #define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset) | ||
| 137 | // Port X Input Pins Address | ||
| 138 | #define PINx_ADDRESS(p) _PIN_ADDRESS(p, 0) | ||
| 139 | // Port X Data Direction Register, 0:input 1:output | ||
| 140 | #define DDRx_ADDRESS(p) _PIN_ADDRESS(p, 1) | ||
| 141 | // Port X Data Register | ||
| 142 | #define PORTx_ADDRESS(p) _PIN_ADDRESS(p, 2) | ||
| 143 | #endif | ||
| 144 | |||
| 135 | #elif defined(PROTOCOL_CHIBIOS) | 145 | #elif defined(PROTOCOL_CHIBIOS) |
| 136 | // Defines mapping for Proton C replacement | 146 | // Defines mapping for Proton C replacement |
| 137 | #ifdef CONVERT_TO_PROTON_C | 147 | #ifdef CONVERT_TO_PROTON_C |
diff --git a/quantum/quantum.h b/quantum/quantum.h index 221462567..2cb26d4f4 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -149,18 +149,17 @@ extern layer_state_t default_layer_state; | |||
| 149 | #if defined(__AVR__) | 149 | #if defined(__AVR__) |
| 150 | typedef uint8_t pin_t; | 150 | typedef uint8_t pin_t; |
| 151 | 151 | ||
| 152 | #define PIN_ADDRESS(p, offset) (_SFR_IO8(ADDRESS_BASE + ((p) >> PORT_SHIFTER) + (offset))) | 152 | #define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin) & 0xF)) |
| 153 | #define setPinInput(pin) (PIN_ADDRESS(pin, 1) &= ~_BV((pin) & 0xF)) | 153 | #define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin) & 0xF), \ |
| 154 | #define setPinInputHigh(pin) (PIN_ADDRESS(pin, 1) &= ~_BV((pin) & 0xF), \ | 154 | PORTx_ADDRESS(pin) |= _BV((pin) & 0xF)) |
| 155 | PIN_ADDRESS(pin, 2) |= _BV((pin) & 0xF)) | ||
| 156 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") | 155 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") |
| 157 | #define setPinOutput(pin) (PIN_ADDRESS(pin, 1) |= _BV((pin) & 0xF)) | 156 | #define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin) & 0xF)) |
| 158 | 157 | ||
| 159 | #define writePinHigh(pin) (PIN_ADDRESS(pin, 2) |= _BV((pin) & 0xF)) | 158 | #define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin) & 0xF)) |
| 160 | #define writePinLow(pin) (PIN_ADDRESS(pin, 2) &= ~_BV((pin) & 0xF)) | 159 | #define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin) & 0xF)) |
| 161 | #define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) | 160 | #define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) |
| 162 | 161 | ||
| 163 | #define readPin(pin) ((bool)(PIN_ADDRESS(pin, 0) & _BV((pin) & 0xF))) | 162 | #define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin) & 0xF))) |
| 164 | #elif defined(PROTOCOL_CHIBIOS) | 163 | #elif defined(PROTOCOL_CHIBIOS) |
| 165 | typedef ioline_t pin_t; | 164 | typedef ioline_t pin_t; |
| 166 | 165 | ||
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 |
