diff options
| author | Joel Challis <git@zvecr.com> | 2021-02-14 00:51:06 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-14 11:51:06 +1100 |
| commit | de8caf708c1a9a80527a04be620ed3969262e50b (patch) | |
| tree | 2b0839ed1f1c77c3bab8c1c28fff6f4ba62696eb /quantum/quantum.h | |
| parent | 101990139f3efc0d61491d58f41474f5bc039c66 (diff) | |
| download | qmk_firmware-de8caf708c1a9a80527a04be620ed3969262e50b.tar.gz qmk_firmware-de8caf708c1a9a80527a04be620ed3969262e50b.zip | |
Split gpio and atomic to platform (#11792)
Diffstat (limited to 'quantum/quantum.h')
| -rw-r--r-- | quantum/quantum.h | 91 |
1 files changed, 2 insertions, 89 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h index f4df5bf15..dd2a6dd53 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -54,6 +54,8 @@ | |||
| 54 | #include "bootloader.h" | 54 | #include "bootloader.h" |
| 55 | #include "timer.h" | 55 | #include "timer.h" |
| 56 | #include "config_common.h" | 56 | #include "config_common.h" |
| 57 | #include "gpio.h" | ||
| 58 | #include "atomic_util.h" | ||
| 57 | #include "led.h" | 59 | #include "led.h" |
| 58 | #include "action_util.h" | 60 | #include "action_util.h" |
| 59 | #include "action_tapping.h" | 61 | #include "action_tapping.h" |
| @@ -192,95 +194,6 @@ extern layer_state_t layer_state; | |||
| 192 | # include "wpm.h" | 194 | # include "wpm.h" |
| 193 | #endif | 195 | #endif |
| 194 | 196 | ||
| 195 | // Function substitutions to ease GPIO manipulation | ||
| 196 | #if defined(__AVR__) | ||
| 197 | typedef uint8_t pin_t; | ||
| 198 | |||
| 199 | # define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | ||
| 200 | # define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 201 | # define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") | ||
| 202 | # define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 203 | |||
| 204 | # define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 205 | # define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | ||
| 206 | # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) | ||
| 207 | |||
| 208 | # define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) | ||
| 209 | |||
| 210 | # define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) | ||
| 211 | |||
| 212 | #elif defined(PROTOCOL_CHIBIOS) | ||
| 213 | typedef ioline_t pin_t; | ||
| 214 | |||
| 215 | # define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) | ||
| 216 | # define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) | ||
| 217 | # define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) | ||
| 218 | # define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) | ||
| 219 | |||
| 220 | # define writePinHigh(pin) palSetLine(pin) | ||
| 221 | # define writePinLow(pin) palClearLine(pin) | ||
| 222 | # define writePin(pin, level) ((level) ? (writePinHigh(pin)) : (writePinLow(pin))) | ||
| 223 | |||
| 224 | # define readPin(pin) palReadLine(pin) | ||
| 225 | |||
| 226 | # define togglePin(pin) palToggleLine(pin) | ||
| 227 | #endif | ||
| 228 | |||
| 229 | // Atomic macro to help make GPIO and other controls atomic. | ||
| 230 | #ifdef IGNORE_ATOMIC_BLOCK | ||
| 231 | /* do nothing atomic macro */ | ||
| 232 | # define ATOMIC_BLOCK for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0) | ||
| 233 | # define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK | ||
| 234 | # define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK | ||
| 235 | |||
| 236 | #elif defined(__AVR__) | ||
| 237 | /* atomic macro for AVR */ | ||
| 238 | # include <util/atomic.h> | ||
| 239 | |||
| 240 | # define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE) | ||
| 241 | # define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) | ||
| 242 | |||
| 243 | #elif defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM) | ||
| 244 | /* atomic macro for ChibiOS / ARM ATSAM */ | ||
| 245 | # if defined(PROTOCOL_ARM_ATSAM) | ||
| 246 | # include "arm_atsam_protocol.h" | ||
| 247 | # endif | ||
| 248 | |||
| 249 | static __inline__ uint8_t __interrupt_disable__(void) { | ||
| 250 | # if defined(PROTOCOL_CHIBIOS) | ||
| 251 | chSysLock(); | ||
| 252 | # endif | ||
| 253 | # if defined(PROTOCOL_ARM_ATSAM) | ||
| 254 | __disable_irq(); | ||
| 255 | # endif | ||
| 256 | return 1; | ||
| 257 | } | ||
| 258 | |||
| 259 | static __inline__ void __interrupt_enable__(const uint8_t *__s) { | ||
| 260 | # if defined(PROTOCOL_CHIBIOS) | ||
| 261 | chSysUnlock(); | ||
| 262 | # endif | ||
| 263 | # if defined(PROTOCOL_ARM_ATSAM) | ||
| 264 | __enable_irq(); | ||
| 265 | # endif | ||
| 266 | __asm__ volatile("" ::: "memory"); | ||
| 267 | (void)__s; | ||
| 268 | } | ||
| 269 | |||
| 270 | # define ATOMIC_BLOCK(type) for (type, __ToDo = __interrupt_disable__(); __ToDo; __ToDo = 0) | ||
| 271 | # define ATOMIC_FORCEON uint8_t sreg_save __attribute__((__cleanup__(__interrupt_enable__))) = 0 | ||
| 272 | |||
| 273 | # define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE dose not implement") | ||
| 274 | # define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) | ||
| 275 | |||
| 276 | /* Other platform */ | ||
| 277 | #else | ||
| 278 | |||
| 279 | # define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE dose not implement") | ||
| 280 | # define ATOMIC_BLOCK_FORCEON _Static_assert(0, "ATOMIC_BLOCK_FORCEON dose not implement") | ||
| 281 | |||
| 282 | #endif | ||
| 283 | |||
| 284 | #define SEND_STRING(string) send_string_P(PSTR(string)) | 197 | #define SEND_STRING(string) send_string_P(PSTR(string)) |
| 285 | #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval) | 198 | #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval) |
| 286 | 199 | ||
