diff options
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/avr.mk | 23 | ||||
-rw-r--r-- | tmk_core/common/action_tapping.c | 20 | ||||
-rw-r--r-- | tmk_core/common/action_tapping.h | 2 | ||||
-rw-r--r-- | tmk_core/common/arm_atsam/suspend.c | 9 | ||||
-rw-r--r-- | tmk_core/common/avr/suspend.c | 9 | ||||
-rw-r--r-- | tmk_core/common/mousekey.c | 372 | ||||
-rw-r--r-- | tmk_core/common/mousekey.h | 56 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam.mk | 5 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/arm_atsam_protocol.h | 3 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/i2c_master.c | 8 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/led_matrix.c | 554 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/led_matrix.h | 84 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/led_matrix_programs.c | 123 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/main_arm_atsam.c | 16 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/usb2422.c | 6 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/adafruit_ble.cpp | 3 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/usbdrv/usbdrv.c | 2 | ||||
-rw-r--r-- | tmk_core/rules.mk | 12 |
18 files changed, 796 insertions, 511 deletions
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk index d22c3bbcad..f6af3f5e29 100644 --- a/tmk_core/avr.mk +++ b/tmk_core/avr.mk @@ -194,7 +194,7 @@ dfu-split-right: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size $(DFU_PROGRAMMER) $(MCU) flash --eeprom $(QUANTUM_PATH)/split_common/eeprom-righthand.eep;\ else\ $(DFU_PROGRAMMER) $(MCU) erase;\ - $(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/eeprom-rightand.eep;\ + $(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/eeprom-righthand.eep;\ fi $(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex $(DFU_PROGRAMMER) $(MCU) reset @@ -214,13 +214,20 @@ define EXEC_AVRDUDE mv /tmp/2 /tmp/1; \ done; \ echo ""; \ - echo "Detected controller on USB port at $$USB"; \ + echo "Device $$USB has appeared; assuming it is the controller."; \ if $(GREP) -q -s 'MINGW\|MSYS' /proc/version; then \ USB=`echo "$$USB" | perl -pne 's/\/dev\/ttyS(\d+)/COM.($$1+1)/e'`; \ echo "Remapped MSYS2 USB port to $$USB"; \ + sleep 1; \ + else \ + printf "Waiting for $$USB to become writable."; \ + while [ ! -w "$$USB" ]; do sleep 0.5; printf "."; done; echo ""; \ fi; \ - sleep 1; \ - avrdude -p $(MCU) -c avr109 -P $$USB -U flash:w:$(BUILD_DIR)/$(TARGET).hex; \ + if [ -z "$(1)" ]; then \ + avrdude -p $(MCU) -c avr109 -P $$USB -U flash:w:$(BUILD_DIR)/$(TARGET).hex; \ + else \ + avrdude -p $(MCU) -c avr109 -P $$USB -U flash:w:$(BUILD_DIR)/$(TARGET).hex -U eeprom:w:$(QUANTUM_PATH)/split_common/$(1); \ + fi \ fi endef @@ -229,9 +236,15 @@ avrdude: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware avrdude-loop: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware while true; do \ - $(call EXEC_AVRDUDE) ; \ + $(call EXEC_AVRDUDE) ; \ done +avrdude-split-left: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware + $(call EXEC_AVRDUDE,eeprom-lefthand.eep) + +avrdude-split-right: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware + $(call EXEC_AVRDUDE,eeprom-righthand.eep) + # Convert hex to bin. bin: $(BUILD_DIR)/$(TARGET).hex $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c index 8adf013e16..3b67ed152f 100644 --- a/tmk_core/common/action_tapping.c +++ b/tmk_core/common/action_tapping.c @@ -18,8 +18,17 @@ #define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed) #define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) #define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) -#define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) +__attribute__ ((weak)) +uint16_t get_tapping_term(uint16_t keycode) { + return TAPPING_TERM; +} + +#ifdef TAPPING_TERM_PER_KEY +#define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event))) +#else +#define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) +#endif static keyrecord_t tapping_key = {}; static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {}; @@ -100,12 +109,17 @@ bool process_tapping(keyrecord_t *keyp) // enqueue return false; } -#if TAPPING_TERM >= 500 || defined PERMISSIVE_HOLD /* Process a key typed within TAPPING_TERM * This can register the key before settlement of tapping, * useful for long TAPPING_TERM but may prevent fast typing. */ - else if (IS_RELEASED(event) && waiting_buffer_typed(event)) { +#if defined(TAPPING_TERM_PER_KEY) || (!defined(PER_KEY_TAPPING_TERM) && TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) +#ifdef TAPPING_TERM_PER_KEY + else if ( ( get_tapping_term(get_event_keycode(tapping_key.event)) >= 500) && IS_RELEASED(event) && waiting_buffer_typed(event)) +#else + else if ( IS_RELEASED(event) && waiting_buffer_typed(event)) +#endif + { debug("Tapping: End. No tap. Interfered by typing key\n"); process_record(&tapping_key); tapping_key = (keyrecord_t){}; diff --git a/tmk_core/common/action_tapping.h b/tmk_core/common/action_tapping.h index 2f143ae8b8..1db43a442e 100644 --- a/tmk_core/common/action_tapping.h +++ b/tmk_core/common/action_tapping.h @@ -35,6 +35,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef NO_ACTION_TAPPING +uint16_t get_event_keycode(keyevent_t event); +uint16_t get_tapping_term(uint16_t keycode); void action_tapping_process(keyrecord_t record); #endif diff --git a/tmk_core/common/arm_atsam/suspend.c b/tmk_core/common/arm_atsam/suspend.c index e34965df64..9c2c47d561 100644 --- a/tmk_core/common/arm_atsam/suspend.c +++ b/tmk_core/common/arm_atsam/suspend.c @@ -35,7 +35,9 @@ void suspend_power_down_kb(void) { */ void suspend_power_down(void) { +#ifdef RGB_MATRIX_ENABLE I2C3733_Control_Set(0); //Disable LED driver +#endif suspend_power_down_kb(); } @@ -75,10 +77,9 @@ void suspend_wakeup_init_kb(void) { * FIXME: needs doc */ void suspend_wakeup_init(void) { - /* If LEDs are set to enabled, enable the hardware */ - if (led_enabled) { - I2C3733_Control_Set(1); - } +#ifdef RGB_MATRIX_ENABLE + I2C3733_Control_Set(1); +#endif suspend_wakeup_init_kb(); } diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index b29447ac4e..2259201b5d 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -11,9 +11,6 @@ #include "led.h" #include "host.h" #include "rgblight_reconfig.h" -#ifdef SPLIT_KEYBOARD - #include "split_flags.h" -#endif #ifdef PROTOCOL_LUFA #include "lufa.h" @@ -135,9 +132,6 @@ static void power_down(uint8_t wdto) { is_suspended = true; rgblight_enabled = rgblight_config.enable; rgblight_disable_noeeprom(); - #ifdef SPLIT_KEYBOARD - RGB_DIRTY = true; - #endif } #endif suspend_power_down_kb(); @@ -216,9 +210,6 @@ void suspend_wakeup_init(void) { wait_ms(10); #endif rgblight_enable_noeeprom(); - #ifdef SPLIT_KEYBOARD - RGB_DIRTY = true; - #endif } #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_enable(); diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c index 581e7b8a07..87239fbb76 100644 --- a/tmk_core/common/mousekey.c +++ b/tmk_core/common/mousekey.c @@ -23,13 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "debug.h" #include "mousekey.h" +inline int8_t times_inv_sqrt2(int8_t x) { + // 181/256 is pretty close to 1/sqrt(2) + // 0.70703125 0.707106781 + // 1 too small for x=99 and x=198 + // This ends up being a mult and discard lower 8 bits + return (x * 181) >> 8; +} - -static report_mouse_t mouse_report = {}; -static uint8_t mousekey_repeat = 0; +static report_mouse_t mouse_report = {0}; +static void mousekey_debug(void); static uint8_t mousekey_accel = 0; +static uint8_t mousekey_repeat = 0; +static uint16_t last_timer = 0; + + + +#ifndef MK_3_SPEED -static void mousekey_debug(void); /* @@ -52,155 +63,256 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX; uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; +static uint8_t move_unit(void) { + uint16_t unit; + if (mousekey_accel & (1<<0)) { + unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/4; + } else if (mousekey_accel & (1<<1)) { + unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/2; + } else if (mousekey_accel & (1<<2)) { + unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed); + } else if (mousekey_repeat == 0) { + unit = MOUSEKEY_MOVE_DELTA; + } else if (mousekey_repeat >= mk_time_to_max) { + unit = MOUSEKEY_MOVE_DELTA * mk_max_speed; + } else { + unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max; + } + return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit)); +} -static uint16_t last_timer = 0; +static uint8_t wheel_unit(void) { + uint16_t unit; + if (mousekey_accel & (1<<0)) { + unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/4; + } else if (mousekey_accel & (1<<1)) { + unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/2; + } else if (mousekey_accel & (1<<2)) { + unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed); + } else if (mousekey_repeat == 0) { + unit = MOUSEKEY_WHEEL_DELTA; + } else if (mousekey_repeat >= mk_wheel_time_to_max) { + unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; + } else { + unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max; + } + return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); +} -inline int8_t times_inv_sqrt2(int8_t x) -{ - // 181/256 is pretty close to 1/sqrt(2) - // 0.70703125 0.707106781 - // 1 too small for x=99 and x=198 - // This ends up being a mult and discard lower 8 bits - return (x * 181) >> 8; +void mousekey_task(void) { + if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10)) { + return; + } + if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) { + return; + } + if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; + if (mouse_report.x > 0) mouse_report.x = move_unit(); + if (mouse_report.x < 0) mouse_report.x = move_unit() * -1; + if (mouse_report.y > 0) mouse_report.y = move_unit(); + if (mouse_report.y < 0) mouse_report.y = move_unit() * -1; + /* diagonal move [1/sqrt(2)] */ + if (mouse_report.x && mouse_report.y) { + mouse_report.x = times_inv_sqrt2(mouse_report.x); + mouse_report.y = times_inv_sqrt2(mouse_report.y); + } + if (mouse_report.v > 0) mouse_report.v = wheel_unit(); + if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1; + if (mouse_report.h > 0) mouse_report.h = wheel_unit(); + if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1; + mousekey_send(); } -static uint8_t move_unit(void) -{ - uint16_t unit; - if (mousekey_accel & (1<<0)) { - unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/4; - } else if (mousekey_accel & (1<<1)) { - unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/2; - } else if (mousekey_accel & (1<<2)) { - unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed); - } else if (mousekey_repeat == 0) { - unit = MOUSEKEY_MOVE_DELTA; - } else if (mousekey_repeat >= mk_time_to_max) { - unit = MOUSEKEY_MOVE_DELTA * mk_max_speed; - } else { - unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max; - } - return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit)); +void mousekey_on(uint8_t code) { + if (code == KC_MS_UP) mouse_report.y = move_unit() * -1; + else if (code == KC_MS_DOWN) mouse_report.y = move_unit(); + else if (code == KC_MS_LEFT) mouse_report.x = move_unit() * -1; + else if (code == KC_MS_RIGHT) mouse_report.x = move_unit(); + else if (code == KC_MS_WH_UP) mouse_report.v = wheel_unit(); + else if (code == KC_MS_WH_DOWN) mouse_report.v = wheel_unit() * -1; + else if (code == KC_MS_WH_LEFT) mouse_report.h = wheel_unit() * -1; + else if (code == KC_MS_WH_RIGHT) mouse_report.h = wheel_unit(); + else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1; + else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2; + else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3; + else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4; + else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5; + else if (code == KC_MS_ACCEL0) mousekey_accel |= (1<<0); + else if (code == KC_MS_ACCEL1) mousekey_accel |= (1<<1); + else if (code == KC_MS_ACCEL2) mousekey_accel |= (1<<2); } -static uint8_t wheel_unit(void) -{ - uint16_t unit; - if (mousekey_accel & (1<<0)) { - unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/4; - } else if (mousekey_accel & (1<<1)) { - unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/2; - } else if (mousekey_accel & (1<<2)) { - unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed); - } else if (mousekey_repeat == 0) { - unit = MOUSEKEY_WHEEL_DELTA; - } else if (mousekey_repeat >= mk_wheel_time_to_max) { - unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; - } else { - unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max; - } - return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); +void mousekey_off(uint8_t code) { + if (code == KC_MS_UP && mouse_report.y < 0) mouse_report.y = 0; + else if (code == KC_MS_DOWN && mouse_report.y > 0) mouse_report.y = 0; + else if (code == KC_MS_LEFT && mouse_report.x < 0) mouse_report.x = 0; + else if (code == KC_MS_RIGHT && mouse_report.x > 0) mouse_report.x = 0; + else if (code == KC_MS_WH_UP && mouse_report.v > 0) mouse_report.v = 0; + else if (code == KC_MS_WH_DOWN && mouse_report.v < 0) mouse_report.v = 0; + else if (code == KC_MS_WH_LEFT && mouse_report.h < 0) mouse_report.h = 0; + else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0; + else if (code == KC_MS_BTN1) mouse_report.buttons &= ~MOUSE_BTN1; + else if (code == KC_MS_BTN2) mouse_report.buttons &= ~MOUSE_BTN2; + else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3; + else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4; + else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5; + else if (code == KC_MS_ACCEL0) mousekey_accel &= ~(1<<0); + else if (code == KC_MS_ACCEL1) mousekey_accel &= ~(1<<1); + else if (code == KC_MS_ACCEL2) mousekey_accel &= ~(1<<2); + if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) + mousekey_repeat = 0; } -void mousekey_task(void) -{ - if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10)) - return; - if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) - return; - if (mousekey_repeat != UINT8_MAX) - mousekey_repeat++; + +#else /* #ifndef MK_3_SPEED */ - if (mouse_report.x > 0) mouse_report.x = move_unit(); - if (mouse_report.x < 0) mouse_report.x = move_unit() * -1; - if (mouse_report.y > 0) mouse_report.y = move_unit(); - if (mouse_report.y < 0) mouse_report.y = move_unit() * -1; - /* diagonal move [1/sqrt(2)] */ - if (mouse_report.x && mouse_report.y) { - mouse_report.x = times_inv_sqrt2(mouse_report.x); - mouse_report.x = mouse_report.x == 0 ? 1 : mouse_report.x; - mouse_report.y = times_inv_sqrt2(mouse_report.y); - mouse_report.y = mouse_report.y == 0 ? 1 : mouse_report.y; - } +enum { + mkspd_slow, + mkspd_med, + mkspd_fast, + mkspd_COUNT +}; +static uint8_t mk_speed = mkspd_med; +#ifdef MK_MOMENTARY_ACCEL +static uint8_t mkspd_DEFAULT = mkspd_med; +#endif +static uint16_t last_timer_c = 0; +static uint16_t last_timer_w = 0; +uint16_t c_offsets[mkspd_COUNT] = { + MK_C_OFFSET_SLOW, MK_C_OFFSET_MED, MK_C_OFFSET_FAST +}; +uint16_t c_intervals[mkspd_COUNT] = { + MK_C_INTERVAL_SLOW, MK_C_INTERVAL_MED, MK_C_INTERVAL_FAST +}; +uint16_t w_offsets[mkspd_COUNT] = { + MK_W_OFFSET_SLOW, MK_W_OFFSET_MED, MK_W_OFFSET_FAST +}; +uint16_t w_intervals[mkspd_COUNT] = { + MK_W_INTERVAL_SLOW, MK_W_INTERVAL_MED, MK_W_INTERVAL_FAST +}; - if (mouse_report.v > 0) mouse_report.v = wheel_unit(); - if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1; - if (mouse_report.h > 0) mouse_report.h = wheel_unit(); - if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1; - mousekey_send(); +void mousekey_task(void) { + // report cursor and scroll movement independently + report_mouse_t const tmpmr = mouse_report; + if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) { + mouse_report.h = 0; + mouse_report.v = 0; + mousekey_send(); + last_timer_c = last_timer; + mouse_report = tmpmr; + } + if ((mouse_report.h || mouse_report.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) { + mouse_report.x = 0; + mouse_report.y = 0; + mousekey_send(); + last_timer_w = last_timer; + mouse_report = tmpmr; + } } -void mousekey_on(uint8_t code) -{ - if (code == KC_MS_UP) mouse_report.y = move_unit() * -1; - else if (code == KC_MS_DOWN) mouse_report.y = move_unit(); - else if (code == KC_MS_LEFT) mouse_report.x = move_unit() * -1; - else if (code == KC_MS_RIGHT) mouse_report.x = move_unit(); - else if (code == KC_MS_WH_UP) mouse_report.v = wheel_unit(); - else if (code == KC_MS_WH_DOWN) mouse_report.v = wheel_unit() * -1; - else if (code == KC_MS_WH_LEFT) mouse_report.h = wheel_unit() * -1; - else if (code == KC_MS_WH_RIGHT) mouse_report.h = wheel_unit(); - else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1; - else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2; - else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3; - else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4; - else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5; - else if (code == KC_MS_ACCEL0) mousekey_accel |= (1<<0); - else if (code == KC_MS_ACCEL1) mousekey_accel |= (1<<1); - else if (code == KC_MS_ACCEL2) mousekey_accel |= (1<<2); +void adjust_speed(void) { + uint16_t const c_offset = c_offsets[mk_speed]; + uint16_t const w_offset = w_offsets[mk_speed]; + if (mouse_report.x > 0) mouse_report.x = c_offset; + if (mouse_report.x < 0) mouse_report.x = c_offset * -1; + if (mouse_report.y > 0) mouse_report.y = c_offset; + if (mouse_report.y < 0) mouse_report.y = c_offset * -1; + if (mouse_report.h > 0) mouse_report.h = w_offset; + if (mouse_report.h < 0) mouse_report.h = w_offset * -1; + if (mouse_report.v > 0) mouse_report.v = w_offset; + if (mouse_report.v < 0) mouse_report.v = w_offset * -1; + // adjust for diagonals + if (mouse_report.x && mouse_report.y) { + mouse_report.x = times_inv_sqrt2(mouse_report.x); + mouse_report.y = times_inv_sqrt2(mouse_report.y); + } + if (mouse_report.h && mouse_report.v) { + mouse_report.h = times_inv_sqrt2(mouse_report.h); + mouse_report.v = times_inv_sqrt2(mouse_report.v); + } } -void mousekey_off(uint8_t code) -{ - if (code == KC_MS_UP && mouse_report.y < 0) mouse_report.y = 0; - else if (code == KC_MS_DOWN && mouse_report.y > 0) mouse_report.y = 0; - else if (code == KC_MS_LEFT && mouse_report.x < 0) mouse_report.x = 0; - else if (code == KC_MS_RIGHT && mouse_report.x > 0) mouse_report.x = 0; - else if (code == KC_MS_WH_UP && mouse_report.v > 0) mouse_report.v = 0; - else if (code == KC_MS_WH_DOWN && mouse_report.v < 0) mouse_report.v = 0; - else if (code == KC_MS_WH_LEFT && mouse_report.h < 0) mouse_report.h = 0; - else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0; - else if (code == KC_MS_BTN1) mouse_report.buttons &= ~MOUSE_BTN1; - else if (code == KC_MS_BTN2) mouse_report.buttons &= ~MOUSE_BTN2; - else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3; - else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4; - else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5; - else if (code == KC_MS_ACCEL0) mousekey_accel &= ~(1<<0); - else if (code == KC_MS_ACCEL1) mousekey_accel &= ~(1<<1); - else if (code == KC_MS_ACCEL2) mousekey_accel &= ~(1<<2); - - if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) - mousekey_repeat = 0; +void mousekey_on(uint8_t code) { + uint16_t const c_offset = c_offsets[mk_speed]; + uint16_t const w_offset = w_offsets[mk_speed]; + uint8_t const old_speed = mk_speed; + if (code == KC_MS_UP) mouse_report.y = c_offset * -1; + else if (code == KC_MS_DOWN) mouse_report.y = c_offset; + else if (code == KC_MS_LEFT) mouse_report.x = c_offset * -1; + else if (code == KC_MS_RIGHT) mouse_report.x = c_offset; + else if (code == KC_MS_WH_UP) mouse_report.v = w_offset; + else if (code == KC_MS_WH_DOWN) mouse_report.v = w_offset * -1; + else if (code == KC_MS_WH_LEFT) mouse_report.h = w_offset * -1; + else if (code == KC_MS_WH_RIGHT) mouse_report.h = w_offset; + else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1; + else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2; + else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3; + else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4; + else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5; + else if (code == KC_MS_ACCEL0) mk_speed = mkspd_slow; + else if (code == KC_MS_ACCEL1) mk_speed = mkspd_med; + else if (code == KC_MS_ACCEL2) mk_speed = mkspd_fast; + if (mk_speed != old_speed) adjust_speed(); } -void mousekey_send(void) -{ - mousekey_debug(); - host_mouse_send(&mouse_report); - last_timer = timer_read(); +void mousekey_off(uint8_t code) { +#ifdef MK_MOMENTARY_ACCEL + uint8_t const old_speed = mk_speed; +#endif + if (code == KC_MS_UP && mouse_report.y < 0) mouse_report.y = 0; + else if (code == KC_MS_DOWN && mouse_report.y > 0) mouse_report.y = 0; + else if (code == KC_MS_LEFT && mouse_report.x < 0) mouse_report.x = 0; + else if (code == KC_MS_RIGHT && mouse_report.x > 0) mouse_report.x = 0; + else if (code == KC_MS_WH_UP && mouse_report.v > 0) mouse_report.v = 0; + else if (code == KC_MS_WH_DOWN && mouse_report.v < 0) mouse_report.v = 0; + else if (code == KC_MS_WH_LEFT && mouse_report.h < 0) mouse_report.h = 0; + else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0; + else if (code == KC_MS_BTN1) mouse_report.buttons &= ~MOUSE_BTN1; + else if (code == KC_MS_BTN2) mouse_report.buttons &= ~MOUSE_BTN2; + else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3; + else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4; + else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5; +#ifdef MK_MOMENTARY_ACCEL + else if (code == KC_MS_ACCEL0) mk_speed = mkspd_DEFAULT; + else if (code == KC_MS_ACCEL1) mk_speed = mkspd_DEFAULT; + else if (code == KC_MS_ACCEL2) mk_speed = mkspd_DEFAULT; + if (mk_speed != old_speed) adjust_speed(); +#endif } -void mousekey_clear(void) -{ - mouse_report = (report_mouse_t){}; - mousekey_repeat = 0; - mousekey_accel = 0; + + + +#endif /* #ifndef MK_3_SPEED */ + + + + +void mousekey_send(void) { + mousekey_debug(); + host_mouse_send(&mouse_report); + last_timer = timer_read(); +} + +void mousekey_clear(void) { + mouse_report = (report_mouse_t){}; + mousekey_repeat = 0; + mousekey_accel = 0; } -static void mousekey_debug(void) -{ - if (!debug_mouse) return; - print("mousekey [btn|x y v h](rep/acl): ["); - phex(mouse_report.buttons); print("|"); - print_decs(mouse_report.x); print(" "); - print_decs(mouse_report.y); print(" "); - print_decs(mouse_report.v); print(" "); - print_decs(mouse_report.h); print("]("); - print_dec(mousekey_repeat); print("/"); - print_dec(mousekey_accel); print(")\n"); +static void mousekey_debug(void) { + if (!debug_mouse) return; + print("mousekey [btn|x y v h](rep/acl): ["); + phex(mouse_report.buttons); print("|"); + print_decs(mouse_report.x); print(" "); + print_decs(mouse_report.y); print(" "); + print_decs(mouse_report.v); print(" "); + print_decs(mouse_report.h); print("]("); + print_dec(mousekey_repeat); print("/"); + print_dec(mousekey_accel); print(")\n"); } diff --git a/tmk_core/common/mousekey.h b/tmk_core/common/mousekey.h index 9338d0af77..ce3501b232 100644 --- a/tmk_core/common/mousekey.h +++ b/tmk_core/common/mousekey.h @@ -16,23 +16,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef MOUSEKEY_H -#define MOUSEKEY_H +#define MOUSEKEY_H +#endif #include <stdbool.h> #include "host.h" +#ifndef MK_3_SPEED /* max value on report descriptor */ #ifndef MOUSEKEY_MOVE_MAX - #define MOUSEKEY_MOVE_MAX 127 + #define MOUSEKEY_MOVE_MAX 127 #elif MOUSEKEY_MOVE_MAX > 127 - #error MOUSEKEY_MOVE_MAX needs to be smaller than 127 + #error MOUSEKEY_MOVE_MAX needs to be smaller than 127 #endif #ifndef MOUSEKEY_WHEEL_MAX - #define MOUSEKEY_WHEEL_MAX 127 + #define MOUSEKEY_WHEEL_MAX 127 #elif MOUSEKEY_WHEEL_MAX > 127 - #error MOUSEKEY_WHEEL_MAX needs to be smaller than 127 + #error MOUSEKEY_WHEEL_MAX needs to be smaller than 127 #endif #ifndef MOUSEKEY_MOVE_DELTA @@ -60,6 +62,47 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MOUSEKEY_WHEEL_TIME_TO_MAX 40 #endif +#else /* #ifndef MK_3_SPEED */ + +#ifndef MK_C_OFFSET_SLOW +#define MK_C_OFFSET_SLOW 1 +#endif +#ifndef MK_C_INTERVAL_SLOW +#define MK_C_INTERVAL_SLOW 100 +#endif +#ifndef MK_C_OFFSET_MED +#define MK_C_OFFSET_MED 4 +#endif +#ifndef MK_C_INTERVAL_MED +#define MK_C_INTERVAL_MED 16 +#endif +#ifndef MK_C_OFFSET_FAST +#define MK_C_OFFSET_FAST 12 +#endif +#ifndef MK_C_INTERVAL_FAST +#define MK_C_INTERVAL_FAST 16 +#endif + +#ifndef MK_W_OFFSET_SLOW +#define MK_W_OFFSET_SLOW 1 +#endif +#ifndef MK_W_INTERVAL_SLOW +#define MK_W_INTERVAL_SLOW 400 +#endif +#ifndef MK_W_OFFSET_MED +#define MK_W_OFFSET_MED 1 +#endif +#ifndef MK_W_INTERVAL_MED +#define MK_W_INTERVAL_MED 200 +#endif +#ifndef MK_W_OFFSET_FAST +#define MK_W_OFFSET_FAST 1 +#endif +#ifndef MK_W_INTERVAL_FAST +#define MK_W_INTERVAL_FAST 100 +#endif + +#endif /* #ifndef MK_3_SPEED */ #ifdef __cplusplus extern "C" { @@ -72,7 +115,6 @@ extern uint8_t mk_time_to_max; extern uint8_t mk_wheel_max_speed; extern uint8_t mk_wheel_time_to_max; - void mousekey_task(void); void mousekey_on(uint8_t code); void mousekey_off(uint8_t code); @@ -82,5 +124,3 @@ void mousekey_send(void); #ifdef __cplusplus } #endif - -#endif diff --git a/tmk_core/protocol/arm_atsam.mk b/tmk_core/protocol/arm_atsam.mk index 04e02790a0..8d6f724f09 100644 --- a/tmk_core/protocol/arm_atsam.mk +++ b/tmk_core/protocol/arm_atsam.mk @@ -4,7 +4,10 @@ SRC += $(ARM_ATSAM_DIR)/adc.c SRC += $(ARM_ATSAM_DIR)/clks.c SRC += $(ARM_ATSAM_DIR)/d51_util.c SRC += $(ARM_ATSAM_DIR)/i2c_master.c -SRC += $(ARM_ATSAM_DIR)/led_matrix.c +ifeq ($(RGB_MATRIX_ENABLE),custom) + SRC += $(ARM_ATSAM_DIR)/led_matrix_programs.c + SRC += $(ARM_ATSAM_DIR)/led_matrix.c +endif SRC += $(ARM_ATSAM_DIR)/main_arm_atsam.c SRC += $(ARM_ATSAM_DIR)/spi.c SRC += $(ARM_ATSAM_DIR)/startup.c diff --git a/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h b/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h index 928af8c7e1..88109186aa 100644 --- a/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h +++ b/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h @@ -34,7 +34,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef MD_BOOTLOADER #include "main_arm_atsam.h" +#ifdef RGB_MATRIX_ENABLE #include "led_matrix.h" +#include "rgb_matrix.h" +#endif #include "issi3733_driver.h" #include "./usb/compiler.h" #include "./usb/udc.h" diff --git a/tmk_core/protocol/arm_atsam/i2c_master.c b/tmk_core/protocol/arm_atsam/i2c_master.c index d91a851f37..1741d9ac5b 100644 --- a/tmk_core/protocol/arm_atsam/i2c_master.c +++ b/tmk_core/protocol/arm_atsam/i2c_master.c @@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "arm_atsam_protocol.h" -#ifndef MD_BOOTLOADER +#if !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE) #include <string.h> @@ -37,7 +37,7 @@ static uint8_t dma_sendbuf[I2C_DMA_MAX_SEND]; //Data being written to I2C volatile uint8_t i2c_led_q_running; -#endif //MD_BOOTLOADER +#endif // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE) void i2c0_init(void) { @@ -112,7 +112,7 @@ void i2c0_stop(void) } } -#ifndef MD_BOOTLOADER +#if !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE) void i2c1_init(void) { DBGC(DC_I2C1_INIT_BEGIN); @@ -583,4 +583,4 @@ uint8_t i2c_led_q_run(void) return 1; } -#endif //MD_BOOTLOADER +#endif // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE) diff --git a/tmk_core/protocol/arm_atsam/led_matrix.c b/tmk_core/protocol/arm_atsam/led_matrix.c index 04d05af6db..e29fb6587c 100644 --- a/tmk_core/protocol/arm_atsam/led_matrix.c +++ b/tmk_core/protocol/arm_atsam/led_matrix.c @@ -17,9 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "arm_atsam_protocol.h" #include "tmk_core/common/led.h" +#include "rgb_matrix.h" #include <string.h> #include <math.h> +#ifdef USE_MASSDROP_CONFIGURATOR +__attribute__((weak)) +led_instruction_t led_instructions[] = { { .end = 1 } }; +static void led_matrix_massdrop_config_override(int i); +#endif // USE_MASSDROP_CONFIGURATOR + +extern rgb_config_t rgb_matrix_config; +extern rgb_counters_t g_rgb_counters; + void SERCOM1_0_Handler( void ) { if (SERCOM1->I2CM.INTFLAG.bit.ERROR) @@ -51,14 +61,17 @@ void DMAC_0_Handler( void ) issi3733_driver_t issidrv[ISSI3733_DRIVER_COUNT]; -issi3733_led_t led_map[ISSI3733_LED_COUNT+1] = ISSI3733_LED_MAP; -issi3733_led_t *lede = led_map + ISSI3733_LED_COUNT; //End pointer of mapping +issi3733_led_t led_map[ISSI3733_LED_COUNT] = ISSI3733_LED_MAP; +RGB led_buffer[ISSI3733_LED_COUNT]; uint8_t gcr_desired; -uint8_t gcr_breathe; -uint8_t gcr_use; uint8_t gcr_actual; uint8_t gcr_actual_last; +#ifdef USE_MASSDROP_CONFIGURATOR +uint8_t gcr_breathe; +float breathe_mult; +float pomod; +#endif #define ACT_GCR_NONE 0 #define ACT_GCR_INC 1 @@ -73,11 +86,14 @@ static uint8_t v_5v_cat_hit; void gcr_compute(void) { uint8_t action = ACT_GCR_NONE; + uint8_t gcr_use = gcr_desired; +#ifdef USE_MASSDROP_CONFIGURATOR if (led_animation_breathing) + { gcr_use = gcr_breathe; - else - gcr_use = gcr_desired; + } +#endif //If the 5v takes a catastrophic hit, disable the LED drivers briefly, assert auto gcr mode, min gcr and let the auto take over if (v_5v < V5_CAT) @@ -151,6 +167,7 @@ void gcr_compute(void) gcr_actual -= LED_GCR_STEP_AUTO; |