diff options
Diffstat (limited to 'quantum')
77 files changed, 2300 insertions, 1067 deletions
diff --git a/quantum/action.c b/quantum/action.c index 6b2e9104e0..78322e4a83 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -293,19 +293,56 @@ void process_record_handler(keyrecord_t *record) { process_action(record, action); } -#if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE) -void register_button(bool pressed, enum mouse_buttons button) { -# ifdef PS2_MOUSE_ENABLE - tp_buttons = pressed ? tp_buttons | button : tp_buttons & ~button; -# endif -# ifdef POINTING_DEVICE_ENABLE - report_mouse_t currentReport = pointing_device_get_report(); - currentReport.buttons = pressed ? currentReport.buttons | button : currentReport.buttons & ~button; - pointing_device_set_report(currentReport); +/** + * @brief handles all the messy mouse stuff + * + * Handles all the edgecases and special stuff that is needed for coexistense + * of the multiple mouse subsystems. + * + * @param mouse_keycode[in] uint8_t mouse keycode + * @param pressed[in] bool + */ + +void register_mouse(uint8_t mouse_keycode, bool pressed) { +#ifdef MOUSEKEY_ENABLE + // if mousekeys is enabled, let it do the brunt of the work + if (pressed) { + mousekey_on(mouse_keycode); + } else { + mousekey_off(mouse_keycode); + } + // should mousekeys send report, or does something else handle this? + switch (mouse_keycode) { +# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE) + case KC_MS_BTN1 ... KC_MS_BTN8: + // let pointing device handle the buttons + // expand if/when it handles more of the code +# if defined(POINTING_DEVICE_ENABLE) + pointing_device_keycode_handler(mouse_keycode, pressed); +# endif + break; # endif -} + default: + mousekey_send(); + break; + } +#elif defined(POINTING_DEVICE_ENABLE) + // if mousekeys isn't enabled, and pointing device is enabled, then + // let pointing device do all the heavy lifting, then + if IS_MOUSEKEY (mouse_keycode) { + pointing_device_keycode_handler(mouse_keycode, pressed); + } #endif +#ifdef PS2_MOUSE_ENABLE + // make sure that ps2 mouse has button report synced + if (KC_MS_BTN1 <= mouse_keycode && mouse_keycode <= KC_MS_BTN3) { + uint8_t tmp_button_msk = MOUSE_BTN_MASK(mouse_keycode - KC_MS_BTN1); + tp_buttons = pressed ? tp_buttons | tmp_button_msk : tp_buttons & ~tmp_button_msk; + } +#endif +} + /** \brief Take an action and processes it. * * FIXME: Needs documentation. @@ -403,9 +440,9 @@ void process_action(keyrecord_t *record, action_t action) { # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 } else if (tap_count == ONESHOT_TAP_TOGGLE) { dprint("MODS_TAP: Toggling oneshot"); + register_mods(mods); clear_oneshot_mods(); set_oneshot_locked_mods(mods | get_oneshot_locked_mods()); - register_mods(mods); # endif } else { register_mods(mods | get_oneshot_mods()); @@ -418,16 +455,16 @@ void process_action(keyrecord_t *record, action_t action) { // Retain Oneshot mods # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 if (mods & get_mods()) { + unregister_mods(mods); clear_oneshot_mods(); set_oneshot_locked_mods(~mods & get_oneshot_locked_mods()); - unregister_mods(mods); } } else if (tap_count == ONESHOT_TAP_TOGGLE) { // Toggle Oneshot Layer # endif } else { - clear_oneshot_mods(); unregister_mods(mods); + clear_oneshot_mods(); } } } @@ -490,46 +527,18 @@ void process_action(keyrecord_t *record, action_t action) { case ACT_USAGE: switch (action.usage.page) { case PAGE_SYSTEM: - if (event.pressed) { - host_system_send(action.usage.code); - } else { - host_system_send(0); - } + host_system_send(event.pressed ? action.usage.code : 0); break; case PAGE_CONSUMER: - if (event.pressed) { - host_consumer_send(action.usage.code); - } else { - host_consumer_send(0); - } + host_consumer_send(event.pressed ? action.usage.code : 0); break; } break; #endif -#ifdef MOUSEKEY_ENABLE /* Mouse key */ case ACT_MOUSEKEY: - if (event.pressed) { - mousekey_on(action.key.code); - } else { - mousekey_off(action.key.code); - } - switch (action.key.code) { -# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE) -# ifdef POINTING_DEVICE_ENABLE - case KC_MS_BTN1 ... KC_MS_BTN8: -# else - case KC_MS_BTN1 ... KC_MS_BTN3: -# endif - register_button(event.pressed, MOUSE_BTN_MASK(action.key.code - KC_MS_BTN1)); - break; -# endif - default: - mousekey_send(); - break; - } + register_mouse(action.key.code, event.pressed); break; -#endif #ifndef NO_ACTION_LAYER case ACT_LAYER: if (action.layer_bitop.on == 0) { @@ -835,9 +844,9 @@ void process_action(keyrecord_t *record, action_t action) { __attribute__((weak)) void register_code(uint8_t code) { if (code == KC_NO) { return; - } + #ifdef LOCKING_SUPPORT_ENABLE - else if (KC_LOCKING_CAPS_LOCK == code) { + } else if (KC_LOCKING_CAPS_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE // Resync: ignore if caps lock already is on if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return; @@ -847,9 +856,8 @@ __attribute__((weak)) void register_code(uint8_t code) { wait_ms(TAP_HOLD_CAPS_DELAY); del_key(KC_CAPS_LOCK); send_keyboard_report(); - } - else if (KC_LOCKING_NUM_LOCK == code) { + } else if (KC_LOCKING_NUM_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return; # endif @@ -858,9 +866,8 @@ __attribute__((weak)) void register_code(uint8_t code) { wait_ms(100); del_key(KC_NUM_LOCK); send_keyboard_report(); - } - else if (KC_LOCKING_SCROLL_LOCK == code) { + } else if (KC_LOCKING_SCROLL_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return; # endif @@ -869,10 +876,9 @@ __attribute__((weak)) void register_code(uint8_t code) { wait_ms(100); del_key(KC_SCROLL_LOCK); send_keyboard_report(); - } #endif - else if IS_KEY (code) { + } else if IS_KEY (code) { // TODO: should push command_proc out of this block? if (command_proc(code)) return; @@ -905,20 +911,17 @@ __attribute__((weak)) void register_code(uint8_t code) { } else if IS_MOD (code) { add_mods(MOD_BIT(code)); send_keyboard_report(); - } + #ifdef EXTRAKEY_ENABLE - else if IS_SYSTEM (code) { + } else if IS_SYSTEM (code) { host_system_send(KEYCODE2SYSTEM(code)); } else if IS_CONSUMER (code) { host_consumer_send(KEYCODE2CONSUMER(code)); - } #endif -#ifdef MOUSEKEY_ENABLE - else if IS_MOUSEKEY (code) { - mousekey_on(code); - mousekey_send(); + + } else if IS_MOUSEKEY (code) { + register_mouse(code, true); } -#endif } /** \brief Utilities for actions. (FIXME: Needs better description) @@ -928,9 +931,9 @@ __attribute__((weak)) void register_code(uint8_t code) { __attribute__((weak)) void unregister_code(uint8_t code) { if (code == KC_NO) { return; - } + #ifdef LOCKING_SUPPORT_ENABLE - else if (KC_LOCKING_CAPS_LOCK == code) { + } else if (KC_LOCKING_CAPS_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE // Resync: ignore if caps lock already is off if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return; @@ -939,9 +942,8 @@ __attribute__((weak)) void unregister_code(uint8_t code) { send_keyboard_report(); del_key(KC_CAPS_LOCK); send_keyboard_report(); - } - else if (KC_LOCKING_NUM_LOCK == code) { + } else if (KC_LOCKING_NUM_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return; # endif @@ -949,9 +951,8 @@ __attribute__((weak)) void unregister_code(uint8_t code) { send_keyboard_report(); del_key(KC_NUM_LOCK); send_keyboard_report(); - } - else if (KC_LOCKING_SCROLL_LOCK == code) { + } else if (KC_LOCKING_SCROLL_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return; # endif @@ -959,26 +960,25 @@ __attribute__((weak)) void unregister_code(uint8_t code) { send_keyboard_report(); del_key(KC_SCROLL_LOCK); send_keyboard_report(); - } #endif - else if IS_KEY (code) { + } else if IS_KEY (code) { del_key(code); send_keyboard_report(); } else if IS_MOD (code) { del_mods(MOD_BIT(code)); send_keyboard_report(); + +#ifdef EXTRAKEY_ENABLE } else if IS_SYSTEM (code) { host_system_send(0); } else if IS_CONSUMER (code) { host_consumer_send(0); - } -#ifdef MOUSEKEY_ENABLE - else if IS_MOUSEKEY (code) { - mousekey_off(code); - mousekey_send(); - } #endif + + } else if IS_MOUSEKEY (code) { + register_mouse(code, false); + } } /** \brief Tap a keycode with a delay. diff --git a/quantum/action_code.h b/quantum/action_code.h index e107f0a740..14cfd025f1 100644 --- a/quantum/action_code.h +++ b/quantum/action_code.h @@ -192,7 +192,11 @@ enum mods_codes { /** \brief Other Keys */ -enum usage_pages { PAGE_SYSTEM, PAGE_CONSUMER }; +enum usage_pages { + PAGE_SYSTEM, + PAGE_CONSUMER, +}; + #define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM << 10 | (id)) #define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER << 10 | (id)) #define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key) diff --git a/quantum/backlight/backlight_chibios.c b/quantum/backlight/backlight_chibios.c index e8f9e70f78..30e95bd5c8 100644 --- a/quantum/backlight/backlight_chibios.c +++ b/quantum/backlight/backlight_chibios.c @@ -40,16 +40,22 @@ # endif #endif -static PWMConfig pwmCFG = {0xFFFF, /* PWM clock frequency */ - 256, /* PWM period (in ticks) 1S (1/10kHz=0.1mS 0.1ms*10000 ticks=1S) */ - NULL, /* Breathing Callback */ - { /* Default all channels to disabled - Channels will be configured durring init */ - {PWM_OUTPUT_DISABLED, NULL}, - {PWM_OUTPUT_DISABLED, NULL}, - {PWM_OUTPUT_DISABLED, NULL}, - {PWM_OUTPUT_DISABLED, NULL}}, - 0, /* HW dependent part.*/ - 0}; +#ifndef BACKLIGHT_PWM_COUNTER_FREQUENCY +# define BACKLIGHT_PWM_COUNTER_FREQUENCY 0xFFFF +#endif + +#ifndef BACKLIGHT_PWM_PERIOD +# define BACKLIGHT_PWM_PERIOD 256 +#endif + +static PWMConfig pwmCFG = { + .frequency = BACKLIGHT_PWM_COUNTER_FREQUENCY, /* PWM clock frequency */ + .period = BACKLIGHT_PWM_PERIOD, /* PWM period in counter ticks. e.g. clock frequency is 10KHz, period is 256 ticks then t_period is 25.6ms */ +}; + +#ifdef BACKLIGHT_BREATHING +static virtual_timer_t breathing_vt; +#endif // See http://jared.geek.nz/2013/feb/linear-led-pwm static uint16_t cie_lightness(uint16_t v) { @@ -60,10 +66,11 @@ static uint16_t cie_lightness(uint16_t v) { // to get a useful result with integer division, we shift left in the expression above // and revert what we've done again after squaring. y = y * y * y >> 8; - if (y > 0xFFFFUL) // prevent overflow + if (y > 0xFFFFUL) { // prevent overflow return 0xFFFFU; - else + } else { return (uint16_t)y; + } } } @@ -85,6 +92,7 @@ void backlight_init_ports(void) { backlight_set(get_backlight_level()); #ifdef BACKLIGHT_BREATHING + chVTObjectInit(&breathing_vt); if (is_backlight_breathing()) { breathing_enable(); } @@ -92,7 +100,9 @@ void backlight_init_ports(void) { } void backlight_set(uint8_t level) { - if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; + if (level > BACKLIGHT_LEVELS) { + level = BACKLIGHT_LEVELS; + } if (level == 0) { // Turn backlight off @@ -115,20 +125,19 @@ void backlight_task(void) {} */ static const uin |