2021-12-30 04:17:34 +00:00
|
|
|
// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-11-17 19:59:54 +00:00
|
|
|
|
2017-11-07 05:11:08 +00:00
|
|
|
#include "drashna.h"
|
|
|
|
|
2018-05-02 15:39:46 +00:00
|
|
|
userspace_config_t userspace_config;
|
|
|
|
|
2022-01-22 03:36:52 +00:00
|
|
|
/**
|
|
|
|
* @brief Handle registering a keycode, with optional modifer based on timed event
|
|
|
|
*
|
|
|
|
* @param code keycode to send to host
|
|
|
|
* @param mod_code modifier to send with code, if held for tapping term or longer
|
|
|
|
* @param pressed the press/release event (can use "record->event.pressed" for this)
|
|
|
|
* @return true exits function
|
|
|
|
* @return false exits function
|
|
|
|
*/
|
2019-07-23 03:22:33 +00:00
|
|
|
bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
|
2019-05-07 05:34:09 +00:00
|
|
|
static uint16_t this_timer;
|
2022-01-22 03:36:52 +00:00
|
|
|
mod_key_press(code, mod_code, pressed, this_timer);
|
2019-05-07 05:34:09 +00:00
|
|
|
return false;
|
2018-07-17 01:04:32 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 03:36:52 +00:00
|
|
|
/**
|
|
|
|
* @brief Handle registation of keycode, with optional modifier based on custom timer
|
|
|
|
*
|
|
|
|
* @param code keycode to send to host
|
|
|
|
* @param mod_code modifier keycode to send with code, if held for tapping term or longer
|
|
|
|
* @param pressed the press/release event
|
|
|
|
* @param this_timer custom timer to use
|
|
|
|
* @return true
|
|
|
|
* @return false
|
|
|
|
*/
|
2019-07-23 03:22:33 +00:00
|
|
|
bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
|
|
|
|
if (pressed) {
|
|
|
|
this_timer = timer_read();
|
2019-05-07 05:34:09 +00:00
|
|
|
} else {
|
2019-07-23 03:22:33 +00:00
|
|
|
if (timer_elapsed(this_timer) < TAPPING_TERM) {
|
2019-05-07 05:34:09 +00:00
|
|
|
tap_code(code);
|
|
|
|
} else {
|
|
|
|
register_code(mod_code);
|
|
|
|
tap_code(code);
|
|
|
|
unregister_code(mod_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-07-17 01:04:32 +00:00
|
|
|
}
|
2017-11-17 19:59:54 +00:00
|
|
|
|
2022-01-22 03:36:52 +00:00
|
|
|
/**
|
|
|
|
* @brief Performs exact match for modifier values
|
|
|
|
*
|
|
|
|
* @param value the modifer varible (get_mods/get_oneshot_mods/get_weak_mods)
|
|
|
|
* @param mask the modifier mask to check for
|
|
|
|
* @return true Has the exact modifiers specifed
|
|
|
|
* @return false Does not have the exact modifiers specified
|
|
|
|
*/
|
2019-10-16 20:11:22 +00:00
|
|
|
bool hasAllBitsInMask(uint8_t value, uint8_t mask) {
|
|
|
|
value &= 0xF;
|
|
|
|
mask &= 0xF;
|
|
|
|
|
|
|
|
return (value & mask) == mask;
|
|
|
|
}
|
2021-08-21 20:34:44 +00:00
|
|
|
|
2022-01-22 03:36:52 +00:00
|
|
|
/**
|
|
|
|
* @brief Tap keycode, with no mods
|
|
|
|
*
|
|
|
|
* @param kc keycode to use
|
|
|
|
*/
|
|
|
|
void tap_code16_nomods(uint16_t kc) {
|
2021-12-30 04:17:34 +00:00
|
|
|
uint8_t temp_mod = get_mods();
|
|
|
|
clear_mods();
|
|
|
|
clear_oneshot_mods();
|
|
|
|
tap_code16(kc);
|
|
|
|
set_mods(temp_mod);
|
2021-11-10 14:10:00 +00:00
|
|
|
}
|
2022-01-22 03:36:52 +00:00
|
|
|
|
2022-08-28 19:55:19 +00:00
|
|
|
#ifdef I2C_SCANNER_ENABLE
|
|
|
|
# include "i2c_master.h"
|
|
|
|
# include "debug.h"
|
2022-01-22 03:36:52 +00:00
|
|
|
|
2022-08-28 19:55:19 +00:00
|
|
|
# ifndef I2C_SCANNER_TIMEOUT
|
|
|
|
# define I2C_SCANNER_TIMEOUT 50
|
2022-01-22 03:36:52 +00:00
|
|
|
# endif
|
|
|
|
|
2022-08-28 19:55:19 +00:00
|
|
|
i2c_status_t i2c_start_bodge(uint8_t address, uint16_t timeout) {
|
|
|
|
i2c_start(address);
|
|
|
|
|
|
|
|
// except on ChibiOS where the only way is do do "something"
|
|
|
|
uint8_t data = 0;
|
|
|
|
return i2c_readReg(address, 0, &data, sizeof(data), I2C_SCANNER_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
# define i2c_start i2c_start_bodge
|
|
|
|
|
|
|
|
void do_scan(void) {
|
|
|
|
uint8_t nDevices = 0;
|
|
|
|
|
|
|
|
dprintf("Scanning...\n");
|
|
|
|
|
|
|
|
for (uint8_t address = 1; address < 127; address++) {
|
|
|
|
// The i2c_scanner uses the return value of
|
|
|
|
// i2c_start to see if a device did acknowledge to the address.
|
|
|
|
i2c_status_t error = i2c_start(address << 1, I2C_SCANNER_TIMEOUT);
|
|
|
|
if (error == I2C_STATUS_SUCCESS) {
|
|
|
|
i2c_stop();
|
|
|
|
xprintf(" I2C device found at address 0x%02X\n", I2C_SCANNER_TIMEOUT);
|
|
|
|
nDevices++;
|
|
|
|
} else {
|
|
|
|
// dprintf(" Unknown error (%u) at address 0x%02X\n", error, address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nDevices == 0)
|
|
|
|
xprintf("No I2C devices found\n");
|
|
|
|
else
|
|
|
|
xprintf("done\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t scan_timer = 0;
|
|
|
|
|
|
|
|
void matrix_scan_i2c(void) {
|
|
|
|
if (timer_elapsed(scan_timer) > 5000) {
|
|
|
|
do_scan();
|
|
|
|
scan_timer = timer_read();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void keyboard_post_init_i2c(void) {
|
|
|
|
i2c_init();
|
|
|
|
scan_timer = timer_read();
|
|
|
|
}
|
2022-01-22 03:36:52 +00:00
|
|
|
#endif
|
2022-09-25 20:04:00 +00:00
|
|
|
|
2022-11-29 19:43:42 +00:00
|
|
|
#if defined(AUTOCORRECT_ENABLE)
|
|
|
|
# if defined(AUDIO_ENABLE)
|
|
|
|
# ifdef USER_SONG_LIST
|
2022-09-25 20:04:00 +00:00
|
|
|
float autocorrect_song[][2] = SONG(MARIO_GAMEOVER);
|
2022-11-29 19:43:42 +00:00
|
|
|
# else
|
2022-09-25 20:04:00 +00:00
|
|
|
float autocorrect_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
|
2022-11-29 19:43:42 +00:00
|
|
|
# endif
|
2022-09-25 20:04:00 +00:00
|
|
|
# endif
|
2022-11-29 19:43:42 +00:00
|
|
|
|
2022-09-25 20:04:00 +00:00
|
|
|
bool apply_autocorrect(uint8_t backspaces, const char *str) {
|
2022-11-29 19:43:42 +00:00
|
|
|
if (layer_state_is(_GAMEPAD)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// TO-DO use unicode stuff for this. Will probably have to reverse engineer
|
|
|
|
// send string to get working properly, to send char string.
|
|
|
|
|
|
|
|
# if defined(AUDIO_ENABLE)
|
2022-09-25 20:04:00 +00:00
|
|
|
PLAY_SONG(autocorrect_song);
|
2022-11-29 19:43:42 +00:00
|
|
|
# endif
|
2022-09-25 20:04:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2022-11-29 19:43:42 +00:00
|
|
|
|
|
|
|
#if defined(CAPS_WORD_ENABLE) && !defined(NO_ACTION_ONESHOT)
|
|
|
|
void oneshot_locked_mods_changed_user(uint8_t mods) {
|
|
|
|
if (mods & MOD_MASK_SHIFT) {
|
|
|
|
del_mods(MOD_MASK_SHIFT);
|
|
|
|
set_oneshot_locked_mods(~MOD_MASK_SHIFT & get_oneshot_locked_mods());
|
|
|
|
caps_word_on();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|