diff options
| author | Konstantin Đorđević <vomindoraan@gmail.com> | 2019-07-09 20:16:24 +0200 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-07-09 11:16:24 -0700 |
| commit | c69060465ea1ce4f77fb69e2dea7cb035f89ba4e (patch) | |
| tree | a6048ea8ce05f2d872a78f27c33b90f66a4d60a8 /quantum/quantum.h | |
| parent | 37be1cb5130c5c9d93175bdd40176a84e8fe3a76 (diff) | |
| download | qmk_firmware-c69060465ea1ce4f77fb69e2dea7cb035f89ba4e.tar.gz qmk_firmware-c69060465ea1ce4f77fb69e2dea7cb035f89ba4e.zip | |
Fix parentheses in macros, and in general clean up quantum.h (#5021)
* Fix up GPIO macros
* Fix up send string macros
`string` arguments must not be parenthesized
* Fix up miscellaneous macros
* Make indentation uniform (4 spaces)
* Make #ifdef vs #if defined usage consistent
* Reorder standard includes
* Revert indentation changes as per review comments
* Revert #if defined(__AVR__) → #ifdef __AVR__ change
* Change 2 space indent to 4 spaces on a couple of lines
* Replace include guard with #pragma once
Diffstat (limited to 'quantum/quantum.h')
| -rw-r--r-- | quantum/quantum.h | 119 |
1 files changed, 53 insertions, 66 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h index 451dd8a4b..f089c6ef6 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -13,8 +13,7 @@ | |||
| 13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ | 15 | */ |
| 16 | #ifndef QUANTUM_H | 16 | #pragma once |
| 17 | #define QUANTUM_H | ||
| 18 | 17 | ||
| 19 | #if defined(__AVR__) | 18 | #if defined(__AVR__) |
| 20 | #include <avr/pgmspace.h> | 19 | #include <avr/pgmspace.h> |
| @@ -24,9 +23,11 @@ | |||
| 24 | #if defined(PROTOCOL_CHIBIOS) | 23 | #if defined(PROTOCOL_CHIBIOS) |
| 25 | #include "hal.h" | 24 | #include "hal.h" |
| 26 | #endif | 25 | #endif |
| 26 | |||
| 27 | #include "wait.h" | 27 | #include "wait.h" |
| 28 | #include "matrix.h" | 28 | #include "matrix.h" |
| 29 | #include "keymap.h" | 29 | #include "keymap.h" |
| 30 | |||
| 30 | #ifdef BACKLIGHT_ENABLE | 31 | #ifdef BACKLIGHT_ENABLE |
| 31 | #ifdef LED_MATRIX_ENABLE | 32 | #ifdef LED_MATRIX_ENABLE |
| 32 | #include "ledmatrix.h" | 33 | #include "ledmatrix.h" |
| @@ -34,14 +35,13 @@ | |||
| 34 | #include "backlight.h" | 35 | #include "backlight.h" |
| 35 | #endif | 36 | #endif |
| 36 | #endif | 37 | #endif |
| 37 | #ifdef RGBLIGHT_ENABLE | 38 | |
| 38 | #include "rgblight.h" | 39 | #if defined(RGBLIGHT_ENABLE) |
| 39 | #else | 40 | #include "rgblight.h" |
| 40 | #ifdef RGB_MATRIX_ENABLE | 41 | #elif defined(RGB_MATRIX_ENABLE) |
| 41 | /* dummy define RGBLIGHT_MODE_xxxx */ | 42 | // Dummy define RGBLIGHT_MODE_xxxx |
| 42 | #define RGBLIGHT_H_DUMMY_DEFINE | 43 | #define RGBLIGHT_H_DUMMY_DEFINE |
| 43 | #include "rgblight.h" | 44 | #include "rgblight.h" |
| 44 | #endif | ||
| 45 | #endif | 45 | #endif |
| 46 | 46 | ||
| 47 | #ifdef RGB_MATRIX_ENABLE | 47 | #ifdef RGB_MATRIX_ENABLE |
| @@ -50,16 +50,16 @@ | |||
| 50 | 50 | ||
| 51 | #include "action_layer.h" | 51 | #include "action_layer.h" |
| 52 | #include "eeconfig.h" | 52 | #include "eeconfig.h" |
| 53 | #include <stddef.h> | ||
| 54 | #include "bootloader.h" | 53 | #include "bootloader.h" |
| 55 | #include "timer.h" | 54 | #include "timer.h" |
| 56 | #include "config_common.h" | 55 | #include "config_common.h" |
| 57 | #include "led.h" | 56 | #include "led.h" |
| 58 | #include "action_util.h" | 57 | #include "action_util.h" |
| 59 | #include <stdlib.h> | ||
| 60 | #include "print.h" | 58 | #include "print.h" |
| 61 | #include "send_string_keycodes.h" | 59 | #include "send_string_keycodes.h" |
| 62 | #include "suspend.h" | 60 | #include "suspend.h" |
| 61 | #include <stddef.h> | ||
| 62 | #include <stdlib.h> | ||
| 63 | 63 | ||
| 64 | extern layer_state_t default_layer_state; | 64 | extern layer_state_t default_layer_state; |
| 65 | 65 | ||
| @@ -67,18 +67,16 @@ extern layer_state_t default_layer_state; | |||
| 67 | extern layer_state_t layer_state; | 67 | extern layer_state_t layer_state; |
| 68 | #endif | 68 | #endif |
| 69 | 69 | ||
| 70 | #ifdef MIDI_ENABLE | 70 | #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) |
| 71 | #ifdef MIDI_ADVANCED | ||
| 72 | #include "process_midi.h" | 71 | #include "process_midi.h" |
| 73 | #endif | 72 | #endif |
| 74 | #endif // MIDI_ENABLE | ||
| 75 | 73 | ||
| 76 | #ifdef AUDIO_ENABLE | 74 | #ifdef AUDIO_ENABLE |
| 77 | #include "audio.h" | 75 | #include "audio.h" |
| 78 | #include "process_audio.h" | 76 | #include "process_audio.h" |
| 79 | #ifdef AUDIO_CLICKY | 77 | #ifdef AUDIO_CLICKY |
| 80 | #include "process_clicky.h" | 78 | #include "process_clicky.h" |
| 81 | #endif // AUDIO_CLICKY | 79 | #endif |
| 82 | #endif | 80 | #endif |
| 83 | 81 | ||
| 84 | #ifdef STENO_ENABLE | 82 | #ifdef STENO_ENABLE |
| @@ -106,7 +104,7 @@ extern layer_state_t default_layer_state; | |||
| 106 | #endif | 104 | #endif |
| 107 | 105 | ||
| 108 | #ifdef TAP_DANCE_ENABLE | 106 | #ifdef TAP_DANCE_ENABLE |
| 109 | #include "process_tap_dance.h" | 107 | #include "process_tap_dance.h" |
| 110 | #endif | 108 | #endif |
| 111 | 109 | ||
| 112 | #ifdef PRINTING_ENABLE | 110 | #ifdef PRINTING_ENABLE |
| @@ -132,7 +130,7 @@ extern layer_state_t default_layer_state; | |||
| 132 | #endif | 130 | #endif |
| 133 | 131 | ||
| 134 | #ifdef SPACE_CADET_ENABLE | 132 | #ifdef SPACE_CADET_ENABLE |
| 135 | #include "process_space_cadet.h" | 133 | #include "process_space_cadet.h" |
| 136 | #endif | 134 | #endif |
| 137 | 135 | ||
| 138 | #ifdef HD44780_ENABLE | 136 | #ifdef HD44780_ENABLE |
| @@ -147,50 +145,38 @@ extern layer_state_t default_layer_state; | |||
| 147 | #include "oled_driver.h" | 145 | #include "oled_driver.h" |
| 148 | #endif | 146 | #endif |
| 149 | 147 | ||
| 150 | //Function substitutions to ease GPIO manipulation | 148 | // Function substitutions to ease GPIO manipulation |
| 151 | #ifdef __AVR__ | 149 | #if defined(__AVR__) |
| 152 | #define PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset) | 150 | typedef uint8_t pin_t; |
| 153 | 151 | ||
| 154 | #define pin_t uint8_t | 152 | #define PIN_ADDRESS(p, offset) (_SFR_IO8(ADDRESS_BASE + ((p) >> PORT_SHIFTER) + (offset))) |
| 155 | #define setPinInput(pin) PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF) | 153 | #define setPinInput(pin) (PIN_ADDRESS(pin, 1) &= ~_BV((pin) & 0xF)) |
| 156 | #define setPinInputHigh(pin) ({\ | 154 | #define setPinInputHigh(pin) (PIN_ADDRESS(pin, 1) &= ~_BV((pin) & 0xF), \ |
| 157 | PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF);\ | 155 | PIN_ADDRESS(pin, 2) |= _BV((pin) & 0xF)) |
| 158 | PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF);\ | 156 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") |
| 159 | }) | 157 | #define setPinOutput(pin) (PIN_ADDRESS(pin, 1) |= _BV((pin) & 0xF)) |
| 160 | #define setPinInputLow(pin) _Static_assert(0, "AVR Processors cannot impliment an input as pull low") | 158 | |
| 161 | #define setPinOutput(pin) PIN_ADDRESS(pin, 1) |= _BV(pin & 0xF) | 159 | #define writePinHigh(pin) (PIN_ADDRESS(pin, 2) |= _BV((pin) & 0xF)) |
| 162 | 160 | #define writePinLow(pin) (PIN_ADDRESS(pin, 2) &= ~_BV((pin) & 0xF)) | |
| 163 | #define writePinHigh(pin) PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF) | 161 | #define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) |
| 164 | #define writePinLow(pin) PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF) | 162 | |
| 165 | static inline void writePin(pin_t pin, uint8_t level){ | 163 | #define readPin(pin) ((bool)(PIN_ADDRESS(pin, 0) & _BV((pin) & 0xF))) |
| 166 | if (level){ | ||
| 167 | PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF); | ||
| 168 | } else { | ||
| 169 | PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF); | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | #define readPin(pin) ((bool)(PIN_ADDRESS(pin, 0) & _BV(pin & 0xF))) | ||
| 174 | #elif defined(PROTOCOL_CHIBIOS) | 164 | #elif defined(PROTOCOL_CHIBIOS) |
| 175 | #define pin_t ioline_t | 165 | typedef ioline_t pin_t; |
| 176 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) | 166 | |
| 177 | #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) | 167 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) |
| 178 | #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) | 168 | #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) |
| 179 | #define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) | 169 | #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) |
| 180 | 170 | #define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) | |
| 181 | #define writePinHigh(pin) palSetLine(pin) | 171 | |
| 182 | #define writePinLow(pin) palClearLine(pin) | 172 | #define writePinHigh(pin) palSetLine(pin) |
| 183 | static inline void writePin(pin_t pin, uint8_t level){ | 173 | #define writePinLow(pin) palClearLine(pin) |
| 184 | if (level){ | 174 | #define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) |
| 185 | palSetLine(pin); | 175 | |
| 186 | } else { | 176 | #define readPin(pin) palReadLine(pin) |
| 187 | palClearLine(pin); | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | #define readPin(pin) palReadLine(pin) | ||
| 192 | #endif | 177 | #endif |
| 193 | 178 | ||
| 179 | // Send string macros | ||
| 194 | #define STRINGIZE(z) #z | 180 | #define STRINGIZE(z) #z |
| 195 | #define ADD_SLASH_X(y) STRINGIZE(\x ## y) | 181 | #define ADD_SLASH_X(y) STRINGIZE(\x ## y) |
| 196 | #define SYMBOL_STR(x) ADD_SLASH_X(x) | 182 | #define SYMBOL_STR(x) ADD_SLASH_X(x) |
| @@ -203,6 +189,7 @@ extern layer_state_t default_layer_state; | |||
| 203 | #define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode) | 189 | #define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode) |
| 204 | #define SS_UP(keycode) "\3" SYMBOL_STR(keycode) | 190 | #define SS_UP(keycode) "\3" SYMBOL_STR(keycode) |
| 205 | 191 | ||
| 192 | // `string` arguments must not be parenthesized | ||
| 206 | #define SS_LCTRL(string) SS_DOWN(X_LCTRL) string SS_UP(X_LCTRL) | 193 | #define SS_LCTRL(string) SS_DOWN(X_LCTRL) string SS_UP(X_LCTRL) |
| 207 | #define SS_LGUI(string) SS_DOWN(X_LGUI) string SS_UP(X_LGUI) | 194 | #define SS_LGUI(string) SS_DOWN(X_LGUI) string SS_UP(X_LGUI) |
| 208 | #define SS_LCMD(string) SS_LGUI(string) | 195 | #define SS_LCMD(string) SS_LGUI(string) |
| @@ -212,10 +199,12 @@ extern layer_state_t default_layer_state; | |||
| 212 | #define SS_RALT(string) SS_DOWN(X_RALT) string SS_UP(X_RALT) | 199 | #define SS_RALT(string) SS_DOWN(X_RALT) string SS_UP(X_RALT) |
| 213 | #define SS_ALGR(string) SS_RALT(string) | 200 | #define SS_ALGR(string) SS_RALT(string) |
| 214 | 201 | ||
| 215 | #define SEND_STRING(str) send_string_P(PSTR(str)) | 202 | #define SEND_STRING(string) send_string_P(PSTR(string)) |
| 203 | |||
| 216 | extern const bool ascii_to_shift_lut[0x80]; | 204 | extern const bool ascii_to_shift_lut[0x80]; |
| 217 | extern const bool ascii_to_altgr_lut[0x80]; | 205 | extern const bool ascii_to_altgr_lut[0x80]; |
| 218 | extern const uint8_t ascii_to_keycode_lut[0x80]; | 206 | extern const uint8_t ascii_to_keycode_lut[0x80]; |
| 207 | |||
| 219 | void send_string(const char *str); | 208 | void send_string(const char *str); |
| 220 | void send_string_with_delay(const char *str, uint8_t interval); | 209 | void send_string_with_delay(const char *str, uint8_t interval); |
| 221 | void send_string_P(const char *str); | 210 | void send_string_P(const char *str); |
| @@ -244,10 +233,10 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record); | |||
| 244 | bool process_record_user(uint16_t keycode, keyrecord_t *record); | 233 | bool process_record_user(uint16_t keycode, keyrecord_t *record); |
| 245 | 234 | ||
| 246 | #ifndef BOOTMAGIC_LITE_COLUMN | 235 | #ifndef BOOTMAGIC_LITE_COLUMN |
| 247 | #define BOOTMAGIC_LITE_COLUMN 0 | 236 | #define BOOTMAGIC_LITE_COLUMN 0 |
| 248 | #endif | 237 | #endif |
| 249 | #ifndef BOOTMAGIC_LITE_ROW | 238 | #ifndef BOOTMAGIC_LITE_ROW |
| 250 | #define BOOTMAGIC_LITE_ROW 0 | 239 | #define BOOTMAGIC_LITE_ROW 0 |
| 251 | #endif | 240 | #endif |
| 252 | 241 | ||
| 253 | void bootmagic_lite(void); | 242 | void bootmagic_lite(void); |
| @@ -268,7 +257,7 @@ void backlight_task_internal(void); | |||
| 268 | void backlight_on(uint8_t backlight_pin); | 257 | void backlight_on(uint8_t backlight_pin); |
| 269 | void backlight_off(uint8_t backlight_pin); | 258 | void backlight_off(uint8_t backlight_pin); |
| 270 | 259 | ||
| 271 | #ifdef BACKLIGHT_BREATHING | 260 | #ifdef BACKLIGHT_BREATHING |
| 272 | void breathing_task(void); | 261 | void breathing_task(void); |
| 273 | void breathing_enable(void); | 262 | void breathing_enable(void); |
| 274 | void breathing_pulse(void); | 263 | void breathing_pulse(void); |
| @@ -282,9 +271,9 @@ void breathing_period_default(void); | |||
| 282 | void breathing_period_set(uint8_t value); | 271 | void breathing_period_set(uint8_t value); |
| 283 | void breathing_period_inc(void); | 272 | void breathing_period_inc(void); |
| 284 | void breathing_period_dec(void); | 273 | void breathing_period_dec(void); |
| 274 | #endif | ||
| 285 | #endif | 275 | #endif |
| 286 | 276 | ||
| 287 | #endif | ||
| 288 | void send_dword(uint32_t number); | 277 | void send_dword(uint32_t number); |
| 289 | void send_word(uint16_t number); | 278 | void send_word(uint16_t number); |
| 290 | void send_byte(uint8_t number); | 279 | void send_byte(uint8_t number); |
| @@ -295,5 +284,3 @@ void led_set_user(uint8_t usb_led); | |||
| 295 | void led_set_kb(uint8_t usb_led); | 284 | void led_set_kb(uint8_t usb_led); |
| 296 | 285 | ||
| 297 | void api_send_unicode(uint32_t unicode); | 286 | void api_send_unicode(uint32_t unicode); |
| 298 | |||
| 299 | #endif | ||
