1
0
Fork 0

Add PS/2 mouse support to connect TrackPoint Unit.

Change build options:  Makefile and config.h. See README.
This commit is contained in:
tmk 2011-01-02 23:52:13 +09:00
parent 1ed336a064
commit 2a562a4191
27 changed files with 954 additions and 314 deletions

View file

@ -39,12 +39,6 @@
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
VENDOR_ID = 0xFEED
PRODUCT_ID = 0xBEEF
MANUFACTURER = 't.m.k.'
PRODUCT = 't.m.k. Macway mod'
DESCRIPTION = 't.m.k. firmware for Macway mod'
# Target file name (without extension).
TARGET = tmk_macway
@ -74,4 +68,11 @@ MCU = atmega32u4 # Teensy 2.0
# examples use this variable to calculate timings. Do not add a "UL" here.
F_CPU = 16000000
# Options
# comment out to disable
#USB_NKRO_ENABLE = yes
MOUSEKEY_ENABLE = yes
PS2_MOUSE_ENABLE = yes
include $(COMMON_DIR)/Makefile.common

38
macway/config.h Normal file
View file

@ -0,0 +1,38 @@
#ifndef CONFIG_H
#define CONFIG_H
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0xBEEF
#define MANUFACTURER t.m.k.
#define PRODUCT Macway mod
#define DESCRIPTION t.m.k. keyboard firmware for Macway mod
/* controller */
#include "controller_teensy.h"
/* matrix size */
#define MATRIX_ROWS 9
#define MATRIX_COLS 8
/* USB NKey Rollover */
#ifdef USB_NKRO_ENABLE
#endif
/* mouse keys */
#ifdef MOUSEKEY_ENABLE
# define MOUSEKEY_DELAY_TIME 192
#endif
/* PS/2 mouse */
#ifdef PS2_MOUSE_ENABLE
# 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
#endif
#endif

View file

@ -1,12 +0,0 @@
#ifndef CONTROLLER_H
#define CONTROLLER_H 1
#include "controller_teensy.h"
/* matrix row size */
#define MATRIX_ROWS 9
/* matrix column size */
#define MATRIX_COLS 8
#endif

View file

@ -10,7 +10,6 @@
#include "print.h"
#include "debug.h"
#include "util.h"
#include "controller.h"
#include "keymap_skel.h"
@ -40,9 +39,9 @@ static const uint8_t PROGMEM fn_layer[] = { 0, 1, 2, 3, 4, 0, 2, 3 };
static const uint8_t PROGMEM fn_keycode[] = {
KB_NO, // FN_0 [NOT USED]
KB_NO, // FN_1 layer 1
KB_QUOTE, // FN_2 layer 2
KB_SCOLON, // FN_3 layer 3
KB_SPACE, // FN_4 layer 4
KB_SLSH, // FN_2 layer 2
KB_SCLN, // FN_3 layer 3
KB_SPC, // FN_4 layer 4
KB_NO, // FN_5 [NOT USED]
KB_NO, // FN_6 layer 2
KB_NO // FN_7 layer 3
@ -55,38 +54,38 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* |-----------------------------------------------------------|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| |
* |-----------------------------------------------------' |
* |Contro| A| S| D| F| G| H| J| K| L|Fn3|Fn2|Return |
* |Contro| A| S| D| F| G| H| J| K| L|Fn3| '|Return |
* |-----------------------------------------------------------|
* |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1|
* |-----------------------------------------------------------|
* |Fn7|Gui |Alt |Fn4 |Fn6 |\ |` | | |
* |Fn7|Gui |Alt |Fn4 |Alt |Gui|Fn6|Fn6|Ctr|
* `-----------------------------------------------------------'
*/
KEYMAP(KB_ESC, KB_1, KB_2, KB_3, KB_4, KB_5, KB_6, KB_7, KB_8, KB_9, KB_0, KB_MINS,KB_EQL, KB_BSPC, \
KB_TAB, KB_Q, KB_W, KB_E, KB_R, KB_T, KB_Y, KB_U, KB_I, KB_O, KB_P, KB_LBRC,KB_RBRC, \
KB_LCTL,KB_A, KB_S, KB_D, KB_F, KB_G, KB_H, KB_J, KB_K, KB_L, FN_3, FN_2, KB_ENT, \
KB_LSFT,KB_Z, KB_X, KB_C, KB_V, KB_B, KB_N, KB_M, KB_COMM,KB_DOT, KB_SLSH,KB_RSFT,FN_1, \
FN_7, KB_LGUI,KB_LALT,FN_4, FN_6, KB_BSLS,KB_GRV, KB_NO, KB_NO),
KB_LCTL,KB_A, KB_S, KB_D, KB_F, KB_G, KB_H, KB_J, KB_K, KB_L, FN_3, KB_QUOT,KB_ENT, \
KB_LSFT,KB_Z, KB_X, KB_C, KB_V, KB_B, KB_N, KB_M, KB_COMM,KB_DOT, FN_2, KB_RSFT,FN_1, \
FN_7, KB_LGUI,KB_LALT,FN_4, KB_RALT,KB_RGUI,FN_6, FN_6, KB_RCTL),
/* Layer 1: HHKB mode (HHKB Fn)
* ,-----------------------------------------------------------.
* |Pow| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete |
* |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete |
* |-----------------------------------------------------------|
* |Caps | | | | | | | |Psc|Slk|Pus|Up | | |
* |-----------------------------------------------------' |
* |Contro| | | | | | *| /|Hom|PgU|Lef|Rig|Enter |
* |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
* |-----------------------------------------------------------|
* |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx|
* |-----------------------------------------------------------|
* | |Gui |Alt | |Alt | | | | |
* | |Gui |Alt | |Alt |Gui| | |Ctr|
* `-----------------------------------------------------------'
*/
KEYMAP(KB_PWR, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_DEL, \
KEYMAP(KB_ESC, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_DEL, \
KB_CAPS,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_PSCR,KB_SLCK,KB_BRK, KB_UP, KB_NO, \
KB_LCTL,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KP_ASTR,KP_SLSH,KB_HOME,KB_PGUP,KB_LEFT,KB_RGHT,KB_ENT, \
KB_LCTL,KB_VOLD,KB_VOLU,KB_MUTE,KB_NO, KB_NO, KP_ASTR,KP_SLSH,KB_HOME,KB_PGUP,KB_LEFT,KB_RGHT,KB_ENT, \
KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KP_PLUS,KP_MINS,KB_END, KB_PGDN,KB_DOWN,KB_RSFT,FN_1, \
KB_NO, KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO),
KB_NO, KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_NO, KB_NO, KB_NO, KB_RCTL),
/* Layer 2: Vi mode (Quote/Rmeta)
@ -95,27 +94,27 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* |-----------------------------------------------------------|
* | \ |Hom|PgD|Up |PgU|End|Hom|PgD|PgU|End| | | | |
* |-----------------------------------------------------' |
* |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| |xxx| \ |
* |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | | \ |
* |-----------------------------------------------------------|
* |Shift | | | | | |Hom|PgD|PgU|End| |Shift | |
* |Shift | | | | | |Hom|PgD|PgU|End|xxx|Shift | |
* |-----------------------------------------------------------|
* | |Gui |Alt |Space |xxxxx| | | | |
* | |Gui |Alt |Space |Alt |Gui|Fn6|Fn6|Ctr|
* `-----------------------------------------------------------'
*/
KEYMAP(KB_GRV, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_GRV, \
KB_BSLS,KB_HOME,KB_PGDN,KB_UP, KB_PGUP,KB_END, KB_HOME,KB_PGDN,KB_PGUP,KB_END, KB_NO, KB_NO, KB_NO, \
KB_LCTL,KB_NO, KB_LEFT,KB_DOWN,KB_RGHT,KB_NO, KB_LEFT,KB_DOWN,KB_UP, KB_RGHT,KB_NO, FN_2, KB_BSLS, \
KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_RSFT,KB_NO, \
KB_NO, KB_LGUI,KB_LALT,KB_SPC, FN_6, KB_NO, KB_NO, KB_NO, KB_NO),
KB_LCTL,KB_NO, KB_LEFT,KB_DOWN,KB_RGHT,KB_NO, KB_LEFT,KB_DOWN,KB_UP, KB_RGHT,KB_NO, KB_NO, KB_BSLS, \
KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, FN_2, KB_RSFT,KB_NO, \
KB_NO, KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_RGUI,FN_6, FN_6, KB_RCTL),
/* Layer 3: Mouse mode (Semicolon)
* ,-------------------------------------------------------- --.
* |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete |
* ,-----------------------------------------------------------.
* | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| ` |
* |-----------------------------------------------------------|
* |Tab |MwL|MwD|McU|MwU|MwR|MwL|MwD|MwU|MwR| | | | |
* | \ |MwL|MwD|McU|MwU|MwR|MwL|MwD|MwU|MwR| | | | |
* |-----------------------------------------------------' |
* |Contro| |McL|McD|McR| |McL|McD|McU|McR|xxx| |Return |
* |Contro| |McL|McD|McR| |McL|McD|McU|McR|xxx| | \ |
* |-----------------------------------------------------------|
* |Shift | | |Mb1|Mb2|Mb3|Mb2|Mb1| | | |Shift | |
* |-----------------------------------------------------------|
@ -123,9 +122,9 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* `-----------------------------------------------------------'
* Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
*/
KEYMAP(KB_ESC, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_DEL, \
KB_TAB, MS_WH_L,MS_WH_D,MS_UP, MS_WH_U,MS_WH_R,MS_WH_L,MS_WH_D,MS_WH_U,MS_WH_R,KB_NO, KB_NO, KB_NO, \
KB_LCTL,KB_NO, MS_LEFT,MS_DOWN,MS_RGHT,KB_NO, MS_LEFT,MS_DOWN,MS_UP, MS_RGHT,FN_3, KB_NO, KB_ENT, \
KEYMAP(KB_GRV, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_GRV, \
KB_BSLS,MS_WH_L,MS_WH_D,MS_UP, MS_WH_U,MS_WH_R,MS_WH_L,MS_WH_D,MS_WH_U,MS_WH_R,KB_NO, KB_NO, KB_NO, \
KB_LCTL,KB_NO, MS_LEFT,MS_DOWN,MS_RGHT,KB_NO, MS_LEFT,MS_DOWN,MS_UP, MS_RGHT,FN_3, KB_NO, KB_BSLS, \
KB_LSFT,KB_NO, KB_NO, MS_BTN1,MS_BTN2,MS_BTN3,MS_BTN2,MS_BTN1,KB_NO, KB_NO, KB_NO, KB_RSFT,KB_NO, \
FN_7, KB_LGUI,KB_LALT,MS_BTN1,KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO),
@ -140,14 +139,14 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* |-----------------------------------------------------------|
* |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | |
* |-----------------------------------------------------------|
* | |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxx|Alt | | | | |
* | |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxx|Alt |Gui| | |Ctr|
* `-----------------------------------------------------------'
*/
KEYMAP(KB_MINS,KB_0, KB_9, KB_8, KB_7, KB_6, KB_5, KB_4, KB_3, KB_2, KB_1, KB_NO, KB_NO, KB_ESC, \
KB_BSPC,KB_P, KB_O, KB_I, KB_U, KB_Y, KB_T, KB_R, KB_E, KB_W, KB_Q, KB_TAB, KB_TAB, \
KB_LCTL,KB_SCLN,KB_L, KB_K, KB_J, KB_H, KB_G, KB_F, KB_D, KB_S, KB_A, KB_RCTL,KB_RCTL, \
KB_LSFT,KB_SLSH,KB_DOT, KB_COMM,KB_M, KB_N, KB_B, KB_V, KB_C, KB_X, KB_Z, KB_RSFT,KB_NO, \
KB_NO, KB_LGUI,KB_LALT,FN_4, KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO),
KB_NO, KB_LGUI,KB_LALT,FN_4, KB_RALT,KB_RGUI,KB_NO, KB_NO, KB_RCTL),
};
@ -168,5 +167,6 @@ uint8_t keymap_fn_keycode(uint8_t fn_bits)
bool keymap_is_special_mode(uint8_t fn_bits)
{
return (usb_keyboard_mods == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI));
//return (usb_keyboard_mods == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI));
return (usb_keyboard_mods == (BIT_RSHIFT));
}

View file

@ -7,16 +7,10 @@
#include <util/delay.h>
#include "print.h"
#include "util.h"
#include "controller.h"
#include "matrix_skel.h"
// matrix is active low. (key on: 0/key off: 1)
// row: Hi-Z(unselected)/low output(selected)
// PD0, PC7, PD7, PF6, PD6, PD1, PD2, PC6, PF7
// col: input w/pullup
// PB0-PB7
// matrix state buffer
// matrix state buffer (key on: 1/key off: 0)
static uint8_t *matrix;
static uint8_t *matrix_prev;
static uint8_t _matrix0[MATRIX_ROWS];
@ -45,6 +39,7 @@ void matrix_init(void)
{
// initialize row and col
unselect_rows();
// Input with pull-up(DDR:0, PORT:1)
DDRB = 0x00;
PORTB = 0xFF;
@ -64,11 +59,12 @@ int matrix_scan(void)
matrix = tmp;
for (int i = 0; i < MATRIX_ROWS; i++) {
unselect_rows();
select_row(i);
_delay_us(30); // without this wait read unstable value.
matrix[i] = ~read_col();
unselect_rows();
}
unselect_rows();
return 1;
}
@ -145,88 +141,56 @@ static uint8_t read_col(void)
static void unselect_rows(void)
{
DDRD = 0x00;
PORTD = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRF = 0x00;
PORTF = 0x00;
// Hi-Z(DDR:0, PORT:0) to unselect
DDRC &= ~0b11000000; // PC: 7,6
PORTC &= ~0b11000000;
DDRD &= ~0b11000111; // PD: 7,6,2,1,0
PORTD &= ~0b11000111;
DDRF &= ~0b11000000; // PF: 7,6
PORTF &= ~0b11000000;
}
static void select_row(uint8_t row)
{
// Output low(DDR:1, PORT:0) to select
// row: 0 1 2 3 4 5 6 7 8
// pin: PD0, PC7, PD7, PF6, PD6, PD1, PD2, PC6, PF7
switch (row) {
case 0:
DDRD = (1<<0);
PORTD = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRF = 0x00;
PORTF = 0x00;
DDRD |= (1<<0);
PORTD &= ~(1<<0);
break;
case 1:
DDRD = 0x00;
PORTD = 0x00;
DDRC = (1<<7);
PORTC = 0x00;
DDRF = 0x00;
PORTF = 0x00;
DDRC |= (1<<7);
PORTC &= ~(1<<7);
break;
case 2:
DDRD = (1<<7);
PORTD = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRF = 0x00;
PORTF = 0x00;
DDRD |= (1<<7);
PORTD &= ~(1<<7);
break;
case 3:
DDRD = 0x00;
PORTD = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRF = (1<<6);
PORTF = 0x00;
DDRF |= (1<<6);
PORTF &= ~(1<<6);
break;
case 4:
DDRD = (1<<6);
PORTD = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRF = 0x00;
PORTF = 0x00;
DDRD |= (1<<6);
PORTD &= ~(1<<6);
break;
case 5:
DDRD = (1<<1);
PORTD = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRF = 0x00;
PORTF = 0x00;
DDRD |= (1<<1);
PORTD &= ~(1<<1);
break;
case 6:
DDRD = (1<<2);
PORTD = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRF = 0x00;
PORTF = 0x00;
DDRD |= (1<<2);
PORTD &= ~(1<<2);
break;
case 7:
DDRD = 0x00;
PORTD = 0x00;
DDRC = (1<<6);
PORTC = 0x00;
DDRF = 0x00;
PORTF = 0x00;
DDRC |= (1<<6);
PORTC &= ~(1<<6);
break;
case 8:
DDRD = 0x00;
PORTD = 0x00;
DDRC = 0x00;
PORTC = 0x00;
DDRF = (1<<7);
PORTF = 0x00;
DDRF |= (1<<7);
PORTF &= ~(1<<7);
break;
}
}