First commit. Added dvorak-qwerty switching with scroll lock led indicator, and ctrl button switches back to qwerty for shortcuts. Also added dvorak layout with layer switching.

This commit is contained in:
Travis Burtrum 2011-05-25 11:49:22 -04:00
parent af85b6bba6
commit 98edc2fcbc
8 changed files with 91 additions and 64 deletions

View File

@ -21,11 +21,16 @@
static void help(void);
static void switch_layer(uint8_t layer);
static uint8_t switch_layer(uint8_t layer);
uint8_t command_proc(void)
{
// check if we just want to swap from qwerty->dvorak and back
if(IS_SWAP()){
return switch_layer(current_layer > 0 ? 0 : 1);
}
if (!IS_COMMAND())
return 0;
@ -138,25 +143,24 @@ uint8_t command_proc(void)
print("clear matrix\n");
break;
case KB_0:
switch_layer(0);
break;
return switch_layer(0);
case KB_1:
switch_layer(1);
break;
return switch_layer(1);
case KB_2:
switch_layer(2);
break;
return switch_layer(2);
case KB_3:
switch_layer(3);
break;
return switch_layer(3);
case KB_4:
switch_layer(4);
break;
return switch_layer(4);
case KB_5:
return switch_layer(5);
case KB_6:
return switch_layer(2);
default:
processed = 0;
}
if (processed)
_delay_ms(500);
//if (processed)
// _delay_ms(500);
print_enable = last_print_enable;
return processed;
}
@ -184,11 +188,24 @@ static void help(void)
print("4: switch to Layer4 \n");
}
static void switch_layer(uint8_t layer)
static uint8_t switch_layer(uint8_t layer)
{
print("current_layer: "); phex(current_layer); print("\n");
print("default_layer: "); phex(default_layer); print("\n");
uint8_t ret = 1;
if(layer == 0 && current_layer != 0){
DEBUG_LED_OFF;
ret = SCROLL_LOCK_TOGGLE;
//led_set(USB_LED_SCROLL_LOCK);
}
else if(current_layer == 0 && layer != 0){
DEBUG_LED_ON;
ret = SCROLL_LOCK_TOGGLE;
//led_set(USB_LED_SCROLL_LOCK);
}
current_layer = layer;
default_layer = layer;
print("switch to Layer: "); phex(layer); print("\n");
//_delay_ms(500); // now done in keyboard.c
return ret;
}

View File

@ -1,6 +1,8 @@
#ifndef COMMAND_H
#define COMMAND
#define SCROLL_LOCK_TOGGLE 5
uint8_t command_proc(void);
#endif

View File

@ -2,7 +2,7 @@
#define TEENSY_H 1
// for Teensy/Teensy++ 2.0
#define DEBUG_LED 1
//#define DEBUG_LED 1
#define DEBUG_LED_CONFIG (DDRD |= (1<<6))
#define DEBUG_LED_ON (PORTD |= (1<<6))
#define DEBUG_LED_OFF (PORTD &= ~(1<<6))

View File

@ -17,6 +17,7 @@
static uint8_t last_leds = 0;
static bool scroll_lock = false;
void keyboard_init(void)
@ -105,11 +106,16 @@ void keyboard_proc(void)
}
layer_switching(fn_bits);
if (command_proc()) {
uint8_t ret = command_proc();
if (ret != 0 && ret != SCROLL_LOCK_TOGGLE) {
_delay_ms(500);
return;
}
if(ret == SCROLL_LOCK_TOGGLE){
scroll_lock = !scroll_lock;
}
// TODO: should send only when changed from last report
if (matrix_is_modified()) {
host_send_keyboard_report();
@ -129,10 +135,12 @@ void keyboard_proc(void)
if (ps2_mouse_read() == 0)
ps2_mouse_usb_send();
#endif
if (last_leds != host_keyboard_leds()) {
keyboard_set_leds(host_keyboard_leds());
last_leds = host_keyboard_leds();
uint8_t current_leds = (scroll_lock || IS_SHORTCUT()) ? (host_keyboard_leds() | (1<<USB_LED_SCROLL_LOCK)) : host_keyboard_leds();
if (last_leds != current_leds) {
keyboard_set_leds(current_leds);
last_leds = current_leds;
if(ret == SCROLL_LOCK_TOGGLE)
_delay_ms(500);
}
}

View File

@ -67,7 +67,7 @@ static uint8_t new_layer(uint8_t fn_bits);
uint8_t layer_get_keycode(uint8_t row, uint8_t col)
{
uint8_t code = keymap_get_keycode(current_layer, row, col);
uint8_t code = keymap_get_keycode(IS_SHORTCUT() ? SHORTCUT_LAYOUT : current_layer, row, col);
// normal key or mouse key
if ((IS_KEY(code) || IS_MOUSEKEY(code))) {
layer_used = true;
@ -82,7 +82,7 @@ void layer_switching(uint8_t fn_bits)
// layer switching
static uint8_t last_fn = 0;
static uint8_t last_mods = 0;
static uint16_t last_timer = 0;
static uint16_t last_timer = 0;
static uint8_t sent_fn = 0;
if (fn_bits == last_fn) { // Fn state is not changed

View File

@ -25,9 +25,9 @@ CONFIG_H = config_pjrc.h
# MCU name, you MUST set this to match the board you are using
# type "make clean" after changing this, so all files will be rebuilt
#MCU = at90usb162 # Teensy 1.0
MCU = atmega32u4 # Teensy 2.0
#MCU = atmega32u4 # Teensy 2.0
#MCU = at90usb646 # Teensy++ 1.0
#MCU = at90usb1286 # Teensy++ 2.0
MCU = at90usb1286 # Teensy++ 2.0
# Processor frequency.

View File

@ -6,8 +6,8 @@
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x6512
#define MANUFACTURER t.m.k.
#define PRODUCT PS/2 keyboard converter
#define MANUFACTURER moparisthebest
#define PRODUCT QWERTY/Dvorak converter
#define DESCRIPTION convert PS/2 keyboard to USB
@ -18,10 +18,19 @@
/* key combination for command */
#define IS_COMMAND() ( \
keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \
keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \
keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) \
)
/* key combination for command, reverts to defined layout */
#define IS_SHORTCUT() ( \
keyboard_report->mods & BIT_LCTRL \
)
#define SHORTCUT_LAYOUT 1
/* key combination for command */
#define IS_SWAP() ( \
keyboard_report->mods == (BIT_LCTRL | BIT_LSHIFT | BIT_RCTRL | BIT_RSHIFT) \
)
/* mouse keys */
#ifdef MOUSEKEY_ENABLE
@ -30,13 +39,13 @@
/* PS/2 lines */
#define PS2_CLOCK_PORT PORTF
#define PS2_CLOCK_PIN PINF
#define PS2_CLOCK_DDR DDRF
#define PS2_CLOCK_BIT 0
#define PS2_DATA_PORT PORTF
#define PS2_DATA_PIN PINF
#define PS2_DATA_DDR DDRF
#define PS2_DATA_BIT 1
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 3
#define PS2_DATA_PORT PORTE
#define PS2_DATA_PIN PINE
#define PS2_DATA_DDR DDRE
#define PS2_DATA_BIT 0
#endif

View File

@ -1,4 +1,4 @@
/*
/*
* Keymap for PS/2 keyboard
*/
#include <stdint.h>
@ -60,9 +60,9 @@
// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed.
static const uint8_t PROGMEM fn_layer[] = {
5, // Fn0
6, // Fn1
5, // Fn2
4, // Fn0
5, // Fn1
4, // Fn2
0, // Fn3
0, // Fn4
0, // Fn5
@ -100,13 +100,13 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| |Lef|Dow|Rig| | 0| .| |
* `-----------------------------------------------------------' `-----------' `---------------'
*/
/* 0: default */
/* 0: Dvorak http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard */
KEYMAP(
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14,
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9,
CAPS,FN2, S, D, F, G, H, J, K, L, FN0, QUOT, ENT, P4, P5, P6, PPLS,
LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, UP, P1, P2, P3,
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, DEL, END, PGDN, P7, P8, P9,
CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, P4, P5, P6, PPLS,
LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, UP, P1, P2, P3,
LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
),
/* 1: plain Qwerty without layer switching */
@ -118,34 +118,25 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3,
LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
),
/* 2: Colemak http://colemak.com */
KEYMAP(
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14,
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9,
BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, P4, P5, P6, PPLS,
LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3,
LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
),
/* 3: Dvorak http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard */
/* 2: Dvorak with layer switching */
KEYMAP(
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14,
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, DEL, END, PGDN, P7, P8, P9,
CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, P4, P5, P6, PPLS,
LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, UP, P1, P2, P3,
CAPS,FN2, O, E, U, I, D, H, T, N, FN0, MINS, ENT, P4, P5, P6, PPLS,
LSFT,SCLN,Q, J, K, X, B, M, W, V, FN1, RSFT, UP, P1, P2, P3,
LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
),
/* 4: Workman http://viralintrospection.wordpress.com/2010/09/06/a-different-philosophy-in-designing-keyboard-layouts/ */
/* 3: Qwerty with layer switching */
KEYMAP(
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14,
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9,
BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, P4, P5, P6, PPLS,
LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3,
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9,
CAPS,FN2, S, D, F, G, H, J, K, L, FN0, QUOT, ENT, P4, P5, P6, PPLS,
LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, UP, P1, P2, P3,
LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
),
/* 5: Mouse keys */
/* 4: Mouse keys */
KEYMAP(
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14,
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
@ -154,7 +145,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LSFT,VOLD,VOLU,MUTE,BTN2,BTN3,BTN2,BTN1,VOLD,VOLU,MUTE, RSFT, UP, P1, P2, P3,
LCTL,LGUI,LALT, BTN1, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
),
/* 6: Cursor keys */
/* 5: Cursor keys */
KEYMAP(
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14,
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,