qmk-keychron-q3-colemak-dh/quantum/qmk_settings.h

232 lines
6.9 KiB
C
Raw Permalink Normal View History

2021-06-30 01:43:11 +02:00
#pragma once
#include <inttypes.h>
#include <stddef.h>
#include "quantum/action.h"
2021-06-30 01:43:11 +02:00
/* take qmk config macros and set up helper variables for default settings */
#ifndef TAP_CODE_DELAY
# define TAP_CODE_DELAY 10
#endif
#ifndef TAP_HOLD_CAPS_DELAY
# define TAP_HOLD_CAPS_DELAY 80
#endif
2021-06-30 01:43:11 +02:00
/* ========================================================================== */
/* Grave escape */
/* ========================================================================== */
#ifdef GRAVE_ESC_ALT_OVERRIDE
#define GRAVE_ESC_ALT_OVERRIDE_Defined 1
#else
#define GRAVE_ESC_ALT_OVERRIDE_Defined 0
#endif
#ifdef GRAVE_ESC_CTRL_OVERRIDE
#define GRAVE_ESC_CTRL_OVERRIDE_Defined 1
#else
#define GRAVE_ESC_CTRL_OVERRIDE_Defined 0
#endif
#ifdef GRAVE_ESC_GUI_OVERRIDE
#define GRAVE_ESC_GUI_OVERRIDE_Defined 1
#else
#define GRAVE_ESC_GUI_OVERRIDE_Defined 0
#endif
#ifdef GRAVE_ESC_SHIFT_OVERRIDE
#define GRAVE_ESC_SHIFT_OVERRIDE_Defined 1
#else
#define GRAVE_ESC_SHIFT_OVERRIDE_Defined 0
#endif
2021-07-01 22:17:15 +02:00
/* ========================================================================== */
/* Auto shift */
/* ========================================================================== */
#ifdef AUTO_SHIFT_ENABLE
#define AUTO_SHIFT_ENABLE_Defined 1
#else
#define AUTO_SHIFT_ENABLE_Defined 0
#endif
#ifdef AUTO_SHIFT_MODIFIERS
#define AUTO_SHIFT_MODIFIERS_Defined 1
#else
#define AUTO_SHIFT_MODIFIERS_Defined 0
#endif
#ifdef NO_AUTO_SHIFT_SPECIAL
#define NO_AUTO_SHIFT_SPECIAL_Defined 1
#else
#define NO_AUTO_SHIFT_SPECIAL_Defined 0
#endif
#ifdef NO_AUTO_SHIFT_NUMERIC
#define NO_AUTO_SHIFT_NUMERIC_Defined 1
#else
#define NO_AUTO_SHIFT_NUMERIC_Defined 0
#endif
#ifdef NO_AUTO_SHIFT_ALPHA
#define NO_AUTO_SHIFT_ALPHA_Defined 1
#else
#define NO_AUTO_SHIFT_ALPHA_Defined 0
#endif
#ifdef AUTO_SHIFT_REPEAT
#define AUTO_SHIFT_REPEAT_Defined 1
#else
#define AUTO_SHIFT_REPEAT_Defined 0
#endif
#ifdef AUTO_SHIFT_NO_AUTO_REPEAT
#define AUTO_SHIFT_NO_AUTO_REPEAT_Defined 1
#else
#define AUTO_SHIFT_NO_AUTO_REPEAT_Defined 0
#endif
/* ========================================================================== */
/* One shot keys */
/* ========================================================================== */
#ifndef ONESHOT_TAP_TOGGLE
#define ONESHOT_TAP_TOGGLE 5
#endif
#ifndef ONESHOT_TIMEOUT
#define ONESHOT_TIMEOUT 5000
#endif
2021-06-30 01:43:11 +02:00
#ifdef QMK_SETTINGS
/* dynamic settings framework is enabled */
/* actual settings - stored in RAM and backed by EEPROM
these are in arbitrary order to ensure they are aligned w/o any holes, and the order can be changed at will */
2021-06-30 01:43:11 +02:00
typedef struct {
uint16_t auto_shift_timeout;
uint16_t osk_timeout;
2021-07-02 02:43:35 +02:00
uint16_t mousekey_delay;
uint16_t mousekey_interval;
uint16_t mousekey_move_delta;
uint16_t mousekey_max_speed;
uint16_t mousekey_time_to_max;
uint16_t mousekey_wheel_delay;
uint16_t mousekey_wheel_interval;
uint16_t mousekey_wheel_max_speed;
uint16_t mousekey_wheel_time_to_max;
2021-07-05 01:04:46 +02:00
uint16_t combo_term;
2021-07-09 00:12:13 +02:00
uint16_t tapping_term;
uint8_t grave_esc_override;
uint8_t auto_shift;
uint8_t osk_tap_toggle;
2021-07-09 00:12:13 +02:00
uint8_t tapping;
uint16_t tap_code_delay;
uint16_t tap_hold_caps_delay;
2022-04-03 00:39:12 +02:00
uint8_t tapping_toggle;
uint8_t unused;
2021-06-30 01:43:11 +02:00
} qmk_settings_t;
2022-04-03 00:39:12 +02:00
_Static_assert(sizeof(qmk_settings_t) == 36, "unexpected size of the qmk_settings_t structure");
2021-06-30 01:43:11 +02:00
struct qmk_settings_proto_t;
2021-07-01 22:17:15 +02:00
typedef void (*qmk_settings_notify_t)(void);
typedef int (*qmk_settings_get_t)(const struct qmk_settings_proto_t *proto, void *setting, size_t maxsz);
typedef int (*qmk_settings_set_t)(const struct qmk_settings_proto_t *proto, const void *setting, size_t maxsz);
/* setting prototype - describes how to get/set settings; this structure is stored in flash */
typedef struct qmk_settings_proto_t {
2021-06-30 01:43:11 +02:00
uint16_t qsid;
uint16_t sz;
void *ptr;
qmk_settings_get_t get;
qmk_settings_set_t set;
qmk_settings_notify_t notify;
2021-06-30 01:43:11 +02:00
} qmk_settings_proto_t;
void qmk_settings_init(void);
void qmk_settings_reset(void);
void qmk_settings_query(uint16_t qsid_gt, void *buffer, size_t sz);
2021-06-30 01:43:11 +02:00
int qmk_settings_get(uint16_t qsid, void *setting, size_t maxsz);
int qmk_settings_set(uint16_t qsid, const void *setting, size_t maxsz);
uint16_t qs_get_tapping_term(uint16_t keycode, keyrecord_t *record);
2021-06-30 01:43:11 +02:00
extern qmk_settings_t QS;
/* Grave escape */
#define QS_grave_esc_alt_override (QS.grave_esc_override & 1)
#define QS_grave_esc_ctrl_override (QS.grave_esc_override & 2)
#define QS_grave_esc_gui_override (QS.grave_esc_override & 4)
#define QS_grave_esc_shift_override (QS.grave_esc_override & 8)
2021-07-01 22:17:15 +02:00
/* Auto shift */
#define QS_auto_shift_enable (QS.auto_shift & 1)
#define QS_auto_shift_modifiers (QS.auto_shift & 2)
#define QS_auto_shift_no_auto_shift_special (QS.auto_shift & 4)
#define QS_auto_shift_no_auto_shift_numeric (QS.auto_shift & 8)
#define QS_auto_shift_no_auto_shift_alpha (QS.auto_shift & 16)
#define QS_auto_shift_repeat (QS.auto_shift & 32)
#define QS_auto_shift_no_auto_repeat (QS.auto_shift & 64)
2021-07-02 02:13:00 +02:00
/* One Shot Keys */
#define QS_oneshot_tap_toggle (QS.osk_tap_toggle)
#define QS_oneshot_timeout (QS.osk_timeout)
2021-07-02 02:43:35 +02:00
/* Mouse keys */
#define QS_mousekey_move_delta (QS.mousekey_move_delta)
2021-07-05 01:04:46 +02:00
/* Combo */
#define QS_combo_term (QS.combo_term)
/* Tap delays */
#define QS_tap_code_delay (QS.tap_code_delay)
#define QS_tap_hold_caps_delay (QS.tap_hold_caps_delay)
2022-04-03 00:39:12 +02:00
/* Tapping Toggle */
#define QS_tapping_toggle (QS.tapping_toggle)
2021-06-30 01:43:11 +02:00
#else
/* dynamic settings framework is disabled => hardcode the settings and let the compiler optimize extra branches out */
/* Grave escape */
#define QS_grave_esc_alt_override GRAVE_ESC_ALT_OVERRIDE_Defined
#define QS_grave_esc_ctrl_override GRAVE_ESC_CTRL_OVERRIDE_Defined
#define QS_grave_esc_gui_override GRAVE_ESC_GUI_OVERRIDE_Defined
#define QS_grave_esc_shift_override GRAVE_ESC_SHIFT_OVERRIDE_Defined
2021-07-01 22:17:15 +02:00
/* Auto shift */
#define QS_auto_shift_enable AUTO_SHIFT_ENABLE_Defined
#define QS_auto_shift_modifiers AUTO_SHIFT_MODIFIERS_Defined
#define QS_auto_shift_no_auto_shift_special NO_AUTO_SHIFT_SPECIAL_Defined
#define QS_auto_shift_no_auto_shift_numeric NO_AUTO_SHIFT_NUMERIC_Defined
#define QS_auto_shift_no_auto_shift_alpha NO_AUTO_SHIFT_ALPHA_Defined
#define QS_auto_shift_repeat AUTO_SHIFT_REPEAT_Defined
#define QS_auto_shift_no_auto_repeat AUTO_SHIFT_NO_AUTO_REPEAT_Defined
2021-07-02 02:13:00 +02:00
/* One Shot Keys */
#define QS_oneshot_tap_toggle ONESHOT_TAP_TOGGLE
#define QS_oneshot_timeout ONESHOT_TIMEOUT
2021-07-02 02:43:35 +02:00
/* Mouse keys */
#define QS_mousekey_move_delta MOUSEKEY_MOVE_DELTA
2021-07-05 01:04:46 +02:00
/* Combo */
#define QS_combo_term COMBO_TERM
/* Tap delays */
#define QS_tap_code_delay TAP_CODE_DELAY
#define QS_tap_hold_caps_delay TAP_HOLD_CAPS_DELAY
2022-04-03 00:39:12 +02:00
/* Tapping Toggle */
#define QS_tapping_toggle TAPPING_TOGGLE
2021-07-01 22:17:15 +02:00
#endif
#if defined(__AVR__) && defined(QMK_SETTINGS)
#include <util/delay.h>
static inline void qs_wait_ms(uint16_t timer) {
while (timer--) _delay_ms(1);
}
#else
#define qs_wait_ms wait_ms
#endif