diff options
58 files changed, 2066 insertions, 1633 deletions
@@ -25,6 +25,7 @@ endif ifdef MOUSEKEY_ENABLE SRC += $(COMMON_DIR)/mousekey.c OPT_DEFS += -DMOUSEKEY_ENABLE + OPT_DEFS += -DMOUSE_ENABLE endif ifdef EXTRAKEY_ENABLE @@ -47,16 +48,6 @@ ifdef NKRO_ENABLE OPT_DEFS += -DNKRO_ENABLE endif -ifdef PS2_MOUSE_ENABLE - SRC += $(COMMON_DIR)/ps2.c \ - $(COMMON_DIR)/ps2_mouse.c - OPT_DEFS += -DPS2_MOUSE_ENABLE -endif - -ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) - OPT_DEFS += -DMOUSE_ENABLE -endif - ifdef SLEEP_LED_ENABLE SRC += $(COMMON_DIR)/sleep_led.c OPT_DEFS += -DSLEEP_LED_ENABLE diff --git a/common/action.c b/common/action.c index f7ae85b941..485abf81e3 100644 --- a/common/action.c +++ b/common/action.c @@ -485,12 +485,6 @@ void clear_keyboard_but_mods(void) #endif } -bool sending_anykey(void) -{ - return (has_anykey() || host_mouse_in_use() || - host_last_sysytem_report() || host_last_consumer_report()); -} - bool is_tap_key(key_t key) { action_t action = layer_switch_get_action(key); diff --git a/common/action.h b/common/action.h index d57f4a86ff..077711c231 100644 --- a/common/action.h +++ b/common/action.h @@ -64,7 +64,6 @@ void unregister_mods(uint8_t mods); //void set_mods(uint8_t mods); void clear_keyboard(void); void clear_keyboard_but_mods(void); -bool sending_anykey(void); void layer_switch(uint8_t new_layer); bool is_tap_key(key_t key); diff --git a/common/action_code.h b/common/action_code.h index c153838f2b..b08d36124e 100644 --- a/common/action_code.h +++ b/common/action_code.h @@ -207,10 +207,10 @@ enum mods_codes { MODS_ONESHOT = 0x00, }; #define ACTION_KEY(key) ACTION(ACT_MODS, (key)) -#define ACTION_MODS(mods) ACTION(ACT_MODS, (mods&0x1f)<<8 | 0) -#define ACTION_MODS_KEY(mods, key) ACTION(ACT_MODS, (mods&0x1f)<<8 | (key)) -#define ACTION_MODS_TAP_KEY(mods, key) ACTION(ACT_MODS_TAP, (mods&0x1f)<<8 | (key)) -#define ACTION_MODS_ONESHOT(mods) ACTION(ACT_MODS_TAP, (mods&0x1f)<<8 | MODS_ONESHOT) +#define ACTION_MODS(mods) ACTION(ACT_MODS, ((mods)&0x1f)<<8 | 0) +#define ACTION_MODS_KEY(mods, key) ACTION(ACT_MODS, ((mods)&0x1f)<<8 | (key)) +#define ACTION_MODS_TAP_KEY(mods, key) ACTION(ACT_MODS_TAP, ((mods)&0x1f)<<8 | (key)) +#define ACTION_MODS_ONESHOT(mods) ACTION(ACT_MODS_TAP, ((mods)&0x1f)<<8 | MODS_ONESHOT) /* diff --git a/common/action_util.h b/common/action_util.h index 939bc2b662..f9d3161a80 100644 --- a/common/action_util.h +++ b/common/action_util.h @@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define ACTION_UTIL_H #include <stdint.h> +#include "report.h" extern report_keyboard_t *keyboard_report; diff --git a/common/host.c b/common/host.c index 0703dba013..1eafef75cc 100644 --- a/common/host.c +++ b/common/host.c @@ -27,9 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. bool keyboard_nkro = false; #endif -report_mouse_t mouse_report = {}; - - static host_driver_t *driver; static uint16_t last_system_report = 0; static uint16_t last_consumer_report = 0; @@ -89,11 +86,6 @@ void host_consumer_send(uint16_t report) (*driver->send_consumer)(report); } -uint8_t host_mouse_in_use(void) -{ - return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h); -} - uint16_t host_last_sysytem_report(void) { return last_system_report; diff --git a/common/host.h b/common/host.h index c1a0fbac40..8ff2629852 100644 --- a/common/host.h +++ b/common/host.h @@ -32,9 +32,6 @@ extern "C" { extern bool keyboard_nkro; #endif -/* report */ -extern report_mouse_t mouse_report; - /* host driver */ void host_set_driver(host_driver_t *driver); @@ -47,9 +44,6 @@ void host_mouse_send(report_mouse_t *report); void host_system_send(uint16_t data); void host_consumer_send(uint16_t data); -/* mouse report utils */ -uint8_t host_mouse_in_use(void); - uint16_t host_last_sysytem_report(void); uint16_t host_last_consumer_report(void); diff --git a/common/keyboard.c b/common/keyboard.c index 601e3abe17..2b66f20a01 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -30,8 +30,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "sendchar.h" #include "bootmagic.h" #include "eeconfig.h" -#include "mousekey.h" #include "backlight.h" +#ifdef MOUSEKEY_ENABLE +# include "mousekey.h" +#endif +#ifdef PS2_MOUSE_ENABLE +# include "ps2_mouse.h" +#endif #ifdef MATRIX_HAS_GHOST @@ -111,10 +116,16 @@ void keyboard_task(void) action_exec(TICK); MATRIX_LOOP_END: + #ifdef MOUSEKEY_ENABLE // mousekey repeat & acceleration mousekey_task(); #endif + +#ifdef PS2_MOUSE_ENABLE + ps2_mouse_task(); +#endif + // update LED if (led_status != host_keyboard_leds()) { led_status = host_keyboard_leds(); diff --git a/common/mousekey.c b/common/mousekey.c index 3068fc5e37..017be94116 100644 --- a/common/mousekey.c +++ b/common/mousekey.c @@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. +static report_mouse_t mouse_report = {}; static uint8_t mousekey_repeat = 0; static uint8_t mousekey_accel = 0; diff --git a/converter/adb_usb/Makefile b/converter/adb_usb/Makefile index 372ef6c09a..2114167424 100644 --- a/converter/adb_usb/Makefile +++ b/converter/adb_usb/Makefile @@ -94,7 +94,7 @@ ARCH = AVR8 F_USB = $(F_CPU) # Interrupt driven control endpoint task(+60) -#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT +OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # Boot Section Size in *bytes* @@ -109,7 +109,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096 # Build Options # comment out to disable the options. # -BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +#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) diff --git a/converter/adb_usb/adb_blargg.c b/converter/adb_usb/adb_blargg.c deleted file mode 100644 index 963758c533..0000000000 --- a/converter/adb_usb/adb_blargg.c +++ /dev/null @@ -1,216 +0,0 @@ -// Bit-banged implementation without any use of interrupts. -// Data pin must have external 1K pull-up resistor. -// Operates data pin as open-collector output. - -#include "adb_blargg.h" - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <avr/io.h> -#include <avr/interrupt.h> -#include <util/delay.h> - -// Copyright 2011 Jun WAKO <wakojun@gmail.com> -// Copyright 2013 Shay Green <gblargg@gmail.com> -// See bottom of file for license - -typedef uint8_t byte; - -// Make loop iteration take us total, including cyc overhead of loop logic -#define delay_loop_usec( us, cyc ) \ - __builtin_avr_delay_cycles( (unsigned long) (F_CPU / 1e6 * (us) + 0.5) - (cyc) ) - -#if !defined(ADB_PORT) || \ - !defined(ADB_PIN) || \ - !defined(ADB_DDR) || \ - !defined(ADB_DATA_BIT) - #error -#endif - -enum { data_mask = 1<<ADB_DATA_BIT }; - -enum { adb_cmd_read = 0x2C }; -enum { adb_cmd_write = 0x28 }; - -// gcc is very unreliable for inlining, so use macros -#define data_lo() (ADB_DDR |= data_mask) -#define data_hi() (ADB_DDR &= ~data_mask) -#define data_in() (ADB_PIN & data_mask) - -static void place_bit( byte bit ) -{ - // 100 us bit cell time - data_lo(); - _delay_us( 35 ); - - // Difference between a 0 and 1 bit is just this 30us portion in the middle - if ( bit ) - data_hi(); - _delay_us( 30 ); - - data_hi(); - _delay_us( 35 ); -} - -static void place_bit0( void ) { place_bit( 0 ); } -static void place_bit1( void ) { place_bit( 1 ); } - -static void send_byte( byte data ) -{ - for ( byte n = 8; n; n-- ) - { - place_bit( data & 0x80 ); - data <<= 1; - } -} - -static void command( byte cmd ) -{ - data_lo(); - _delay_us( 800 ); - place_bit1(); - send_byte( cmd ); - place_bit0(); -} - -void adb_host_init( void ) -{ - // Always keep port output 0, then just toggle DDR to be GND or leave it floating (high). - ADB_DDR &= ~data_mask; - ADB_PORT &= ~data_mask; - - #ifdef ADB_PSW_BIT - // Weak pull-up - ADB_PORT |= (1<<ADB_PSW_BIT); - ADB_DDR &= ~(1<<ADB_PSW_BIT); - #endif -} - -bool adb_host_psw( void ) -{ - #ifdef ADB_PSW_BIT - return (ADB_PIN & (1<<ADB_PSW_BIT)) != 0; - #else - return true; - #endif -} - -// Waits while data == val, or until us timeout expires. Returns remaining time, -// zero if timed out. -static byte while_data( byte us, byte data ) -{ - while ( data_in() == data ) - { - delay_loop_usec( 1 /* us period */, 7 /* cycles loop overhead */ ); - if ( !--us ) - break; - } - return us; -} - -static byte while_lo( byte us ) { return while_data( us, 0 ); } -static byte while_hi( byte us ) { return while_data( us, data_mask ); } - -static uint16_t adb_host_talk( byte cmd ) -{ - command( cmd ); - _delay_us( 5 ); - if ( !while_hi( 260 - 5 ) ) // avg 160 - return adb_host_nothing; - - // Receive start bit and 16 data bits. - // Doing them all in loop allows consistent error checking - uint16_t data = 0; - byte n = 17; - do - { - data <<= 1; - enum { timeout = 130 }; // maximum bit cell time - - byte lo = while_lo( timeout ); - if ( !lo ) - goto error; // timeout - - byte hi = while_hi( lo ); - if ( !hi ) - goto error; // timeout - - if ( timeout-lo < lo-hi ) - data |= 1; - else if ( n == 17 ) - goto error; // start bit is wrong - } - while ( --n ); - - // duration must be split in two due to 255 limit - if ( !while_lo( 255 ) && !while_lo( 351 - 255 ) ) - goto error; - - if ( while_hi( 91 ) ) - goto error; - - return data; - -error: - return adb_host_error; -} - -uint16_t adb_host_kbd_recv( void ) -{ - return adb_host_talk( adb_cmd_read + 0 ); -} - -uint16_t adb_host_kbd_modifiers( void ) -{ - return adb_host_talk( adb_cmd_read + 2 ); -} - -void adb_host_listen( byte cmd, byte data_h, byte data_l ) -{ - command( cmd ); - _delay_us( 200 ); - - place_bit1(); - send_byte( data_h ); - send_byte( data_l ); - place_bit0(); -} - -void adb_host_kbd_led( byte led ) -{ - adb_host_listen( adb_cmd_write + 2, 0, led & 0x07 ); -} - -/* This software is licensed with a Modified BSD License. -All of this is supposed to be Free Software, Open Source, DFSG-free, -GPL-compatible, and OK to use in both free and proprietary applications. -Additions and corrections to this file are welcome. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - -* Neither the name of the copyright holders nor the names of - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. */ diff --git a/converter/adb_usb/adb_blargg.h b/converter/adb_usb/adb_blargg.h deleted file mode 100644 index 2542cb5496..0000000000 --- a/converter/adb_usb/adb_blargg.h +++ /dev/null @@ -1,38 +0,0 @@ -// Basic support for ADB keyboard - -#ifndef ADB_BLARGG_H -#define ADB_BLARGG_H - -#include <stdint.h> -#include <stdbool.h> - -// Sets up ADB bus. Doesn't send anything to keyboard. -void adb_host_init( void ); - -// Receives key press event from keyboard. -// 0xKKFF: one key changed state -// 0xKKKK: two keys changed state -enum { adb_host_nothing = 0 }; // no keys changed state -enum { adb_host_error = 0xFFFE }; // receive error -uint16_t adb_host_kbd_recv( void ); - -// Current state of keyboard modifiers and a few other keys -// Returns adb_host_nothing if keyboard didn't respond. -// Returns adb_host_error if error receiving. -uint16_t adb_host_kbd_modifiers( void ); - -// Sends command and two bytes of data to keyboard -void adb_host_listen( uint8_t cmd, uint8_t data_h, uint8_t data_l ); - -// Sets keyboard LEDs. Note that bits are inverted here, so 1 means off, 0 means on. -void adb_host_kbd_led( uint8_t led ); - -// State of power switch (false = pressed), or true if unsupported -bool adb_host_psw( void ); - - -// Legacy support -#define ADB_POWER 0x7F -#define ADB_CAPS 0x39 - -#endif diff --git a/converter/adb_usb/config.h b/converter/adb_usb/config.h index 4ce27bbfeb..5ce5c22159 100644 --- a/converter/adb_usb/config.h +++ b/converter/adb_usb/config.h @@ -44,12 +44,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define USE_LEGACY_KEYMAP -/* mouse keys */ -#ifdef MOUSEKEY_ENABLE -# define MOUSEKEY_DELAY_TIME 192 -#endif - - /* ADB port setting */ #define ADB_PORT PORTD #define ADB_PIN PIND diff --git a/converter/adb_usb/led.c b/converter/adb_usb/led.c index 1e7911f942..3ee64a8e7d 100644 --- a/converter/adb_usb/led.c +++ b/converter/adb_usb/led.c @@ -23,7 +23,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. void led_set(uint8_t usb_led) { - // need a wait to send command without miss - _delay_ms(100); adb_host_kbd_led(~usb_led); } diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c index 54be2b0f57..d1b67d38d6 100644 --- a/converter/adb_usb/matrix.c +++ b/converter/adb_usb/matrix.c @@ -79,9 +79,9 @@ void matrix_init(void) for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; debug_enable = true; - debug_matrix = true; - debug_keyboard = true; - debug_mouse = true; + //debug_matrix = true; + //debug_keyboard = true; + //debug_mouse = true; print("debug enabled.\n"); return; } @@ -108,7 +108,7 @@ uint8_t matrix_scan(void) } else if (codes == 0xFFFF) { // power key release register_key(0xFF); } else if (key0 == 0xFF) { // error - xprintf("adb_host_kbd_recv: ERROR(%02X)\n", codes); + xprintf("adb_host_kbd_recv: ERROR(%d)\n", codes); return key1; } else { register_key(key0); diff --git a/converter/news_usb/config_pjrc.h b/converter/news_usb/config_pjrc.h index 92751d1eea..adce014c9e 100644 --- a/converter/news_usb/config_pjrc.h +++ b/converter/news_usb/config_pjrc.h @@ -42,12 +42,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ) -/* mouse keys */ -#ifdef MOUSEKEY_ENABLE -# define MOUSEKEY_DELAY_TIME 255 -#endif - - /* Asynchronous USART * 8-data bit, non parity, 1-stop bit, no flow control */ diff --git a/converter/ps2_usb/Makefile b/converter/ps2_usb/Makefile index 0c6442374c..04bf28a00c 100644 --- a/converter/ps2_usb/Makefile +++ b/converter/ps2_usb/Makefile @@ -1,5 +1,5 @@ # Target file name (without extension). -TARGET = ps2_usb +TARGET = ps2_usb_lufa # Directory common source filess exist TOP_DIR = ../.. @@ -7,69 +7,96 @@ TOP_DIR = ../.. # Directory keyboard dependent files exist TARGET_DIR = . +# project specific files +SRC = keymap_common.c \ + matrix.c \ + led.c + +ifdef KEYMAP + SRC := keymap_$(KEYMAP).c $(SRC) +else + SRC := keymap_plain.c $(SRC) +endif + +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 +# MCU name +#MCU = at90usb1287 +MCU = atmega32u4 # 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. +# 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 a |