qmk_firmware

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

action.h (4208B)


      1 /*
      2 Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
      3 
      4 This program is free software: you can redistribute it and/or modify
      5 it under the terms of the GNU General Public License as published by
      6 the Free Software Foundation, either version 2 of the License, or
      7 (at your option) any later version.
      8 
      9 This program is distributed in the hope that it will be useful,
     10 but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 GNU General Public License for more details.
     13 
     14 You should have received a copy of the GNU General Public License
     15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17 
     18 #pragma once
     19 
     20 #include <stdint.h>
     21 #include <stdbool.h>
     22 #include "progmem.h"
     23 #include "keyboard.h"
     24 #include "keycode.h"
     25 #include "action_code.h"
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 #ifndef TAP_CODE_DELAY
     32 #    define TAP_CODE_DELAY 0
     33 #endif
     34 #ifndef TAP_HOLD_CAPS_DELAY
     35 #    define TAP_HOLD_CAPS_DELAY 80
     36 #endif
     37 
     38 /* tapping count and state */
     39 typedef struct {
     40     bool    interrupted : 1;
     41     bool    speculated : 1;
     42     bool    reserved1 : 1;
     43     bool    reserved0 : 1;
     44     uint8_t count : 4;
     45 } tap_t;
     46 
     47 /* Key event container for recording */
     48 typedef struct keyrecord_t {
     49     keyevent_t event;
     50 #ifndef NO_ACTION_TAPPING
     51     tap_t tap;
     52 #endif
     53 #if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE)
     54     uint16_t keycode;
     55 #endif
     56 } keyrecord_t;
     57 
     58 /* Execute action per keyevent */
     59 void action_exec(keyevent_t event);
     60 
     61 /* action for key */
     62 action_t action_for_key(uint8_t layer, keypos_t key);
     63 action_t action_for_keycode(uint16_t keycode);
     64 
     65 /* keyboard-specific key event (pre)processing */
     66 bool process_record_quantum(keyrecord_t *record);
     67 
     68 /* Utilities for actions.  */
     69 #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
     70 extern bool disable_action_cache;
     71 #endif
     72 
     73 /* Code for handling one-handed key modifiers. */
     74 #ifdef SWAP_HANDS_ENABLE
     75 extern bool                   swap_hands;
     76 extern const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
     77 #    if (MATRIX_COLS <= 8)
     78 typedef uint8_t swap_state_row_t;
     79 #    elif (MATRIX_COLS <= 16)
     80 typedef uint16_t swap_state_row_t;
     81 #    elif (MATRIX_COLS <= 32)
     82 typedef uint32_t swap_state_row_t;
     83 #    else
     84 #        error "MATRIX_COLS: invalid value"
     85 #    endif
     86 
     87 /**
     88  * @brief Enable swap hands
     89  */
     90 void swap_hands_on(void);
     91 /**
     92  * @brief Disable swap hands
     93  */
     94 void swap_hands_off(void);
     95 /**
     96  * @brief Toggle swap hands enable state
     97  */
     98 void swap_hands_toggle(void);
     99 /**
    100  * @brief Get the swap hands enable state
    101  *
    102  * @return true
    103  * @return false
    104  */
    105 bool is_swap_hands_on(void);
    106 
    107 void process_hand_swap(keyevent_t *record);
    108 #endif
    109 
    110 void process_record_nocache(keyrecord_t *record);
    111 void process_record(keyrecord_t *record);
    112 void process_record_handler(keyrecord_t *record);
    113 void post_process_record_quantum(keyrecord_t *record);
    114 void process_action(keyrecord_t *record, action_t action);
    115 void register_code(uint8_t code);
    116 void unregister_code(uint8_t code);
    117 void tap_code(uint8_t code);
    118 void tap_code_delay(uint8_t code, uint16_t delay);
    119 void register_mods(uint8_t mods);
    120 void unregister_mods(uint8_t mods);
    121 void register_weak_mods(uint8_t mods);
    122 void unregister_weak_mods(uint8_t mods);
    123 // void set_mods(uint8_t mods);
    124 void clear_keyboard(void);
    125 void clear_keyboard_but_mods(void);
    126 void clear_keyboard_but_mods_and_keys(void);
    127 void layer_switch(uint8_t new_layer);
    128 bool is_tap_record(keyrecord_t *record);
    129 bool is_tap_action(action_t action);
    130 
    131 /**
    132  * Given an MT or LT keycode, returns the tap keycode. Otherwise returns the
    133  * original keycode unchanged.
    134  */
    135 uint16_t get_tap_keycode(uint16_t keycode);
    136 
    137 #ifndef NO_ACTION_TAPPING
    138 void process_record_tap_hint(keyrecord_t *record);
    139 #endif
    140 
    141 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    142 // Helpers
    143 
    144 #ifdef ACTION_DEBUG
    145 #    include "debug.h"
    146 #    include "print.h"
    147 #    define ac_dprintf(...) dprintf(__VA_ARGS__)
    148 #else
    149 #    define ac_dprintf(...) \
    150         do {                \
    151         } while (0)
    152 #endif
    153 
    154 void debug_event(keyevent_t event);
    155 void debug_record(keyrecord_t record);
    156 void debug_action(action_t action);
    157 
    158 #ifdef __cplusplus
    159 }
    160 #endif