qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

quantum.h (6261B)


      1 /* Copyright 2016-2018 Erez Zukerman, Jack Humbert, Yiancar
      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 2 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 "platform_deps.h"
     19 #include "wait.h"
     20 #include "matrix.h"
     21 #include "keyboard.h"
     22 
     23 #ifdef BACKLIGHT_ENABLE
     24 #    include "backlight.h"
     25 #endif
     26 
     27 #ifdef LED_MATRIX_ENABLE
     28 #    include "led_matrix.h"
     29 #endif
     30 
     31 #if defined(RGBLIGHT_ENABLE)
     32 #    include "rgblight.h"
     33 #endif
     34 
     35 #ifdef RGB_MATRIX_ENABLE
     36 #    include "rgb_matrix.h"
     37 #endif
     38 
     39 #include "keymap_common.h"
     40 #include "quantum_keycodes.h"
     41 #include "keycode_config.h"
     42 #include "keycode_string.h"
     43 #include "action_layer.h"
     44 #include "eeconfig.h"
     45 #include "bootloader.h"
     46 #include "timer.h"
     47 #include "sync_timer.h"
     48 #include "gpio.h"
     49 #include "atomic_util.h"
     50 #include "host.h"
     51 #include "led.h"
     52 #include "action_util.h"
     53 #include "action_tapping.h"
     54 #include "print.h"
     55 #include "debug.h"
     56 #include "suspend.h"
     57 #include <stddef.h>
     58 #include <stdlib.h>
     59 #include <stdio.h>
     60 #include <string.h>
     61 
     62 #ifdef BOOTMAGIC_ENABLE
     63 #    include "bootmagic.h"
     64 #endif
     65 
     66 #ifdef BATTERY_ENABLE
     67 #    include "battery.h"
     68 #endif
     69 
     70 #ifdef DEFERRED_EXEC_ENABLE
     71 #    include "deferred_exec.h"
     72 #endif
     73 
     74 extern layer_state_t default_layer_state;
     75 
     76 #ifndef NO_ACTION_LAYER
     77 extern layer_state_t layer_state;
     78 #endif
     79 
     80 #if defined(SEQUENCER_ENABLE)
     81 #    include "sequencer.h"
     82 #    include "process_sequencer.h"
     83 #endif
     84 
     85 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
     86 #    include "process_midi.h"
     87 #endif
     88 
     89 #ifdef AUDIO_ENABLE
     90 #    include "audio.h"
     91 #    include "process_audio.h"
     92 #    include "song_list.h"
     93 #    ifdef AUDIO_CLICKY
     94 #        include "process_clicky.h"
     95 #    endif
     96 #endif
     97 
     98 #ifdef STENO_ENABLE
     99 #    include "process_steno.h"
    100 #endif
    101 
    102 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
    103 #    include "process_music.h"
    104 #endif
    105 
    106 #ifdef LEADER_ENABLE
    107 #    include "leader.h"
    108 #endif
    109 
    110 #ifdef UNICODE_COMMON_ENABLE
    111 #    include "unicode.h"
    112 #endif
    113 
    114 #ifdef UCIS_ENABLE
    115 #    include "ucis.h"
    116 #endif
    117 
    118 #ifdef UNICODEMAP_ENABLE
    119 #    include "unicodemap.h"
    120 #endif
    121 
    122 #ifdef KEY_OVERRIDE_ENABLE
    123 #    include "process_key_override.h"
    124 #endif
    125 
    126 #ifdef TAP_DANCE_ENABLE
    127 #    include "process_tap_dance.h"
    128 #endif
    129 
    130 #ifdef AUTO_SHIFT_ENABLE
    131 #    include "process_auto_shift.h"
    132 #endif
    133 
    134 #ifdef DYNAMIC_TAPPING_TERM_ENABLE
    135 #    include "process_dynamic_tapping_term.h"
    136 #endif
    137 
    138 #ifdef COMBO_ENABLE
    139 #    include "process_combo.h"
    140 #endif
    141 
    142 #ifdef KEY_LOCK_ENABLE
    143 #    include "process_key_lock.h"
    144 #endif
    145 
    146 #ifdef SPACE_CADET_ENABLE
    147 #    include "process_space_cadet.h"
    148 #endif
    149 
    150 #ifdef PROGRAMMABLE_BUTTON_ENABLE
    151 #    include "programmable_button.h"
    152 #endif
    153 
    154 #ifdef HD44780_ENABLE
    155 #    include "hd44780.h"
    156 #endif
    157 
    158 #ifdef SEND_STRING_ENABLE
    159 #    include "send_string.h"
    160 #endif
    161 
    162 #ifdef HAPTIC_ENABLE
    163 #    include "haptic.h"
    164 #endif
    165 
    166 #ifdef OLED_ENABLE
    167 #    include "oled_driver.h"
    168 #endif
    169 
    170 #ifdef ST7565_ENABLE
    171 #    include "st7565.h"
    172 #endif
    173 
    174 #ifdef QUANTUM_PAINTER_ENABLE
    175 #    include "qp.h"
    176 #endif
    177 
    178 #ifdef DIP_SWITCH_ENABLE
    179 #    include "dip_switch.h"
    180 #endif
    181 
    182 #ifdef DYNAMIC_MACRO_ENABLE
    183 #    include "process_dynamic_macro.h"
    184 #endif
    185 
    186 #ifdef SECURE_ENABLE
    187 #    include "secure.h"
    188 #endif
    189 
    190 #ifdef DYNAMIC_KEYMAP_ENABLE
    191 #    include "dynamic_keymap.h"
    192 #endif
    193 
    194 #ifdef JOYSTICK_ENABLE
    195 #    include "joystick.h"
    196 #endif
    197 
    198 #ifdef DIGITIZER_ENABLE
    199 #    include "digitizer.h"
    200 #endif
    201 
    202 #ifdef VIA_ENABLE
    203 #    include "via.h"
    204 #endif
    205 
    206 #ifdef WPM_ENABLE
    207 #    include "wpm.h"
    208 #endif
    209 
    210 #ifdef USBPD_ENABLE
    211 #    include "usbpd.h"
    212 #endif
    213 
    214 #ifdef ENCODER_ENABLE
    215 #    include "encoder.h"
    216 #endif
    217 
    218 #ifdef POINTING_DEVICE_ENABLE
    219 #    include "pointing_device.h"
    220 #endif
    221 
    222 #ifdef MOUSEKEY_ENABLE
    223 #    include "mousekey.h"
    224 #endif
    225 
    226 #ifdef CAPS_WORD_ENABLE
    227 #    include "caps_word.h"
    228 #    include "process_caps_word.h"
    229 #endif
    230 
    231 #ifdef AUTOCORRECT_ENABLE
    232 #    include "process_autocorrect.h"
    233 #endif
    234 
    235 #ifdef TRI_LAYER_ENABLE
    236 #    include "tri_layer.h"
    237 #endif
    238 
    239 #ifdef REPEAT_KEY_ENABLE
    240 #    include "repeat_key.h"
    241 #    include "process_repeat_key.h"
    242 #endif
    243 
    244 #ifdef OS_DETECTION_ENABLE
    245 #    include "os_detection.h"
    246 #endif
    247 
    248 #ifdef LAYER_LOCK_ENABLE
    249 #    include "layer_lock.h"
    250 #endif
    251 
    252 #ifdef COMMUNITY_MODULES_ENABLE
    253 #    include "community_modules.h"
    254 #endif
    255 
    256 void set_single_default_layer(uint8_t default_layer);
    257 void set_single_persistent_default_layer(uint8_t default_layer);
    258 
    259 #define IS_LAYER_ON(layer) layer_state_is(layer)
    260 #define IS_LAYER_OFF(layer) !layer_state_is(layer)
    261 
    262 #define IS_LAYER_ON_STATE(state, layer) layer_state_cmp(state, layer)
    263 #define IS_LAYER_OFF_STATE(state, layer) !layer_state_cmp(state, layer)
    264 
    265 uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache);
    266 uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache);
    267 bool     pre_process_record_quantum(keyrecord_t *record);
    268 bool     pre_process_record_kb(uint16_t keycode, keyrecord_t *record);
    269 bool     pre_process_record_user(uint16_t keycode, keyrecord_t *record);
    270 bool     process_record_kb(uint16_t keycode, keyrecord_t *record);
    271 bool     process_record_user(uint16_t keycode, keyrecord_t *record);
    272 void     post_process_record_kb(uint16_t keycode, keyrecord_t *record);
    273 void     post_process_record_user(uint16_t keycode, keyrecord_t *record);
    274 
    275 void reset_keyboard(void);
    276 void soft_reset_keyboard(void);
    277 
    278 bool shutdown_kb(bool jump_to_bootloader);
    279 bool shutdown_user(bool jump_to_bootloader);
    280 
    281 void register_code16(uint16_t code);
    282 void unregister_code16(uint16_t code);
    283 void tap_code16(uint16_t code);
    284 void tap_code16_delay(uint16_t code, uint16_t delay);
    285 
    286 const char *get_numeric_str(char *buf, size_t buf_len, uint32_t curr_num, char curr_pad);
    287 const char *get_u8_str(uint8_t curr_num, char curr_pad);
    288 const char *get_u16_str(uint16_t curr_num, char curr_pad);