Add mechanical locking switch support for NumLock and ScrollLock
parent
5b425731c5
commit
2721022078
10
README.md
10
README.md
|
@ -164,12 +164,12 @@ TODO: Magic key combination to avoid unintentional press during plug in
|
||||||
**TBD**
|
**TBD**
|
||||||
|
|
||||||
|
|
||||||
Mechanical Locking support for CapsLock
|
Mechanical Locking support
|
||||||
---------------------------------------
|
--------------------------
|
||||||
To enable this feature define these two macros in `config.h` and use `KC_LCAP` for locking CapsLock in keymap instead of normal `KC_CAPS`. Resync option tries to keep lock switch state consistent with keyboard LED state.
|
This feature makes it possible for you to use mechanical switch for `CapsLock`, `NumLock` or `ScrollLock`. To enable this feature define these macros in `config.h` and use `KC_LCAP`, `KC_LNUM` or `KC_LSCR` in keymap for locking key instead of normal `KC_CAPS`, `KC_NLCK` or `KC_SLCK`. Resync option tries to keep lock switch state consistent with keyboard LED state.
|
||||||
|
|
||||||
#define CAPSLOCK_LOCKING_ENABLE
|
#define LOCKING_SUPPORT_ENABLE
|
||||||
#define CAPSLOCK_LOCKING_RESYNC_ENABLE
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
|
|
||||||
Start Your Own Project
|
Start Your Own Project
|
||||||
|
|
|
@ -336,9 +336,10 @@ void register_code(uint8_t code)
|
||||||
if (code == KC_NO) {
|
if (code == KC_NO) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef CAPSLOCK_LOCKING_ENABLE
|
|
||||||
|
#ifdef LOCKING_SUPPORT_ENABLE
|
||||||
else if (KC_LOCKING_CAPS == code) {
|
else if (KC_LOCKING_CAPS == code) {
|
||||||
#ifdef CAPSLOCK_LOCKING_RESYNC_ENABLE
|
#ifdef LOCKING_RESYNC_ENABLE
|
||||||
// Resync: ignore if caps lock already is on
|
// Resync: ignore if caps lock already is on
|
||||||
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return;
|
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return;
|
||||||
#endif
|
#endif
|
||||||
|
@ -347,7 +348,28 @@ void register_code(uint8_t code)
|
||||||
host_del_key(KC_CAPSLOCK);
|
host_del_key(KC_CAPSLOCK);
|
||||||
host_send_keyboard_report();
|
host_send_keyboard_report();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (KC_LOCKING_NUM == code) {
|
||||||
|
#ifdef LOCKING_RESYNC_ENABLE
|
||||||
|
if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return;
|
||||||
#endif
|
#endif
|
||||||
|
host_add_key(KC_NUMLOCK);
|
||||||
|
host_send_keyboard_report();
|
||||||
|
host_del_key(KC_NUMLOCK);
|
||||||
|
host_send_keyboard_report();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (KC_LOCKING_SCROLL == code) {
|
||||||
|
#ifdef LOCKING_RESYNC_ENABLE
|
||||||
|
if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return;
|
||||||
|
#endif
|
||||||
|
host_add_key(KC_SCROLLLOCK);
|
||||||
|
host_send_keyboard_report();
|
||||||
|
host_del_key(KC_SCROLLLOCK);
|
||||||
|
host_send_keyboard_report();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
else if IS_KEY(code) {
|
else if IS_KEY(code) {
|
||||||
// TODO: should push command_proc out of this block?
|
// TODO: should push command_proc out of this block?
|
||||||
if (command_proc(code)) return;
|
if (command_proc(code)) return;
|
||||||
|
@ -386,9 +408,10 @@ void unregister_code(uint8_t code)
|
||||||
if (code == KC_NO) {
|
if (code == KC_NO) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef CAPSLOCK_LOCKING_ENABLE
|
|
||||||
|
#ifdef LOCKING_SUPPORT_ENABLE
|
||||||
else if (KC_LOCKING_CAPS == code) {
|
else if (KC_LOCKING_CAPS == code) {
|
||||||
#ifdef CAPSLOCK_LOCKING_RESYNC_ENABLE
|
#ifdef LOCKING_RESYNC_ENABLE
|
||||||
// Resync: ignore if caps lock already is off
|
// Resync: ignore if caps lock already is off
|
||||||
if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return;
|
if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return;
|
||||||
#endif
|
#endif
|
||||||
|
@ -397,7 +420,28 @@ void unregister_code(uint8_t code)
|
||||||
host_del_key(KC_CAPSLOCK);
|
host_del_key(KC_CAPSLOCK);
|
||||||
host_send_keyboard_report();
|
host_send_keyboard_report();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (KC_LOCKING_NUM == code) {
|
||||||
|
#ifdef LOCKING_RESYNC_ENABLE
|
||||||
|
if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return;
|
||||||
#endif
|
#endif
|
||||||
|
host_add_key(KC_NUMLOCK);
|
||||||
|
host_send_keyboard_report();
|
||||||
|
host_del_key(KC_NUMLOCK);
|
||||||
|
host_send_keyboard_report();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (KC_LOCKING_SCROLL == code) {
|
||||||
|
#ifdef LOCKING_RESYNC_ENABLE
|
||||||
|
if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return;
|
||||||
|
#endif
|
||||||
|
host_add_key(KC_SCROLLLOCK);
|
||||||
|
host_send_keyboard_report();
|
||||||
|
host_del_key(KC_SCROLLLOCK);
|
||||||
|
host_send_keyboard_report();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
else if IS_KEY(code) {
|
else if IS_KEY(code) {
|
||||||
host_del_key(code);
|
host_del_key(code);
|
||||||
host_send_keyboard_report();
|
host_send_keyboard_report();
|
||||||
|
|
|
@ -60,10 +60,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define KC_DEL KC_DELETE
|
#define KC_DEL KC_DELETE
|
||||||
#define KC_INS KC_INSERT
|
#define KC_INS KC_INSERT
|
||||||
#define KC_CAPS KC_CAPSLOCK
|
#define KC_CAPS KC_CAPSLOCK
|
||||||
|
#define KC_CLCK KC_CAPSLOCK
|
||||||
#define KC_RGHT KC_RIGHT
|
#define KC_RGHT KC_RIGHT
|
||||||
#define KC_PGDN KC_PGDOWN
|
#define KC_PGDN KC_PGDOWN
|
||||||
#define KC_PSCR KC_PSCREEN
|
#define KC_PSCR KC_PSCREEN
|
||||||
#define KC_SLCK KC_SCKLOCK
|
#define KC_SLCK KC_SCROLLLOCK
|
||||||
#define KC_PAUS KC_PAUSE
|
#define KC_PAUS KC_PAUSE
|
||||||
#define KC_BRK KC_PAUSE
|
#define KC_BRK KC_PAUSE
|
||||||
#define KC_NLCK KC_NUMLOCK
|
#define KC_NLCK KC_NUMLOCK
|
||||||
|
@ -82,6 +83,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define KC_NUHS KC_NONUS_HASH
|
#define KC_NUHS KC_NONUS_HASH
|
||||||
#define KC_NUBS KC_NONUS_BSLASH
|
#define KC_NUBS KC_NONUS_BSLASH
|
||||||
#define KC_LCAP KC_LOCKING_CAPS
|
#define KC_LCAP KC_LOCKING_CAPS
|
||||||
|
#define KC_LNUM KC_LOCKING_NUM
|
||||||
|
#define KC_LSCR KC_LOCKING_SCROLL
|
||||||
#define KC_ERAS KC_ALT_ERASE,
|
#define KC_ERAS KC_ALT_ERASE,
|
||||||
#define KC_CLR KC_CLEAR
|
#define KC_CLR KC_CLEAR
|
||||||
/* Japanese specific */
|
/* Japanese specific */
|
||||||
|
@ -230,7 +233,7 @@ enum hid_keyboard_keypad_usage {
|
||||||
KC_F11,
|
KC_F11,
|
||||||
KC_F12,
|
KC_F12,
|
||||||
KC_PSCREEN,
|
KC_PSCREEN,
|
||||||
KC_SCKLOCK,
|
KC_SCROLLLOCK,
|
||||||
KC_PAUSE,
|
KC_PAUSE,
|
||||||
KC_INSERT,
|
KC_INSERT,
|
||||||
KC_HOME,
|
KC_HOME,
|
||||||
|
|
|
@ -9,10 +9,10 @@ Discuss: http://geekhack.org/showwiki.php?title=Island:14290
|
||||||
|
|
||||||
Build
|
Build
|
||||||
-----
|
-----
|
||||||
0. Connect ADB keyboard to Teensy by 3 lines(Vcc, GND, Data). By default Data line uses port F0.
|
0. Connect ADB keyboard to Teensy by 3 lines(Vcc, GND, Data). By default Data line uses port D0.
|
||||||
This converter uses AVR's internal pull-up, but it seems to be too weak, in particular when you want to use a long or coiled cable.
|
This converter uses AVR's internal pull-up, but it seems to be too weak, in particular when you want to use a long or coiled cable.
|
||||||
The external pull-up resistor(1K-10K Ohm) on Data is strongly recommended.
|
The external pull-up resistor(1K-10K Ohm) on Data is strongly recommended.
|
||||||
1. Define following macros for ADB connection in config.h if you use other than port F0.
|
1. Define following macros for ADB connection in config.h if you use other than port D0.
|
||||||
ADB_PORT, ADB_PIN, ADB_DDR, ADB_DATA_BIT
|
ADB_PORT, ADB_PIN, ADB_DDR, ADB_DATA_BIT
|
||||||
2. make
|
2. make
|
||||||
3. program Teensy
|
3. program Teensy
|
||||||
|
|
|
@ -34,10 +34,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define MATRIX_COL(code) ((code)&0x07)
|
#define MATRIX_COL(code) ((code)&0x07)
|
||||||
|
|
||||||
|
|
||||||
/* Mechanical locking CapsLock support. Use KC_LCAP instead of KC_CAPS in keymap */
|
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||||
#define CAPSLOCK_LOCKING_ENABLE
|
#define LOCKING_SUPPORT_ENABLE
|
||||||
/* Locking CapsLock resynchronize hack */
|
/* Locking resynchronize hack */
|
||||||
#define CAPSLOCK_LOCKING_RESYNC_ENABLE
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
|
|
||||||
/* legacy keymap support */
|
/* legacy keymap support */
|
||||||
|
@ -51,9 +51,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
/* ADB port setting */
|
/* ADB port setting */
|
||||||
#define ADB_PORT PORTF
|
#define ADB_PORT PORTD
|
||||||
#define ADB_PIN PINF
|
#define ADB_PIN PIND
|
||||||
#define ADB_DDR DDRF
|
#define ADB_DDR DDRD
|
||||||
#define ADB_DATA_BIT 0
|
#define ADB_DATA_BIT 0
|
||||||
//#define ADB_PSW_BIT 1 // optional
|
//#define ADB_PSW_BIT 1 // optional
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define USE_LEGACY_KEYMAP
|
#define USE_LEGACY_KEYMAP
|
||||||
|
|
||||||
|
|
||||||
/* Mechanical locking CapsLock support. Use KC_LCAP instead of KC_CAPS in keymap */
|
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||||
#define CAPSLOCK_LOCKING_ENABLE
|
#define LOCKING_SUPPORT_ENABLE
|
||||||
/* Locking CapsLock resynchronize hack */
|
/* Locking resynchronize hack */
|
||||||
#define CAPSLOCK_LOCKING_RESYNC_ENABLE
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
|
|
||||||
/* magic key */
|
/* magic key */
|
||||||
|
|
|
@ -37,10 +37,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
/* Set 0 if debouncing isn't needed */
|
/* Set 0 if debouncing isn't needed */
|
||||||
#define DEBOUNCE 5
|
#define DEBOUNCE 5
|
||||||
|
|
||||||
/* Mechanical locking CapsLock support. Use KC_LCAP instead of KC_CAPS in keymap */
|
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||||
#define CAPSLOCK_LOCKING_ENABLE
|
#define LOCKING_SUPPORT_ENABLE
|
||||||
/* Locking CapsLock resynchronize hack */
|
/* Locking resynchronize hack */
|
||||||
#define CAPSLOCK_LOCKING_RESYNC_ENABLE
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
/* key combination for command */
|
/* key combination for command */
|
||||||
#define IS_COMMAND() ( \
|
#define IS_COMMAND() ( \
|
||||||
|
|
Loading…
Reference in New Issue