diff options
| -rw-r--r-- | quantum/config_common.h | 351 | ||||
| -rw-r--r-- | quantum/quantum.h | 91 | ||||
| -rw-r--r-- | tmk_core/common/atomic_util.h | 32 | ||||
| -rw-r--r-- | tmk_core/common/avr/atomic_util.h | 22 | ||||
| -rw-r--r-- | tmk_core/common/avr/gpio.h | 34 | ||||
| -rw-r--r-- | tmk_core/common/avr/pin_defs.h | 128 | ||||
| -rw-r--r-- | tmk_core/common/chibios/atomic_util.h | 37 | ||||
| -rw-r--r-- | tmk_core/common/chibios/gpio.h | 34 | ||||
| -rw-r--r-- | tmk_core/common/chibios/pin_defs.h | 242 | ||||
| -rw-r--r-- | tmk_core/common/gpio.h | 22 | ||||
| -rw-r--r-- | tmk_core/common/pin_defs.h | 23 |
11 files changed, 580 insertions, 436 deletions
diff --git a/quantum/config_common.h b/quantum/config_common.h index 5973232ef..fa1ff2a5f 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h | |||
| @@ -16,357 +16,14 @@ | |||
| 16 | 16 | ||
| 17 | #pragma once | 17 | #pragma once |
| 18 | 18 | ||
| 19 | #ifndef __ASSEMBLER__ | ||
| 20 | # include "pin_defs.h" | ||
| 21 | #endif | ||
| 22 | |||
| 19 | /* diode directions */ | 23 | /* diode directions */ |
| 20 | #define COL2ROW 0 | 24 | #define COL2ROW 0 |
| 21 | #define ROW2COL 1 | 25 | #define ROW2COL 1 |
| 22 | 26 | ||
| 23 | // useful for direct pin mapping | ||
| 24 | #define NO_PIN (pin_t)(~0) | ||
| 25 | |||
| 26 | #ifdef __AVR__ | ||
| 27 | # ifndef __ASSEMBLER__ | ||
| 28 | # include <avr/io.h> | ||
| 29 | # endif | ||
| 30 | # define PORT_SHIFTER 4 // this may be 4 for all AVR chips | ||
| 31 | |||
| 32 | // If you want to add more to this list, reference the PINx definitions in these header | ||
| 33 | // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr | ||
| 34 | |||
| 35 | # if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) | ||
| 36 | # define ADDRESS_BASE 0x00 | ||
| 37 | # define PINB_ADDRESS 0x3 | ||
| 38 | # define PINC_ADDRESS 0x6 | ||
| 39 | # define PIND_ADDRESS 0x9 | ||
| 40 | # define PINE_ADDRESS 0xC | ||
| 41 | # define PINF_ADDRESS 0xF | ||
| 42 | # elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) | ||
| 43 | # define ADDRESS_BASE 0x00 | ||
| 44 | # define PINB_ADDRESS 0x3 | ||
| 45 | # define PINC_ADDRESS 0x6 | ||
| 46 | # define PIND_ADDRESS 0x9 | ||
| 47 | # elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) | ||
| 48 | # define ADDRESS_BASE 0x00 | ||
| 49 | # define PINA_ADDRESS 0x0 | ||
| 50 | # define PINB_ADDRESS 0x3 | ||
| 51 | # define PINC_ADDRESS 0x6 | ||
| 52 | # define PIND_ADDRESS 0x9 | ||
| 53 | # define PINE_ADDRESS 0xC | ||
| 54 | # define PINF_ADDRESS 0xF | ||
| 55 | # elif defined(__AVR_ATmega32A__) | ||
| 56 | # define ADDRESS_BASE 0x10 | ||
| 57 | # define PIND_ADDRESS 0x0 | ||
| 58 | # define PINC_ADDRESS 0x3 | ||
| 59 | # define PINB_ADDRESS 0x6 | ||
| 60 | # define PINA_ADDRESS 0x9 | ||
| 61 | # elif defined(__AVR_ATtiny85__) | ||
| 62 | # define ADDRESS_BASE 0x10 | ||
| 63 | # define PINB_ADDRESS 0x6 | ||
| 64 | # else | ||
| 65 | # error "Pins are not defined" | ||
| 66 | # endif | ||
| 67 | |||
| 68 | /* I/O pins */ | ||
| 69 | # define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin) | ||
| 70 | |||
| 71 | # ifdef PORTA | ||
| 72 | # define A0 PINDEF(A, 0) | ||
| 73 | # define A1 PINDEF(A, 1) | ||
| 74 | # define A2 PINDEF(A, 2) | ||
| 75 | # define A3 PINDEF(A, 3) | ||
| 76 | # define A4 PINDEF(A, 4) | ||
| 77 | # define A5 PINDEF(A, 5) | ||
| 78 | # define A6 PINDEF(A, 6) | ||
| 79 | # define A7 PINDEF(A, 7) | ||
| 80 | # endif | ||
| 81 | # ifdef PORTB | ||
| 82 | # define B0 PINDEF(B, 0) | ||
| 83 | # define B1 PINDEF(B, 1) | ||
| 84 | # define B2 PINDEF(B, 2) | ||
| 85 | # define B3 PINDEF(B, 3) | ||
| 86 | # define B4 PINDEF(B, 4) | ||
| 87 | # define B5 PINDEF(B, 5) | ||
| 88 | # define B6 PINDEF(B, 6) | ||
| 89 | # define B7 PINDEF(B, 7) | ||
| 90 | # endif | ||
| 91 | # ifdef PORTC | ||
| 92 | # define C0 PINDEF(C, 0) | ||
| 93 | # define C1 PINDEF(C, 1) | ||
| 94 | # define C2 PINDEF(C, 2) | ||
| 95 | # define C3 PINDEF(C, 3) | ||
| 96 | # define C4 PINDEF(C, 4) | ||
| 97 | # define C5 PINDEF(C, 5) | ||
| 98 | # define C6 PINDEF(C, 6) | ||
| 99 | # define C7 PINDEF(C, 7) | ||
| 100 | # endif | ||
| 101 | # ifdef PORTD | ||
| 102 | # define D0 PINDEF(D, 0) | ||
| 103 | # define D1 PINDEF(D, 1) | ||
| 104 | # define D2 PINDEF(D, 2) | ||
| 105 | # define D3 PINDEF(D, 3) | ||
| 106 | # define D4 PINDEF(D, 4) | ||
| 107 | # define D5 PINDEF(D, 5) | ||
| 108 | # define D6 PINDEF(D, 6) | ||
| 109 | # define D7 PINDEF(D, 7) | ||
| 110 | # endif | ||
| 111 | # ifdef PORTE | ||
| 112 | # define E0 PINDEF(E, 0) | ||
| 113 | # define E1 PINDEF(E, 1) | ||
| 114 | # define E2 PINDEF(E, 2) | ||
| 115 | # define E3 PINDEF(E, 3) | ||
| 116 | # define E4 PINDEF(E, 4) | ||
| 117 | # define E5 PINDEF(E, 5) | ||
| 118 | # define E6 PINDEF(E, 6) | ||
| 119 | # define E7 PINDEF(E, 7) | ||
| 120 | # endif | ||
| 121 | # ifdef PORTF | ||
| 122 | # define F0 PINDEF(F, 0) | ||
| 123 | # define F1 PINDEF(F, 1) | ||
| 124 | # define F2 PINDEF(F, 2) | ||
| 125 | # define F3 PINDEF(F, 3) | ||
| 126 | # define F4 PINDEF(F, 4) | ||
| 127 | # define F5 PINDEF(F, 5) | ||
| 128 | # define F6 PINDEF(F, 6) | ||
| 129 | # define F7 PINDEF(F, 7) | ||
| 130 | # endif | ||
| 131 | |||
| 132 | # ifndef __ASSEMBLER__ | ||
| 133 | # define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + ((p) >> PORT_SHIFTER) + (offset)) | ||
| 134 | // Port X Input Pins Address | ||
| 135 | # define PINx_ADDRESS(p) _PIN_ADDRESS(p, 0) | ||
| 136 | // Port X Data Direction Register, 0:input 1:output | ||
| 137 | # define DDRx_ADDRESS(p) _PIN_ADDRESS(p, 1) | ||
| 138 | // Port X Data Register | ||
| 139 | # define PORTx_ADDRESS(p) _PIN_ADDRESS(p, 2) | ||
| 140 | # endif | ||
| 141 | |||
| 142 | #elif defined(PROTOCOL_CHIBIOS) | ||
| 143 | // Defines mapping for Proton C replacement | ||
| 144 | # ifdef CONVERT_TO_PROTON_C | ||
| 145 | // Left side (front) | ||
| 146 | # define D3 PAL_LINE(GPIOA, 9) | ||
| 147 | # define D2 PAL_LINE(GPIOA, 10) | ||
| 148 | // GND | ||
| 149 | // GND | ||
| 150 | # define D1 PAL_LINE(GPIOB, 7) | ||
| 151 | # define D0 PAL_LINE(GPIOB, 6) | ||
| 152 | # define D4 PAL_LINE(GPIOB, 5) | ||
| 153 | # define C6 PAL_LINE(GPIOB, 4) | ||
| 154 | # define D7 PAL_LINE(GPIOB, 3) | ||
| 155 | # define E6 PAL_LINE(GPIOB, 2) | ||
| 156 | # define B4 PAL_LINE(GPIOB, 1) | ||
| 157 | # define B5 PAL_LINE(GPIOB, 0) | ||
| 158 | |||
| 159 | // Right side (front) | ||
| 160 | // RAW | ||
| 161 | // GND | ||
| 162 | // RESET | ||
| 163 | // VCC | ||
| 164 | # define F4 PAL_LINE(GPIOA, 2) | ||
| 165 | # define F5 PAL_LINE(GPIOA, 1) | ||
| 166 | # define F6 PAL_LINE(GPIOA, 0) | ||
| 167 | # define F7 PAL_LINE(GPIOB, 8) | ||
| 168 | # define B1 PAL_LINE(GPIOB, 13) | ||
| 169 | # define B3 PAL_LINE(GPIOB, 14) | ||
| 170 | # define B2 PAL_LINE(GPIOB, 15) | ||
| 171 | # define B6 PAL_LINE(GPIOB, 9) | ||
| 172 | |||
| 173 | // LEDs (only D5/C13 uses an actual LED) | ||
| 174 | # ifdef CONVERT_TO_PROTON_C_RXLED | ||
| 175 | # define D5 PAL_LINE(GPIOC, 14) | ||
| 176 | # define B0 PAL_LINE(GPIOC, 13) | ||
| 177 | # else | ||
| 178 | # define D5 PAL_LINE(GPIOC, 13) | ||
| 179 | # define B0 PAL_LINE(GPIOC, 14) | ||
| 180 | # endif | ||
| 181 | # else | ||
| 182 | # define A0 PAL_LINE(GPIOA, 0) | ||
| 183 | # define A1 PAL_LINE(GPIOA, 1) | ||
| 184 | # define A2 PAL_LINE(GPIOA, 2) | ||
| 185 | # define A3 PAL_LINE(GPIOA, 3) | ||
| 186 | # define A4 PAL_LINE(GPIOA, 4) | ||
| 187 | # define A5 PAL_LINE(GPIOA, 5) | ||
| 188 | # define A6 PAL_LINE(GPIOA, 6) | ||
| 189 | # define A7 PAL_LINE(GPIOA, 7) | ||
| 190 | # define A8 PAL_LINE(GPIOA, 8) | ||
| 191 | # define A9 PAL_LINE(GPIOA, 9) | ||
| 192 | # define A10 PAL_LINE(GPIOA, 10) | ||
| 193 | # define A11 PAL_LINE(GPIOA, 11) | ||
| 194 | # define A12 PAL_LINE(GPIOA, 12) | ||
| 195 | # define A13 PAL_LINE(GPIOA, 13) | ||
| 196 | # define A14 PAL_LINE(GPIOA, 14) | ||
| 197 | # define A15 PAL_LINE(GPIOA, 15) | ||
| 198 | # define B0 PAL_LINE(GPIOB, 0) | ||
| 199 | # define B1 PAL_LINE(GPIOB, 1) | ||
| 200 | # define B2 PAL_LINE(GPIOB, 2) | ||
| 201 | # define B3 PAL_LINE(GPIOB, 3) | ||
| 202 | # define B4 PAL_LINE(GPIOB, 4) | ||
| 203 | # define B5 PAL_LINE(GPIOB, 5) | ||
| 204 | # define B6 PAL_LINE(GPIOB, 6) | ||
| 205 | # define B7 PAL_LINE(GPIOB, 7) | ||
| 206 | # define B8 PAL_LINE(GPIOB, 8) | ||
| 207 | # define B9 PAL_LINE(GPIOB, 9) | ||
| 208 | # define B10 PAL_LINE(GPIOB, 10) | ||
| 209 | # define B11 PAL_LINE(GPIOB, 11) | ||
| 210 | # define B12 PAL_LINE(GPIOB, 12) | ||
| 211 | # define B13 PAL_LINE(GPIOB, 13) | ||
| 212 | # define B14 PAL_LINE(GPIOB, 14) | ||
| 213 | # define B15 PAL_LINE(GPIOB, 15) | ||
| 214 | # define B16 PAL_LINE(GPIOB, 16) | ||
| 215 | # define B17 PAL_LINE(GPIOB, 17) | ||
| 216 | # define B18 PAL_LINE(GPIOB, 18) | ||
| 217 | # define B19 PAL_LINE(GPIOB, 19) | ||
| 218 | # define C0 PAL_LINE(GPIOC, 0) | ||
| 219 | # define C1 PAL_LINE(GPIOC, 1) | ||
| 220 | # define C2 PAL_LINE(GPIOC, 2) | ||
| 221 | # define C3 PAL_LINE(GPIOC, 3) | ||
| 222 | # define C4 PAL_LINE(GPIOC, 4) | ||
| 223 | # define C5 PAL_LINE(GPIOC, 5) | ||
| 224 | # define C6 PAL_LINE(GPIOC, 6) | ||
| 225 | # define C7 PAL_LINE(GPIOC, 7) | ||
| 226 | # define C8 PAL_LINE(GPIOC, 8) | ||
| 227 | # define C9 PAL_LINE(GPIOC, 9) | ||
| 228 | # define C10 PAL_LINE(GPIOC, 10) | ||
| 229 | # define C11 PAL_LINE(GPIOC, 11) | ||
| 230 | # define C12 PAL_LINE(GPIOC, 12) | ||
| 231 | # define C13 PAL_LINE(GPIOC, 13) | ||
| 232 | # define C14 PAL_LINE(GPIOC, 14) | ||
| 233 | # define C15 PAL_LINE(GPIOC, 15) | ||
| 234 | # define D0 PAL_LINE(GPIOD, 0) | ||
| 235 | # define D1 PAL_LINE(GPIOD, 1) | ||
| 236 | # define D2 PAL_LINE(GPIOD, 2) | ||
| 237 | # define D3 PAL_LINE(GPIOD, 3) | ||
| 238 | # define D4 PAL_LINE(GPIOD, 4) | ||
| 239 | # define D5 PAL_LINE(GPIOD, 5) | ||
| 240 | # define D6 PAL_LINE(GPIOD, 6) | ||
| 241 | # define D7 PAL_LINE(GPIOD, 7) | ||
| 242 | # define D8 PAL_LINE(GPIOD, 8) | ||
| 243 | # define D9 PAL_LINE(GPIOD, 9) | ||
| 244 | # define D10 PAL_LINE(GPIOD, 10) | ||
| 245 | # define D11 PAL_LINE(GPIOD, 11) | ||
| 246 | # define D12 PAL_LINE(GPIOD, 12) | ||
| 247 | # define D13 PAL_LINE(GPIOD, 13) | ||
| 248 | # define D14 PAL_LINE(GPIOD, 14) | ||
| 249 | # define D15 PAL_LINE(GPIOD, 15) | ||
| 250 | # define E0 PAL_LINE(GPIOE, 0) | ||
| 251 | # define E1 PAL_LINE(GPIOE, 1) | ||
| 252 | # define E2 PAL_LINE(GPIOE, 2) | ||
| 253 | # define E3 PAL_LINE(GPIOE, 3) | ||
| 254 | # define E4 PAL_LINE(GPIOE, 4) | ||
| 255 | # define E5 PAL_LINE(GPIOE, 5) | ||
| 256 | # define E6 PAL_LINE(GPIOE, 6) | ||
| 257 | # define E7 PAL_LINE(GPIOE, 7) | ||
| 258 | # define E8 PAL_LINE(GPIOE, 8) | ||
| 259 | # define E9 PAL_LINE(GPIOE, 9) | ||
| 260 | # define E10 PAL_LINE(GPIOE, 10) | ||
| 261 | # define E11 PAL_LINE(GPIOE, 11) | ||
| 262 | # define E12 PAL_LINE(GPIOE, 12) | ||
| 263 | # define E13 PAL_LINE(GPIOE, 13) | ||
| 264 | # define E14 PAL_LINE(GPIOE, 14) | ||
| 265 | # define E15 PAL_LINE(GPIOE, 15) | ||
| 266 | # define F0 PAL_LINE(GPIOF, 0) | ||
| 267 | # define F1 PAL_LINE(GPIOF, 1) | ||
| 268 | # define F2 PAL_LINE(GPIOF, 2) | ||
| 269 | # define F3 PAL_LINE(GPIOF, 3) | ||
| 270 | # define F4 PAL_LINE(GPIOF, 4) | ||
| 271 | # define F5 PAL_LINE(GPIOF, 5) | ||
| 272 | # define F6 PAL_LINE(GPIOF, 6) | ||
| 273 | # define F7 PAL_LINE(GPIOF, 7) | ||
| 274 | # define F8 PAL_LINE(GPIOF, 8) | ||
| 275 | # define F9 PAL_LINE(GPIOF, 9) | ||
| 276 | # define F10 PAL_LINE(GPIOF, 10) | ||
| 277 | # define F11 PAL_LINE(GPIOF, 11) | ||
| 278 | # define F12 PAL_LINE(GPIOF, 12) | ||
| 279 | # define F13 PAL_LINE(GPIOF, 13) | ||
| 280 | # define F14 PAL_LINE(GPIOF, 14) | ||
| 281 | # define F15 PAL_LINE(GPIOF, 15) | ||
| 282 | # define G0 PAL_LINE(GPIOG, 0) | ||
| 283 | # define G1 PAL_LINE(GPIOG, 1) | ||
| 284 | # define G2 PAL_LINE(GPIOG, 2) | ||
| 285 | # define G3 PAL_LINE(GPIOG, 3) | ||
| 286 | # define G4 PAL_LINE(GPIOG, 4) | ||
| 287 | # define G5 PAL_LINE(GPIOG, 5) | ||
| 288 | # define G6 PAL_LINE(GPIOG, 6) | ||
| 289 | # define G7 PAL_LINE(GPIOG, 7) | ||
| 290 | # define G8 PAL_LINE(GPIOG, 8) | ||
| 291 | # define G9 PAL_LINE(GPIOG, 9) | ||
| 292 | # define G10 PAL_LINE(GPIOG, 10) | ||
| 293 | # define G11 PAL_LINE(GPIOG, 11) | ||
| 294 | # define G12 PAL_LINE(GPIOG, 12) | ||
| 295 | # define G13 PAL_LINE(GPIOG, 13) | ||
| 296 | # define G14 PAL_LINE(GPIOG, 14) | ||
| 297 | # define G15 PAL_LINE(GPIOG, 15) | ||
| 298 | # define H0 PAL_LINE(GPIOH, 0) | ||
| 299 | # define H1 PAL_LINE(GPIOH, 1) | ||
| 300 | # define H2 PAL_LINE(GPIOH, 2) | ||
| 301 | # define H3 PAL_LINE(GPIOH, 3) | ||
| 302 | # define H4 PAL_LINE(GPIOH, 4) | ||
| 303 | # define H5 PAL_LINE(GPIOH, 5) | ||
| 304 | # define H6 PAL_LINE(GPIOH, 6) | ||
| 305 | # define H7 PAL_LINE(GPIOH, 7) | ||
| 306 | # define H8 PAL_LINE(GPIOH, 8) | ||
| 307 | # define H9 PAL_LINE(GPIOH, 9) | ||
| 308 | # define H10 PAL_LINE(GPIOH, 10) | ||
| 309 | # define H11 PAL_LINE(GPIOH, 11) | ||
| 310 | # define H12 PAL_LINE(GPIOH, 12) | ||
| 311 | # define H13 PAL_LINE(GPIOH, 13) | ||
| 312 | # define H14 PAL_LINE(GPIOH, 14) | ||
| 313 | # define H15 PAL_LINE(GPIOH, 15) | ||
| 314 | # define I0 PAL_LINE(GPIOI, 0) | ||
| 315 | # define I1 PAL_LINE(GPIOI, 1) | ||
| 316 | # define I2 PAL_LINE(GPIOI, 2) | ||
| 317 | # define I3 PAL_LINE(GPIOI, 3) | ||
| 318 | # define I4 PAL_LINE(GPIOI, 4) | ||
| 319 | # define I5 PAL_LINE(GPIOI, 5) | ||
| 320 | # define I6 PAL_LINE(GPIOI, 6) | ||
| 321 | # define I7 PAL_LINE(GPIOI, 7) | ||
| 322 | # define I8 PAL_LINE(GPIOI, 8) | ||
| 323 | # define I9 PAL_LINE(GPIOI, 9) | ||
| 324 | # define I10 PAL_LINE(GPIOI, 10) | ||
| 325 | # define I11 PAL_LINE(GPIOI, 11) | ||
| 326 | # define I12 PAL_LINE(GPIOI, 12) | ||
| 327 | # define I13 PAL_LINE(GPIOI, 13) | ||
| 328 | # define I14 PAL_LINE(GPIOI, 14) | ||
| 329 | # define I15 PAL_LINE(GPIOI, 15) | ||
| 330 | # define J0 PAL_LINE(GPIOJ, 0) | ||
| 331 | # define J1 PAL_LINE(GPIOJ, 1) | ||
| 332 | # define J2 PAL_LINE(GPIOJ, 2) | ||
| 333 | # define J3 PAL_LINE(GPIOJ, 3) | ||
| 334 | # define J4 PAL_LINE(GPIOJ, 4) | ||
| 335 | # define J5 PAL_LINE(GPIOJ, 5) | ||
| 336 | # define J6 PAL_LINE(GPIOJ, 6) | ||
| 337 | # define J7 PAL_LINE(GPIOJ, 7) | ||
| 338 | # define J8 PAL_LINE(GPIOJ, 8) | ||
| 339 | # define J9 PAL_LINE(GPIOJ, 9) | ||
| 340 | # define J10 PAL_LINE(GPIOJ, 10) | ||
| 341 | # define J11 PAL_LINE(GPIOJ, 11) | ||
| 342 | # define J12 PAL_LINE(GPIOJ, 12) | ||
| 343 | # define J13 PAL_LINE(GPIOJ, 13) | ||
| 344 | # define J14 PAL_LINE(GPIOJ, 14) | ||
| 345 | # define J15 PAL_LINE(GPIOJ, 15) | ||
| 346 | // Keyboards can `#define KEYBOARD_REQUIRES_GPIOK` if they need to access GPIO-K pins. These conflict with a whole | ||
| 347 | // bunch of layout definitions, so it's intentionally left out unless absolutely required -- in that case, the | ||
| 348 | // keyboard designer should use a different symbol when defining their layout macros. | ||
| 349 | # ifdef KEYBOARD_REQUIRES_GPIOK | ||
| 350 | # define K0 PAL_LINE(GPIOK, 0) | ||
| 351 | # define K1 PAL_LINE(GPIOK, 1) | ||
| 352 | # define K2 PAL_LINE(GPIOK, 2) | ||
| 353 | # define K3 PAL_LINE(GPIOK, 3) | ||
| 354 | # define K4 PAL_LINE(GPIOK, 4) | ||
| 355 | # define K5 PAL_LINE(GPIOK, 5) | ||
| 356 | # define K6 PAL_LINE(GPIOK, 6) | ||
| 357 | # define K7 PAL_LINE(GPIOK, 7) | ||
| 358 | # define K8 PAL_LINE(GPIOK, 8) | ||
| 359 | # define K9 PAL_LINE(GPIOK, 9) | ||
| 360 | # define K10 PAL_LINE(GPIOK, 10) | ||
| 361 | # define K11 PAL_LINE(GPIOK, 11) | ||
| 362 | # define K12 PAL_LINE(GPIOK, 12) | ||
| 363 | # define K13 PAL_LINE(GPIOK, 13) | ||
| 364 | # define K14 PAL_LINE(GPIOK, 14) | ||
| 365 | # define K15 PAL_LINE(GPIOK, 15) | ||
| 366 | # endif | ||
| 367 | # endif | ||
| 368 | #endif | ||
| 369 | |||
| 370 | #define API_SYSEX_MAX_SIZE 32 | 27 | #define API_SYSEX_MAX_SIZE 32 |
| 371 | 28 | ||
| 372 | #include "song_list.h" | 29 | #include "song_list.h" |
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 | ||
diff --git a/tmk_core/common/atomic_util.h b/tmk_core/common/atomic_util.h new file mode 100644 index 000000000..2c95302a1 --- /dev/null +++ b/tmk_core/common/atomic_util.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | // Macro to help make GPIO and other controls atomic. | ||
| 19 | |||
| 20 | #ifndef IGNORE_ATOMIC_BLOCK | ||
| 21 | # if __has_include_next("atomic_util.h") | ||
| 22 | # include_next "atomic_util.h" /* Include the platforms atomic.h */ | ||
| 23 | # else | ||
| 24 | # define ATOMIC_BLOCK _Static_assert(0, "ATOMIC_BLOCK not implemented") | ||
| 25 | # define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE not implemented") | ||
| 26 | # define ATOMIC_BLOCK_FORCEON _Static_assert(0, "ATOMIC_BLOCK_FORCEON not implemented") | ||
| 27 | # endif | ||
| 28 | #else /* do nothing atomic macro */ | ||
| 29 | # define ATOMIC_BLOCK for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0) | ||
| 30 | # define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK | ||
| 31 | # define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK | ||
| 32 | #endif | ||
diff --git a/tmk_core/common/avr/atomic_util.h b/tmk_core/common/avr/atomic_util.h new file mode 100644 index 000000000..7c5d2e7dc --- /dev/null +++ b/tmk_core/common/avr/atomic_util.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | /* atomic macro for AVR */ | ||
| 19 | #include <util/atomic.h> | ||
| 20 | |||
| 21 | #define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE) | ||
| 22 | #define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) | ||
diff --git a/tmk_core/common/avr/gpio.h b/tmk_core/common/avr/gpio.h new file mode 100644 index 000000000..231556c29 --- /dev/null +++ b/tmk_core/common/avr/gpio.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | #include <avr/io.h> | ||
| 19 | #include "pin_defs.h" | ||
| 20 | |||
| 21 | typedef uint8_t pin_t; | ||
| 22 | |||
| 23 | #define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | ||
| 24 | #define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 25 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") | ||
| 26 | #define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 27 | |||
| 28 | #define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | ||
| 29 | #define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | ||
| 30 | #define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) | ||
| 31 | |||
| 32 | #define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) | ||
| 33 | |||
| 34 | #define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) | ||
diff --git a/tmk_core/common/avr/pin_defs.h b/tmk_core/common/avr/pin_defs.h new file mode 100644 index 000000000..dbfed21f4 --- /dev/null +++ b/tmk_core/common/avr/pin_defs.h | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | #include <avr/io.h> | ||
| 19 | |||
| 20 | #define PORT_SHIFTER 4 // this may be 4 for all AVR chips | ||
| 21 | |||
| 22 | // If you want to add more to this list, reference the PINx definitions in these header | ||
| 23 | // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr | ||
| 24 | |||
| 25 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) | ||
| 26 | # define ADDRESS_BASE 0x00 | ||
| 27 | # define PINB_ADDRESS 0x3 | ||
| 28 | # define PINC_ADDRESS 0x6 | ||
| 29 | # define PIND_ADDRESS 0x9 | ||
| 30 | # define PINE_ADDRESS 0xC | ||
| 31 | # define PINF_ADDRESS 0xF | ||
| 32 | #elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) | ||
| 33 | # define ADDRESS_BASE 0x00 | ||
| 34 | # define PINB_ADDRESS 0x3 | ||
| 35 | # define PINC_ADDRESS 0x6 | ||
| 36 | # define PIND_ADDRESS 0x9 | ||
| 37 | #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) | ||
| 38 | # define ADDRESS_BASE 0x00 | ||
| 39 | # define PINA_ADDRESS 0x0 | ||
| 40 | # define PINB_ADDRESS 0x3 | ||
| 41 | # define PINC_ADDRESS 0x6 | ||
| 42 | # define PIND_ADDRESS 0x9 | ||
| 43 | # define PINE_ADDRESS 0xC | ||
| 44 | # define PINF_ADDRESS 0xF | ||
| 45 | #elif defined(__AVR_ATmega32A__) | ||
| 46 | # define ADDRESS_BASE 0x10 | ||
| 47 | # define PIND_ADDRESS 0x0 | ||
| 48 | # define PINC_ADDRESS 0x3 | ||
| 49 | # define PINB_ADDRESS 0x6 | ||
| 50 | # define PINA_ADDRESS 0x9 | ||
| 51 | #elif defined(__AVR_ATtiny85__) | ||
| 52 | # define ADDRESS_BASE 0x10 | ||
| 53 | # define PINB_ADDRESS 0x6 | ||
| 54 | #else | ||
| 55 | # error "Pins are not defined" | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin) | ||
| 59 | |||
| 60 | #define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + ((p) >> PORT_SHIFTER) + (offset)) | ||
| 61 | // Port X Input Pins Address | ||
| 62 | #define PINx_ADDRESS(p) _PIN_ADDRESS(p, 0) | ||
| 63 | // Port X Data Direction Register, 0:input 1:output | ||
| 64 | #define DDRx_ADDRESS(p) _PIN_ADDRESS(p, 1) | ||
| 65 | // Port X Data Register | ||
| 66 | #define PORTx_ADDRESS(p) _PIN_ADDRESS(p, 2) | ||
| 67 | |||
| 68 | /* I/O pins */ | ||
| 69 | #ifdef PORTA | ||
| 70 | # define A0 PINDEF(A, 0) | ||
| 71 | # define A1 PINDEF(A, 1) | ||
| 72 | # define A2 PINDEF(A, 2) | ||
| 73 | # define A3 PINDEF(A, 3) | ||
| 74 | # define A4 PINDEF(A, 4) | ||
| 75 | # define A5 PINDEF(A, 5) | ||
| 76 | # define A6 PINDEF(A, 6) | ||
| 77 | # define A7 PINDEF(A, 7) | ||
| 78 | #endif | ||
| 79 | #ifdef PORTB | ||
| 80 | # define B0 PINDEF(B, 0) | ||
| 81 | # define B1 PINDEF(B, 1) | ||
| 82 | # define B2 PINDEF(B, 2) | ||
| 83 | # define B3 PINDEF(B, 3) | ||
| 84 | # define B4 PINDEF(B, 4) | ||
| 85 | # define B5 PINDEF(B, 5) | ||
| 86 | # define B6 PINDEF(B, 6) | ||
| 87 | # define B7 PINDEF(B, 7) | ||
| 88 | #endif | ||
| 89 | #ifdef PORTC | ||
| 90 | # define C0 PINDEF(C, 0) | ||
| 91 | # define C1 PINDEF(C, 1) | ||
| 92 | # define C2 PINDEF(C, 2) | ||
| 93 | # define C3 PINDEF(C, 3) | ||
| 94 | # define C4 PINDEF(C, 4) | ||
| 95 | # define C5 PINDEF(C, 5) | ||
| 96 | # define C6 PINDEF(C, 6) | ||
| 97 | # define C7 PINDEF(C, 7) | ||
| 98 | #endif | ||
| 99 | #ifdef PORTD | ||
| 100 | # define D0 PINDEF(D, 0) | ||
| 101 | # define D1 PINDEF(D, 1) | ||
| 102 | # define D2 PINDEF(D, 2) | ||
| 103 | # define D3 PINDEF(D, 3) | ||
| 104 | # define D4 PINDEF(D, 4) | ||
| 105 | # define D5 PINDEF(D, 5) | ||
| 106 | # define D6 PINDEF(D, 6) | ||
| 107 | # define D7 PINDEF(D, 7) | ||
| 108 | #endif | ||
| 109 | #ifdef PORTE | ||
| 110 | # define E0 PINDEF(E, 0) | ||
| 111 | # define E1 PINDEF(E, 1) | ||
| 112 | # define E2 PINDEF(E, 2) | ||
| 113 | # define E3 PINDEF(E, 3) | ||
| 114 | # define E4 PINDEF(E, 4) | ||
| 115 | # define E5 PINDEF(E, 5) | ||
| 116 | # define E6 PINDEF(E, 6) | ||
| 117 | # define E7 PINDEF(E, 7) | ||
| 118 | #endif | ||
| 119 | #ifdef PORTF | ||
| 120 | # define F0 PINDEF(F, 0) | ||
| 121 | # define F1 PINDEF(F, 1) | ||
| 122 | # define F2 PINDEF(F, 2) | ||
| 123 | # define F3 PINDEF(F, 3) | ||
| 124 | # define F4 PINDEF(F, 4) | ||
| 125 | # define F5 PINDEF(F, 5) | ||
| 126 | # define F6 PINDEF(F, 6) | ||
| 127 | # define F7 PINDEF(F, 7) | ||
| 128 | #endif \ No newline at end of file | ||
diff --git a/tmk_core/common/chibios/atomic_util.h b/tmk_core/common/chibios/atomic_util.h new file mode 100644 index 000000000..897504515 --- /dev/null +++ b/tmk_core/common/chibios/atomic_util.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | #include <ch.h> | ||
| 19 | |||
| 20 | static __inline__ uint8_t __interrupt_disable__(void) { | ||
| 21 | chSysLock(); | ||
| 22 | |||
| 23 | return 1; | ||
| 24 | } | ||
| 25 | |||
| 26 | static __inline__ void __interrupt_enable__(const uint8_t *__s) { | ||
| 27 | chSysUnlock(); | ||
| 28 | |||
| 29 | __asm__ volatile("" ::: "memory"); | ||
| 30 | (void)__s; | ||
| 31 | } | ||
| 32 | |||
| 33 | #define ATOMIC_BLOCK(type) for (type, __ToDo = __interrupt_disable__(); __ToDo; __ToDo = 0) | ||
| 34 | #define ATOMIC_FORCEON uint8_t sreg_save __attribute__((__cleanup__(__interrupt_enable__))) = 0 | ||
| 35 | |||
| 36 | #define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE not implemented") | ||
| 37 | #define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) | ||
diff --git a/tmk_core/common/chibios/gpio.h b/tmk_core/common/chibios/gpio.h new file mode 100644 index 000000000..5d0e142ab --- /dev/null +++ b/tmk_core/common/chibios/gpio.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | #include <hal.h> | ||
| 19 | #include "pin_defs.h" | ||
| 20 | |||
| 21 | typedef ioline_t pin_t; | ||
| 22 | |||
| 23 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) | ||
| 24 | #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) | ||
| 25 | #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) | ||
| 26 | #define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) | ||
| 27 | |||
| 28 | #define writePinHigh(pin) palSetLine(pin) | ||
| 29 | #define writePinLow(pin) palClearLine(pin) | ||
| 30 | #define writePin(pin, level) ((level) ? (writePinHigh(pin)) : (writePinLow(pin))) | ||
| 31 | |||
| 32 | #define readPin(pin) palReadLine(pin) | ||
| 33 | |||
| 34 | #define togglePin(pin) palToggleLine(pin) | ||
diff --git a/tmk_core/common/chibios/pin_defs.h b/tmk_core/common/chibios/pin_defs.h new file mode 100644 index 000000000..86bc1076e --- /dev/null +++ b/tmk_core/common/chibios/pin_defs.h | |||
| @@ -0,0 +1,242 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | // Defines mapping for Proton C replacement | ||
| 19 | #ifdef CONVERT_TO_PROTON_C | ||
| 20 | // Left side (front) | ||
| 21 | # define D3 PAL_LINE(GPIOA, 9) | ||
| 22 | # define D2 PAL_LINE(GPIOA, 10) | ||
| 23 | // GND | ||
| 24 | // GND | ||
| 25 | # define D1 PAL_LINE(GPIOB, 7) | ||
| 26 | # define D0 PAL_LINE(GPIOB, 6) | ||
| 27 | # define D4 PAL_LINE(GPIOB, 5) | ||
| 28 | # define C6 PAL_LINE(GPIOB, 4) | ||
| 29 | # define D7 PAL_LINE(GPIOB, 3) | ||
| 30 | # define E6 PAL_LINE(GPIOB, 2) | ||
| 31 | # define B4 PAL_LINE(GPIOB, 1) | ||
| 32 | # define B5 PAL_LINE(GPIOB, 0) | ||
| 33 | |||
| 34 | // Right side (front) | ||
| 35 | // RAW | ||
| 36 | // GND | ||
| 37 | // RESET | ||
| 38 | // VCC | ||
| 39 | # define F4 PAL_LINE(GPIOA, 2) | ||
| 40 | # define F5 PAL_LINE(GPIOA, 1) | ||
| 41 | # define F6 PAL_LINE(GPIOA, 0) | ||
| 42 | # define F7 PAL_LINE(GPIOB, 8) | ||
| 43 | # define B1 PAL_LINE(GPIOB, 13) | ||
| 44 | # define B3 PAL_LINE(GPIOB, 14) | ||
| 45 | # define B2 PAL_LINE(GPIOB, 15) | ||
| 46 | # define B6 PAL_LINE(GPIOB, 9) | ||
| 47 | |||
| 48 | // LEDs (only D5/C13 uses an actual LED) | ||
| 49 | # ifdef CONVERT_TO_PROTON_C_RXLED | ||
| 50 | # define D5 PAL_LINE(GPIOC, 14) | ||
| 51 | # define B0 PAL_LINE(GPIOC, 13) | ||
| 52 | # else | ||
| 53 | # define D5 PAL_LINE(GPIOC, 13) | ||
| 54 | # define B0 PAL_LINE(GPIOC, 14) | ||
| 55 | # endif | ||
| 56 | #else | ||
| 57 | # define A0 PAL_LINE(GPIOA, 0) | ||
| 58 | # define A1 PAL_LINE(GPIOA, 1) | ||
| 59 | # define A2 PAL_LINE(GPIOA, 2) | ||
| 60 | # define A3 PAL_LINE(GPIOA, 3) | ||
| 61 | # define A4 PAL_LINE(GPIOA, 4) | ||
| 62 | # define A5 PAL_LINE(GPIOA, 5) | ||
| 63 | # define A6 PAL_LINE(GPIOA, 6) | ||
| 64 | # define A7 PAL_LINE(GPIOA, 7) | ||
| 65 | # define A8 PAL_LINE(GPIOA, 8) | ||
| 66 | # define A9 PAL_LINE(GPIOA, 9) | ||
| 67 | # define A10 PAL_LINE(GPIOA, 10) | ||
| 68 | # define A11 PAL_LINE(GPIOA, 11) | ||
| 69 | # define A12 PAL_LINE(GPIOA, 12) | ||
| 70 | # define A13 PAL_LINE(GPIOA, 13) | ||
| 71 | # define A14 PAL_LINE(GPIOA, 14) | ||
| 72 | # define A15 PAL_LINE(GPIOA, 15) | ||
| 73 | # define B0 PAL_LINE(GPIOB, 0) | ||
| 74 | # define B1 PAL_LINE(GPIOB, 1) | ||
| 75 | # define B2 PAL_LINE(GPIOB, 2) | ||
| 76 | # define B3 PAL_LINE(GPIOB, 3) | ||
| 77 | # define B4 PAL_LINE(GPIOB, 4) | ||
| 78 | # define B5 PAL_LINE(GPIOB, 5) | ||
| 79 | # define B6 PAL_LINE(GPIOB, 6) | ||
| 80 | # define B7 PAL_LINE(GPIOB, 7) | ||
| 81 | # define B8 PAL_LINE(GPIOB, 8) | ||
| 82 | # define B9 PAL_LINE(GPIOB, 9) | ||
| 83 | # define B10 PAL_LINE(GPIOB, 10) | ||
| 84 | # define B11 PAL_LINE(GPIOB, 11) | ||
| 85 | # define B12 PAL_LINE(GPIOB, 12) | ||
| 86 | # define B13 PAL_LINE(GPIOB, 13) | ||
| 87 | # define B14 PAL_LINE(GPIOB, 14) | ||
| 88 | # define B15 PAL_LINE(GPIOB, 15) | ||
| 89 | # define B16 PAL_LINE(GPIOB, 16) | ||
| 90 | # define B17 PAL_LINE(GPIOB, 17) | ||
| 91 | # define B18 PAL_LINE(GPIOB, 18) | ||
| 92 | # define B19 PAL_LINE(GPIOB, 19) | ||
| 93 | # define C0 PAL_LINE(GPIOC, 0) | ||
| 94 | # define C1 PAL_LINE(GPIOC, 1) | ||
| 95 | # define C2 PAL_LINE(GPIOC, 2) | ||
| 96 | # define C3 PAL_LINE(GPIOC, 3) | ||
| 97 | # define C4 PAL_LINE(GPIOC, 4) | ||
| 98 | # define C5 PAL_LINE(GPIOC, 5) | ||
| 99 | # define C6 PAL_LINE(GPIOC, 6) | ||
| 100 | # define C7 PAL_LINE(GPIOC, 7) | ||
| 101 | # define C8 PAL_LINE(GPIOC, 8) | ||
| 102 | # define C9 PAL_LINE(GPIOC, 9) | ||
| 103 | # define C10 PAL_LINE(GPIOC, 10) | ||
| 104 | # define C11 PAL_LINE(GPIOC, 11) | ||
| 105 | # define C12 PAL_LINE(GPIOC, 12) | ||
| 106 | # define C13 PAL_LINE(GPIOC, 13) | ||
| 107 | # define C14 PAL_LINE(GPIOC, 14) | ||
| 108 | # define C15 PAL_LINE(GPIOC, 15) | ||
| 109 | # define D0 PAL_LINE(GPIOD, 0) | ||
| 110 | # define D1 PAL_LINE(GPIOD, 1) | ||
| 111 | # define D2 PAL_LINE(GPIOD, 2) | ||
| 112 | # define D3 PAL_LINE(GPIOD, 3) | ||
| 113 | # define D4 PAL_LINE(GPIOD, 4) | ||
| 114 | # define D5 PAL_LINE(GPIOD, 5) | ||
| 115 | # define D6 PAL_LINE(GPIOD, 6) | ||
| 116 | # define D7 PAL_LINE(GPIOD, 7) | ||
| 117 | # define D8 PAL_LINE(GPIOD, 8) | ||
| 118 | # define D9 PAL_LINE(GPIOD, 9) | ||
| 119 | # define D10 PAL_LINE(GPIOD, 10) | ||
| 120 | # define D11 PAL_LINE(GPIOD, 11) | ||
| 121 | # define D12 PAL_LINE(GPIOD, 12) | ||
| 122 | # define D13 PAL_LINE(GPIOD, 13) | ||
| 123 | # define D14 PAL_LINE(GPIOD, 14) | ||
| 124 | # define D15 PAL_LINE(GPIOD, 15) | ||
| 125 | # define E0 PAL_LINE(GPIOE, 0) | ||
| 126 | # define E1 PAL_LINE(GPIOE, 1) | ||
| 127 | # define E2 PAL_LINE(GPIOE, 2) | ||
| 128 | # define E3 PAL_LINE(GPIOE, 3) | ||
| 129 | # define E4 PAL_LINE(GPIOE, 4) | ||
| 130 | # define E5 PAL_LINE(GPIOE, 5) | ||
| 131 | # define E6 PAL_LINE(GPIOE, 6) | ||
| 132 | # define E7 PAL_LINE(GPIOE, 7) | ||
| 133 | # define E8 PAL_LINE(GPIOE, 8) | ||
| 134 | # define E9 PAL_LINE(GPIOE, 9) | ||
| 135 | # define E10 PAL_LINE(GPIOE, 10) | ||
| 136 | # define E11 PAL_LINE(GPIOE, 11) | ||
| 137 | # define E12 PAL_LINE(GPIOE, 12) | ||
| 138 | # define E13 PAL_LINE(GPIOE, 13) | ||
| 139 | # define E14 PAL_LINE(GPIOE, 14) | ||
| 140 | # define E15 PAL_LINE(GPIOE, 15) | ||
| 141 | # define F0 PAL_LINE(GPIOF, 0) | ||
| 142 | # define F1 PAL_LINE(GPIOF, 1) | ||
| 143 | # define F2 PAL_LINE(GPIOF, 2) | ||
| 144 | # define F3 PAL_LINE(GPIOF, 3) | ||
| 145 | # define F4 PAL_LINE(GPIOF, 4) | ||
| 146 | # define F5 PAL_LINE(GPIOF, 5) | ||
| 147 | # define F6 PAL_LINE(GPIOF, 6) | ||
| 148 | # define F7 PAL_LINE(GPIOF, 7) | ||
| 149 | # define F8 PAL_LINE(GPIOF, 8) | ||
| 150 | # define F9 PAL_LINE(GPIOF, 9) | ||
| 151 | # define F10 PAL_LINE(GPIOF, 10) | ||
| 152 | # define F11 PAL_LINE(GPIOF, 11) | ||
| 153 | # define F12 PAL_LINE(GPIOF, 12) | ||
| 154 | # define F13 PAL_LINE(GPIOF, 13) | ||
| 155 | # define F14 PAL_LINE(GPIOF, 14) | ||
| 156 | # define F15 PAL_LINE(GPIOF, 15) | ||
| 157 | # define G0 PAL_LINE(GPIOG, 0) | ||
| 158 | # define G1 PAL_LINE(GPIOG, 1) | ||
| 159 | # define G2 PAL_LINE(GPIOG, 2) | ||
| 160 | # define G3 PAL_LINE(GPIOG, 3) | ||
| 161 | # define G4 PAL_LINE(GPIOG, 4) | ||
| 162 | # define G5 PAL_LINE(GPIOG, 5) | ||
| 163 | # define G6 PAL_LINE(GPIOG, 6) | ||
| 164 | # define G7 PAL_LINE(GPIOG, 7) | ||
| 165 | # define G8 PAL_LINE(GPIOG, 8) | ||
| 166 | # define G9 PAL_LINE(GPIOG, 9) | ||
| 167 | # define G10 PAL_LINE(GPIOG, 10) | ||
| 168 | # define G11 PAL_LINE(GPIOG, 11) | ||
| 169 | # define G12 PAL_LINE(GPIOG, 12) | ||
| 170 | # define G13 PAL_LINE(GPIOG, 13) | ||
| 171 | # define G14 PAL_LINE(GPIOG, 14) | ||
| 172 | # define G15 PAL_LINE(GPIOG, 15) | ||
| 173 | # define H0 PAL_LINE(GPIOH, 0) | ||
| 174 | # define H1 PAL_LINE(GPIOH, 1) | ||
| 175 | # define H2 PAL_LINE(GPIOH, 2) | ||
| 176 | # define H3 PAL_LINE(GPIOH, 3) | ||
| 177 | # define H4 PAL_LINE(GPIOH, 4) | ||
| 178 | # define H5 PAL_LINE(GPIOH, 5) | ||
| 179 | # define H6 PAL_LINE(GPIOH, 6) | ||
| 180 | # define H7 PAL_LINE(GPIOH, 7) | ||
| 181 | # define H8 PAL_LINE(GPIOH, 8) | ||
| 182 | # define H9 PAL_LINE(GPIOH, 9) | ||
| 183 | # define H10 PAL_LINE(GPIOH, 10) | ||
| 184 | # define H11 PAL_LINE(GPIOH, 11) | ||
| 185 | # define H12 PAL_LINE(GPIOH, 12) | ||
| 186 | # define H13 PAL_LINE(GPIOH, 13) | ||
| 187 | # define H14 PAL_LINE(GPIOH, 14) | ||
| 188 | # define H15 PAL_LINE(GPIOH, 15) | ||
| 189 | # define I0 PAL_LINE(GPIOI, 0) | ||
| 190 | # define I1 PAL_LINE(GPIOI, 1) | ||
| 191 | # define I2 PAL_LINE(GPIOI, 2) | ||
| 192 | # define I3 PAL_LINE(GPIOI, 3) | ||
| 193 | # define I4 PAL_LINE(GPIOI, 4) | ||
| 194 | # define I5 PAL_LINE(GPIOI, 5) | ||
| 195 | # define I6 PAL_LINE(GPIOI, 6) | ||
| 196 | # define I7 PAL_LINE(GPIOI, 7) | ||
| 197 | # define I8 PAL_LINE(GPIOI, 8) | ||
| 198 | # define I9 PAL_LINE(GPIOI, 9) | ||
| 199 | # define I10 PAL_LINE(GPIOI, 10) | ||
| 200 | # define I11 PAL_LINE(GPIOI, 11) | ||
| 201 | # define I12 PAL_LINE(GPIOI, 12) | ||
| 202 | # define I13 PAL_LINE(GPIOI, 13) | ||
| 203 | # define I14 PAL_LINE(GPIOI, 14) | ||
| 204 | # define I15 PAL_LINE(GPIOI, 15) | ||
| 205 | # define J0 PAL_LINE(GPIOJ, 0) | ||
| 206 | # define J1 PAL_LINE(GPIOJ, 1) | ||
| 207 | # define J2 PAL_LINE(GPIOJ, 2) | ||
| 208 | # define J3 PAL_LINE(GPIOJ, 3) | ||
| 209 | # define J4 PAL_LINE(GPIOJ, 4) | ||
| 210 | # define J5 PAL_LINE(GPIOJ, 5) | ||
| 211 | # define J6 PAL_LINE(GPIOJ, 6) | ||
| 212 | # define J7 PAL_LINE(GPIOJ, 7) | ||
| 213 | # define J8 PAL_LINE(GPIOJ, 8) | ||
| 214 | # define J9 PAL_LINE(GPIOJ, 9) | ||
| 215 | # define J10 PAL_LINE(GPIOJ, 10) | ||
| 216 | # define J11 PAL_LINE(GPIOJ, 11) | ||
| 217 | # define J12 PAL_LINE(GPIOJ, 12) | ||
| 218 | # define J13 PAL_LINE(GPIOJ, 13) | ||
| 219 | # define J14 PAL_LINE(GPIOJ, 14) | ||
| 220 | # define J15 PAL_LINE(GPIOJ, 15) | ||
| 221 | // Keyboards can `#define KEYBOARD_REQUIRES_GPIOK` if they need to access GPIO-K pins. These conflict with a whole | ||
| 222 | // bunch of layout definitions, so it's intentionally left out unless absolutely required -- in that case, the | ||
| 223 | // keyboard designer should use a different symbol when defining their layout macros. | ||
| 224 | # ifdef KEYBOARD_REQUIRES_GPIOK | ||
| 225 | # define K0 PAL_LINE(GPIOK, 0) | ||
| 226 | # define K1 PAL_LINE(GPIOK, 1) | ||
| 227 | # define K2 PAL_LINE(GPIOK, 2) | ||
| 228 | # define K3 PAL_LINE(GPIOK, 3) | ||
| 229 | # define K4 PAL_LINE(GPIOK, 4) | ||
| 230 | # define K5 PAL_LINE(GPIOK, 5) | ||
| 231 | # define K6 PAL_LINE(GPIOK, 6) | ||
| 232 | # define K7 PAL_LINE(GPIOK, 7) | ||
| 233 | # define K8 PAL_LINE(GPIOK, 8) | ||
| 234 | # define K9 PAL_LINE(GPIOK, 9) | ||
| 235 | # define K10 PAL_LINE(GPIOK, 10) | ||
| 236 | # define K11 PAL_LINE(GPIOK, 11) | ||
| 237 | # define K12 PAL_LINE(GPIOK, 12) | ||
| 238 | # define K13 PAL_LINE(GPIOK, 13) | ||
| 239 | # define K14 PAL_LINE(GPIOK, 14) | ||
| 240 | # define K15 PAL_LINE(GPIOK, 15) | ||
| 241 | # endif | ||
| 242 | #endif | ||
diff --git a/tmk_core/common/gpio.h b/tmk_core/common/gpio.h new file mode 100644 index 000000000..b47f6f8e4 --- /dev/null +++ b/tmk_core/common/gpio.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | #include "pin_defs.h" | ||
| 19 | |||
| 20 | #if __has_include_next("gpio.h") | ||
| 21 | # include_next "gpio.h" /* Include the platforms gpio.h */ | ||
| 22 | #endif \ No newline at end of file | ||
diff --git a/tmk_core/common/pin_defs.h b/tmk_core/common/pin_defs.h new file mode 100644 index 000000000..ea730138f --- /dev/null +++ b/tmk_core/common/pin_defs.h | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | // useful for direct pin mapping | ||
| 19 | #define NO_PIN (pin_t)(~0) | ||
| 20 | |||
| 21 | #if __has_include_next("pin_defs.h") | ||
| 22 | # include_next "pin_defs.h" /* Include the platforms pin_defs.h */ | ||
| 23 | #endif | ||
