diff options
| -rw-r--r-- | Makefile.common | 58 | ||||
| -rw-r--r-- | README | 41 | ||||
| -rw-r--r-- | USB_NKRO.txt | 14 | ||||
| -rw-r--r-- | hhkb/Makefile | 17 | ||||
| -rw-r--r-- | hhkb/config.h | 40 | ||||
| -rw-r--r-- | hhkb/controller.h | 12 | ||||
| -rw-r--r-- | hhkb/keymap.c | 3 | ||||
| -rw-r--r-- | hhkb/matrix.c | 5 | ||||
| -rw-r--r-- | jump_bootloader.c | 31 | ||||
| -rw-r--r-- | key_process.c | 110 | ||||
| -rw-r--r-- | macway/Makefile | 13 | ||||
| -rw-r--r-- | macway/config.h | 38 | ||||
| -rw-r--r-- | macway/controller.h | 12 | ||||
| -rw-r--r-- | macway/keymap.c | 62 | ||||
| -rw-r--r-- | macway/matrix.c | 100 | ||||
| -rw-r--r-- | mousekey.c | 74 | ||||
| -rw-r--r-- | mousekey.h | 11 | ||||
| -rw-r--r-- | ps2.c | 248 | ||||
| -rw-r--r-- | ps2.h | 72 | ||||
| -rw-r--r-- | ps2_mouse.c | 161 | ||||
| -rw-r--r-- | ps2_mouse.h | 26 | ||||
| -rw-r--r-- | tmk.c | 11 | ||||
| -rwxr-xr-x | usb.c | 16 | ||||
| -rw-r--r-- | usb_keyboard.c | 10 | ||||
| -rw-r--r-- | usb_keyboard.h | 2 | ||||
| -rw-r--r-- | usb_mouse.c | 57 | ||||
| -rw-r--r-- | usb_mouse.h | 20 |
27 files changed, 952 insertions, 312 deletions
diff --git a/Makefile.common b/Makefile.common index d21242436..9e995c908 100644 --- a/Makefile.common +++ b/Makefile.common | |||
| @@ -62,6 +62,13 @@ SRC = tmk.c \ | |||
| 62 | timer.c \ | 62 | timer.c \ |
| 63 | util.c | 63 | util.c |
| 64 | SRC += $(TARGET_SRC) | 64 | SRC += $(TARGET_SRC) |
| 65 | ifdef MOUSEKEY_ENABLE | ||
| 66 | SRC += mousekey.c | ||
| 67 | endif | ||
| 68 | ifdef PS2_MOUSE_ENABLE | ||
| 69 | SRC += ps2.c \ | ||
| 70 | ps2_mouse.c | ||
| 71 | endif | ||
| 65 | 72 | ||
| 66 | # C source file search path | 73 | # C source file search path |
| 67 | VPATH = $(TARGET_DIR):$(COMMON_DIR) | 74 | VPATH = $(TARGET_DIR):$(COMMON_DIR) |
| @@ -119,45 +126,32 @@ EXTRAINCDIRS = $(TARGET_DIR) $(COMMON_DIR) | |||
| 119 | CSTANDARD = -std=gnu99 | 126 | CSTANDARD = -std=gnu99 |
| 120 | 127 | ||
| 121 | 128 | ||
| 122 | # Place -D or -U options here for C sources | 129 | OPT_DEFS = |
| 123 | CDEFS = -DF_CPU=$(F_CPU)UL | 130 | ifdef USB_NKRO_ENABLE |
| 124 | CDEFS += -DDESCRIPTION=$(DESCRIPTION) | 131 | OPT_DEFS += -DUSB_NKRO_ENABLE |
| 125 | CDEFS += -DVENDOR_ID=$(VENDOR_ID) | 132 | endif |
| 126 | CDEFS += -DPRODUCT_ID=$(PRODUCT_ID) | 133 | ifdef MOUSEKEY_ENABLE |
| 127 | CDEFS += -DMANUFACTURER=$(MANUFACTURER) | 134 | OPT_DEFS += -DMOUSEKEY_ENABLE |
| 128 | CDEFS += -DPRODUCT=$(PRODUCT) | ||
| 129 | ifdef MOUSE_DELAY_TIME | ||
| 130 | CDEFS += -DMOUSE_DELAY_TIME=$(MOUSE_DELAY_TIME) | ||
| 131 | endif | 135 | endif |
| 132 | ifdef NKRO_ENABLE | 136 | ifdef PS2_MOUSE_ENABLE |
| 133 | CDEFS += -DNKRO_ENABLE | 137 | OPT_DEFS += -DPS2_MOUSE_ENABLE |
| 134 | endif | 138 | endif |
| 135 | 139 | ||
| 140 | # Place -D or -U options here for C sources | ||
| 141 | CDEFS = -DF_CPU=$(F_CPU)UL | ||
| 142 | CDEFS += $(OPT_DEFS) | ||
| 143 | |||
| 136 | 144 | ||
| 137 | # Place -D or -U options here for ASM sources | 145 | # Place -D or -U options here for ASM sources |
| 138 | ADEFS = -DF_CPU=$(F_CPU) | 146 | ADEFS = -DF_CPU=$(F_CPU) |
| 139 | ADEFS += -DDESCRIPTION=$(DESCRIPTION) | 147 | ADEFS += $(OPT_DEFS) |
| 140 | ADEFS += -DVENDOR_ID=$(VENDOR_ID) | ||
| 141 | ADEFS += -DPRODUCT_ID=$(PRODUCT_ID) | ||
| 142 | ADEFS += -DMANUFACTURER=$(MANUFACTURER) | ||
| 143 | ADEFS += -DPRODUCT=$(PRODUCT) | ||
| 144 | ifdef MOUSE_DELAY_TIME | ||
| 145 | ADEFS += -DMOUSE_DELAY_TIME=$(MOUSE_DELAY_TIME) | ||
| 146 | endif | ||
| 147 | 148 | ||
| 148 | 149 | ||
| 149 | # Place -D or -U options here for C++ sources | 150 | # Place -D or -U options here for C++ sources |
| 150 | CPPDEFS = -DF_CPU=$(F_CPU)UL -DDESCRIPTION=$(DESCRIPTION) -DVENDOR_ID=$(VENDOR_ID) -DPRODUCT_ID=$(PRODUCT_ID) | 151 | CPPDEFS = -DF_CPU=$(F_CPU)UL |
| 151 | #CPPDEFS += -D__STDC_LIMIT_MACROS | 152 | #CPPDEFS += -D__STDC_LIMIT_MACROS |
| 152 | #CPPDEFS += -D__STDC_CONSTANT_MACROS | 153 | #CPPDEFS += -D__STDC_CONSTANT_MACROS |
| 153 | CPPDEFS += -DDESCRIPTION=$(DESCRIPTION) | 154 | CPPDEFS += $(OPT_DEFS) |
| 154 | CPPDEFS += -DVENDOR_ID=$(VENDOR_ID) | ||
| 155 | CPPDEFS += -DPRODUCT_ID=$(PRODUCT_ID) | ||
| 156 | CPPDEFS += -DMANUFACTURER=$(MANUFACTURER) | ||
| 157 | CPPDEFS += -DPRODUCT=$(PRODUCT) | ||
| 158 | ifdef MOUSE_DELAY_TIME | ||
| 159 | CPPDEFS += -DMOUSE_DELAY_TIME=$(MOUSE_DELAY_TIME) | ||
| 160 | endif | ||
| 161 | 155 | ||
| 162 | 156 | ||
| 163 | 157 | ||
| @@ -186,6 +180,7 @@ CFLAGS += -Wstrict-prototypes | |||
| 186 | CFLAGS += -Wa,-adhlns=$(@:%.o=$(OBJDIR)/%.lst) | 180 | CFLAGS += -Wa,-adhlns=$(@:%.o=$(OBJDIR)/%.lst) |
| 187 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | 181 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
| 188 | CFLAGS += $(CSTANDARD) | 182 | CFLAGS += $(CSTANDARD) |
| 183 | CFLAGS += -include config.h | ||
| 189 | 184 | ||
| 190 | 185 | ||
| 191 | #---------------- Compiler Options C++ ---------------- | 186 | #---------------- Compiler Options C++ ---------------- |
| @@ -213,6 +208,7 @@ CPPFLAGS += -Wundef | |||
| 213 | CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst) | 208 | CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst) |
| 214 | CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | 209 | CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
| 215 | #CPPFLAGS += $(CSTANDARD) | 210 | #CPPFLAGS += $(CSTANDARD) |
| 211 | CPPFLAGS += -include config.h | ||
| 216 | 212 | ||
| 217 | 213 | ||
| 218 | #---------------- Assembler Options ---------------- | 214 | #---------------- Assembler Options ---------------- |
| @@ -225,6 +221,7 @@ CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | |||
| 225 | # -listing-cont-lines: Sets the maximum number of continuation lines of hex | 221 | # -listing-cont-lines: Sets the maximum number of continuation lines of hex |
| 226 | # dump that will be displayed for a given single line of source input. | 222 | # dump that will be displayed for a given single line of source input. |
| 227 | ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100 | 223 | ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100 |
| 224 | ASFLAGS += -include config.h | ||
| 228 | 225 | ||
| 229 | 226 | ||
| 230 | #---------------- Library Options ---------------- | 227 | #---------------- Library Options ---------------- |
| @@ -421,6 +418,11 @@ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) | |||
| 421 | # Default target. | 418 | # Default target. |
| 422 | all: begin gccversion sizebefore build sizeafter end | 419 | all: begin gccversion sizebefore build sizeafter end |
| 423 | 420 | ||
| 421 | depend: tmk.c | ||
| 422 | @echo $< | ||
| 423 | @echo $(<F) | ||
| 424 | # $(CC) -E $(ALL_CFLAGS) $< | ||
| 425 | |||
| 424 | # Change the build target to build a HEX file or a library. | 426 | # Change the build target to build a HEX file or a library. |
| 425 | build: elf hex eep lss sym | 427 | build: elf hex eep lss sym |
| 426 | #build: lib | 428 | #build: lib |
| @@ -31,6 +31,47 @@ $ make | |||
| 31 | http://winavr.sourceforge.net/ | 31 | http://winavr.sourceforge.net/ |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | Build Options | ||
| 35 | ------------- | ||
| 36 | Makefile: | ||
| 37 | Comment out to disable the option | ||
| 38 | # USB NKey Rollover | ||
| 39 | USB_NKRO_ENABLE = yes | ||
| 40 | |||
| 41 | # mouse keys | ||
| 42 | MOUSEKEY_ENABLE = yes | ||
| 43 | |||
| 44 | # PS/2 mouse support | ||
| 45 | PS2_MOUSE_ENABLE = yes | ||
| 46 | |||
| 47 | config.h: | ||
| 48 | /* USB ID */ | ||
| 49 | #define VENDOR_ID 0xFEED | ||
| 50 | #define PRODUCT_ID 0xBEEF | ||
| 51 | /* device description */ | ||
| 52 | #define MANUFACTURER t.m.k. | ||
| 53 | #define PRODUCT Macway mod | ||
| 54 | #define DESCRIPTION t.m.k. keyboard firmware for Macway mod | ||
| 55 | /* matrix size */ | ||
| 56 | #define MATRIX_ROWS 8 | ||
| 57 | #define MATRIX_COLS 8 | ||
| 58 | /* mouse keys repeat delay */ | ||
| 59 | #define MOUSEKEY_DELAY_TIME 192 | ||
| 60 | /* PS/2 lines */ | ||
| 61 | #define PS2_CLOCK_PORT PORTF | ||
| 62 | #define PS2_CLOCK_PIN PINF | ||
| 63 | #define PS2_CLOCK_DDR DDRF | ||
| 64 | #define PS2_CLOCK_BIT 0 | ||
| 65 | #define PS2_DATA_PORT PORTF | ||
| 66 | #define PS2_DATA_PIN PINF | ||
| 67 | #define PS2_DATA_DDR DDRF | ||
| 68 | #define PS2_DATA_BIT 1 | ||
| 69 | |||
| 70 | |||
| 71 | Configuration | ||
| 72 | ------------- | ||
| 73 | |||
| 74 | |||
| 34 | Debuging & Rescue | 75 | Debuging & Rescue |
| 35 | ----------------- | 76 | ----------------- |
| 36 | Use PJRC's hid_listen.exe to see debug messages. | 77 | Use PJRC's hid_listen.exe to see debug messages. |
diff --git a/USB_NKRO.txt b/USB_NKRO.txt index b681d85dc..4751bca86 100644 --- a/USB_NKRO.txt +++ b/USB_NKRO.txt | |||
| @@ -143,4 +143,18 @@ This problem will be reportedly fixed soon.(2010/12/05) | |||
| 143 | http://forums.anandtech.com/showpost.php?p=30873364&postcount=17 | 143 | http://forums.anandtech.com/showpost.php?p=30873364&postcount=17 |
| 144 | 144 | ||
| 145 | 145 | ||
| 146 | Tools for testing NKRO | ||
| 147 | ---------------------- | ||
| 148 | Browser App: | ||
| 149 | http://www.microsoft.com/appliedsciences/content/projects/KeyboardGhostingDemo.aspx | ||
| 150 | http://random.xem.us/rollover.html | ||
| 151 | |||
| 152 | Windows: | ||
| 153 | AquaKeyTest.exe http://geekhack.org/showthread.php?t=6643 | ||
| 154 | |||
| 155 | Linux: | ||
| 156 | xkeycaps | ||
| 157 | xev | ||
| 158 | showkeys | ||
| 159 | |||
| 146 | EOF | 160 | EOF |
diff --git a/hhkb/Makefile b/hhkb/Makefile index bf5d75ee9..943785fef 100644 --- a/hhkb/Makefile +++ b/hhkb/Makefile | |||
| @@ -39,16 +39,6 @@ | |||
| 39 | # To rebuild project do "make clean" then "make all". | 39 | # To rebuild project do "make clean" then "make all". |
| 40 | #---------------------------------------------------------------------------- | 40 | #---------------------------------------------------------------------------- |
| 41 | 41 | ||
| 42 | # TODO: use config.h for build options? | ||
| 43 | VENDOR_ID = 0xFEED | ||
| 44 | PRODUCT_ID = 0xCAFE | ||
| 45 | MANUFACTURER = 't.m.k.' | ||
| 46 | PRODUCT = 'HHKB Mod' | ||
| 47 | DESCRIPTION = 't.m.k. firmware for HHKB pro' | ||
| 48 | |||
| 49 | MOUSE_DELAY_TIME = 127 | ||
| 50 | NKRO_ENABLE = true | ||
| 51 | |||
| 52 | # Target file name (without extension). | 42 | # Target file name (without extension). |
| 53 | TARGET = tmk_hhkb | 43 | TARGET = tmk_hhkb |
| 54 | 44 | ||
| @@ -78,4 +68,11 @@ MCU = at90usb1286 # Teensy++ 2.0 | |||
| 78 | # examples use this variable to calculate timings. Do not add a "UL" here. | 68 | # examples use this variable to calculate timings. Do not add a "UL" here. |
| 79 | F_CPU = 16000000 | 69 | F_CPU = 16000000 |
| 80 | 70 | ||
| 71 | |||
| 72 | # Options | ||
| 73 | # comment out to disable | ||
| 74 | USB_NKRO_ENABLE = yes | ||
| 75 | MOUSEKEY_ENABLE = yes | ||
| 76 | #PS2_MOUSE_ENABLE = yes | ||
| 77 | |||
| 81 | include $(COMMON_DIR)/Makefile.common | 78 | include $(COMMON_DIR)/Makefile.common |
diff --git a/hhkb/config.h b/hhkb/config.h new file mode 100644 index 000000000..7722ed46a --- /dev/null +++ b/hhkb/config.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #ifndef CONFIG_H | ||
| 2 | #define CONFIG_H | ||
| 3 | |||
| 4 | #define VENDOR_ID 0xFEED | ||
| 5 | #define PRODUCT_ID 0xCAFE | ||
| 6 | #define MANUFACTURER t.m.k. | ||
| 7 | #define PRODUCT HHKB mod | ||
| 8 | #define DESCRIPTION t.m.k. keyboard firmware for HHKB mod | ||
| 9 | |||
| 10 | /* controller */ | ||
| 11 | #include "controller_teensy.h" | ||
| 12 | |||
| 13 | /* matrix size */ | ||
| 14 | #define MATRIX_ROWS 8 | ||
| 15 | #define MATRIX_COLS 8 | ||
| 16 | |||
| 17 | /* USB NKey Rollover */ | ||
| 18 | #ifdef USB_NKRO_ENABLE | ||
| 19 | #endif | ||
| 20 | |||
| 21 | /* mouse keys */ | ||
| 22 | #ifdef MOUSEKEY_ENABLE | ||
| 23 | # define MOUSEKEY_DELAY_TIME 192 | ||
| 24 | #endif | ||
| 25 | |||
| 26 | /* PS/2 mouse */ | ||
| 27 | #ifdef PS2_MOUSE_ENABLE | ||
| 28 | /* | ||
| 29 | # define PS2_CLOCK_PORT PORTF | ||
| 30 | # define PS2_CLOCK_PIN PINF | ||
| 31 | # define PS2_CLOCK_DDR DDRF | ||
| 32 | # define PS2_CLOCK_BIT 0 | ||
| 33 | # define PS2_DATA_PORT PORTF | ||
| 34 | # define PS2_DATA_PIN PINF | ||
| 35 | # define PS2_DATA_DDR DDRF | ||
| 36 | # define PS2_DATA_BIT 1 | ||
| 37 | */ | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #endif | ||
diff --git a/hhkb/controller.h b/hhkb/controller.h deleted file mode 100644 index 32a10b7cd..000000000 --- a/hhkb/controller.h +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | #ifndef CONTROLLER_H | ||
| 2 | #define CONTROLLER_H 1 | ||
| 3 | |||
| 4 | #include "controller_teensy.h" | ||
| 5 | |||
| 6 | |||
| 7 | /* matrix row size */ | ||
| 8 | #define MATRIX_ROWS 8 | ||
| 9 | /* matrix column size */ | ||
| 10 | #define MATRIX_COLS 8 | ||
| 11 | |||
| 12 | #endif | ||
diff --git a/hhkb/keymap.c b/hhkb/keymap.c index fd9bcce8a..4273835e9 100644 --- a/hhkb/keymap.c +++ b/hhkb/keymap.c | |||
| @@ -9,7 +9,6 @@ | |||
| 9 | #include "print.h" | 9 | #include "print.h" |
| 10 | #include "debug.h" | 10 | #include "debug.h" |
| 11 | #include "util.h" | 11 | #include "util.h" |
| 12 | #include "controller.h" | ||
| 13 | #include "keymap_skel.h" | 12 | #include "keymap_skel.h" |
| 14 | 13 | ||
| 15 | 14 | ||
| @@ -75,7 +74,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 75 | * |-----------------------------------------------------------| | 74 | * |-----------------------------------------------------------| |
| 76 | * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs| | 75 | * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs| |
| 77 | * |-----------------------------------------------------------| | 76 | * |-----------------------------------------------------------| |
| 78 | * |Contro| | | | | | *| /|Hom|PgU|Lef|Rig|Enter | | 77 | * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter | |
| 79 | * |-----------------------------------------------------------| | 78 | * |-----------------------------------------------------------| |
| 80 | * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx| | 79 | * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx| |
| 81 | * `-----------------------------------------------------------' | 80 | * `-----------------------------------------------------------' |
diff --git a/hhkb/matrix.c b/hhkb/matrix.c index a6e0bf633..dd4440d9e 100644 --- a/hhkb/matrix.c +++ b/hhkb/matrix.c | |||
| @@ -7,7 +7,6 @@ | |||
| 7 | #include <util/delay.h> | 7 | #include <util/delay.h> |
| 8 | #include "print.h" | 8 | #include "print.h" |
| 9 | #include "util.h" | 9 | #include "util.h" |
| 10 | #include "controller.h" | ||
| 11 | #include "matrix_skel.h" | 10 | #include "matrix_skel.h" |
| 12 | 11 | ||
| 13 | // matrix is active low. (key on: 0/key off: 1) | 12 | // matrix is active low. (key on: 0/key off: 1) |
| @@ -22,7 +21,7 @@ | |||
| 22 | // KEY_PREV: (on: 1/ off: 0) | 21 | // KEY_PREV: (on: 1/ off: 0) |
| 23 | // PE6,PE7(KEY, KEY_PREV) | 22 | // PE6,PE7(KEY, KEY_PREV) |
| 24 | #define COL_ENABLE (1<<6) | 23 | #define COL_ENABLE (1<<6) |
| 25 | #define KEY_SELELCT(ROW, COL) (PORTB = COL_ENABLE|(((COL)&0x07)<<3)|((ROW)&0x07)) | 24 | #define KEY_SELELCT(ROW, COL) (PORTB = (PORTB&(1<<7))|COL_ENABLE|(((COL)&0x07)<<3)|((ROW)&0x07)) |
| 26 | #define KEY_ENABLE (PORTB &= ~COL_ENABLE) | 25 | #define KEY_ENABLE (PORTB &= ~COL_ENABLE) |
| 27 | #define KEY_UNABLE (PORTB |= COL_ENABLE) | 26 | #define KEY_UNABLE (PORTB |= COL_ENABLE) |
| 28 | #define KEY_STATE (PINE&(1<<6)) | 27 | #define KEY_STATE (PINE&(1<<6)) |
| @@ -53,7 +52,7 @@ void matrix_init(void) | |||
| 53 | { | 52 | { |
| 54 | // row & col output(PB0-6) | 53 | // row & col output(PB0-6) |
| 55 | DDRB = 0xFF; | 54 | DDRB = 0xFF; |
| 56 | PORTB = KEY_SELELCT(0, 0); | 55 | KEY_SELELCT(0, 0); |
| 57 | // KEY: input with pullup(PE6) | 56 | // KEY: input with pullup(PE6) |
| 58 | // KEY_PREV: output(PE7) | 57 | // KEY_PREV: output(PE7) |
| 59 | DDRE = 0xBF; | 58 | DDRE = 0xBF; |
diff --git a/jump_bootloader.c b/jump_bootloader.c index e4c0b967f..5710e052f 100644 --- a/jump_bootloader.c +++ b/jump_bootloader.c | |||
| @@ -13,23 +13,28 @@ void jump_bootloader(void) { | |||
| 13 | UCSR1B = 0; | 13 | UCSR1B = 0; |
| 14 | _delay_ms(5); | 14 | _delay_ms(5); |
| 15 | #if defined(__AVR_AT90USB162__) // Teensy 1.0 | 15 | #if defined(__AVR_AT90USB162__) // Teensy 1.0 |
| 16 | EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; | ||
| 17 | TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0; | ||
| 16 | DDRB = 0; DDRC = 0; DDRD = 0; | 18 | DDRB = 0; DDRC = 0; DDRD = 0; |
| 17 | TIMSK0 = 0; TIMSK1 = 0; | 19 | PORTB = 0; PORTC = 0; PORTD = 0; |
| 18 | asm volatile("jmp 0x1F00"); | 20 | asm volatile("jmp 0x3E00"); |
| 19 | #elif defined(__AVR_ATmega32U4__) // Teensy 2.0 | 21 | #elif defined(__AVR_ATmega32U4__) // Teensy 2.0 |
| 20 | DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; | 22 | EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; |
| 21 | TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; | 23 | TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0; |
| 22 | ADCSRA = 0; | 24 | DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0; |
| 23 | asm volatile("jmp 0x3F00"); | 25 | PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; |
| 26 | asm volatile("jmp 0x7E00"); | ||
| 24 | #elif defined(__AVR_AT90USB646__) // Teensy++ 1.0 | 27 | #elif defined(__AVR_AT90USB646__) // Teensy++ 1.0 |
| 28 | EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; | ||
| 29 | TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0; | ||
| 25 | DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; | 30 | DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; |
| 26 | TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; | 31 | PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; |
| 27 | ADCSRA = 0; | 32 | asm volatile("jmp 0xFC00"); |
| 28 | asm volatile("jmp 0x7E00"); | ||
| 29 | #elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0 | 33 | #elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0 |
| 34 | EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; | ||
| 35 | TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0; | ||
| 30 | DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; | 36 | DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; |
| 31 | TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; | 37 | PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; |
| 32 | ADCSRA = 0; | 38 | asm volatile("jmp 0x1FC00"); |
| 33 | asm volatile("jmp 0xFE00"); | 39 | #endif |
| 34 | #endif | ||
| 35 | } | 40 | } |
diff --git a/key_process.c b/key_process.c index bb1bca02d..f3b65d101 100644 --- a/key_process.c +++ b/key_process.c | |||
| @@ -15,29 +15,18 @@ | |||
| 15 | #include "layer.h" | 15 | #include "layer.h" |
| 16 | #include "matrix_skel.h" | 16 | #include "matrix_skel.h" |
| 17 | #include "keymap_skel.h" | 17 | #include "keymap_skel.h" |
| 18 | #include "controller.h" | ||
| 19 | #include "key_process.h" | 18 | #include "key_process.h" |
| 20 | 19 | #ifdef MOUSEKEY_ENABLE | |
| 21 | 20 | # include "mousekey.h" | |
| 22 | #define MOUSE_MOVE_UNIT 10 | 21 | #endif |
| 23 | #define MOUSE_MOVE_ACCEL (mouse_repeat < 50 ? mouse_repeat/5 : 10) | 22 | #ifdef PS2_MOUSE_ENABLE |
| 24 | 23 | # include "ps2_mouse.h" | |
| 25 | #ifndef MOUSE_DELAY_TIME | ||
| 26 | # define MOUSE_DELAY_TIME 255 | ||
| 27 | #endif | 24 | #endif |
| 28 | #define MOUSE_DELAY_MS (MOUSE_DELAY_TIME >> (mouse_repeat < 5 ? mouse_repeat : 4)) | ||
| 29 | 25 | ||
| 30 | 26 | ||
| 31 | // TODO: refactoring | 27 | // TODO: refactoring |
| 32 | void proc_matrix(void) { | 28 | void proc_matrix(void) { |
| 33 | static int mouse_repeat = 0; | ||
| 34 | |||
| 35 | bool modified = false; | 29 | bool modified = false; |
| 36 | uint8_t mouse_btn = 0; | ||
| 37 | int8_t mouse_x = 0; | ||
| 38 | int8_t mouse_y = 0; | ||
| 39 | int8_t mouse_vwheel = 0; | ||
| 40 | int8_t mouse_hwheel = 0; | ||
| 41 | uint8_t fn_bits = 0; | 30 | uint8_t fn_bits = 0; |
| 42 | 31 | ||
| 43 | matrix_scan(); | 32 | matrix_scan(); |
| @@ -73,19 +62,9 @@ void proc_matrix(void) { | |||
| 73 | } else if (IS_FN(code)) { | 62 | } else if (IS_FN(code)) { |
| 74 | fn_bits |= FN_BIT(code); | 63 | fn_bits |= FN_BIT(code); |
| 75 | } else if (IS_MOUSE(code)) { | 64 | } else if (IS_MOUSE(code)) { |
| 76 | if (code == MS_UP) mouse_y -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; | 65 | #ifdef MOUSEKEY_ENABLE |
| 77 | if (code == MS_DOWN) mouse_y += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; | 66 | mousekey_decode(code); |
| 78 | if (code == MS_LEFT) mouse_x -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; | 67 | #endif |
| 79 | if (code == MS_RGHT) mouse_x += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; | ||
| 80 | if (code == MS_BTN1) mouse_btn |= BIT_BTN1; | ||
| 81 | if (code == MS_BTN2) mouse_btn |= BIT_BTN2; | ||
| 82 | if (code == MS_BTN3) mouse_btn |= BIT_BTN3; | ||
| 83 | if (code == MS_BTN4) mouse_btn |= BIT_BTN4; | ||
| 84 | if (code == MS_BTN5) mouse_btn |= BIT_BTN5; | ||
| 85 | if (code == MS_WH_U) mouse_vwheel += 1; | ||
| 86 | if (code == MS_WH_D) mouse_vwheel -= 1; | ||
| 87 | if (code == MS_WH_L) mouse_hwheel -= 1; | ||
| 88 | if (code == MS_WH_R) mouse_hwheel += 1; | ||
| 89 | } | 68 | } |
| 90 | 69 | ||
| 91 | // audio control & system control | 70 | // audio control & system control |
| @@ -143,13 +122,39 @@ void proc_matrix(void) { | |||
| 143 | print("t: print timer count\n"); | 122 | print("t: print timer count\n"); |
| 144 | print("s: print status\n"); | 123 | print("s: print status\n"); |
| 145 | print("`: toggle protcol(boot/report)\n"); | 124 | print("`: toggle protcol(boot/report)\n"); |
| 146 | #ifdef NKRO_ENABLE | 125 | #ifdef USB_NKRO_ENABLE |
| 147 | print("n: toggle NKRO\n"); | 126 | print("n: toggle USB_NKRO\n"); |
| 148 | #endif | 127 | #endif |
| 149 | print("ESC: power down/wake up\n"); | 128 | print("ESC: power down/wake up\n"); |
| 129 | #ifdef PS2_MOUSE_ENABLE | ||
| 130 | print("1: ps2_mouse_init \n"); | ||
| 131 | print("2: ps2_mouse_read \n"); | ||
| 132 | #endif | ||
| 150 | _delay_ms(500); | 133 | _delay_ms(500); |
| 151 | print_enable = false; | 134 | print_enable = false; |
| 152 | break; | 135 | break; |
| 136 | #ifdef PS2_MOUSE_ENABLE | ||
| 137 | case KB_1: | ||
| 138 | usb_keyboard_clear_report(); | ||
| 139 | usb_keyboard_send(); | ||
| 140 | print_enable = true; | ||
| 141 | print("ps2_mouse_init...\n"); | ||
| 142 | _delay_ms(500); | ||
| 143 | ps2_mouse_init(); | ||
| 144 | break; | ||
| 145 | case KB_2: | ||
| 146 | usb_keyboard_clear_report(); | ||
| 147 | usb_keyboard_send(); | ||
| 148 | print_enable = true; | ||
| 149 | print("ps2_mouse_read[btn x y]: "); | ||
| 150 | _delay_ms(100); | ||
| 151 | ps2_mouse_read(); | ||
| 152 | phex(ps2_mouse_btn); print(" "); | ||
| 153 | phex(ps2_mouse_x); print(" "); | ||
| 154 | phex(ps2_mouse_y); print("\n"); | ||
| 155 | print("ps2_mouse_error_count: "); phex(ps2_mouse_error_count); print("\n"); | ||
| 156 | break; | ||
| 157 | #endif | ||
| 153 | case KB_B: // bootloader | 158 | case KB_B: // bootloader |
| 154 | usb_keyboard_clear_report(); | 159 | usb_keyboard_clear_report(); |
| 155 | usb_keyboard_send(); | 160 | usb_keyboard_send(); |
| @@ -243,29 +248,29 @@ void proc_matrix(void) { | |||
| 243 | print("usb_keyboard_protocol:"); phex(usb_keyboard_protocol); print("\n"); | 248 | print("usb_keyboard_protocol:"); phex(usb_keyboard_protocol); print("\n"); |
| 244 | print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n"); | 249 | print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n"); |
| 245 | print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n"); | 250 | print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n"); |
| 246 | print("mouse_protocol:"); phex(mouse_protocol); print("\n"); | 251 | print("usb_mouse_protocol:"); phex(usb_mouse_protocol); print("\n"); |
| 247 | if (usb_keyboard_nkro) print("NKRO: enabled\n"); else print("NKRO: disabled\n"); | 252 | if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n"); |
| 248 | _delay_ms(500); | 253 | _delay_ms(500); |
| 249 | break; | 254 | break; |
| 250 | case KB_GRV: | 255 | case KB_GRV: |
| 251 | usb_keyboard_clear_report(); | 256 | usb_keyboard_clear_report(); |
| 252 | usb_keyboard_send(); | 257 | usb_keyboard_send(); |
| 253 | usb_keyboard_protocol = !usb_keyboard_protocol; | 258 | usb_keyboard_protocol = !usb_keyboard_protocol; |
| 254 | mouse_protocol = !mouse_protocol; | 259 | usb_mouse_protocol = !usb_mouse_protocol; |
| 255 | print("keyboard protcol: "); | 260 | print("keyboard protcol: "); |
| 256 | if (usb_keyboard_protocol) print("report"); else print("boot"); | 261 | if (usb_keyboard_protocol) print("report"); else print("boot"); |
| 257 | print("\n"); | 262 | print("\n"); |
| 258 | print("mouse protcol: "); | 263 | print("mouse protcol: "); |
| 259 | if (mouse_protocol) print("report"); else print("boot"); | 264 | if (usb_mouse_protocol) print("report"); else print("boot"); |
| 260 | print("\n"); | 265 | print("\n"); |
| 261 | _delay_ms(1000); | 266 | _delay_ms(1000); |
| 262 | break; | 267 | break; |
| 263 | #ifdef NKRO_ENABLE | 268 | #ifdef USB_NKRO_ENABLE |
| 264 | case KB_N: | 269 | case KB_N: |
| 265 | usb_keyboard_clear_report(); | 270 | usb_keyboard_clear_report(); |
| 266 | usb_keyboard_send(); | 271 | usb_keyboard_send(); |
| 267 | usb_keyboard_nkro = !usb_keyboard_nkro; | 272 | usb_keyboard_nkro = !usb_keyboard_nkro; |
| 268 | if (usb_keyboard_nkro) print("NKRO: enabled\n"); else print("NKRO: disabled\n"); | 273 | if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n"); |
| 269 | _delay_ms(1000); | 274 | _delay_ms(1000); |
| 270 | break; | 275 | break; |
| 271 | #endif | 276 | #endif |
| @@ -283,25 +288,20 @@ void proc_matrix(void) { | |||
| 283 | } | 288 | } |
| 284 | 289 | ||
| 285 | 290 | ||
| 286 | // send mouse packet to host | ||
| 287 | if (mouse_x || mouse_y || mouse_vwheel || mouse_hwheel || mouse_btn != mouse_buttons) { | ||
| 288 | mouse_buttons = mouse_btn; | ||
| 289 | if (mouse_x && mouse_y) | ||
| 290 | usb_mouse_move(mouse_x*0.7, mouse_y*0.7, mouse_vwheel, mouse_hwheel); | ||
| 291 | else | ||
| 292 | usb_mouse_move(mouse_x, mouse_y, mouse_vwheel, mouse_hwheel); | ||
| 293 | usb_mouse_print(mouse_x, mouse_y, mouse_vwheel, mouse_hwheel); | ||
| 294 | |||
| 295 | // acceleration | ||
| 296 | _delay_ms(MOUSE_DELAY_MS); | ||
| 297 | mouse_repeat++; | ||
| 298 | } else { | ||
| 299 | mouse_repeat = 0; | ||
| 300 | } | ||
| 301 | |||
| 302 | |||
| 303 | // send key packet to host | ||
| 304 | if (modified) { | 291 | if (modified) { |
| 305 | usb_keyboard_send(); | 292 | usb_keyboard_send(); |
| 306 | } | 293 | } |
| 294 | |||
| 295 | #ifdef MOUSEKEY_ENABLE | ||
| 296 | // mouse keys | ||
| 297 | mousekey_usb_send(); | ||
| 298 | #endif | ||
| 299 | |||
| 300 | #ifdef PS2_MOUSE_ENABLE | ||
| 301 | // ps2 mouse | ||
| 302 | //if (ps2_mouse_error_count > 10) { | ||
| 303 | ps2_mouse_read(); | ||
| 304 | ps2_mouse_usb_send(); | ||
| 305 | //} | ||
| 306 | #endif | ||
| 307 | } | 307 | } |
diff --git a/macway/Makefile b/macway/Makefile index b69b2d2e4..fffe1ad54 100644 --- a/macway/Makefile +++ b/macway/Makefile | |||
| @@ -39,12 +39,6 @@ | |||
| 39 | # To rebuild project do "make clean" then "make all". | 39 | # To rebuild project do "make clean" then "make all". |
| 40 | #---------------------------------------------------------------------------- | 40 | #---------------------------------------------------------------------------- |
| 41 | 41 | ||
| 42 | VENDOR_ID = 0xFEED | ||
| 43 | PRODUCT_ID = 0xBEEF | ||
| 44 | MANUFACTURER = 't.m.k.' | ||
| 45 | PRODUCT = 't.m.k. Macway mod' | ||
| 46 | DESCRIPTION = 't.m.k. firmware for Macway mod' | ||
| 47 | |||
| 48 | # Target file name (without extension). | 42 | # Target file name (without extension). |
| 49 | TARGET = tmk_macway | 43 | TARGET = tmk_macway |
| 50 | 44 | ||
| @@ -74,4 +68,11 @@ MCU = atmega32u4 # Teensy 2.0 | |||
| 74 | # examples use this variable to calculate timings. Do not add a "UL" here. | 68 | # examples use this variable to calculate timings. Do not add a "UL" here. |
| 75 | F_CPU = 16000000 | 69 | F_CPU = 16000000 |
| 76 | 70 | ||
| 71 | |||
| 72 | # Options | ||
| 73 | # comment out to disable | ||
| 74 | #USB_NKRO_ENABLE = yes | ||
| 75 | MOUSEKEY_ENABLE = yes | ||
| 76 | PS2_MOUSE_ENABLE = yes | ||
| 77 | |||
| 77 | include $(COMMON_DIR)/Makefile.common | 78 | include $(COMMON_DIR)/Makefile.common |
diff --git a/macway/config.h b/macway/config.h new file mode 100644 index 000000000..de9fc78b1 --- /dev/null +++ b/macway/config.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #ifndef CONFIG_H | ||
| 2 | #define CONFIG_H | ||
| 3 | |||
| 4 | #define VENDOR_ID 0xFEED | ||
| 5 | #define PRODUCT_ID 0xBEEF | ||
| 6 | #define MANUFACTURER t.m.k. | ||
| 7 | #define PRODUCT Macway mod | ||
| 8 | #define DESCRIPTION t.m.k. keyboard firmware for Macway mod | ||
| 9 | |||
| 10 | /* controller */ | ||
| 11 | #include "controller_teensy.h" | ||
| 12 | |||
| 13 | /* matrix size */ | ||
| 14 | #define MATRIX_ROWS 9 | ||
| 15 | #define MATRIX_COLS 8 | ||
| 16 | |||
| 17 | /* USB NKey Rollover */ | ||
| 18 | #ifdef USB_NKRO_ENABLE | ||
| 19 | #endif | ||
| 20 | |||
| 21 | /* mouse keys */ | ||
| 22 | #ifdef MOUSEKEY_ENABLE | ||
| 23 | # define MOUSEKEY_DELAY_TIME 192 | ||
| 24 | #endif | ||
| 25 | |||
| 26 | /* PS/2 mouse */ | ||
| 27 | #ifdef PS2_MOUSE_ENABLE | ||
| 28 | # define PS2_CLOCK_PORT PORTF | ||
| 29 | # define PS2_CLOCK_PIN PINF | ||
| 30 | # define PS2_CLOCK_DDR DDRF | ||
| 31 | # define PS2_CLOCK_BIT 0 | ||
| 32 | # define PS2_DATA_PORT PORTF | ||
| 33 | # define PS2_DATA_PIN PINF | ||
| 34 | # define PS2_DATA_DDR DDRF | ||
| 35 | # define PS2_DATA_BIT 1 | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #endif | ||
diff --git a/macway/controller.h b/macway/controller.h deleted file mode 100644 index 22fd694ff..000000000 --- a/macway/controller.h +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | #ifndef CONTROLLER_H | ||
| 2 | #define CONTROLLER_H 1 | ||
| 3 | |||
| 4 | #include "controller_teensy.h" | ||
| 5 | |||
| 6 | |||
| 7 | /* matrix row size */ | ||
| 8 | #define MATRIX_ROWS 9 | ||
| 9 | /* matrix column size */ | ||
| 10 | #define MATRIX_COLS 8 | ||
| 11 | |||
| 12 | #endif | ||
diff --git a/macway/keymap.c b/macway/keymap.c index e78d6b7d1..0e71e3f76 100644 --- a/macway/keymap.c +++ b/macway/keymap.c | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | #include "print.h" | 10 | #include "print.h" |
| 11 | #include "debug.h" | 11 | #include "debug.h" |
| 12 | #include "util.h" | 12 | #include "util.h" |
| 13 | #include "controller.h" | ||
| 14 | #include "keymap_skel.h" | 13 | #include "keymap_skel.h" |
| 15 | 14 | ||
| 16 | 15 | ||
| @@ -40,9 +39,9 @@ static const uint8_t PROGMEM fn_layer[] = { 0, 1, 2, 3, 4, 0, 2, 3 }; | |||
| 40 | static const uint8_t PROGMEM fn_keycode[] = { | 39 | static const uint8_t PROGMEM fn_keycode[] = { |
| 41 | KB_NO, // FN_0 [NOT USED] | 40 | KB_NO, // FN_0 [NOT USED] |
| 42 | KB_NO, // FN_1 layer 1 | 41 | KB_NO, // FN_1 layer 1 |
| 43 | KB_QUOTE, // FN_2 layer 2 | 42 | KB_SLSH, // FN_2 layer 2 |
| 44 | KB_SCOLON, // FN_3 layer 3 | 43 | KB_SCLN, // FN_3 layer 3 |
| 45 | KB_SPACE, // FN_4 layer 4 | 44 | KB_SPC, // FN_4 layer 4 |
| 46 | KB_NO, // FN_5 [NOT USED] | 45 | KB_NO, // FN_5 [NOT USED] |
| 47 | KB_NO, // FN_6 layer 2 | 46 | KB_NO, // FN_6 layer 2 |
| 48 | KB_NO // FN_7 layer 3 | 47 | KB_NO // FN_7 layer 3 |
| @@ -55,38 +54,38 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 55 | * |-----------------------------------------------------------| | 54 | * |-----------------------------------------------------------| |
| 56 | * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | | 55 | * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | |
| 57 | * |-----------------------------------------------------' | | 56 | * |-----------------------------------------------------' | |
| 58 | * |Contro| A| S| D| F| G| H| J| K| L|Fn3|Fn2|Return | | 57 | * |Contro| A| S| D| F| G| H| J| K| L|Fn3| '|Return | |
| 59 | * |-----------------------------------------------------------| | 58 | * |-----------------------------------------------------------| |
| 60 | * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1| | 59 | * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1| |
| 61 | * |-----------------------------------------------------------| | 60 | * |-----------------------------------------------------------| |
| 62 | * |Fn7|Gui |Alt |Fn4 |Fn6 |\ |` | | | | 61 | * |Fn7|Gui |Alt |Fn4 |Alt |Gui|Fn6|Fn6|Ctr| |
| 63 | * `-----------------------------------------------------------' | 62 | * `-----------------------------------------------------------' |
| 64 | */ | 63 | */ |
| 65 | 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, \ | 64 | 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, \ |
| 66 | 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, \ | 65 | 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, \ |
| 67 | 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, \ | 66 | 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, \ |
| 68 | 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, \ | 67 | 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, \ |
| 69 | FN_7, KB_LGUI,KB_LALT,FN_4, FN_6, KB_BSLS,KB_GRV, KB_NO, KB_NO), | 68 | FN_7, KB_LGUI,KB_LALT,FN_4, KB_RALT,KB_RGUI,FN_6, FN_6, KB_RCTL), |
| 70 | 69 | ||
| 71 | 70 | ||
| 72 | /* Layer 1: HHKB mode (HHKB Fn) | 71 | /* Layer 1: HHKB mode (HHKB Fn) |
| 73 | * ,-----------------------------------------------------------. | 72 | * ,-----------------------------------------------------------. |
| 74 | * |Pow| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | | 73 | * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | |
| 75 | * |-----------------------------------------------------------| | 74 | * |-----------------------------------------------------------| |
| 76 | * |Caps | | | | | | | |Psc|Slk|Pus|Up | | | | 75 | * |Caps | | | | | | | |Psc|Slk|Pus|Up | | | |
| 77 | * |-----------------------------------------------------' | | 76 | * |-----------------------------------------------------' | |
| 78 | * |Contro| | | | | | *| /|Hom|PgU|Lef|Rig|Enter | | 77 | * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter | |
| 79 | * |-----------------------------------------------------------| | 78 | * |-----------------------------------------------------------| |
| 80 | * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx| | 79 | * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx| |
| 81 | * |-----------------------------------------------------------| | 80 | * |-----------------------------------------------------------| |
| 82 | * | |Gui |Alt | |Alt | | | | | | 81 | * | |Gui |Alt | |Alt |Gui| | |Ctr| |
| 83 | * `-----------------------------------------------------------' | 82 | * `-----------------------------------------------------------' |
| 84 | */ | 83 | */ |
| 85 | 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, \ | 84 | 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, \ |
| 86 | 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, \ | 85 | 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, \ |
| 87 | 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, \ | 86 | 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, \ |
| 88 | 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, \ | 87 | 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, \ |
| 89 | KB_NO, KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO), | 88 | KB_NO, KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_NO, KB_NO, KB_NO, KB_RCTL), |
| 90 | 89 | ||
| 91 | 90 | ||
| 92 | /* Layer 2: Vi mode (Quote/Rmeta) | 91 | /* Layer 2: Vi mode (Quote/Rmeta) |
| @@ -95,27 +94,27 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 95 | * |-----------------------------------------------------------| | 94 | * |-----------------------------------------------------------| |
| 96 | * | \ |Hom|PgD|Up |PgU|End|Hom|PgD|PgU|End| | | | | | 95 | * | \ |Hom|PgD|Up |PgU|End|Hom|PgD|PgU|End| | | | | |
| 97 | * |-----------------------------------------------------' | | 96 | * |-----------------------------------------------------' | |
| 98 | * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| |xxx| \ | | 97 | * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | | \ | |
| 99 | * |-----------------------------------------------------------| | 98 | * |-----------------------------------------------------------| |
| 100 | * |Shift | | | | | |Hom|PgD|PgU|End| |Shift | | | 99 | * |Shift | | | | | |Hom|PgD|PgU|End|xxx|Shift | | |
| 101 | * |-----------------------------------------------------------| | 100 | * |-----------------------------------------------------------| |
| 102 | * | |Gui |Alt |Space |xxxxx| | | | | | 101 | * | |Gui |Alt |Space |Alt |Gui|Fn6|Fn6|Ctr| |
| 103 | * `-----------------------------------------------------------' | 102 | * `-----------------------------------------------------------' |
| 104 | */ | 103 | */ |
| 105 | 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, \ | 104 | 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, \ |
| 106 | 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, \ | 105 | 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, \ |
| 107 | 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, \ | 106 | 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, \ |
| 108 | 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, \ | 107 | 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, \ |
| 109 | KB_NO, KB_LGUI,KB_LALT,KB_SPC, FN_6, KB_NO, KB_NO, KB_NO, KB_NO), | 108 | KB_NO, KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_RGUI,FN_6, FN_6, KB_RCTL), |
| 110 | 109 | ||
| 111 | 110 | ||
| 112 | /* Layer 3: Mouse mode (Semicolon) | 111 | /* Layer 3: Mouse mode (Semicolon) |
| 113 | * ,-------------------------------------------------------- --. | 112 | * ,-----------------------------------------------------------. |
| 114 | * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | | 113 | * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| ` | |
| 115 | * |-----------------------------------------------------------| | 114 | * |-----------------------------------------------------------| |
| 116 | * |Tab |MwL|MwD|McU|MwU|MwR|MwL|MwD|MwU|MwR| | | | | | 115 | * | \ |MwL|MwD|McU|MwU|MwR|MwL|MwD|MwU|MwR| | | | | |
| 117 | * |-----------------------------------------------------' | | 116 | * |-----------------------------------------------------' | |
| 118 | * |Contro| |McL|McD|McR| |McL|McD|McU|McR|xxx| |Return | | 117 | * |Contro| |McL|McD|McR| |McL|McD|McU|McR|xxx| | \ | |
| 119 | * |-----------------------------------------------------------| | 118 | * |-----------------------------------------------------------| |
| 120 | * |Shift | | |Mb1|Mb2|Mb3|Mb2|Mb1| | | |Shift | | | 119 | * |Shift | | |Mb1|Mb2|Mb3|Mb2|Mb1| | | |Shift | | |
| 121 | * |-----------------------------------------------------------| | 120 | * |-----------------------------------------------------------| |
| @@ -123,9 +122,9 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 123 | * `-----------------------------------------------------------' | 122 | * `-----------------------------------------------------------' |
| 124 | * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel | 123 | * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel |
| 125 | */ | 124 | */ |
| 126 | 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, \ | 125 | 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, \ |
| 127 | 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, \ | 126 | 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, \ |
| 128 | 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, \ | 127 | 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, \ |
| 129 | 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, \ | 128 | 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, \ |
| 130 | FN_7, KB_LGUI,KB_LALT,MS_BTN1,KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO), | 129 | FN_7, KB_LGUI,KB_LALT,MS_BTN1,KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO), |
| 131 | 130 | ||
| @@ -140,14 +139,14 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 140 | * |-----------------------------------------------------------| | 139 | * |-----------------------------------------------------------| |
| 141 | * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | | | 140 | * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | | |
| 142 | * |-----------------------------------------------------------| | 141 | * |-----------------------------------------------------------| |
| 143 | * | |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxx|Alt | | | | | | 142 | * | |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxx|Alt |Gui| | |Ctr| |
| 144 | * `-----------------------------------------------------------' | 143 | * `-----------------------------------------------------------' |
| 145 | */ | 144 | */ |
| 146 | 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, \ | 145 | 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, \ |
| 147 | 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, \ | 146 | 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, \ |
| 148 | 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, \ | 147 | 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, \ |
| 149 | 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, \ | 148 | 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, \ |
| 150 | KB_NO, KB_LGUI,KB_LALT,FN_4, KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO), | 149 | KB_NO, KB_LGUI,KB_LALT,FN_4, KB_RALT,KB_RGUI,KB_NO, KB_NO, KB_RCTL), |
| 151 | }; | 150 | }; |
| 152 | 151 | ||
| 153 | 152 | ||
| @@ -168,5 +167,6 @@ uint8_t keymap_fn_keycode(uint8_t fn_bits) | |||
| 168 | 167 | ||
| 169 | bool keymap_is_special_mode(uint8_t fn_bits) | 168 | bool keymap_is_special_mode(uint8_t fn_bits) |
| 170 | { | 169 | { |
| 171 | return (usb_keyboard_mods == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI)); | 170 | //return (usb_keyboard_mods == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI)); |
| 171 | return (usb_keyboard_mods == (BIT_RSHIFT)); | ||
| 172 | } | 172 | } |
diff --git a/macway/matrix.c b/macway/matrix.c index c2b3fb8b2..7c2a42105 100644 --- a/macway/matrix.c +++ b/macway/matrix.c | |||
| @@ -7,16 +7,10 @@ | |||
| 7 | #include <util/delay.h> | 7 | #include <util/delay.h> |
| 8 | #include "print.h" | 8 | #include "print.h" |
| 9 | #include "util.h" | 9 | #include "util.h" |
| 10 | #include "controller.h" | ||
| 11 | #include "matrix_skel.h" | 10 | #include "matrix_skel.h" |
| 12 | 11 | ||
| 13 | // matrix is active low. (key on: 0/key off: 1) | ||
| 14 | // row: Hi-Z(unselected)/low output(selected) | ||
| 15 | // PD0, PC7, PD7, PF6, PD6, PD1, PD2, PC6, PF7 | ||
| 16 | // col: input w/pullup | ||
| 17 | // PB0-PB7 | ||
| 18 | 12 | ||
| 19 | // matrix state buffer | 13 | // matrix state buffer (key on: 1/key off: 0) |
| 20 | static uint8_t *matrix; | 14 | static uint8_t *matrix; |
| 21 | static uint8_t *matrix_prev; | 15 | static uint8_t *matrix_prev; |
| 22 | static uint8_t _matrix0[MATRIX_ROWS]; | 16 | static uint8_t _matrix0[MATRIX_ROWS]; |
| @@ -45,6 +39,7 @@ void matrix_init(void) | |||
| 45 | { | 39 | { |
| 46 | // initialize row and col | 40 | // initialize row and col |
| 47 | unselect_rows(); | 41 | unselect_rows(); |
| 42 | // Input with pull-up(DDR:0, PORT:1) | ||
| 48 | DDRB = 0x00; | 43 | DDRB = 0x00; |
| 49 | PORTB = 0xFF; | 44 | PORTB = 0xFF; |
| 50 | 45 | ||
| @@ -64,11 +59,12 @@ int matrix_scan(void) | |||
| 64 | matrix = tmp; | 59 | matrix = tmp; |
| 65 | 60 | ||
| 66 | for (int i = 0; i < MATRIX_ROWS; i++) { | 61 | for (int i = 0; i < MATRIX_ROWS; i++) { |
| 62 | unselect_rows(); | ||
| 67 | select_row(i); | 63 | select_row(i); |
| 68 | _delay_us(30); // without this wait read unstable value. | 64 | _delay_us(30); // without this wait read unstable value. |
| 69 | matrix[i] = ~read_col(); | 65 | matrix[i] = ~read_col(); |
| 70 | unselect_rows(); | ||
| 71 | } | 66 | } |
| 67 | unselect_rows(); | ||
| 72 | return 1; | 68 | return 1; |
| 73 | } | 69 | } |
| 74 | 70 | ||
| @@ -145,88 +141,56 @@ static uint8_t read_col(void) | |||
| 145 | 141 | ||
| 146 | static void unselect_rows(void) | 142 | static void unselect_rows(void) |
| 147 | { | 143 | { |
| 148 | DDRD = 0x00; | 144 | // Hi-Z(DDR:0, PORT:0) to unselect |
| 149 | PORTD = 0x00; | 145 | DDRC &= ~0b11000000; // PC: 7,6 |
| 150 | DDRC = 0x00; | 146 | PORTC &= ~0b11000000; |
| 151 | PORTC = 0x00; | 147 | DDRD &= ~0b11000111; // PD: 7,6,2,1,0 |
| 152 | DDRF = 0x00; | 148 | PORTD &= ~0b11000111; |
| 153 | PORTF = 0x00; | 149 | DDRF &= ~0b11000000; // PF: 7,6 |
| 150 | PORTF &= ~0b11000000; | ||
| 154 | } | 151 | } |
| 155 | 152 | ||
| 156 | static void select_row(uint8_t row) | 153 | static void select_row(uint8_t row) |
| 157 | { | 154 | { |
| 155 | // Output low(DDR:1, PORT:0) to select | ||
| 156 | // row: 0 1 2 3 4 5 6 7 8 | ||
| 157 | // pin: PD0, PC7, PD7, PF6, PD6, PD1, PD2, PC6, PF7 | ||
| 158 | switch (row) { | 158 | switch (row) { |
| 159 | case 0: | 159 | case 0: |
| 160 | DDRD = (1<<0); | 160 | DDRD |= (1<<0); |
| 161 | PORTD = 0x00; | 161 | PORTD &= ~(1<<0); |
| 162 | DDRC = 0x00; | ||
| 163 | PORTC = 0x00; | ||
| 164 | DDRF = 0x00; | ||
| 165 | PORTF = 0x00; | ||
| 166 | break; | 162 | break; |
| 167 | case 1: | 163 | case 1: |
| 168 | DDRD = 0x00; | 164 | DDRC |= (1<<7); |
| 169 | PORTD = 0x00; | 165 | PORTC &= ~(1<<7); |
| 170 | DDRC = (1<<7); | ||
| 171 | PORTC = 0x00; | ||
| 172 | DDRF = 0x00; | ||
| 173 | PORTF = 0x00; | ||
| 174 | break; | 166 | break; |
| 175 | case 2: | 167 | case 2: |
| 176 | DDRD = (1<<7); | 168 | DDRD |= (1<<7); |
| 177 | PORTD = 0x00; | 169 | PORTD &= ~(1<<7); |
| 178 | DDRC = 0x00; | ||
| 179 | PORTC = 0x00; | ||
| 180 | DDRF = 0x00; | ||
| 181 | PORTF = 0x00; | ||
| 182 | break; | 170 | break; |
| 183 | case 3: | 171 | case 3: |
| 184 | DDRD = 0x00; | 172 | DDRF |= (1<<6); |
| 185 | PORTD = 0x00; | 173 | PORTF &= ~(1<<6); |
| 186 | DDRC = 0x00; | ||
| 187 | PORTC = 0x00; | ||
| 188 | DDRF = (1<<6); | ||
| 189 | PORTF = 0x00; | ||
| 190 | break; | 174 | break; |
| 191 | case 4: | 175 | case 4: |
| 192 | DDRD = (1<<6); | 176 | DDRD |= (1<<6); |
| 193 | PORTD = 0x00; | 177 | PORTD &= ~(1<<6); |
| 194 | DDRC = 0x00; | ||
| 195 | PORTC = 0x00; | ||
| 196 | DDRF = 0x00; | ||
| 197 | PORTF = 0x00; | ||
| 198 | break; | 178 | break; |
| 199 | case 5: | 179 | case 5: |
| 200 | DDRD = (1<<1); | 180 | DDRD |= (1<<1); |
| 201 | PORTD = 0x00; | 181 | PORTD &= ~(1<<1); |
| 202 | DDRC = 0x00; | ||
| 203 | PORTC = 0x00; | ||
| 204 | DDRF = 0x00; | ||
| 205 | PORTF = 0x00; | ||
| 206 | break; | 182 | break; |
| 207 | case 6: | 183 | case 6: |
| 208 | DDRD = (1<<2); | 184 | DDRD |= (1<<2); |
| 209 | PORTD = 0x00; | 185 | PORTD &= ~(1<<2); |
| 210 | DDRC = 0x00; | ||
| 211 | PORTC = 0x00; | ||
| 212 | DDRF = 0x00; | ||
| 213 | PORTF = 0x00; | ||
| 214 | break; | 186 | break; |
| 215 | case 7: | 187 | case 7: |
| 216 | DDRD = 0x00; | 188 | DDRC |= (1<<6); |
| 217 | PORTD = 0x00; | 189 | PORTC &= ~(1<<6); |
| 218 | DDRC = (1<<6); | ||
| 219 | PORTC = 0x00; | ||
| 220 | DDRF = 0x00; | ||
| 221 | PORTF = 0x00; | ||
| 222 | break; | 190 | break; |
| 223 | case 8: | 191 | case 8: |
| 224 | DDRD = 0x00; | 192 | DDRF |= (1<<7); |
| 225 | PORTD = 0x00; | 193 | PORTF &= ~(1<<7); |
| 226 | DDRC = 0x00; | ||
| 227 | PORTC = 0x00; | ||
| 228 | DDRF = (1<<7); | ||
| 229 | PORTF = 0x00; | ||
| 230 | break; | 194 | break; |
| 231 | } | 195 | } |
| 232 | } | 196 | } |
diff --git a/mousekey.c b/mousekey.c new file mode 100644 index 000000000..be454e13e --- /dev/null +++ b/mousekey.c | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | #include <stdint.h> | ||
| 2 | #include <util/delay.h> | ||
| 3 | #include "usb_keycodes.h" | ||
| 4 | #include "usb_mouse.h" | ||
| 5 | #include "mousekey.h" | ||
| 6 | |||
| 7 | |||
| 8 | static int8_t mousekey_x = 0; | ||
| 9 | static int8_t mousekey_y = 0; | ||
| 10 | static int8_t mousekey_v = 0; | ||
| 11 | static int8_t mousekey_h = 0; | ||
| 12 | static uint8_t mousekey_btn = 0; | ||
| 13 | static uint8_t mousekey_btn_prev = 0; | ||
| 14 | static uint8_t mousekey_repeat = 0; | ||
| 15 | |||
| 16 | |||
| 17 | /* | ||
| 18 | * TODO: fix acceleration algorithm | ||
| 19 | * see wikipedia http://en.wikipedia.org/wiki/Mouse_keys | ||
| 20 | */ | ||
| 21 | #ifndef MOUSEKEY_DELAY_TIME | ||
| 22 | # define MOUSEKEY_DELAY_TIME 255 | ||
| 23 | #endif | ||
| 24 | |||
| 25 | |||
| 26 | static inline uint8_t move_unit(void) | ||
| 27 | { | ||
| 28 | return 10 + (mousekey_repeat < 50 ? mousekey_repeat/5 : 10); | ||
| 29 | } | ||
| 30 | |||
| 31 | void mousekey_decode(uint8_t code) | ||
| 32 | { | ||
| 33 | if (code == MS_UP) mousekey_y -= move_unit(); | ||
| 34 | else if (code == MS_DOWN) mousekey_y += move_unit(); | ||
| 35 | else if (code == MS_LEFT) mousekey_x -= move_unit(); | ||
| 36 | else if (code == MS_RGHT) mousekey_x += move_unit(); | ||
| 37 | else if (code == MS_BTN1) mousekey_btn |= MOUSE_BTN1; | ||
| 38 | else if (code == MS_BTN2) mousekey_btn |= MOUSE_BTN2; | ||
| 39 | else if (code == MS_BTN3) mousekey_btn |= MOUSE_BTN3; | ||
| 40 | else if (code == MS_BTN4) mousekey_btn |= MOUSE_BTN4; | ||
| 41 | else if (code == MS_BTN5) mousekey_btn |= MOUSE_BTN5; | ||
| 42 | else if (code == MS_WH_U) mousekey_v += 1; | ||
| 43 | else if (code == MS_WH_D) mousekey_v -= 1; | ||
| 44 | else if (code == MS_WH_L) mousekey_h -= 1; | ||
| 45 | else if (code == MS_WH_R) mousekey_h += 1; | ||
| 46 | } | ||
| 47 | |||
| 48 | bool mousekey_changed(void) | ||
| 49 | { | ||
| 50 | return (mousekey_x || mousekey_y || mousekey_v || mousekey_h || mousekey_btn != mousekey_btn_prev); | ||
| 51 | } | ||
| 52 | |||
| 53 | void mousekey_usb_send(void) | ||
| 54 | { | ||
| 55 | if (mousekey_changed()) { | ||
| 56 | mousekey_btn_prev = mousekey_btn; | ||
| 57 | if (mousekey_x && mousekey_y) | ||
| 58 | usb_mouse_send(mousekey_x*0.7, mousekey_y*0.7, mousekey_v, mousekey_h, mousekey_btn); | ||
| 59 | else | ||
| 60 | usb_mouse_send(mousekey_x, mousekey_y, mousekey_v, mousekey_h, mousekey_btn); | ||
| 61 | |||
| 62 | usb_mouse_print(mousekey_x, mousekey_y, mousekey_v, mousekey_h, mousekey_btn); | ||
| 63 | |||
| 64 | _delay_ms(MOUSEKEY_DELAY_TIME >> (mousekey_repeat < 5 ? mousekey_repeat : 4)); | ||
| 65 | mousekey_repeat++; | ||
| 66 | } else { | ||
| 67 | mousekey_repeat = 0; | ||
| 68 | } | ||
| 69 | mousekey_x = 0; | ||
| 70 | mousekey_y = 0; | ||
| 71 | mousekey_v = 0; | ||
| 72 | mousekey_h = 0; | ||
| 73 | mousekey_btn = 0; | ||
| 74 | } | ||
diff --git a/mousekey.h b/mousekey.h new file mode 100644 index 000000000..c5d4561cd --- /dev/null +++ b/mousekey.h | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | #ifndef MOUSEKEY_H | ||
| 2 | #define MOUSEKEY_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | |||
| 6 | void mousekey_decode(uint8_t code); | ||
| 7 | bool mousekey_changed(void); | ||
| 8 | void mousekey_usb_send(void); | ||
| 9 | |||
| 10 | #endif | ||
| 11 | |||
| @@ -0,0 +1,248 @@ | |||
| 1 | /* | ||
| 2 | Copyright (c) 2010 Jun WAKO <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This software is licensed with a Modified BSD License. | ||
| 5 | All of this is supposed to be Free Software, Open Source, DFSG-free, | ||
| 6 | GPL-compatible, and OK to use in both free and proprietary applications. | ||
| 7 | Additions and corrections to this file are welcome. | ||
| 8 | |||
| 9 | |||
| 10 | Redistribution and use in source and binary forms, with or without | ||
| 11 | modification, are permitted provided that the following conditions are met: | ||
| 12 | |||
| 13 | * Redistributions of source code must retain the above copyright | ||
| 14 | notice, this list of conditions and the following disclaimer. | ||
| 15 | |||
| 16 | * Redistributions in binary form must reproduce the above copyright | ||
| 17 | notice, this list of conditions and the following disclaimer in | ||
| 18 | the documentation and/or other materials provided with the | ||
| 19 | distribution. | ||
| 20 | |||
| 21 | * Neither the name of the copyright holders nor the names of | ||
| 22 | contributors may be used to endorse or promote products derived | ||
| 23 | from this software without specific prior written permission. | ||
| 24 | |||
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 27 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 28 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 29 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 30 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 31 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 33 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 35 | POSSIBILITY OF SUCH DAMAGE. | ||
| 36 | */ | ||
| 37 | #include <stdbool.h> | ||
| 38 | #include <avr/io.h> | ||
| 39 | #include <util/delay.h> | ||
| 40 | #include "ps2.h" | ||
| 41 | #include "print.h" | ||
| 42 | #include "debug.h" | ||
| 43 | |||
| 44 | |||
| 45 | static inline void clock_lo(void); | ||
| 46 | static inline void clock_hi(void); | ||
| 47 | static inline bool clock_in(void); | ||
| 48 | static inline void data_lo(void); | ||
| 49 | static inline void data_hi(void); | ||
| 50 | static inline bool data_in(void); | ||
| 51 | static inline uint16_t wait_clock_lo(uint16_t us); | ||
| 52 | static inline uint16_t wait_clock_hi(uint16_t us); | ||
| 53 | static inline uint16_t wait_data_lo(uint16_t us); | ||
| 54 | static inline uint16_t wait_data_hi(uint16_t us); | ||
| 55 | |||
| 56 | |||
| 57 | /* | ||
| 58 | Primitive PS/2 Library for AVR | ||
| 59 | ============================== | ||
| 60 | Host side is only supported now. | ||
| 61 | |||
| 62 | |||
| 63 | I/O control | ||
| 64 | ----------- | ||
| 65 | High state is asserted by input with pull up. | ||
| 66 | |||
| 67 | |||
| 68 | PS/2 References | ||
| 69 | --------------- | ||
| 70 | http://www.computer-engineering.org/ps2protocol/ | ||
| 71 | http://www.mcamafia.de/pdf/ibm_hitrc07.pdf | ||
| 72 | */ | ||
| 73 | |||
| 74 | |||
| 75 | #define WAIT(stat, us, err) do { \ | ||
| 76 | if (!wait_##stat(us)) { \ | ||
| 77 | ps2_error = err; \ | ||
| 78 | goto ERROR; \ | ||
| 79 | } \ | ||
| 80 | } while (0) | ||
| 81 | |||
| 82 | #define WAIT_NORETRY(stat, us, err) do { \ | ||
| 83 | if (!wait_##stat(us)) { \ | ||
| 84 | ps2_error = err; \ | ||
| 85 | return 0; \ | ||
| 86 | } \ | ||
| 87 | } while (0) | ||
| 88 | |||
| 89 | |||
| 90 | uint8_t ps2_error = PS2_ERR_NONE; | ||
| 91 | |||
| 92 | |||
| 93 | void ps2_host_init(void) | ||
| 94 | { | ||
| 95 | /* inhibit */ | ||
| 96 | clock_lo(); | ||
| 97 | data_hi(); | ||
| 98 | } | ||
| 99 | |||
| 100 | uint8_t ps2_host_send(uint8_t data) | ||
| 101 | { | ||
| 102 | bool parity = true; | ||
| 103 | ps2_error = 0; | ||
| 104 | |||
| 105 | /* request to send */ | ||
| 106 | clock_lo(); | ||
| 107 | data_lo(); | ||
| 108 | _delay_us(100); | ||
| 109 | /* start bit [1] */ | ||
| 110 | clock_hi(); | ||
| 111 | WAIT(clock_lo, 15000, 1); | ||
| 112 | /* data [2-9] */ | ||
| 113 | for (uint8_t i = 0; i < 8; i++) { | ||
| 114 | if (data&(1<<i)) { | ||
| 115 | parity = !parity; | ||
| 116 | data_hi(); | ||
| 117 | } else { | ||
| 118 | data_lo(); | ||
| 119 | } | ||
| 120 | WAIT(clock_hi, 50, 2); | ||
| 121 | WAIT(clock_lo, 50, 3); | ||
| 122 | } | ||
| 123 | /* parity [10] */ | ||
| 124 | if (parity) { data_hi(); } else { data_lo(); } | ||
| 125 | WAIT(clock_hi, 50, 4); | ||
| 126 | WAIT(clock_lo, 50, 5); | ||
| 127 | /* stop bit [11] */ | ||
| 128 | data_hi(); | ||
| 129 | /* ack [12] */ | ||
| 130 | WAIT(data_lo, 50, 6); | ||
| 131 | WAIT(clock_lo, 50, 7); | ||
| 132 | WAIT(clock_hi, 50, 8); | ||
| 133 | WAIT(data_hi, 50, 9); | ||
| 134 | |||
| 135 | /* inhibit device to send */ | ||
| 136 | clock_lo(); | ||
| 137 | |||
| 138 | return 1; | ||
| 139 | ERROR: | ||
| 140 | return 0; | ||
| 141 | } | ||
| 142 | |||
| 143 | uint8_t ps2_host_recv(void) | ||
| 144 | { | ||
| 145 | uint8_t data = 0; | ||
| 146 | bool parity = true; | ||
| 147 | ps2_error = 0; | ||
| 148 | |||
| 149 | /* cancel to sync */ | ||
| 150 | clock_lo(); | ||
| 151 | _delay_us(100); | ||
| 152 | |||
| 153 | /* release lines(idle state) */ | ||
| 154 | clock_hi(); | ||
| 155 | data_hi(); | ||
| 156 | |||
| 157 | /* start bit [1] */ | ||
| 158 | WAIT(clock_lo, 20000, 1); | ||
| 159 | WAIT(data_lo, 1, 2); | ||
| 160 | WAIT(clock_hi, 50, 3); | ||
| 161 | |||
| 162 | /* data [2-9] */ | ||
| 163 | for (uint8_t i = 0; i < 8; i++) { | ||
| 164 | WAIT(clock_lo, 50, 4); | ||
| 165 | if (data_in()) { | ||
| 166 | parity = !parity; | ||
| 167 | data |= (1<<i); | ||
| 168 | } | ||
| 169 | WAIT(clock_hi, 50, 5); | ||
| 170 | } | ||
| 171 | |||
| 172 | /* parity [10] */ | ||
| 173 | WAIT(clock_lo, 50, 6); | ||
| 174 | if (data_in() != parity) { | ||
| 175 | ps2_error = PS2_ERR_PARITY; | ||
| 176 | goto ERROR; | ||
| 177 | } | ||
| 178 | WAIT(clock_hi, 50, 7); | ||
| 179 | |||
| 180 | /* stop bit [11] */ | ||
| 181 | WAIT(clock_lo, 50, 8); | ||
| 182 | WAIT(data_hi, 1, 9); | ||
| 183 | WAIT(clock_hi, 50, 10); | ||
| 184 | |||
| 185 | /* inhibit device to send */ | ||
| 186 | clock_lo(); | ||
| 187 | |||
| 188 | return data; | ||
| 189 | ERROR: | ||
| 190 | return 0; | ||
| 191 | } | ||
| 192 | |||
| 193 | |||
| 194 | static inline void clock_lo() | ||
| 195 | { | ||
| 196 | PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT); | ||
| 197 | PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT); | ||
| 198 | } | ||
| 199 | static inline void clock_hi() | ||
| 200 | { | ||
| 201 | /* input with pull up */ | ||
| 202 | PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); | ||
| 203 | PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT); | ||
| 204 | } | ||
| 205 | static inline bool clock_in() | ||
| 206 | { | ||
| 207 | PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); | ||
| 208 | PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT); | ||
| 209 | return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT); | ||
| 210 | } | ||
| 211 | static inline void data_lo() | ||
| 212 | { | ||
| 213 | PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT); | ||
| 214 | PS2_DATA_DDR |= (1<<PS2_DATA_BIT); | ||
| 215 | } | ||
| 216 | static inline void data_hi() | ||
| 217 | { | ||
| 218 | /* input with pull up */ | ||
| 219 | PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); | ||
| 220 | PS2_DATA_PORT |= (1<<PS2_DATA_BIT); | ||
| 221 | } | ||
| 222 | static inline bool data_in() | ||
| 223 | { | ||
| 224 | PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); | ||
| 225 | PS2_DATA_PORT |= (1<<PS2_DATA_BIT); | ||
| 226 | return PS2_DATA_PIN&(1<<PS2_DATA_BIT); | ||
| 227 | } | ||
| 228 | |||
| 229 | static inline uint16_t wait_clock_lo(uint16_t us) | ||
| 230 | { | ||
| 231 | while (clock_in() && us) { asm(""); _delay_us(1); us--; } | ||
| 232 | return us; | ||
| 233 | } | ||
| 234 | static inline uint16_t wait_clock_hi(uint16_t us) | ||
| 235 | { | ||
| 236 | while (!clock_in() && us) { asm(""); _delay_us(1); us--; } | ||
| 237 | return us; | ||
| 238 | } | ||
| 239 | static inline uint16_t wait_data_lo(uint16_t us) | ||
| 240 | { | ||
| 241 | while (data_in() && us) { asm(""); _delay_us(1); us--; } | ||
| 242 | return us; | ||
| 243 | } | ||
| 244 | static inline uint16_t wait_data_hi(uint16_t us) | ||
| 245 | { | ||
| 246 | while (!data_in() && us) { asm(""); _delay_us(1); us--; } | ||
| 247 | return us; | ||
| 248 | } | ||
| @@ -0,0 +1,72 @@ | |||
| 1 | /* | ||
| 2 | Copyright (c) 2010 Jun WAKO <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This software is licensed with a Modified BSD License. | ||
| 5 | All of this is supposed to be Free Software, Open Source, DFSG-free, | ||
| 6 | GPL-compatible, and OK to use in both free and proprietary applications. | ||
| 7 | Additions and corrections to this file are welcome. | ||
| 8 | |||
| 9 | |||
| 10 | Redistribution and use in source and binary forms, with or without | ||
| 11 | modification, are permitted provided that the following conditions are met: | ||
| 12 | |||
| 13 | * Redistributions of source code must retain the above copyright | ||
| 14 | notice, this list of conditions and the following disclaimer. | ||
| 15 | |||
| 16 | * Redistributions in binary form must reproduce the above copyright | ||
| 17 | notice, this list of conditions and the following disclaimer in | ||
| 18 | the documentation and/or other materials provided with the | ||
| 19 | distribution. | ||
| 20 | |||
| 21 | * Neither the name of the copyright holders nor the names of | ||
| 22 | contributors may be used to endorse or promote products derived | ||
| 23 | from this software without specific prior written permission. | ||
| 24 | |||
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 27 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 28 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 29 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 30 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 31 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 33 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 35 | POSSIBILITY OF SUCH DAMAGE. | ||
| 36 | */ | ||
| 37 | #ifndef PS2_H | ||
| 38 | #define PS2_H | ||
| 39 | /* | ||
| 40 | * Primitive PS/2 Library for AVR | ||
| 41 | */ | ||
| 42 | |||
| 43 | |||
| 44 | /* port settings for clock and data line */ | ||
| 45 | #if !(defined(PS2_CLOCK_PORT) && \ | ||
| 46 | defined(PS2_CLOCK_PIN) && \ | ||
| 47 | defined(PS2_CLOCK_DDR) && \ | ||
| 48 | defined(PS2_CLOCK_BIT)) | ||
| 49 | # error "PS/2 clock port setting is required in config.h" | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #if !(defined(PS2_DATA_PORT) && \ | ||
| 53 | defined(PS2_DATA_PIN) && \ | ||
| 54 | defined(PS2_DATA_DDR) && \ | ||
| 55 | defined(PS2_DATA_BIT)) | ||
| 56 | # error "PS/2 data port setting is required in config.h" | ||
| 57 | #endif | ||
| 58 | |||
| 59 | #define PS2_ERR_NONE 0 | ||
| 60 | #define PS2_ERR_PARITY 0x10 | ||
| 61 | |||
| 62 | |||
| 63 | extern uint8_t ps2_error; | ||
| 64 | |||
| 65 | /* host side */ | ||
| 66 | void ps2_host_init(void); | ||
| 67 | uint8_t ps2_host_send(uint8_t); | ||
| 68 | uint8_t ps2_host_recv(void); | ||
| 69 | |||
| 70 | /* TODO: device side */ | ||
| 71 | |||
| 72 | #endif | ||
diff --git a/ps2_mouse.c b/ps2_mouse.c new file mode 100644 index 000000000..e22ce6337 --- /dev/null +++ b/ps2_mouse.c | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include<avr/io.h> | ||
| 3 | #include<util/delay.h> | ||
| 4 | #include "ps2.h" | ||
| 5 | #include "ps2_mouse.h" | ||
| 6 | #include "usb_mouse.h" | ||
| 7 | |||
| 8 | #define PS2_MOUSE_DEBUG | ||
| 9 | #ifdef PS2_MOUSE_DEBUG | ||
| 10 | # include "print.h" | ||
| 11 | # include "debug.h" | ||
| 12 | #else | ||
| 13 | # define print(s) | ||
| 14 | # define phex(h) | ||
| 15 | # define phex16(h) | ||
| 16 | #endif | ||
| 17 | |||
| 18 | /* | ||
| 19 | TODO | ||
| 20 | ---- | ||
| 21 | - Error handling | ||
| 22 | - Stream mode | ||
| 23 | - Tracpoint command support: needed | ||
| 24 | - Middle button + move = Wheel traslation | ||
| 25 | */ | ||
| 26 | uint8_t ps2_mouse_x = 0; | ||
| 27 | uint8_t ps2_mouse_y = 0; | ||
| 28 | uint8_t ps2_mouse_btn = 0; | ||
| 29 | uint8_t ps2_mouse_error_count = 0; | ||
| 30 | static uint8_t ps2_mouse_btn_prev = 0; | ||
| 31 | |||
| 32 | void ps2_mouse_init(void) { | ||
| 33 | uint8_t rcv; | ||
| 34 | |||
| 35 | // Reset | ||
| 36 | rcv = ps2_host_send(0xFF); | ||
| 37 | print("ps2_mouse_init: send 0xFF: "); | ||
| 38 | phex(ps2_error); print("\n"); | ||
| 39 | |||
| 40 | // ACK | ||
| 41 | rcv = ps2_host_recv(); | ||
| 42 | print("ps2_mouse_init: read ACK: "); | ||
| 43 | phex(rcv); phex(ps2_error); print("\n"); | ||
| 44 | |||
| 45 | // BAT takes some time | ||
| 46 | _delay_ms(100); | ||
| 47 | rcv = ps2_host_recv(); | ||
| 48 | print("ps2_mouse_init: read BAT: "); | ||
| 49 | phex(rcv); phex(ps2_error); print("\n"); | ||
| 50 | |||
| 51 | // Device ID | ||
| 52 | rcv = ps2_host_recv(); | ||
| 53 | print("ps2_mouse_init: read DevID: "); | ||
| 54 | phex(rcv); phex(ps2_error); print("\n"); | ||
| 55 | |||
| 56 | // Enable data reporting | ||
| 57 | ps2_host_send(0xF4); | ||
| 58 | print("ps2_mouse_init: send 0xF4: "); | ||
| 59 | phex(ps2_error); print("\n"); | ||
| 60 | |||
| 61 | // ACK | ||
| 62 | rcv = ps2_host_recv(); | ||
| 63 | print("ps2_mouse_init: read ACK: "); | ||
| 64 | phex(rcv); phex(ps2_error); print("\n"); | ||
| 65 | |||
| 66 | // Set Remote mode | ||
| 67 | ps2_host_send(0xF0); | ||
| 68 | print("ps2_mouse_init: send 0xF0: "); | ||
| 69 | phex(ps2_error); print("\n"); | ||
| 70 | |||
| 71 | // ACK | ||
| 72 | rcv = ps2_host_recv(); | ||
| 73 | print("ps2_mouse_init: read ACK: "); | ||
| 74 | phex(rcv); phex(ps2_error); print("\n"); | ||
| 75 | |||
| 76 | if (ps2_error) ps2_mouse_error_count++; | ||
| 77 | } | ||
| 78 | |||
| 79 | /* | ||
| 80 | Data format: | ||
| 81 | bit: 7 6 5 4 3 2 1 0 | ||
| 82 | ----------------------------------------------------------------------- | ||
| 83 | 0 btn: Yovflw Xovflw Ysign Xsign 1 Middle Right Left | ||
| 84 | 1 x: X movement(0-255) | ||
| 85 | 2 y: Y movement(0-255) | ||
| 86 | */ | ||
| 87 | void ps2_mouse_read(void) | ||
| 88 | { | ||
| 89 | uint8_t rcv; | ||
| 90 | |||
| 91 | ps2_host_send(0xEB); | ||
| 92 | rcv=ps2_host_recv(); | ||
| 93 | if(rcv==0xFA) { | ||
| 94 | ps2_mouse_btn = ps2_host_recv(); | ||
| 95 | ps2_mouse_x = ps2_host_recv(); | ||
| 96 | ps2_mouse_y = ps2_host_recv(); | ||
| 97 | } | ||
| 98 | if (ps2_error) ps2_mouse_error_count++; | ||
| 99 | } | ||
| 100 | |||
| 101 | bool ps2_mouse_changed(void) | ||
| 102 | { | ||
| 103 | return (ps2_mouse_x || ps2_mouse_y || (ps2_mouse_btn & PS2_MOUSE_BTN_MASK) != ps2_mouse_btn_prev); | ||
| 104 | } | ||
| 105 | |||
| 106 | #define PS2_MOUSE_SCROLL_BUTTON 0x04 | ||
| 107 | void ps2_mouse_usb_send(void) | ||
| 108 | { | ||
| 109 | static bool scrolled = false; | ||
| 110 | if (ps2_mouse_changed()) { | ||
| 111 | int8_t x, y, v, h; | ||
| 112 | x = y = v = h = 0; | ||
| 113 | |||
| 114 | // convert scale of X, Y: PS/2(-256/255) -> USB(-127/127) | ||
| 115 | if (ps2_mouse_btn & (1<<PS2_MOUSE_X_SIGN)) | ||
| 116 | x = ps2_mouse_x > 128 ? (int8_t)ps2_mouse_x : -127; | ||
| 117 | else | ||
| 118 | x = ps2_mouse_x < 128 ? (int8_t)ps2_mouse_x : 127; | ||
| 119 | |||
| 120 | if (ps2_mouse_btn & (1<<PS2_MOUSE_Y_SIGN)) | ||
| 121 | y = ps2_mouse_y > 128 ? (int8_t)ps2_mouse_y : -127; | ||
| 122 | else | ||
| 123 | y = ps2_mouse_y < 128 ? (int8_t)ps2_mouse_y : 127; | ||
| 124 | |||
| 125 | // Y is needed to reverse | ||
| 126 | y = -y; | ||
| 127 | |||
| 128 | if (ps2_mouse_btn & PS2_MOUSE_SCROLL_BUTTON) { | ||
| 129 | // scroll | ||
| 130 | if (x > 0 || x < 0) h = (x > 64 ? 64 : (x < -64 ? -64 :x)); | ||
| 131 | if (y > 0 || y < 0) v = (y > 64 ? 64 : (y < -64 ? -64 :y)); | ||
| 132 | if (h || v) { | ||
| 133 | scrolled = true; | ||
| 134 | usb_mouse_send(0,0, -v/16, h/16, 0); | ||
| 135 | _delay_ms(100); | ||
| 136 | } | ||
| 137 | } else if (!scrolled && (ps2_mouse_btn_prev & PS2_MOUSE_SCROLL_BUTTON)) { | ||
| 138 | usb_mouse_send(0,0,0,0, PS2_MOUSE_SCROLL_BUTTON); | ||
| 139 | _delay_ms(100); | ||
| 140 | usb_mouse_send(0,0,0,0, 0); | ||
| 141 | } else { | ||
| 142 | scrolled = false; | ||
| 143 | usb_mouse_send(x, y, 0, 0, ps2_mouse_btn & PS2_MOUSE_BTN_MASK); | ||
| 144 | } | ||
| 145 | |||
| 146 | ps2_mouse_btn_prev = (ps2_mouse_btn & PS2_MOUSE_BTN_MASK); | ||
| 147 | ps2_mouse_print(); | ||
| 148 | } | ||
| 149 | ps2_mouse_x = 0; | ||
| 150 | ps2_mouse_y = 0; | ||
| 151 | ps2_mouse_btn = 0; | ||
| 152 | } | ||
| 153 | |||
| 154 | void ps2_mouse_print(void) | ||
| 155 | { | ||
| 156 | if (!debug_mouse) return; | ||
| 157 | print("ps2_mouse[btn|x y]: "); | ||
| 158 | phex(ps2_mouse_btn); print("|"); | ||
| 159 | phex(ps2_mouse_x); print(" "); | ||
| 160 | phex(ps2_mouse_y); print("\n"); | ||
| 161 | } | ||
diff --git a/ps2_mouse.h b/ps2_mouse.h new file mode 100644 index 000000000..f590f3ad5 --- /dev/null +++ b/ps2_mouse.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #ifndef PS2_MOUSE_H | ||
| 2 | #define PS2_MOUSE_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | |||
| 6 | #define PS2_MOUSE_BTN_MASK 0x07 | ||
| 7 | #define PS2_MOUSE_BTN_LEFT 0 | ||
| 8 | #define PS2_MOUSE_BTN_RIGHT 1 | ||
| 9 | #define PS2_MOUSE_BTN_MIDDLE 2 | ||
| 10 | #define PS2_MOUSE_X_SIGN 4 | ||
| 11 | #define PS2_MOUSE_Y_SIGN 5 | ||
| 12 | #define PS2_MOUSE_X_OVFLW 6 | ||
| 13 | #define PS2_MOUSE_Y_OVFLW 7 | ||
| 14 | |||
| 15 | extern uint8_t ps2_mouse_x; | ||
| 16 | extern uint8_t ps2_mouse_y; | ||
| 17 | extern uint8_t ps2_mouse_btn; | ||
| 18 | extern uint8_t ps2_mouse_error_count; | ||
| 19 | |||
| 20 | void ps2_mouse_init(void); | ||
| 21 | void ps2_mouse_read(void); | ||
| 22 | bool ps2_mouse_changed(void); | ||
| 23 | void ps2_mouse_usb_send(void); | ||
| 24 | void ps2_mouse_print(void); | ||
| 25 | |||
| 26 | #endif | ||
| @@ -34,9 +34,12 @@ | |||
| 34 | #include "print.h" | 34 | #include "print.h" |
| 35 | #include "debug.h" | 35 | #include "debug.h" |
| 36 | #include "util.h" | 36 | #include "util.h" |
| 37 | #include "controller.h" | ||
| 38 | #include "timer.h" | 37 | #include "timer.h" |
| 39 | #include "jump_bootloader.h" | 38 | #include "jump_bootloader.h" |
| 39 | #ifdef PS2_MOUSE_ENABLE | ||
| 40 | # include "ps2.h" | ||
| 41 | # include "ps2_mouse.h" | ||
| 42 | #endif | ||
| 40 | 43 | ||
| 41 | 44 | ||
| 42 | #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) | 45 | #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) |
| @@ -91,8 +94,12 @@ int main(void) | |||
| 91 | jump_bootloader(); // not return | 94 | jump_bootloader(); // not return |
| 92 | } | 95 | } |
| 93 | 96 | ||
| 97 | #ifdef PS2_MOUSE_ENABLE | ||
| 98 | ps2_host_init(); | ||
| 99 | ps2_mouse_init(); | ||
| 100 | #endif | ||
| 101 | |||
| 94 | while (1) { | 102 | while (1) { |
| 95 | proc_matrix(); | 103 | proc_matrix(); |
| 96 | _delay_ms(2); | ||
| 97 | } | 104 | } |
| 98 | } | 105 | } |
| @@ -94,7 +94,7 @@ static const uint8_t PROGMEM endpoint_config_table[] = { | |||
| 94 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER, // 2 | 94 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER, // 2 |
| 95 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3 | 95 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3 |
| 96 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER, // 4 | 96 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER, // 4 |
| 97 | #ifdef NKRO_ENABLE | 97 | #ifdef USB_NKRO_ENABLE |
| 98 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD2_SIZE) | KBD2_BUFFER, // 5 | 98 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD2_SIZE) | KBD2_BUFFER, // 5 |
| 99 | #else | 99 | #else |
| 100 | 0, // 5 | 100 | 0, // 5 |
| @@ -168,7 +168,7 @@ static uint8_t PROGMEM keyboard_hid_report_desc[] = { | |||
| 168 | 0x81, 0x00, // Input (Data, Array), | 168 | 0x81, 0x00, // Input (Data, Array), |
| 169 | 0xc0 // End Collection | 169 | 0xc0 // End Collection |
| 170 | }; | 170 | }; |
| 171 | #ifdef NKRO_ENABLE | 171 | #ifdef USB_NKRO_ENABLE |
| 172 | static uint8_t PROGMEM keyboard2_hid_report_desc[] = { | 172 | static uint8_t PROGMEM keyboard2_hid_report_desc[] = { |
| 173 | 0x05, 0x01, // Usage Page (Generic Desktop), | 173 | 0x05, 0x01, // Usage Page (Generic Desktop), |
| 174 | 0x09, 0x06, // Usage (Keyboard), | 174 | 0x09, 0x06, // Usage (Keyboard), |
| @@ -336,7 +336,7 @@ static uint8_t PROGMEM extra_hid_report_desc[] = { | |||
| 336 | #define MOUSE_HID_DESC_OFFSET (9+(9+9+7)*1+9) | 336 | #define MOUSE_HID_DESC_OFFSET (9+(9+9+7)*1+9) |
| 337 | #define DEBUG_HID_DESC_OFFSET (9+(9+9+7)*2+9) | 337 | #define DEBUG_HID_DESC_OFFSET (9+(9+9+7)*2+9) |
| 338 | #define EXTRA_HID_DESC_OFFSET (9+(9+9+7)*3+9) | 338 | #define EXTRA_HID_DESC_OFFSET (9+(9+9+7)*3+9) |
| 339 | #ifdef NKRO_ENABLE | 339 | #ifdef USB_NKRO_ENABLE |
| 340 | # define NUM_INTERFACES 5 | 340 | # define NUM_INTERFACES 5 |
| 341 | # define KBD2_HID_DESC_OFFSET (9+(9+9+7)*4+9) | 341 | # define KBD2_HID_DESC_OFFSET (9+(9+9+7)*4+9) |
| 342 | #else | 342 | #else |
| @@ -468,7 +468,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = { | |||
| 468 | EXTRA_SIZE, 0, // wMaxPacketSize | 468 | EXTRA_SIZE, 0, // wMaxPacketSize |
| 469 | 10, // bInterval | 469 | 10, // bInterval |
| 470 | 470 | ||
| 471 | #ifdef NKRO_ENABLE | 471 | #ifdef USB_NKRO_ENABLE |
| 472 | // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 | 472 | // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 |
| 473 | 9, // bLength | 473 | 9, // bLength |
| 474 | 4, // bDescriptorType | 474 | 4, // bDescriptorType |
| @@ -543,7 +543,7 @@ static struct descriptor_list_struct { | |||
| 543 | {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)}, | 543 | {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)}, |
| 544 | {0x2100, EXTRA_INTERFACE, config1_descriptor+EXTRA_HID_DESC_OFFSET, 9}, | 544 | {0x2100, EXTRA_INTERFACE, config1_descriptor+EXTRA_HID_DESC_OFFSET, 9}, |
| 545 | {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)}, | 545 | {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)}, |
| 546 | #ifdef NKRO_ENABLE | 546 | #ifdef USB_NKRO_ENABLE |
| 547 | {0x2100, KBD2_INTERFACE, config1_descriptor+KBD2_HID_DESC_OFFSET, 9}, | 547 | {0x2100, KBD2_INTERFACE, config1_descriptor+KBD2_HID_DESC_OFFSET, 9}, |
| 548 | {0x2200, KBD2_INTERFACE, keyboard2_hid_report_desc, sizeof(keyboard2_hid_report_desc)}, | 548 | {0x2200, KBD2_INTERFACE, keyboard2_hid_report_desc, sizeof(keyboard2_hid_report_desc)}, |
| 549 | #endif | 549 | #endif |
| @@ -884,7 +884,7 @@ ISR(USB_COM_vect) | |||
| 884 | if (bRequest == HID_GET_REPORT) { | 884 | if (bRequest == HID_GET_REPORT) { |
| 885 | if (wValue == HID_REPORT_INPUT) { | 885 | if (wValue == HID_REPORT_INPUT) { |
| 886 | usb_wait_in_ready(); | 886 | usb_wait_in_ready(); |
| 887 | UEDATX = mouse_buttons; | 887 | UEDATX = 0; |
| 888 | UEDATX = 0; | 888 | UEDATX = 0; |
| 889 | UEDATX = 0; | 889 | UEDATX = 0; |
| 890 | UEDATX = 0; | 890 | UEDATX = 0; |
| @@ -900,14 +900,14 @@ ISR(USB_COM_vect) | |||
| 900 | } | 900 | } |
| 901 | if (bRequest == HID_GET_PROTOCOL) { | 901 | if (bRequest == HID_GET_PROTOCOL) { |
| 902 | usb_wait_in_ready(); | 902 | usb_wait_in_ready(); |
| 903 | UEDATX = mouse_protocol; | 903 | UEDATX = usb_mouse_protocol; |
| 904 | usb_send_in(); | 904 | usb_send_in(); |
| 905 | return; | 905 | return; |
| 906 | } | 906 | } |
| 907 | } | 907 | } |
| 908 | if (bmRequestType == 0x21) { | 908 | if (bmRequestType == 0x21) { |
| 909 | if (bRequest == HID_SET_PROTOCOL) { | 909 | if (bRequest == HID_SET_PROTOCOL) { |
| 910 | mouse_protocol = wValue; | 910 | usb_mouse_protocol = wValue; |
| 911 | usb_send_in(); | 911 | usb_send_in(); |
| 912 | return; | 912 | return; |
| 913 | } | 913 | } |
diff --git a/usb_keyboard.c b/usb_keyboard.c index 3b071e336..57e23d5fc 100644 --- a/usb_keyboard.c +++ b/usb_keyboard.c | |||
| @@ -28,7 +28,7 @@ uint8_t usb_keyboard_idle_count=0; | |||
| 28 | // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana | 28 | // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana |
| 29 | volatile uint8_t usb_keyboard_leds=0; | 29 | volatile uint8_t usb_keyboard_leds=0; |
| 30 | 30 | ||
| 31 | // enable NKRO | 31 | // enable USB NKRO |
| 32 | bool usb_keyboard_nkro = false; | 32 | bool usb_keyboard_nkro = false; |
| 33 | 33 | ||
| 34 | 34 | ||
| @@ -42,7 +42,7 @@ int8_t usb_keyboard_send_report(usb_keyboard_report_t *report) | |||
| 42 | { | 42 | { |
| 43 | int8_t result = 0; | 43 | int8_t result = 0; |
| 44 | 44 | ||
| 45 | #ifdef NKRO_ENABLE | 45 | #ifdef USB_NKRO_ENABLE |
| 46 | if (usb_keyboard_nkro) | 46 | if (usb_keyboard_nkro) |
| 47 | result = _send_report(report, KBD2_ENDPOINT, 0, KBD2_REPORT_KEYS); | 47 | result = _send_report(report, KBD2_ENDPOINT, 0, KBD2_REPORT_KEYS); |
| 48 | else | 48 | else |
| @@ -106,7 +106,7 @@ static inline void _add_key_byte(uint8_t code); | |||
| 106 | static inline void _add_key_bit(uint8_t code); | 106 | static inline void _add_key_bit(uint8_t code); |
| 107 | void usb_keyboard_add_key(uint8_t code) | 107 | void usb_keyboard_add_key(uint8_t code) |
| 108 | { | 108 | { |
| 109 | #ifdef NKRO_ENABLE | 109 | #ifdef USB_NKRO_ENABLE |
| 110 | if (usb_keyboard_nkro) { | 110 | if (usb_keyboard_nkro) { |
| 111 | _add_key_bit(code); | 111 | _add_key_bit(code); |
| 112 | return; | 112 | return; |
| @@ -131,7 +131,7 @@ void usb_keyboard_del_code(uint8_t code) | |||
| 131 | 131 | ||
| 132 | void usb_keyboard_del_key(uint8_t code) | 132 | void usb_keyboard_del_key(uint8_t code) |
| 133 | { | 133 | { |
| 134 | #ifdef NKRO_ENABLE | 134 | #ifdef USB_NKRO_ENABLE |
| 135 | if ((code>>3) < KEYS_MAX) { | 135 | if ((code>>3) < KEYS_MAX) { |
| 136 | usb_keyboard_keys[code>>3] &= ~(1<<(code&7)); | 136 | usb_keyboard_keys[code>>3] &= ~(1<<(code&7)); |
| 137 | } | 137 | } |
| @@ -169,7 +169,7 @@ bool usb_keyboard_has_mod(void) | |||
| 169 | 169 | ||
| 170 | uint8_t usb_keyboard_get_key(void) | 170 | uint8_t usb_keyboard_get_key(void) |
| 171 | { | 171 | { |
| 172 | #ifdef NKRO_ENABLE | 172 | #ifdef USB_NKRO_ENABLE |
| 173 | if (usb_keyboard_nkro) { | 173 | if (usb_keyboard_nkro) { |
| 174 | uint8_t i = 0; | 174 | uint8_t i = 0; |
| 175 | for (; i < KEYS_MAX && !usb_keyboard_keys[i]; i++); | 175 | for (; i < KEYS_MAX && !usb_keyboard_keys[i]; i++); |
diff --git a/usb_keyboard.h b/usb_keyboard.h index ebb3eb048..141efc97a 100644 --- a/usb_keyboard.h +++ b/usb_keyboard.h | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | #define KBD_REPORT_KEYS (KBD_SIZE - 2) | 13 | #define KBD_REPORT_KEYS (KBD_SIZE - 2) |
| 14 | 14 | ||
| 15 | // secondary keyboard | 15 | // secondary keyboard |
| 16 | #ifdef NKRO_ENABLE | 16 | #ifdef USB_NKRO_ENABLE |
| 17 | #define KBD2_INTERFACE 4 | 17 | #define KBD2_INTERFACE 4 |
| 18 | #define KBD2_ENDPOINT 5 | 18 | #define KBD2_ENDPOINT 5 |
| 19 | #define KBD2_SIZE 16 | 19 | #define KBD2_SIZE 16 |
diff --git a/usb_mouse.c b/usb_mouse.c index 98292bdd8..319b65a1c 100644 --- a/usb_mouse.c +++ b/usb_mouse.c | |||
| @@ -5,40 +5,18 @@ | |||
| 5 | #include "debug.h" | 5 | #include "debug.h" |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | static bool is_sent = false; | 8 | uint8_t usb_mouse_protocol=1; |
| 9 | 9 | ||
| 10 | // which buttons are currently pressed | ||
| 11 | uint8_t mouse_buttons=0; | ||
| 12 | 10 | ||
| 13 | // protocol setting from the host. We use exactly the same report | 11 | int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons) |
| 14 | // either way, so this variable only stores the setting since we | ||
| 15 | // are required to be able to report which setting is in use. | ||
| 16 | uint8_t mouse_protocol=1; | ||
| 17 | |||
| 18 | |||
| 19 | // Set the mouse buttons. To create a "click", 2 calls are needed, | ||
| 20 | // one to push the button down and the second to release it | ||
| 21 | int8_t usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right) | ||
| 22 | { | ||
| 23 | uint8_t mask=0; | ||
| 24 | |||
| 25 | if (left) mask |= 1; | ||
| 26 | if (middle) mask |= 4; | ||
| 27 | if (right) mask |= 2; | ||
| 28 | mouse_buttons = mask; | ||
| 29 | return usb_mouse_move(0, 0, 0, 0); | ||
| 30 | } | ||
| 31 | |||
| 32 | // Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement. | ||
| 33 | int8_t usb_mouse_move(int8_t x, int8_t y, int8_t wheel, int8_t hwheel) | ||
| 34 | { | 12 | { |
| 35 | uint8_t intr_state, timeout; | 13 | uint8_t intr_state, timeout; |
| 36 | 14 | ||
| 37 | if (!usb_configured()) return -1; | 15 | if (!usb_configured()) return -1; |
| 38 | if (x == -128) x = -127; | 16 | if (x == -128) x = -127; |
| 39 | if (y == -128) y = -127; | 17 | if (y == -128) y = -127; |
| 40 | if (wheel == -128) wheel = -127; | 18 | if (wheel_v == -128) wheel_v = -127; |
| 41 | if (hwheel == -128) hwheel = -127; | 19 | if (wheel_h == -128) wheel_h = -127; |
| 42 | intr_state = SREG; | 20 | intr_state = SREG; |
| 43 | cli(); | 21 | cli(); |
| 44 | UENUM = MOUSE_ENDPOINT; | 22 | UENUM = MOUSE_ENDPOINT; |
| @@ -56,34 +34,25 @@ int8_t usb_mouse_move(int8_t x, int8_t y, int8_t wheel, int8_t hwheel) | |||
| 56 | cli(); | 34 | cli(); |
| 57 | UENUM = MOUSE_ENDPOINT; | 35 | UENUM = MOUSE_ENDPOINT; |
| 58 | } | 36 | } |
| 59 | UEDATX = mouse_buttons; | 37 | UEDATX = buttons; |
| 60 | UEDATX = x; | 38 | UEDATX = x; |
| 61 | UEDATX = y; | 39 | UEDATX = y; |
| 62 | if (mouse_protocol) { | 40 | if (usb_mouse_protocol) { |
| 63 | UEDATX = wheel; | 41 | UEDATX = wheel_v; |
| 64 | UEDATX = hwheel; | 42 | UEDATX = wheel_h; |
| 65 | } | 43 | } |
| 66 | 44 | ||
| 67 | UEINTX = 0x3A; | 45 | UEINTX = 0x3A; |
| 68 | SREG = intr_state; | 46 | SREG = intr_state; |
| 69 | is_sent = true; | ||
| 70 | return 0; | 47 | return 0; |
| 71 | } | 48 | } |
| 72 | 49 | ||
| 73 | void usb_mouse_clear(void) { | 50 | void usb_mouse_print(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons) { |
| 74 | is_sent = false; | ||
| 75 | } | ||
| 76 | |||
| 77 | bool usb_mouse_is_sent(void) { | ||
| 78 | return is_sent; | ||
| 79 | } | ||
| 80 | |||
| 81 | void usb_mouse_print(int8_t mouse_x, int8_t mouse_y, int8_t wheel_v, int8_t wheel_h) { | ||
| 82 | if (!debug_mouse) return; | 51 | if (!debug_mouse) return; |
| 83 | print("mouse btn|x y v h: "); | 52 | print("usb_mouse[btn|x y v h]: "); |
| 84 | phex(mouse_buttons); print("|"); | 53 | phex(buttons); print("|"); |
| 85 | phex(mouse_x); print(" "); | 54 | phex(x); print(" "); |
| 86 | phex(mouse_y); print(" "); | 55 | phex(y); print(" "); |
| 87 | phex(wheel_v); print(" "); | 56 | phex(wheel_v); print(" "); |
| 88 | phex(wheel_h); print("\n"); | 57 | phex(wheel_h); print("\n"); |
| 89 | } | 58 | } |
diff --git a/usb_mouse.h b/usb_mouse.h index da975c262..c092e89ff 100644 --- a/usb_mouse.h +++ b/usb_mouse.h | |||
| @@ -11,21 +11,17 @@ | |||
| 11 | #define MOUSE_SIZE 8 | 11 | #define MOUSE_SIZE 8 |
| 12 | #define MOUSE_BUFFER EP_DOUBLE_BUFFER | 12 | #define MOUSE_BUFFER EP_DOUBLE_BUFFER |
| 13 | 13 | ||
| 14 | #define BIT_BTN1 (1<<0) | 14 | #define MOUSE_BTN1 (1<<0) |
| 15 | #define BIT_BTN2 (1<<1) | 15 | #define MOUSE_BTN2 (1<<1) |
| 16 | #define BIT_BTN3 (1<<2) | 16 | #define MOUSE_BTN3 (1<<2) |
| 17 | #define BIT_BTN4 (1<<3) | 17 | #define MOUSE_BTN4 (1<<3) |
| 18 | #define BIT_BTN5 (1<<4) | 18 | #define MOUSE_BTN5 (1<<4) |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | extern uint8_t mouse_buttons; | 21 | extern uint8_t usb_mouse_protocol; |
| 22 | extern uint8_t mouse_protocol; | ||
| 23 | 22 | ||
| 24 | 23 | ||
| 25 | int8_t usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right); | 24 | int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons); |
| 26 | int8_t usb_mouse_move(int8_t x, int8_t y, int8_t wheel, int8_t hwheel); | 25 | void usb_mouse_print(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons); |
| 27 | void usb_mouse_clear(void); | ||
| 28 | bool usb_mouse_is_sent(void); | ||
| 29 | void usb_mouse_print(int8_t mouse_x, int8_t mouse_y, int8_t wheel_v, int8_t wheel_h); | ||
| 30 | 26 | ||
| 31 | #endif | 27 | #endif |
