diff options
52 files changed, 1924 insertions, 47 deletions
diff --git a/.gitignore b/.gitignore index b79d72b7c7..f3f46872a0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,6 @@ *.map *.sym tags +*~ build/ *.bak @@ -8,6 +8,7 @@ SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/action_util.c \ $(COMMON_DIR)/keymap.c \ $(COMMON_DIR)/print.c \ + $(COMMON_DIR)/debug.c \ $(COMMON_DIR)/util.c \ $(COMMON_DIR)/avr/suspend.c \ $(COMMON_DIR)/avr/xprintf.S \ diff --git a/common/action.c b/common/action.c index 94498fe6cb..ec8eeae7bc 100644 --- a/common/action.c +++ b/common/action.c @@ -237,6 +237,16 @@ void process_action(keyrecord_t *record) case ACT_LAYER_TAP: case ACT_LAYER_TAP_EXT: switch (action.layer_tap.code) { + case 0xe0 ... 0xef: + /* layer On/Off with modifiers(left only) */ + if (event.pressed) { + layer_on(action.layer_tap.val); + register_mods(action.layer_tap.code & 0x0f); + } else { + layer_off(action.layer_tap.val); + unregister_mods(action.layer_tap.code & 0x0f); + } + break; case OP_TAP_TOGGLE: /* tap toggle */ if (event.pressed) { diff --git a/common/action_code.h b/common/action_code.h index 50112d4d20..bc40e2c6fb 100644 --- a/common/action_code.h +++ b/common/action_code.h @@ -71,7 +71,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. * * ACT_LAYER_TAP(101x): * 101E|LLLL| keycode On/Off with tap key - * 101E|LLLL|1110 xxxx Reserved(0xE0-EF) + * 101E|LLLL|1110 mods On/Off with modifiers(0xE0-EF) * 101E|LLLL|1111 0000 Invert with tap toggle(0xF0) * 101E|LLLL|1111 0001 On/Off * 101E|LLLL|1111 0010 Off/On @@ -266,6 +266,7 @@ enum layer_pram_tap_op { #define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF) #define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON) #define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR) +#define ACTION_LAYER_MODS(layer, mods) ACTION_LAYER_TAP((layer), 0xe0 | (mods)&0x0f) /* With Tapping */ #define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key)) #define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE) diff --git a/common/avr/xprintf.h b/common/avr/xprintf.h index f58bca817b..59c6f25312 100644 --- a/common/avr/xprintf.h +++ b/common/avr/xprintf.h @@ -8,6 +8,10 @@ #include <inttypes.h>
#include <avr/pgmspace.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
extern void (*xfunc_out)(uint8_t);
#define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)
@@ -99,5 +103,9 @@ char xatoi(char **str, long *ret); Pointer to return value
*/
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/common/debug.c b/common/debug.c new file mode 100644 index 0000000000..18613fc28b --- /dev/null +++ b/common/debug.c @@ -0,0 +1,24 @@ +#include <stdbool.h> +#include "debug.h" + +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) + +debug_config_t debug_config = { +/* GCC Bug 10676 - Using unnamed fields in initializers + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676 */ +#if GCC_VERSION >= 40600 + .enable = false, + .matrix = false, + .keyboard = false, + .mouse = false, + .reserved = 0 +#else + { + false, // .enable + false, // .matrix + false, // .keyboard + false, // .mouse + 0 // .reserved + } +#endif +}; diff --git a/common/debug.h b/common/debug.h index 26472c8fa3..472dd478c4 100644 --- a/common/debug.h +++ b/common/debug.h @@ -29,7 +29,6 @@ extern "C" { #endif typedef union { - uint8_t raw; struct { bool enable:1; bool matrix:1; @@ -37,6 +36,7 @@ typedef union { bool mouse:1; uint8_t reserved:4; }; + uint8_t raw; } debug_config_t; extern debug_config_t debug_config; diff --git a/common/debug_config.h b/common/debug_config.h new file mode 100644 index 0000000000..28bc34cd57 --- /dev/null +++ b/common/debug_config.h @@ -0,0 +1,51 @@ +/* +Copyright 2013 Jun Wako <wakojun@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef DEBUG_CONFIG_H +#define DEBUG_CONFIG_H 1 + +#include <stdbool.h> + + +#ifdef __cplusplus +extern "C" { +#endif + +/* NOTE: Not portable. Bit field order depends on implementation */ +typedef union { + struct { + bool enable:1; + bool matrix:1; + bool keyboard:1; + bool mouse:1; + uint8_t reserved:4; + }; + uint8_t raw; +} debug_config_t; +extern debug_config_t debug_config; + +/* for backward compatibility */ +#define debug_enable (debug_config.enable) +#define debug_matrix (debug_config.matrix) +#define debug_keyboard (debug_config.keyboard) +#define debug_mouse (debug_config.mouse) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/common/keyboard.c b/common/keyboard.c index 9a809ff4a1..1e3fb510a4 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -36,6 +36,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifdef PS2_MOUSE_ENABLE # include "ps2_mouse.h" #endif +#ifdef SERIAL_MOUSE_ENABLE +#include "serial_mouse.h" +#endif #ifdef MATRIX_HAS_GHOST @@ -63,6 +66,10 @@ void keyboard_init(void) #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif +#ifdef SERIAL_MOUSE_ENABLE + serial_mouse_init(); +#endif + #ifdef BOOTMAGIC_ENABLE bootmagic(); @@ -125,6 +132,10 @@ MATRIX_LOOP_END: ps2_mouse_task(); #endif +#ifdef SERIAL_MOUSE_ENABLE + serial_mouse_task(); +#endif + // update LED if (led_status != host_keyboard_leds()) { led_status = host_keyboard_leds(); diff --git a/converter/adb_usb/Makefile b/converter/adb_usb/Makefile index 73cae8ab30..bbb7810eef 100644 --- a/converter/adb_usb/Makefile +++ b/converter/adb_usb/Makefile @@ -121,7 +121,7 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450) CONSOLE_ENABLE = yes # Console for debug(+400) COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend -#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA +#NKRO_ENABLE = yes # USB Nkey Rollover # Optimize size but this may cause error "relocation truncated to fit" diff --git a/converter/next_usb/Makefile b/converter/next_usb/Makefile index 51d9de6b11..fef539a147 100644 --- a/converter/next_usb/Makefile +++ b/converter/next_usb/Makefile @@ -20,6 +20,7 @@ CONFIG_H = config.h MCU = atmega32u4 # Teensy 2.0 #MCU = at90usb646 # Teensy++ 1.0 #MCU = at90usb1286 # Teensy++ 2.0 +#MCU = atmega32u2 # TMK converter # Processor frequency. @@ -30,6 +31,29 @@ MCU = atmega32u4 # Teensy 2.0 F_CPU = 16000000 +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + +# Interrupt driven control endpoint task(+60) +#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT + + # Boot Section Size in *bytes* # Teensy halfKay 512 # Teensy++ halfKay 1024 @@ -58,6 +82,6 @@ VPATH += $(TOP_DIR) include $(TOP_DIR)/protocol.mk -include $(TOP_DIR)/protocol/pjrc.mk +include $(TOP_DIR)/protocol/lufa.mk include $(TOP_DIR)/common.mk include $(TOP_DIR)/rules.mk diff --git a/converter/next_usb/Makefile.pjrc b/converter/next_usb/Makefile.pjrc new file mode 100644 index 0000000000..51d9de6b11 --- /dev/null +++ b/converter/next_usb/Makefile.pjrc @@ -0,0 +1,63 @@ +# Target file name (without extension). +TARGET = next_usb + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# keyboard dependent files +SRC = keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h + +# MCU name, you MUST set this to match the board you are using +# type "make clean" after changing this, so all files will be rebuilt +#MCU = at90usb162 # Teensy 1.0 +MCU = atmega32u4 # Teensy 2.0 +#MCU = at90usb646 # Teensy++ 1.0 +#MCU = at90usb1286 # Teensy++ 2.0 + + +# Processor frequency. +# Normally the first thing your program should do is set the clock prescaler, +# so your program will run at the correct speed. You should also set this +# variable to same clock speed. The _delay_ms() macro uses this, and many +# examples use this variable to calculate timings. Do not add a "UL" here. +F_CPU = 16000000 + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Teensy++ halfKay 1024 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +# USBaspLoader 2048 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + + +# Build Options +# *Comment out* to disable the options. +# +#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = yes # Console for debug(+400) +COMMAND_ENABLE = yes # Commands for debug and configuration +#NKRO_ENABLE = yes # USB Nkey Rollover + +SRC += next_kbd.c + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + + +include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/protocol/pjrc.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/converter/next_usb/config.h b/converter/next_usb/config.h index b3d188b0c1..cd80b5af1b 100644 --- a/converter/next_usb/config.h +++ b/converter/next_usb/config.h @@ -60,6 +60,7 @@ POSSIBILITY OF SUCH DAMAGE. //#define TEENSY_CONFIG 1 #define PRO_MICRO_CONFIG 1 +//#define TMK_CONFIG 1 // comment out if you don't want the keyboard's LEDs to flash upon initialization #define NEXT_KBD_INIT_FLASH_LEDS @@ -143,6 +144,43 @@ POSSIBILITY OF SUCH DAMAGE. #endif //================= End of Teensy 2.0 Configuration ================== + +//================ Start of TMK converter Configuration ================= +#ifdef TMK_CONFIG + +// this is the debugging LED that flashes when a key is being pressed +// comment out in order to disable debugging LED +#define NEXT_KBD_LED1_PORT PORTD +#define NEXT_KBD_LED1_PIN PIND +#define NEXT_KBD_LED1_DDR DDRD +#define NEXT_KBD_LED1_BIT 6 + +#define NEXT_KBD_LED1_ON NEXT_KBD_LED1_PORT |= (1<<NEXT_KBD_LED1_BIT); +#define NEXT_KBD_LED1_OFF NEXT_KBD_LED1_PORT &= ~(1<<NEXT_KBD_LED1_BIT); + +// corresponds to the Keyboard In wire on the NeXT connector +#define NEXT_KBD_OUT_PORT PORTD +#define NEXT_KBD_OUT_PIN PIND +#define NEXT_KBD_OUT_DDR DDRD +#define NEXT_KBD_OUT_BIT 1 + +// corresponds to the Keyboard Out wire on the NeXT connector +#define NEXT_KBD_IN_PORT PORTD +#define NEXT_KBD_IN_PIN PIND +#define NEXT_KBD_IN_DDR DDRD +#define NEXT_KBD_IN_BIT 0 + +// this pin is an input for the power key on the NeXT keyboard +// as the keyboard is powered on this should be normally high; +// if it is pulled low it means the power button is being preseed +#define NEXT_KBD_PWR_PORT PORTD +#define NEXT_KBD_PWR_PIN PIND +#define NEXT_KBD_PWR_DDR DDRD +#define NEXT_KBD_PWR_BIT 4 + +#endif +//================= End of TMK converter Configuration ================== + /* key combination for command */ #define IS_COMMAND() ( \ (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))|| \ diff --git a/converter/ps2_usb/Makefile.vusb b/converter/ps2_usb/Makefile.vusb index 1bb44f8875..ddf1868459 100644 --- a/converter/ps2_usb/Makefile.vusb +++ b/converter/ps2_usb/Makefile.vusb @@ -8,10 +8,16 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = keymap.c \ +SRC = keymap_common.c \ matrix.c \ led.c +ifdef KEYMAP + SRC := keymap_$(KEYMAP).c $(SRC) +else + SRC := keymap_plain.c $(SRC) +endif + # Use USART for PS/2. With V-USB INT and BUSYWAIT code is not useful. SRC += protocol/ps2_usart.c OPT_DEFS += -DPS2_USE_USART @@ -95,7 +101,7 @@ VPATH += $(TARGET_DIR) VPATH += $(TOP_DIR) -include $(TOP_DIR)/protocol/vusb.mk include $(TOP_DIR)/protocol.mk include $(TOP_DIR)/common.mk +include $(TOP_DIR)/protocol/vusb.mk include $(TOP_DIR)/rules.mk diff --git a/converter/ps2_usb/README.md b/converter/ps2_usb/README.md index 586394b23a..8a535949d8 100644 --- a/converter/ps2_usb/README.md +++ b/converter/ps2_usb/README.md @@ -58,8 +58,7 @@ To select method edit Makefile. V-USB Support ------------- -You can also use this converter on ATmega(168/328) with V-USB instead of Teensy. -The converter on V-USB lacks some features for now: USB NKRO and System/Media control. +With V-USB you can use this converter on ATmega(168/328) but it doesn't support NKRO at this time. Circuit: diff --git a/converter/serialmouse_usb/Makefile b/converter/serialmouse_usb/Makefile new file mode 100644 index 0000000000..ea0e439bd7 --- /dev/null +++ b/converter/serialmouse_usb/Makefile @@ -0,0 +1,106 @@ +# +# Makefile for Teensy +# +# Target file name (without extension). +TARGET = serialmouse_usb + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# project specific files +SRC = keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h + + +# MCU name +#MCU = at90usb1287 +MCU = atmega32u4 + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 16000000 + + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + +# Interrupt driven control endpoint task(+60) +#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Teensy++ halfKay 1024 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +# USBaspLoader 2048 +OPT_DEFS += -DBOOTLOADER_SIZE=512 + + +# Build Options +# comment out to disable the options. +# +#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +#MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +#EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = yes # Console for debug(+400) +#COMMAND_ENABLE = yes # Commands for debug and configuration +#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA + + +# Serial Mouse Options +# You can choose a mouse protocol and the implementation of +# the underlying serial connection. +# +SERIAL_MOUSE_MICROSOFT_ENABLE = yes # Enable support for Microsoft-compatible mice +#SERIAL_MOUSE_MOUSESYSTEMS_ENABLE = yes # Enable support for Mousesystems-compatible mice +#SERIAL_MOUSE_USE_UART = yes # use hardware UART for serial connection +SERIAL_MOUSE_USE_SOFT = yes # use software serial implementation + +# Optional serial mouse driver features +# Support scrolling while holding the middle mouse button +# (currently only supported for Mousesystems mice): +#OPT_DEFS += -DSERIAL_MOUSE_CENTER_SCROLL + +# Optimize size but this may cause error "relocation truncated to fit" +#EXTRALDFLAGS = -Wl,--relax + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/converter/serialmouse_usb/README.md b/converter/serialmouse_usb/README.md new file mode 100644 index 0000000000..ef8a006716 --- /dev/null +++ b/converter/serialmouse_usb/README.md @@ -0,0 +1,11 @@ +Serial mouse converter +====================== +See https://github.com/tmk/tmk_keyboard/pull/131 + + +Supported protocols +------------------- +### Microsoft +Not tested. + +### Mousesystems diff --git a/converter/serialmouse_usb/config.h b/converter/serialmouse_usb/config.h new file mode 100644 index 0000000000..b257d997cf --- /dev/null +++ b/converter/serialmouse_usb/config.h @@ -0,0 +1,119 @@ +/* +Copyright 2012 Jun Wako <wakojun@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +#include <avr/interrupt.h> + +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x2222 +#define DEVICE_VER 0x0001 +#define MANUFACTURER t.m.k. +#define PRODUCT serial mouse converter +#define DESCRIPTION convert serial mouse into USB + + +/* matrix size */ +#define MATRIX_ROWS 0 +#define MATRIX_COLS 0 + + +/* key combination for command */ +#define IS_COMMAND() false + + + +#ifdef SERIAL_MOUSE_MICROSOFT + /* + * Serial(USART) configuration (for Microsoft serial mice) + * asynchronous, positive logic, 1200baud, bit order: LSB first + * 1-start bit, 7-data bit, no parity, 1-stop bit + */ + #define SERIAL_UART_BAUD 1200 + #define SERIAL_UART_DATA UDR1 + #define SERIAL_UART_UBRR ((F_CPU/(16UL*SERIAL_UART_BAUD))-1) + #define SERIAL_UART_RXD_VECT USART1_RX_vect + #define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1)) + #define SERIAL_UART_INIT() do { \ + UBRR1L = (uint8_t) SERIAL_UART_UBRR; /* baud rate */ \ + UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8); /* baud rate */ \ + UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); /* RX interrupt, RX: enable */ \ + UCSR1C = (1<<UCSZ11) | (0<<UCSZ10); /* no parity, 1 stop bit, 7-bit characters */ \ + sei(); \ + } while(0) + + // for Microsoft mouse protocol + /* Serial(USART) configuration + * asynchronous, negative logic, 1200baud, no flow control + * 1-start bit, 7-data bit, non parity, 1-stop bit + */ + #define SERIAL_SOFT_BAUD 1200 + #define SERIAL_SOFT_DATA_7BIT + #define SERIAL_SOFT_PARITY_NONE + #define SERIAL_SOFT_BIT_ORDER_LSB + #define SERIAL_SOFT_LOGIC_NEGATIVE + /* RXD Port */ + #define SERIAL_SOFT_RXD_DDR DDRD + #define SERIAL_SOFT_RXD_PORT PORTD + #define SERIAL_SOFT_RXD_PIN PIND + #define SERIAL_SOFT_RXD_BIT 2 + #define SERIAL_SOFT_RXD_VECT INT2_vect + /* RXD Interupt */ + #define SERIAL_SOFT_RXD_INIT() do { \ + /* pin configuration: input with pull-up */ \ + SERIAL_SOFT_RXD_DDR &= ~(1<<SERIAL_SOFT_RXD_BIT); \ + SERIAL_SOFT_RXD_PORT |= (1<<SERIAL_SOFT_RXD_BIT); \ + /* enable interrupt: INT2(rising edge) */ \ + EICRA |= ((1<<ISC21)|(1<<ISC20)); \ + EIMSK |= (1<<INT2); \ + sei(); \ + } while (0) + #define SERIAL_SOFT_RXD_INT_ENTER() + #define SERIAL_SOFT_RXD_INT_EXIT() do { \ + /* clear interrupt flag */ \ + EIFR = (1<<INTF2); \ + } while (0) + #define SERIAL_SOFT_RXD_READ() (SERIAL_SOFT_RXD_PIN&(1<<SERIAL_SOFT_RXD_BIT)) + /* TXD Port */ + #define SERIAL_SOFT_TXD_HI() + #define SERIAL_SOFT_TXD_LO() + #define SERIAL_SOFT_TXD_INIT() +#elif defined(SERIAL_MOUSE_MOUSESYSTEMS) + /* + * Serial(USART) configuration (for Mousesystems serial mice) + * asynchronous, positive logic, 1200baud, bit order: LSB first + * 1-start bit, 8-data bit, no parity, 1-stop bit + */ + #define SERIAL_UART_BAUD 1200 + #define SERIAL_UART_DATA UDR1 + #define SERIAL_UART_UBRR ((F_CPU/(16UL*SERIAL_UART_BAUD))-1) + #define SERIAL_UART_RXD_VECT USART1_RX_vect + #define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1)) + #define SERIAL_UART_INIT() do { \ + UBRR1L = (uint8_t) SERIAL_UART_UBRR; /* baud rate */ \ + UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8); /* baud rate */ \ + UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); /* RX interrupt, RX: enable */ \ + UCSR1C = (1<<UCSZ11) | (1<<UCSZ10); /* no parity, 1 stop bit, 8-bit characters */ \ + sei(); \ + } while(0) +#endif + + + + +#endif diff --git a/converter/serialmouse_usb/keymap.c b/converter/serialmouse_usb/keymap.c new file mode 100644 index 0000000000..de8f75c2af --- /dev/null +++ b/converter/serialmouse_usb/keymap.c @@ -0,0 +1,33 @@ +/* +Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#include <stdint.h> +#include <stdbool.h> +#include "keymap.h" + + +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ + return KC_NO; +} + +/* translates Fn keycode to action */ +action_t keymap_fn_to_action(uint8_t keycode) +{ + return (action_t){}; +} + diff --git a/converter/serialmouse_usb/keymap_common.c b/converter/serialmouse_usb/keymap_common.c new file mode 100644 index 0000000000..241d2e33b1 --- /dev/null +++ b/converter/serialmouse_usb/keymap_common.c @@ -0,0 +1,30 @@ +/* +Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "keymap_common.h" + + +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ + return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); +} + +/* translates Fn keycode to action */ +action_t keymap_fn_to_action(uint8_t keycode) +{ + return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) }; +} diff --git a/converter/serialmouse_usb/keymap_common.h b/converter/serialmouse_usb/keymap_common.h new file mode 100644 index 0000000000..216a8dc020 --- /dev/null +++ b/converter/serialmouse_usb/keymap_common.h @@ -0,0 +1,174 @@ +/* +Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef KEYMAP_COMMON_H +#define KEYMAP_COMMON_H + +#include <stdint.h> +#include <stdbool.h> +#include <avr/pgmspace.h> +#include "keycode.h" +#include "action.h" +#include "action_macro.h" +#include "report.h" +#include "print.h" +#include "debug.h" +#include "keymap.h" + + +// 32*8(256) byte array which converts PS/2 code into USB code +extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; +extern const uint16_t fn_actions[]; + + +/* All keys */ +#define KEYMAP_ALL( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ + K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA, \ + \ + K61, /* for European ISO */ \ + K51, K13, K6A, K64, K67, /* for Japanese JIS */ \ + K08, K10, K18, K20, K28, K30, K38, K40, K48, K50, K57, K5F, /* F13-24 */ \ + KB7, KBF, KDE, /* System Power, Sleep, Wake */ \ + KA3, KB2, KA1, /* Mute, Volume Up, Volume Down */ \ + KCD, K95, KBB, KB4, KD0, /* Next, Previous, Stop, Pause, Media Select */ \ + KC8, KAB, KC0, /* Mail, Calculator, My Computer */ \ + K90, KBA, KB8, KB0, /* WWW Search, Home, Back, Forward */ \ + KA8, KA0, K98 /* WWW Stop, Refresh, Favorites */ \ +) { \ + { KC_NO, KC_##K01, KC_NO, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \ + { KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_NO }, \ + { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_NO }, \ + { KC_##K18, KC_NO, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_NO }, \ + { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_NO }, \ + { KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_NO }, \ + { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_NO }, \ + { KC_##K38, KC_NO, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_NO }, \ + { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_NO }, \ + { KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_NO }, \ + { KC_##K50, KC_##K51, KC_##K52, KC_NO, KC_##K54, KC_##K55, KC_NO, KC_##K57 }, \ + { KC_##K58, KC_##K59, KC_##K5A, KC_##K5B, KC_NO, KC_##K5D, KC_NO, KC_##K5F }, \ + { KC_NO, KC_##K61, KC_NO, KC_NO, KC_##K64, KC_NO, KC_##K66, KC_##K67 }, \ + { KC_NO, KC_##K69, KC_##K6A, KC_##K6B, KC_##K6C, KC_NO, KC_NO, KC_NO }, \ + { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_##K77 }, \ + { KC_##K78, KC_##K79, KC_##K7A, KC_##K7B, KC_##K7C, KC_##K7D, KC_##K7E, KC_NO }, \ + { KC_NO, KC_NO, KC_NO, KC_##K83, KC_NO, KC_NO, KC_NO, KC_NO }, \ + { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ + { KC_##K90, KC_##K91, KC_NO, KC_NO, KC_##K94, KC_##K95, KC_NO, KC_NO }, \ + { KC_##K98, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_##K9F }, \ + { KC_##KA0, KC_##KA1, KC_NO, KC_##KA3, KC_NO, KC_NO, KC_NO, KC_##KA7 }, \ + { KC_##KA8, KC_NO, KC_NO, KC_##KAB, KC_NO, KC_NO, KC_NO, KC_##KAF }, \ + { KC_##KB0, KC_NO, KC_##KB2, KC_NO, KC_##KB4, KC_NO, KC_NO, KC_##KB7 }, \ + { KC_##KB8, KC_NO, KC_##KBA, KC_##KBB, KC_NO, KC_NO, KC_NO, KC_##KBF }, \ + { KC_##KC0, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ + { KC_##KC8, KC_NO, KC_##KCA, KC_NO, KC_NO, KC_##KCD, KC_NO, KC_NO }, \ + { KC_##KD0, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ + { KC_NO, KC_NO, KC_##KDA, KC_NO, KC_NO, KC_NO, KC_##KDE, KC_NO }, \ + { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ + { KC_NO, KC_##KE9, KC_NO, KC_##KEB, KC_##KEC, KC_NO, KC_NO, KC_NO }, \ + { KC_##KF0, KC_##KF1, KC_##KF2, KC_NO, KC_##KF4, KC_##KF5, KC_NO, KC_NO }, \ + { KC_NO, KC_NO, KC_##KFA, KC_NO, KC_##KFC, KC_##KFD, KC_##KFE, KC_NO }, \ +} + +/* US layout */ +#define KEYMAP( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ + K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA \ +) \ +KEYMAP_ALL( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ + K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA, \ + \ + NUBS, \ + RO, KANA, JYEN, HENK, MHEN, \ + F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24, \ + SYSTEM_POWER, SYSTEM_SLEEP, SYSTEM_WAKE, \ + AUDIO_MUTE, AUDIO_VOL_UP, AUDIO_VOL_DOWN, \ + MEDIA_NEXT_TRACK, MEDIA_PREV_TRACK, MEDIA_STOP, MEDIA_PLAY_PAUSE, MEDIA_SELECT, \ + MAIL, CALCULATOR, MY_COMPUTER, \ + WWW_SEARCH, WWW_HOME, WWW_BACK, WWW_FORWARD, \ + WWW_STOP, WWW_REFRESH, WWW_FAVORITES \ +) + +/* ISO layout */ +#define KEYMAP_ISO( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52,K5D,K5A, K6B,K73,K74,K79, \ + K12,K61,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA \ +) \ +KEYMAP_ALL( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ + K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA, \ + \ + K61, \ + RO, KANA, JYEN, HENK, MHEN, \ + F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24, \ + SYSTEM_POWER, SYSTEM_SLEEP, SYSTEM_WAKE, \ + AUDIO_MUTE, AUDIO_VOL_UP, AUDIO_VOL_DOWN, \ + MEDIA_NEXT_TRACK, MEDIA_PREV_TRACK, MEDIA_STOP, MEDIA_PLAY_PAUSE, MEDIA_SELECT, \ + MAIL, CALCULATOR, MY_COMPUTER, \ + WWW_SEARCH, WWW_HOME, WWW_BACK, WWW_FORWARD, \ + WWW_STOP, WWW_REFRESH, WWW_FAVORITES \ +) + +/* JIS layout */ +#define KEYMAP_JIS( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K6A,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52,K5D, K5A, K6B,K73,K74,K79, \ + K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A,K51, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K67,K29,K64,K13, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA \ +) \ +KEYMAP_ALL( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ + K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA, \ + \ + NUBS, \ + K51, K13, K6A, K64, K67, \ + F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24, \ + SYSTEM_POWER, SYSTEM_SLEEP, SYSTEM_WAKE, \ + AUDIO_MUTE, AUDIO_VOL_UP, AUDIO_VOL_DOWN, \ + MEDIA_NEXT_TRACK, MEDIA_PREV_TRACK, MEDIA_STOP, MEDIA_PLAY_PAUSE, MEDIA_SELECT, \ + MAIL, CALCULATOR, MY_COMPUTER, \ + WWW_SEARCH, WWW_HOME, WWW_BACK, WWW_FORWARD, \ + WWW_STOP, WWW_REFRESH, WWW_FAVORITES \ +) + +#endif diff --git a/converter/serialmouse_usb/led.c b/converter/serialmouse_usb/led.c new file mode 100644 index 0000000000..f76545f0ba --- /dev/null +++ b/converter/serialmouse_usb/led.c @@ -0,0 +1,24 @@ +/* +Copyright 2011 Jun Wako <wakojun@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdint.h" +#include "led.h" + + +void led_set(uint8_t usb_led) +{ +} diff --git a/converter/serialmouse_usb/matrix.c b/converter/serialmouse_usb/matrix.c new file mode 100644 index 0000000000..0e0d87f80e --- /dev/null +++ b/converter/serialmouse_usb/matrix.c @@ -0,0 +1,83 @@ +/* +Copyright 2011 Jun Wako <wakojun@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <stdint.h> +#include <stdbool.h> +#include <avr/io.h> +#include <util/delay.h> +#include "action.h" +#include "print.h" +#include "util.h" +#include "debug.h" +#include "matrix.h" + + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ + debug_enable = true; + debug_mouse=true; + return; +} + +uint8_t matrix_scan(void) +{ + return 0; +} + +bool matrix_is_modified(void) +{ + return false; +} + +inline +bool matrix_has_ghost(void) +{ + return false; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return false; +} + +inline +uint8_t matrix_get_row(uint8_t row) +{ + return 0; +} + +void matrix_print(void) +{ +} + +uint8_t matrix_key_count(void) +{ + return 0; +} diff --git a/converter/sun_usb/Makefile b/converter/sun_usb/Makefile index 35c4bb123b..b32497cd95 100644 --- a/converter/sun_usb/Makefile +++ b/converter/sun_usb/Makefile @@ -63,6 +63,7 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT MOUSEKEY_ENABLE = yes # Mouse keys EXTRAKEY_ENABLE = yes # Audio control and System control CONSOLE_ENABLE = yes # Console for debug +COMMAND_ENABLE = yes # Commands for debug and configuration #NKRO_ENABLE = yes # USB Nkey Rollover diff --git a/converter/sun_usb/README b/converter/sun_usb/README index ee59fc757c..276f6bfff8 100644 --- a/converter/sun_usb/README +++ b/converter/sun_usb/README @@ -77,3 +77,23 @@ Just use 'make' $ cd sun_usb $ make Then, load the binary to MCU with your favorite programmer. + + +Sun commands +------------ +You can send Sun protocol commands with TMK `Magic` key combo. By default `Magic` key is `LShift` + `RShift`, `LAlt` + `RAlt' or `LMeta` + `RMeta`. +https://github.com/tmk/tmk_keyboard#magic-commands + +Following Sun specific commands are available. For example, to send 'Bell On' you can press `LShift` + `RShift` + `Up` keys simultaneously. + +``` +----- Sun converter Help ----- +Up: Bell On +Down: Bell Off +Left: Click On +Right: Click Off +PgUp: LED all On +PgDown: LED all On +Insert: Layout +Delete: Reset +``` diff --git a/converter/sun_usb/command_extra.c b/converter/sun_usb/command_extra.c index 50389467ea..aba3fe6da3 100644 --- a/converter/sun_usb/command_extra.c +++ b/converter/sun_usb/command_extra.c @@ -11,11 +11,19 @@ bool command_extra(uint8_t code) case KC_H: case KC_SLASH: /* ? */ print("\n\n----- Sun converter Help -----\n"); - print("UP: Bell On\n"); - print("DOWN: Bell Off\n"); - print("LEFT: Click On\n"); - print("RIGHT: Click Off\n"); + print("Up: Bell On\n"); + print("Down: Bell Off\n"); + print("Left: Click On\n"); + print("Right: Click Off\n"); + print("PgUp: LED all On\n"); + print("PgDown: LED all On\n"); + print("Insert: Layout\n"); + print("Delete: Reset\n"); return false; + case KC_DEL: + print("Reset\n"); + serial_send(0x01); + break; case KC_UP: print("Bell On\n"); serial_send(0x02); @@ -32,7 +40,17 @@ bool command_extra(uint8_t code) print("Click Off\n"); serial_send(0x0B); break; - case KC_NUMLOCK: + case KC_PGUP: + print("LED all on\n"); + serial_send(0x0E); + serial_send(0xFF); + break; + case KC_PGDOWN: + print("LED all off\n"); + serial_send(0x0E); + serial_send(0x00); + break; + case KC_INSERT: print("layout\n"); serial_send(0x0F); break; diff --git a/converter/sun_usb/matrix.c b/converter/sun_usb/matrix.c index 988622bc39..f333f542bd 100644 --- a/converter/sun_usb/matrix.c +++ b/converter/sun_usb/matrix.c @@ -65,7 +65,7 @@ void matrix_init(void) { DDRD |= (1<<6); PORTD |= (1<<6); - debug_enable = true; + //debug_enable = true; serial_init(); @@ -86,14 +86,16 @@ uint8_t matrix_scan(void) debug_hex(code); debug(" "); switch (code) { - case 0x7E: // reset fail - case 0xFE: // layout case 0xFF: // reset success + case 0xFE: // layout + case 0x7E: // reset fail + if (code == 0xFF) print("reset: 0xFF "); + if (code == 0x7E) print("reset fail: 0x7E "); + if (code == 0xFE) print("layout: 0xFE "); + // response byte _delay_ms(500); - // ignore response byte - debug("(response ignored:"); - while ((code = serial_recv())) { debug(" "); debug_hex(code); } - debug(") "); + if (code = serial_recv()) print_hex8(code); + print("\n"); // FALL THROUGH case 0x7F: // all keys up diff --git a/converter/usb_usb/README b/converter/usb_usb/README index d0547cde90..a489371107 100644 --- a/converter/usb_usb/README +++ b/converter/usb_usb/README @@ -14,12 +14,8 @@ Build firmware -------------- $ git clone git://github.com/tmk/tmk_keyboard.git $ cd tmk_keyboard - $ git checkout usb_hid $ git submodule init $ git submodule update - -and download LUFA and unzip under protocol/lufa and edit LUFA_PATH in protocol/lufa.mk. Then, - $ cd converter/usb_usb $ make diff --git a/converter/usb_usb/config.h b/converter/usb_usb/config.h index ecf4ed9b19..d614973f7e 100644 --- a/converter/usb_usb/config.h +++ b/converter/usb_usb/config.h @@ -33,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MATRIX_ROWS 32 #define MATRIX_COLS 8 +#define USE_LEGACY_KEYMAP /* key combination for command */ #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) diff --git a/converter/usb_usb/main.cpp b/converter/usb_usb/main.cpp index 46c728e9b5..20b7af66a2 100644 --- a/converter/usb_usb/main.cpp +++ b/converter/usb_usb/main.cpp @@ -59,7 +59,6 @@ int main(void) LED_TX_INIT; LED_TX_ON; - print_enable = true; debug_enable = true; debug_matrix = true; debug_keyboard = true; diff --git a/doc/keymap.md b/doc/keymap.md index 11feeac218..9d986a8c51 100644 --- a/doc/keymap.md +++ b/doc/keymap.md @@ -497,6 +497,13 @@ Number of taps can be configured with `TAPPING_TOGGLE` in `config.h`, `5` by def +### 3.5 Momentary switching with Modifiers +This registers modifier key(s) simultaneously with layer switching. + + ACTION_LAYER_MODS(2, MOD_LSFT | MOD_LALT) + + + ## 4. Tapping Tapping is to press and release a key quickly. Tapping speed is determined with setting of `TAPPING_TERM`, which can be defined in `config.h`, 200ms by default. diff --git a/keyboard/lightpad/Makefile.lufa b/keyboard/lightpad/Makefile.lufa new file mode 100644 index 0000000000..7bce7ebffc --- /dev/null +++ b/keyboard/lightpad/Makefile.lufa @@ -0,0 +1,117 @@ +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF. +# +# make extcoff = Convert ELF to AVR Extended COFF. +# +# make program = Download the hex file to the device. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# make dfu = Download the hex file to the device, using dfu-programmer (must +# have dfu-programmer installed). +# +# make flip = Download the hex file to the device, using Atmel FLIP (must +# have Atmel FLIP installed). +# +# make dfu-ee = Download the eeprom file to the device, using dfu-programmer +# (must have dfu-programmer installed). +# +# make flip-ee = Download the eeprom file to the device, using Atmel FLIP +# (must have Atmel FLIP installed). +# +# make debug = Start either simulavr or avarice as specified for debugging, +# with avr-gdb or avr-insight as the front end for debugging. +# +# make filename.s = Just compile filename.c into the assembler code only. +# +# make filename.i = Create a preprocessed source file for use in submitting +# bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = lightpad_lufa + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# List C source files here. (C dependencies are automatically generated.) +SRC = keymap.c \ + matrix.c \ + led.c \ + backlight.c + +CONFIG_H = config.h + +# MCU name +MCU = atmega32u4 + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 8000000 + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + +# Build Options +# comment out to disable the options. +# +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +#MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +#CONSOLE_ENABLE = yes # Console for debug(+400) +#COMMAND_ENABLE = yes # Commands for debug and configuration +#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality + +# Boot Section Size in bytes +# Teensy halfKay 512 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/keyboard/lightpad/README.md b/keyboard/lightpad/README.md new file mode 100644 index 0000000000..b21cccc6a2 --- /dev/null +++ b/keyboard/lightpad/README.md @@ -0,0 +1,24 @@ +Lightpad keypad firmware +====================== +Korean custom keypad designed by Duck. + +*Note that this is not the official firmware* + + +Supported models +---------------- +All pcb options are supported. + + +Build +----- +Move to this directory then just run `make` like: + + $ make -f Makefile.lufa + + +Bootloader +--------- +The PCB is hardwired to run the bootloader if the key at the `top left` position is held down when connecting the keyboard. + +It is still possible to use Boot Magic and Command to access the bootloader though. diff --git a/keyboard/lightpad/backlight.c b/keyboard/lightpad/backlight.c new file mode 100644 index 0000000000..693c566fc5 --- /dev/null +++ b/keyboard/lightpad/backlight.c @@ -0,0 +1,129 @@ +/* +Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <avr/io.h> +#include "backlight.h" + +/* Backlight pin configuration + * + * FN1 PB0 (low) + * FN2 PB5 (low) + * FN3 PB4 (low) + * FN4 PD7 (low) + * REAR PD6 (high) + * NUMPAD PB2 (high) + * NUMLOCK PB1 (low) + */ +void backlight_init_ports() { + DDRB |= (1<<0) | (1<<1) | (1<<2) | (1<<4) | (1<<5); + DDRD |= (1<<6) | (1<<7); + + backlight_disable_numlock(); +} + +void backlight_set(uint8_t level) { + (level & BACKLIGHT_FN1) ? backlight_enable_fn1() : backlight_disable_fn1(); + (level & BACKLIGHT_FN2) ? backlight_enable_fn2() : backlight_disable_fn2(); + (level & BACKLIGHT_FN3) ? backlight_enable_fn3() : backlight_disable_fn3(); + (level & BACKLIGHT_FN4) ? backlight_enable_fn4() : backlight_disable_fn4(); + (level & BACKLIGHT_NUMPAD) ? backlight_enable_numpad() : backlight_disable_numpad(); + (level & BACKLIGHT_REAR) ? backlight_enable_rear() : backlight_disable_rear(); +} + +void backlight_enable_fn1() { + PORTB &= ~(1<<0); +} + +void backlight_disable_fn1() { + PORTB |= (1<<0); +} + +void backlight_invert_fn1() { + PORTB ^= (1<<0); +} + +void backlight_enable_fn2() { + PORTB &= ~(1<<5); +} + +void backlight_disable_fn2() { + PORTB |= (1<<5); +} + +void backlight_invert_fn2() { + PORTB ^= (1<<5); +} + +void backlight_enable_fn3() { + PORTB &= ~(1<<4); +} + +void backlight_disable_fn3() { + PORTB |= (1<<4); +} + +void backlight_invert_fn3() { + PORTB ^= (1<<4); +} + +void backlight_enable_fn4() { + PORTD &= ~(1<<7); +} + +void backlight_disable_fn4() { + PORTD |= (1<<7); +} + +void backlight_invert_fn4() { + PORTD ^= (1<<7); +} + +void backlight_enable_numpad() { + PORTB |= (1<<2); +} + +void backlight_disable_numpad() { + PORTB &= ~(1<<2); +} + +void backlight_invert_numpad() { + PORTB ^= (1<<2); +} + +void backlight_enable_numlock() { + PORTB &= ~(1<<1); +} + +void backlight_disable_numlock() { + PORTB |= (1<<1); +} + +void backlight_invert_numlock() { + PORTB ^= (1<<1); +} + +void backlight_enable_rear() { + PORTD |= (1<<6); +} + +void backlight_disable_rear() { + PORTD &= ~(1<<6); +} + +void backlight_invert_rear() { + PORTD ^= (1<<6); +} diff --git a/keyboard/lightpad/backlight.h b/keyboard/lightpad/backlight.h new file mode 100644 index 0000000000..3b3cfd9aea --- /dev/null +++ b/keyboard/lightpad/backlight.h @@ -0,0 +1,39 @@ + +enum backlight_level { + BACKLIGHT_FN1 = 0b0000001, + BACKLIGHT_FN2 = 0b0000010, + BACKLIGHT_FN3 = 0b0000100, + BACKLIGHT_FN4 = 0b0001000, + BACKLIGHT_NUMPAD = 0b0010000, + BACKLIGHT_REAR = 0b0100000, +}; + +void backlight_init_ports(void); + +void backlight_invert_fn1(void); +void backlight_enable_fn1(void); +void backlight_disable_fn1(void); + +void backlight_invert_fn2(void); +void backlight_enable_fn2(void); +void backlight_disable_fn2(void); + +void backlight_invert_fn3(void); +void backlight_enable_fn3(void); +void backlight_disable_fn3(void); + +void backlight_invert_fn4(void); +void backlight_enable_fn4(void); +void backlight_disable_fn4(void); + +void backlight_invert_numlock(void); +void backlight_enable_numlock(void); +void backlight_disable_numlock(void); + +void backlight_enable_numpad(void); +void backlight_disable_numpad(void); +void backlight_invert_numpad(void); + +void backlight_enable_rear(void); +void backlight_disable_rear(void); +void backlight_invert_rear(void); diff --git a/keyboard/lightpad/config.h b/keyboard/lightpad/config.h new file mode 100644 index 0000000000..7f5a596c0c --- /dev/null +++ b/keyboard/lightpad/config.h @@ -0,0 +1,46 @@ +/* +Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x6050 +#define DEVICE_VER 0x0104 +#define MANUFACTURER Duck +#define PRODUCT Lightpad + +/* message strings */ +#define DESCRIPTION t.m.k. keyboard firmware for Lightpad + +/* matrix size */ +#define MATRIX_ROWS 6 +#define MATRIX_COLS 4 + +/* number of backlight levels */ +#define BACKLIGHT_LEVELS 1 + +/* Set 0 if need no debouncing */ +#define DEBOUNCE 5 + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +#endif diff --git a/keyboard/lightpad/keymap.c b/keyboard/lightpad/keymap.c new file mode 100644 index 0000000000..6d078230bb --- /dev/null +++ b/keyboard/lightpad/keymap.c @@ -0,0 +1,73 @@ +/* +Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <stdint.h> +#include <stdbool.h> +#include <avr/pgmspace.h> +#include "keycode.h" +#include "action.h" +#include "action_macro.h" +#include "report.h" +#include "host.h" +#include "debug.h" +#include "keymap.h" + +/* Map physical keyboard layout to matrix array */ +#define KEYMAP( \ + K5A, K5B, K5C, K5D, \ + K4A, K4B, K4C, K4D, \ + K3A, K3B, K3C, K3D, \ + K2A, K2B, K2C, \ + K1A, K1B, K1C, K1D, \ + K0A, K0B, K0C \ +) { \ +/* 0 1 2 3 */ \ +/* 5 */ { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D}, \ +/* 4 */ { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D}, \ +/* 3 */ { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D}, \ +/* 2 */ { KC_##K2A, KC_##K2B, KC_##K2C, KC_NO}, \ +/* 1 */ { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D}, \ +/* 0 */ { KC_##K0A, KC_##K0B, KC_##K0C, KC_NO, } \ +} + +#include "keymap_lightpad.h" + +#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) +#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) + +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ + if (layer < KEYMAPS_SIZE) { + return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); + } else { + // fall back to layer 0 + return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); + } +} + +/* translates Fn keycode to action */ +action_t keymap_fn_to_action(uint8_t keycode) +{ + action_t action; + if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) { + action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); + } else { + action.code = ACTION_NO; + } + return action; +} diff --git a/keyboard/lightpad/keymap_lightpad.h b/keyboard/lightpad/keymap_lightpad.h new file mode 100644 index 0000000000..9333964e39 --- /dev/null +++ b/keyboard/lightpad/keymap_lightpad.h @@ -0,0 +1,29 @@ +#include "backlight.h" + +static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + KEYMAP(\ + FN0, F1, DEL, BSPC, \ + NLCK,PSLS,PAST,PMNS, \ + P7, P8, P9, PPLS, \ + P4, P5, P6, \ + P1, P2, P3, PENT, \ + P0, NO, PDOT), \ + KEYMAP(\ + TRNS,PGDN,PGUP,MUTE, \ + MSEL,MPRV,MNXT,VOLD, \ + P7, P8, P9, VOLU, \ + FN4, FN5, FN6, \ + FN1, FN2, FN3, MPLY, \ + FN7, NO, MSTP) +}; + +static const uint16_t PROGMEM fn_actions[] = { + [0] = ACTION_LAYER_MOMENTARY(1), + [1] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FN1), + [2] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FN2), + [3] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FN3), + [4] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FN4), + [5] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_NUMPAD), + [6] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_REAR), + [7] = ACTION_BACKLIGHT_TOGGLE() +}; diff --git a/keyboard/lightpad/led.c b/keyboard/lightpad/led.c new file mode 100644 index 0000000000..ebfac3af89 --- /dev/null +++ b/keyboard/lightpad/led.c @@ -0,0 +1,24 @@ +/* +Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <avr/io.h> +#include "stdint.h" +#include "led.h" + +void led_set(uint8_t usb_led) { + (usb_led & (1<<USB_LED_NUM_LOCK)) ? backlight_enable_numlock() : backlight_disable_numlock(); +} diff --git a/keyboard/lightpad/matrix.c b/keyboard/lightpad/matrix.c new file mode 100644 index 0000000000..87d338395b --- /dev/null +++ b/keyboard/lightpad/matrix.c @@ -0,0 +1,205 @@ +/* +Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <stdint.h> +#include <stdbool.h> +#include <avr/io.h> +#include <util/delay.h> +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" +#include "eeconfig.h" +#include "action_layer.h" +#include "backlight.h" + +#ifndef DEBOUNCE +# define DEBOUNCE 0 +#endif +static uint8_t debouncing = DEBOUNCE; + +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +static uint8_t read_rows(void); +static uint8_t read_fwkey(void); +static void init_rows(void); +static void unselect_cols(void); +static void select_col(uint8_t col); + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void misc_init(void) { +} + +void matrix_init(void) +{ + backlight_init_ports(); + unselect_cols(); + init_rows(); + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + matrix_debouncing[i] = 0; + } +} + +uint8_t matrix_scan(void) +{ + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + select_col(col); + _delay_us(3); + uint8_t rows = read_rows(); + // Use the otherwise unused col: 0 row: 0 for firmware key + if(col == 0) { + rows |= read_fwkey(); + } + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col); + bool curr_bit = rows & (1<<row); + if (prev_bit != curr_bit) { + matrix_debouncing[row] ^= ((matrix_row_t)1<<col); + if (debouncing) { + dprint("bounce!: "); dprintf("%02X", debouncing); dprintln(); + } + debouncing = DEBOUNCE; + } + } + unselect_cols(); + } + + if (debouncing) { + if (--debouncing) { + _delay_ms(1); + } else { + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + matrix[i] = matrix_debouncing[i]; + } + } + } + + return 1; +} + +bool matrix_is_modified(void) +{ + if (debouncing) return false; + return true; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & ((matrix_row_t)1<<col)); +} + +inline +matrix_row_t matrix_get_row(uint8_t row) +{ + return matrix[row]; +} + +void matrix_print(void) +{ + print("\nr/c 0123456789ABCDEF\n"); + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + xprintf("%02X: %032lb\n", row, bitrev32(matrix_get_row(row))); + } +} + +uint8_t matrix_key_count(void) +{ + uint8_t count = 0; + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + count += bitpop32(matrix[i]); + } + return count; +} + +/* Row configuration + * + * row: 0 1 2 3 4 5 + * pin: PD0 PD1 PD2 PD3 PD5 PB7 + * + * Firmware uses pin PE2 + */ +static void init_rows(void) +{ + DDRD &= ~0b00101111; + PORTD |= 0b00101111; + + DDRB &= ~0b10000000; + PORTB |= 0b10000000; + + DDRE &= ~0b00000100; + PORTE |= 0b00000100; +} + +static uint8_t read_rows(void) +{ + return (PIND&(1<<0) ? (1<<0) : 0) | + (PIND&(1<<1) ? (1<<1) : 0) | + (PIND&(1<<2) ? (1<<2) : 0) | + (PIND&(1<<3) ? (1<<3) : 0) | + (PIND&(1<<5) ? (1<<4) : 0) | + (PINB&(1<<7) ? (1<<5) : 0); +} + +static uint8_t read_fwkey(void) +{ + return PINE&(1<<2) ? 0 : (1<<0); +} + +/* Column configuration + * + * col: 0 1 2 3 + * pin: PF0 PF1 PC7 PC6 + */ +static void unselect_cols(void) +{ + DDRF |= 0b00000011; + PORTF &= ~0b00000011; + DDRC |= 0b11000000; + PORTC &= ~0b11000000; +} + +static void select_col(uint8_t col) +{ + switch (col) { + case 0: + PORTF |= (1<<0); + break; + case 1: + PORTF |= (1<<1); + break; + case 2: + PORTC |= (1<<7); + break; + case 3: + PORTC |= (1<<6); + break; + } +} diff --git a/protocol.mk b/protocol.mk index ca435ba43c..e057d1d601 100644 --- a/protocol.mk +++ b/protocol.mk @@ -24,5 +24,25 @@ ifdef PS2_USE_USART endif +ifdef SERIAL_MOUSE_MICROSOFT_ENABLE + SRC += $(PROTOCOL_DIR)/serial_mouse_microsoft.c + OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MICROSOFT \ + -DMOUSE_ENABLE +endif + +ifdef SERIAL_MOUSE_MOUSESYSTEMS_ENABLE + SRC += $(PROTOCOL_DIR)/serial_mouse_mousesystems.c + OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MOUSESYSTEMS \ + -DMOUSE_ENABLE +endif + +ifdef SERIAL_MOUSE_USE_SOFT + SRC += $(PROTOCOL_DIR)/serial_soft.c +endif + +ifdef SERIAL_MOUSE_USE_UART + SRC += $(PROTOCOL_DIR)/serial_uart.c +endif + # Search Path VPATH += $(TOP_DIR)/protocol diff --git a/protocol/pjrc/usb_keyboard.c b/protocol/pjrc/usb_keyboard.c index d168331879..758a4edc6c 100644 --- a/protocol/pjrc/usb_keyboard.c +++ b/protocol/pjrc/usb_keyboard.c @@ -39,7 +39,7 @@ uint8_t keyboard_protocol=1; // the idle configuration, how often we send the report to the // host (ms * 4) even when it hasn't changed // Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request. -uint8_t keyobard_idle=125; +uint8_t keyboard_idle=125; // count until idle timeout uint8_t usb_keyboard_idle_count=0; diff --git a/protocol/serial_mouse.h b/protocol/serial_mouse.h new file mode 100644 index 0000000000..226314fc0e --- /dev/null +++ b/protocol/serial_mouse.h @@ -0,0 +1,33 @@ +/* +Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef SERIAL_MOUSE_H +#define SERIAL_MOUSE_H + +#include <stdint.h> + +#include "serial.h" + +static inline uint8_t serial_mouse_init(void) +{ + serial_init(); + return 0; +} + +void serial_mouse_task(void); + +#endif diff --git a/protocol/serial_mouse_microsoft.c b/protocol/serial_mouse_microsoft.c new file mode 100644 index 0000000000..ab74b7cdd3 --- /dev/null +++ b/protocol/serial_mouse_microsoft.c @@ -0,0 +1,124 @@ +/* +Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <stdint.h> +#include <avr/io.h> +#include <util/delay.h> + +#include "serial.h" +#include "serial_mouse.h" +#include "report.h" +#include "host.h" +#include "timer.h" +#include "print.h" +#include "debug.h" + +#ifdef MAX +#undef MAX +#endif +#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) + +static void print_usb_data(const report_mouse_t *report); + +void serial_mouse_task(void) +{ + /* 3 byte ring buffer */ + static uint8_t buffer[3]; + static int buffer_cur = 0; + + static report_mouse_t report = {}; + + int16_t rcv; + + rcv = serial_recv2(); + if (rcv < 0) + /* no new data */ + return; + + if (debug_mouse) + xprintf("serial_mouse: byte: %04X\n", rcv); + + /* + * If bit 6 is one, this signals the beginning + * of a 3 byte sequence/packet. + */ + if (rcv & (1 << 6)) + buffer_cur = 0; + + buffer[buffer_cur] = (uint8_t)rcv; + + if (buffer_cur == 0 && buffer[buffer_cur] == 0x20) { + /* + * Logitech extension: This must be a follow-up on + * the last 3-byte packet signaling a middle button click + */ + report.buttons |= MOUSE_BTN3; + report.x = report.y = 0; + + print_usb_data(&report); + host_mouse_send(&report); + return; + } + + buffer_cur++; + + if (buffer_cur < 3) + return; + buffer_cur = 0; + + /* + * parse 3 byte packet. + * NOTE: We only get a complete packet + * if the mouse moved or the button states + * change. + */ + report.buttons = 0; + if (buffer[0] & (1 << 5)) + report.buttons |= MOUSE_BTN1; + if (buffer[0] & (1 << 4)) + report.buttons |= MOUSE_BTN2; + + report.x = (buffer[0] << 6) | buffer[1]; + report.y = ((buffer[0] << 4) & 0xC0) | buffer[2]; + + /* USB HID uses values from -127 to 127 only */ + report.x = MAX(report.x, -127); + report.y = MAX(report.y, -127); + +#if 0 + if (!report.buttons && !report.x && !report.y) { + /* + * Microsoft extension: Middle mouse button pressed + * FIXME: I don't know how exactly this extension works. + */ + report.buttons |= MOUSE_BTN3; + } +#endif + + print_usb_data(&report); + host_mouse_send(&report); +} + +static void print_usb_data(const report_mouse_t *report) +{ + if (!debug_mouse) + return; + + xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n", + report->buttons, report->x, report->y, + report->v, report->h); +} diff --git a/protocol/serial_mouse_mousesystems.c b/protocol/serial_mouse_mousesystems.c new file mode 100644 index 0000000000..cfe8996216 --- /dev/null +++ b/protocol/serial_mouse_mousesystems.c @@ -0,0 +1,131 @@ +/* +Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <stdint.h> +#include <avr/io.h> +#include <util/delay.h> + +#include "serial.h" +#include "serial_mouse.h" +#include "report.h" +#include "host.h" +#include "timer.h" +#include "print.h" +#include "debug.h" + +#ifdef MAX +#undef MAX +#endif +#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) + +//#define SERIAL_MOUSE_CENTER_SCROLL + +static void print_usb_data(const report_mouse_t *report); + +void serial_mouse_task(void) +{ + /* 5 byte ring buffer */ + static uint8_t buffer[5]; + static int buffer_cur = 0; + + int16_t rcv; + + report_mouse_t report = {0, 0, 0, 0, 0}; + + rcv = serial_recv2(); + if (rcv < 0) + /* no new data */ + return; + + if (debug_mouse) + xprintf("serial_mouse: byte: %04X\n", rcv); + + /* + * Synchronization: mouse(4) says that all + * bytes but the first one in the packet have + * bit 7 == 0, but this is untrue. + * Therefore we discard all bytes up to the + * first one with the characteristic bit pattern. + */ + if (buffer_cur == 0 && (rcv >> 3) != 0x10) + return; + + buffer[buffer_cur++] = (uint8_t)rcv; + + if (buffer_cur < 5) + return; + buffer_cur = 0; + +#ifdef SERIAL_MOUSE_CENTER_SCROLL + if ((buffer[0] & 0x7) == 0x5 && (buffer[1] || buffer[2])) { + /* USB HID uses only values from -127 to 127 */ + report.h = MAX((int8_t)buffer[1], -127); + report.v = MAX((int8_t)buffer[2], -127); + + print_usb_data(&report); + host_mouse_send(&report); + + if (buffer[3] || buffer[4]) { + report.h = MAX((int8_t)buffer[3], -127); + report.v = MAX((int8_t)buffer[4], -127); + + print_usb_data(&report); + host_mouse_send(&report); + } + + return; + } +#endif + + /* + * parse 5 byte packet. + * NOTE: We only get a complete packet + * if the mouse moved or the button states + * change. + */ + if (!(buffer[0] & (1 << 2))) + report.buttons |= MOUSE_BTN1; + if (!(buffer[0] & (1 << 1))) + report.buttons |= MOUSE_BTN3; + if (!(buffer[0] & (1 << 0))) + report.buttons |= MOUSE_BTN2; + + /* USB HID uses only values from -127 to 127 */ + report.x = MAX((int8_t)buffer[1], -127); + report.y = MAX(-(int8_t)buffer[2], -127); + + print_usb_data(&report); + host_mouse_send(&report); + + if (buffer[3] || buffer[4]) { + report.x = MAX((int8_t)buffer[3], -127); + report.y = MAX(-(int8_t)buffer[4], -127); + + print_usb_data(&report); + host_mouse_send(&report); + } +} + +static void print_usb_data(const report_mouse_t *report) +{ + if (!debug_mouse) + return; + + xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n", + report->buttons, report->x, report->y, + report->v, report->h); +} diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c index e8870bcd79..44822b7e43 100644 --- a/protocol/serial_soft.c +++ b/protocol/serial_soft.c @@ -122,7 +122,11 @@ void serial_send(uint8_t data) /* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */ #ifdef SERIAL_SOFT_BIT_ORDER_MSB + #ifdef SERIAL_SOFT_DATA_7BIT + uint8_t mask = 0x40; + #else uint8_t mask = 0x80; + #endif #else uint8_t mask = 0x01; #endif @@ -133,7 +137,11 @@ void serial_send(uint8_t data) SERIAL_SOFT_TXD_OFF(); _delay_us(WAIT_US); - while (mask) { +#ifdef SERIAL_SOFT_DATA_7BIT + while (mask&0x7F) { +#else + while (mask&0xFF) { +#endif if (data&mask) { SERIAL_SOFT_TXD_ON(); parity ^= 1; @@ -173,7 +181,11 @@ ISR(SERIAL_SOFT_RXD_VECT) uint8_t data = 0; #ifdef SERIAL_SOFT_BIT_ORDER_MSB + #ifdef SERIAL_SOFT_DATA_7BIT + uint8_t mask = 0x40; + #else uint8_t mask = 0x80; + #endif #else uint8_t mask = 0x01; #endif @@ -197,7 +209,11 @@ ISR(SERIAL_SOFT_RXD_VECT) #else mask <<= 1; #endif - } while (mask); +#ifdef SERIAL_SOFT_DATA_7BIT + } while (mask&0x7F); +#else + } while (mask&0xFF); +#endif #if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD) /* to center of parity bit */ diff --git a/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h b/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h index d76d2a33d4..947325e5f5 100644 --- a/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h +++ b/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h @@ -35,7 +35,7 @@ // -std=c++0x class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal))) +#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal))) // An inherited class for holding the result of a concatenation. These // result objects are assumed to be writable by subsequent concatenations. diff --git a/protocol/usb_hid/override_wiring.c b/protocol/usb_hid/override_wiring.c index 3b3f5e3028..1e9a94ce26 100644 --- a/protocol/usb_hid/override_wiring.c +++ b/protocol/usb_hid/override_wiring.c @@ -1,6 +1,7 @@ /* * To keep Timer0 for common/timer.c override arduino/wiring.c. */ +#define __DELAY_BACKWARD_COMPATIBLE__ #include <util/delay.h> #include "common/timer.h" #include "Arduino.h" diff --git a/protocol/usb_hid/parser.cpp b/protocol/usb_hid/parser.cpp index 66e949518e..28151f9d59 100644 --- a/protocol/usb_hid/parser.cpp +++ b/protocol/usb_hid/parser.cpp @@ -1,5 +1,3 @@ -#include <cstring.h> - #include "parser.h" #include "usb_hid.h" diff --git a/protocol/vusb/usbdrv/usbdrv.c b/protocol/vusb/usbdrv/usbdrv.c index 21ed554f86..2e8dd8756b 100644 --- a/protocol/vusb/usbdrv/usbdrv.c +++ b/protocol/vusb/usbdrv/usbdrv.c @@ -67,7 +67,7 @@ optimizing hints: #if USB_CFG_DESCR_PROPS_STRING_0 == 0 #undef USB_CFG_DESCR_PROPS_STRING_0 #define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0) -PROGMEM char usbDescriptorString0[] = { /* language descriptor */ +const PROGMEM char usbDescriptorString0[] = { /* language descriptor */ 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */ 3, /* descriptor type */ 0x09, 0x04, /* language index (0x0409 = US-English) */ @@ -77,7 +77,7 @@ PROGMEM char usbDescriptorString0[] = { /* language descriptor */ #if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN #undef USB_CFG_DESCR_PROPS_STRING_VENDOR #define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor) -PROGMEM int usbDescriptorStringVendor[] = { +const PROGMEM int usbDescriptorStringVendor[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), USB_CFG_VENDOR_NAME }; @@ -86,7 +86,7 @@ PROGMEM int usbDescriptorStringVendor[] = { #if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN #undef USB_CFG_DESCR_PROPS_STRING_PRODUCT #define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice) -PROGMEM int usbDescriptorStringDevice[] = { +const PROGMEM int usbDescriptorStringDevice[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), USB_CFG_DEVICE_NAME }; @@ -108,7 +108,7 @@ PROGMEM int usbDescriptorStringSerialNumber[] = { #if USB_CFG_DESCR_PROPS_DEVICE == 0 #undef USB_CFG_DESCR_PROPS_DEVICE #define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice) -PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */ +const PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */ 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */ USBDESCR_DEVICE, /* descriptor type */ 0x10, 0x01, /* USB version supported */ diff --git a/protocol/vusb/usbdrv/usbdrv.h b/protocol/vusb/usbdrv/usbdrv.h index 3a78f307bf..42fe163720 100644 --- a/protocol/vusb/usbdrv/usbdrv.h +++ b/protocol/vusb/usbdrv/usbdrv.h @@ -452,43 +452,43 @@ extern #if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM) PROGMEM #endif -char usbDescriptorDevice[]; +const char usbDescriptorDevice[]; extern #if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM) PROGMEM #endif -char usbDescriptorConfiguration[]; +const char usbDescriptorConfiguration[]; extern #if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM) PROGMEM #endif -char usbDescriptorHidReport[]; +const char usbDescriptorHidReport[]; extern #if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM) PROGMEM #endif -char usbDescriptorString0[]; +const char usbDescriptorString0[]; extern #if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM) PROGMEM #endif -int usbDescriptorStringVendor[]; +const int usbDescriptorStringVendor[]; extern #if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM) PROGMEM #endif -int usbDescriptorStringDevice[]; +const int usbDescriptorStringDevice[]; extern #if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM) PROGMEM #endif -int usbDescriptorStringSerialNumber[]; +const int usbDescriptorStringSerialNumber[]; #endif /* __ASSEMBLER__ */ diff --git a/protocol/vusb/vusb.c b/protocol/vusb/vusb.c index 328885a9b5..7d0292ed17 100644 --- a/protocol/vusb/vusb.c +++ b/protocol/vusb/vusb.c @@ -35,6 +35,13 @@ static report_keyboard_t kbuf[KBUF_SIZE]; static uint8_t kbuf_head = 0; static uint8_t kbuf_tail = 0; +typedef struct { + uint8_t modifier; + uint8_t reserved; + uint8_t keycode[6]; +} keyboard_report_t; + +static keyboard_report_t keyboard_report; // sent to PC /* transfer keyboard report from buffer */ void vusb_transfer_keyboard(void) @@ -168,8 +175,8 @@ usbRequest_t *rq = (void *)data; if(rq->bRequest == USBRQ_HID_GET_REPORT){ debug("GET_REPORT:"); /* we only have one report type, so don't look at wValue */ - usbMsgPtr = (void *)keyboard_report; - return sizeof(*keyboard_report); + usbMsgPtr = (void *)&keyboard_report; + return sizeof(keyboard_report); }else if(rq->bRequest == USBRQ_HID_GET_IDLE){ debug("GET_IDLE: "); //debug_hex(vusb_idle_rate); @@ -232,7 +239,7 @@ uchar usbFunctionWrite(uchar *data, uchar len) * * from an example in HID spec appendix */ -PROGMEM uchar keyboard_hid_report[] = { +const PROGMEM uchar keyboard_hid_report[] = { 0x05, 0x01, // Usage Page (Generic Desktop), 0x09, 0x06, // Usage (Keyboard), 0xA1, 0x01, // Collection (Application), @@ -275,7 +282,7 @@ PROGMEM uchar keyboard_hid_report[] = { * http://www.keil.com/forum/15671/ * http://www.microsoft.com/whdc/device/input/wheel.mspx */ -PROGMEM uchar mouse_hid_report[] = { +const PROGMEM uchar mouse_hid_report[] = { /* mouse */ 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x02, // USAGE (Mouse) @@ -358,7 +365,7 @@ PROGMEM uchar mouse_hid_report[] = { * contains: device, interface, HID and endpoint descriptors */ #if USB_CFG_DESCR_PROPS_CONFIGURATION -PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ +const PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ USBDESCR_CONFIG, /* descriptor type */ 9 + (9 + 9 + 7) + (9 + 9 + 7), 0, |