diff options
| author | Joshua Diamond <josh@windowoffire.com> | 2021-02-14 19:59:26 -0500 |
|---|---|---|
| committer | Joshua Diamond <josh@windowoffire.com> | 2021-02-14 19:59:26 -0500 |
| commit | f1a3ce49ccdfee79fbad76fd13bcf4448318eb6b (patch) | |
| tree | 8725ba276f485dc62a40d8f6d1ebe1bbc84e6fb3 /quantum/quantum.h | |
| parent | c80e5f9f8868ccaa8cb990be6f4da3f1011c2b78 (diff) | |
| parent | 6f44c2ec31a6aeacd9e90060a9670be03be372fe (diff) | |
| download | qmk_firmware-f1a3ce49ccdfee79fbad76fd13bcf4448318eb6b.tar.gz qmk_firmware-f1a3ce49ccdfee79fbad76fd13bcf4448318eb6b.zip | |
Merge branch 'master' into develop
Diffstat (limited to 'quantum/quantum.h')
| -rw-r--r-- | quantum/quantum.h | 90 |
1 files changed, 3 insertions, 87 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h index b7bf5be31..36a983d57 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -55,6 +55,8 @@ | |||
| 55 | #include "timer.h" | 55 | #include "timer.h" |
| 56 | #include "sync_timer.h" | 56 | #include "sync_timer.h" |
| 57 | #include "config_common.h" | 57 | #include "config_common.h" |
| 58 | #include "gpio.h" | ||
| 59 | #include "atomic_util.h" | ||
| 58 | #include "led.h" | 60 | #include "led.h" |
| 59 | #include "action_util.h" | 61 | #include "action_util.h" |
| 60 | #include "action_tapping.h" | 62 | #include "action_tapping.h" |
| @@ -199,20 +201,6 @@ extern layer_state_t layer_state; | |||
| 199 | 201 | ||
| 200 | // Function substitutions to ease GPIO manipulation | 202 | // Function substitutions to ease GPIO manipulation |
| 201 | #if defined(__AVR__) | 203 | #if defined(__AVR__) |
| 202 | typedef uint8_t pin_t; | ||
| 203 | |||
| 204 | # define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | ||
| 205 | # define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 206 | # define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") | ||
| 207 | # define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 208 | |||
| 209 | # define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 210 | # define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | ||
| 211 | # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) | ||
| 212 | |||
| 213 | # define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) | ||
| 214 | |||
| 215 | # define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) | ||
| 216 | 204 | ||
| 217 | /* The AVR series GPIOs have a one clock read delay for changes in the digital input signal. | 205 | /* The AVR series GPIOs have a one clock read delay for changes in the digital input signal. |
| 218 | * But here's more margin to make it two clocks. */ | 206 | * But here's more margin to make it two clocks. */ |
| @@ -221,25 +209,8 @@ typedef uint8_t pin_t; | |||
| 221 | # endif | 209 | # endif |
| 222 | # define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) | 210 | # define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) |
| 223 | 211 | ||
| 224 | #elif defined(PROTOCOL_CHIBIOS) | 212 | #elif defined(__ARMEL__) || defined(__ARMEB__) |
| 225 | typedef ioline_t pin_t; | ||
| 226 | |||
| 227 | # define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) | ||
| 228 | # define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) | ||
| 229 | # define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) | ||
| 230 | # define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) | ||
| 231 | |||
| 232 | # define writePinHigh(pin) palSetLine(pin) | ||
| 233 | # define writePinLow(pin) palClearLine(pin) | ||
| 234 | # define writePin(pin, level) ((level) ? (writePinHigh(pin)) : (writePinLow(pin))) | ||
| 235 | |||
| 236 | # define readPin(pin) palReadLine(pin) | ||
| 237 | 213 | ||
| 238 | # define togglePin(pin) palToggleLine(pin) | ||
| 239 | |||
| 240 | #endif | ||
| 241 | |||
| 242 | #if defined(__ARMEL__) || defined(__ARMEB__) | ||
| 243 | /* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus | 214 | /* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus |
| 244 | * to which the GPIO is connected. | 215 | * to which the GPIO is connected. |
| 245 | * The connected buses differ depending on the various series of MCUs. | 216 | * The connected buses differ depending on the various series of MCUs. |
| @@ -258,63 +229,8 @@ typedef ioline_t pin_t; | |||
| 258 | # endif | 229 | # endif |
| 259 | # endif | 230 | # endif |
| 260 | # define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) | 231 | # define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) |
| 261 | #endif | ||
| 262 | |||
| 263 | // Atomic macro to help make GPIO and other controls atomic. | ||
| 264 | #ifdef IGNORE_ATOMIC_BLOCK | ||
| 265 | /* do nothing atomic macro */ | ||
| 266 | # define ATOMIC_BLOCK for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0) | ||
| 267 | # define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK | ||
| 268 | # define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK | ||
| 269 | |||
| 270 | #elif defined(__AVR__) | ||
| 271 | /* atomic macro for AVR */ | ||
| 272 | # include <util/atomic.h> | ||
| 273 | |||
| 274 | # define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE) | ||
| 275 | # define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) | ||
| 276 | |||
| 277 | #elif defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM) | ||
| 278 | /* atomic macro for ChibiOS / ARM ATSAM */ | ||
| 279 | # if defined(PROTOCOL_ARM_ATSAM) | ||
| 280 | # include "arm_atsam_protocol.h" | ||
| 281 | # endif | ||
| 282 | |||
| 283 | static __inline__ uint8_t __interrupt_disable__(void) { | ||
| 284 | # if defined(PROTOCOL_CHIBIOS) | ||
| 285 | chSysLock(); | ||
| 286 | # endif | ||
| 287 | # if defined(PROTOCOL_ARM_ATSAM) | ||
| 288 | __disable_irq(); | ||
| 289 | # endif | ||
| 290 | return 1; | ||
| 291 | } | ||
| 292 | |||
| 293 | static __inline__ void __interrupt_enable__(const uint8_t *__s) { | ||
| 294 | # if defined(PROTOCOL_CHIBIOS) | ||
| 295 | chSysUnlock(); | ||
| 296 | # endif | ||
| 297 | # if defined(PROTOCOL_ARM_ATSAM) | ||
| 298 | __enable_irq(); | ||
| 299 | # endif | ||
| 300 | __asm__ volatile("" ::: "memory"); | ||
| 301 | (void)__s; | ||
| 302 | } | ||
| 303 | |||
| 304 | # define ATOMIC_BLOCK(type) for (type, __ToDo = __interrupt_disable__(); __ToDo; __ToDo = 0) | ||
| 305 | # define ATOMIC_FORCEON uint8_t sreg_save __attribute__((__cleanup__(__interrupt_enable__))) = 0 | ||
| 306 | |||
| 307 | # define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE dose not implement") | ||
| 308 | # define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) | ||
| 309 | |||
| 310 | /* Other platform */ | ||
| 311 | #else | ||
| 312 | |||
| 313 | # define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE dose not implement") | ||
| 314 | # define ATOMIC_BLOCK_FORCEON _Static_assert(0, "ATOMIC_BLOCK_FORCEON dose not implement") | ||
| 315 | 232 | ||
| 316 | #endif | 233 | #endif |
| 317 | |||
| 318 | #define SEND_STRING(string) send_string_P(PSTR(string)) | 234 | #define SEND_STRING(string) send_string_P(PSTR(string)) |
| 319 | #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval) | 235 | #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval) |
| 320 | 236 | ||
