From 3def1c3065a3b1f85a99cc7336f41f486d9ec67d Mon Sep 17 00:00:00 2001 From: Ethan Apodaca Date: Tue, 1 Mar 2016 21:37:22 -0800 Subject: [PATCH] Codes appear to be detected correctly, the break codes are broken. --- converter/xt_usb/Makefile | 103 ++++++++ converter/xt_usb/README.md | 84 +++++++ converter/xt_usb/config.h | 71 ++++++ converter/xt_usb/keymap_common.c | 31 +++ converter/xt_usb/keymap_common.h | 144 +++++++++++ converter/xt_usb/keymap_jis.c | 34 +++ converter/xt_usb/keymap_plain.c | 32 +++ converter/xt_usb/keymap_spacefn.c | 61 +++++ converter/xt_usb/led.c | 20 ++ converter/xt_usb/matrix.c | 382 ++++++++++++++++++++++++++++++ tmk_core/protocol.mk | 7 + tmk_core/protocol/pbuff.h | 57 +++++ tmk_core/protocol/ps2_interrupt.c | 60 +---- tmk_core/protocol/xt.h | 75 ++++++ tmk_core/protocol/xt_interrupt.c | 113 +++++++++ tmk_core/protocol/xt_io.h | 7 + tmk_core/protocol/xt_io_avr.c | 34 +++ 17 files changed, 1256 insertions(+), 59 deletions(-) create mode 100644 converter/xt_usb/Makefile create mode 100644 converter/xt_usb/README.md create mode 100644 converter/xt_usb/config.h create mode 100644 converter/xt_usb/keymap_common.c create mode 100644 converter/xt_usb/keymap_common.h create mode 100644 converter/xt_usb/keymap_jis.c create mode 100644 converter/xt_usb/keymap_plain.c create mode 100644 converter/xt_usb/keymap_spacefn.c create mode 100644 converter/xt_usb/led.c create mode 100644 converter/xt_usb/matrix.c create mode 100644 tmk_core/protocol/pbuff.h create mode 100644 tmk_core/protocol/xt.h create mode 100644 tmk_core/protocol/xt_interrupt.c create mode 100644 tmk_core/protocol/xt_io.h create mode 100644 tmk_core/protocol/xt_io_avr.c diff --git a/converter/xt_usb/Makefile b/converter/xt_usb/Makefile new file mode 100644 index 00000000..cd8230cb --- /dev/null +++ b/converter/xt_usb/Makefile @@ -0,0 +1,103 @@ +# +# Makefile for Teensy +# +# Target file name (without extension). +TARGET = xt_usb_lufa + +# Directory common source filess exist +TMK_DIR = ../../tmk_core + +# 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 +#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 + + +# XT/2 Options +# +XT_USE_INT = yes # uses external interrupt for falling edge of PS/2 clock pin + + +# Optimize size but this may cause error "relocation truncated to fit" +#EXTRALDFLAGS = -Wl,--relax + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TMK_DIR) + +include $(TMK_DIR)/protocol.mk +include $(TMK_DIR)/protocol/lufa.mk +include $(TMK_DIR)/common.mk +include $(TMK_DIR)/rules.mk diff --git a/converter/xt_usb/README.md b/converter/xt_usb/README.md new file mode 100644 index 00000000..74464e26 --- /dev/null +++ b/converter/xt_usb/README.md @@ -0,0 +1,84 @@ +PS/2 to USB keyboard converter +============================== +This firmware converts PS/2 keyboard protocol to USB.(It supports Scan Code Set 2.) + + +Connect Wires +------------- +In case of Teensy2.0(ATMega32U4): + +1. Connect **Vcc** and **GND**. +2. Connect **Clock** and **Data** line. + - **Interrupt**: **Clock** is on `PD1` and **Data** on `PD0`.(Recommended. Soarer's converter compatible) + - **Busywait**: **Clock** is on `PD1` and **Data** on `PD0`. + - **USART**: **Clock** is on `PD5` and **Data** on `PD2`. +3. Optionally you need pull-up resistor. 1K-10K Ohm is OK. + +To change pin configuration edit **config.h** and **Makefile**. + + +Build Firmware +-------------- +For **PJRC Teensy** just run `make`: + + $ make clean + $ make + +To select keymap: + + $ make clean + $ make KEYMAP=[plain|jis|spacefn|...] + +After that you will find HEX file `ps2_usb_lufa.hex` in current directory. + + +- For **TMK converter Rev.1** use `make -f Makefile.tmk_rev1` instead of `make` and HEX file is `ps2_usb_tmk_rev1.hex`. + +- For **TMK converter Rev.2** use `make -f Makefile.tmk_rev2` instead of `make` and HEX file is `ps2_usb_tmk_rev2.hex`. + + +Keymap +------ +Several version of keymap are available in advance but you are recommended to define your favorite layout yourself. To define your own keymap create file named `keymap_.c` and see keymap document(you can find in README.md of top directory) and existent keymap files. + + +PS/2 signal handling implementations +------------------------------------ +Following three methods can be used to implement PS/2 signal handling. + +### Simple and stupid busy-wait(ps2_busywait.c) + This is expected to implemented with portable C code for reference. +### Interrupt driven(ps2_interrupt.c) + Uses pin interrupt to detect falling edge of clock line. +### USART hardware module(ps2_usart.c) + Uses AVR USART engine to receive PS/2 signal. + +To select method edit Makefile. + + +V-USB Support +------------- +With V-USB you can use this converter on ATmega(168/328) but it doesn't support NKRO at this time. + +Circuit: + + +---+ +---------------+ + USB GND | | ATmega168 | + === C3 | | + 5V <-------+--------+---|Vcc,AVCC | PS/2 + R1 | | ==== + D- <----+--+-----R2-----|INT1 RXD|------->DATA + D+ <----|---+----R3-----|INT0 XCK|------->CLOCK + Z1 Z2 | | ->5V + GND<----+---+--+--+-----|GND | ->GND + | | | | + | C2-+--|XTAL1 | + | X1 | | + +--C3-+--|XTAL2 | + +---------------+ + R1: 1.5K Ohm + R2,R3: 68 Ohm + Z1,Z2: Zenner 3.6V + C1,C2: 22pF + C3: 0.1uF + X1: Crystal 20MHz(16MHz/12MHz) diff --git a/converter/xt_usb/config.h b/converter/xt_usb/config.h new file mode 100644 index 00000000..21e76400 --- /dev/null +++ b/converter/xt_usb/config.h @@ -0,0 +1,71 @@ +/* +Copyright 2012 Jun Wako + +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 . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +#include + +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x6512 +#define DEVICE_VER 0x0001 +#define MANUFACTURER t.m.k. +#define PRODUCT XT keyboard converter +#define DESCRIPTION convert XT keyboard to USB + + +/* matrix size */ +#define MATRIX_ROWS 16 // keycode bit: 3-0 +#define MATRIX_COLS 8 // keycode bit: 6-4 + + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) || \ + keyboard_report->mods == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \ +) + + +//#define NO_SUSPEND_POWER_DOWN + +/* + * XT Pin interrupt + */ +#ifdef XT_USE_INT +/* uses INT1 for clock line(ATMega32U4) */ +#define XT_CLOCK_PORT PORTD +#define XT_CLOCK_PIN PIND +#define XT_CLOCK_DDR DDRD +#define XT_CLOCK_BIT 1 +#define XT_DATA_PORT PORTD +#define XT_DATA_PIN PIND +#define XT_DATA_DDR DDRD +#define XT_DATA_BIT 0 +#define XT_INT_INIT() do { \ + EICRA |= ((1< + +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 . +*/ +#include "keymap_common.h" +#include "progmem.h" + + +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, keypos_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/xt_usb/keymap_common.h b/converter/xt_usb/keymap_common.h new file mode 100644 index 00000000..b9de6a86 --- /dev/null +++ b/converter/xt_usb/keymap_common.h @@ -0,0 +1,144 @@ +/* +Copyright 2011,2012,2013 Jun Wako + +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 . +*/ +#ifndef KEYMAP_COMMON_H +#define KEYMAP_COMMON_H + +#include +#include +#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( \ + K00, K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D, K0E,K0F,K0G, \ + K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B,K1C,K1D, K1E,K1F,K1G, K1H,K1I,K1J,K1K, \ + K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K2A,K2B,K2C,K2D, K2E,K2F,K2G, K2H,K2I,K2J, \ + K30,K31,K32,K33,K34,K35,K36,K37,K38,K39,K3A,K3B, K3D, K3H,K3I,K3J,K3K, \ + K40,K41,K42,K43,K44,K45,K46,K47,K48,K49,K4A, K4D, K4F, K4H,K4I,K4J, \ + K50,K51,K52, K55, K5A,K5B,K5C,K5D, K5E,K5F,K5G, K5H, K5J,K5K, \ + \ + K60, K61, K62, /* System Power, Sleep, Wake */ \ + K70, K71, K72, /* Mute, Volume Up, Volume Down */ \ + K80, K81, K82, K83, K84, /* Next, Previous, Stop, Pause, Media Select */ \ + K90, K91, K92, /* Mail, Calculator, My Computer */ \ + KA0, KA1, KA2, KA3, /* WWW Search, Home, Back, Forward */ \ + KB0, KB1, KB2 /* WWW Stop, Refresh, Favorites */ \ +) { \ + { KC_NO, KC_##K00, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16 }, \ + { KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K20 }, \ + { KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28 }, \ + { KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K3D, KC_##K50, KC_##K31, KC_##K32 }, \ + { KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A }, \ + { KC_##K3B, KC_##K10, KC_##K40, KC_##K2D, KC_##K41, KC_##K42, KC_##K43, KC_##K44 }, \ + { KC_##K45, KC_##K46, KC_##K47, KC_##K48, KC_##K49, KC_##K4A, KC_##K4D, KC_##K1J }, \ + { KC_##K52, KC_##K55, KC_##K30, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06 }, \ + { KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K1H, KC_##K0F, KC_##K2H }, \ + { KC_##K2I, KC_##K2J, KC_##K1K, KC_##K3H, KC_##K3I, KC_##K3J, KC_##K3K, KC_##K4H }, \ + { KC_##K4I, KC_##K4J, KC_##K5H, KC_##K5J, KC_##K5K, KC_##K5D, KC_##K1I, KC_##K0C }, \ + { KC_##K0D, KC_##K5A, KC_##K80, KC_##K51, KC_##K5B, KC_##K5C, KC_##K60, KC_##K61 }, \ + { KC_##K70, KC_##K91, KC_##K83, KC_##K62, KC_##K82, KC_##KA0, KC_##KB2, KC_##KB1 }, \ + { KC_##KB0, KC_##KA3, KC_##KA2, KC_##K92, KC_##K90, KC_##K84, KC_##K81, KC_##K1F }, \ + { KC_##K4F, KC_##K1G, KC_##K72, KC_##K5E, KC_##K71, KC_##K5G, KC_##KA1, KC_##K2F }, \ + { KC_##K5F, KC_##K2G, KC_##K1E, KC_##K2E, KC_##K0E, KC_##K0G, KC_NO , 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, \ + \ + 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, \ + \ + 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, \ + \ + 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/xt_usb/keymap_jis.c b/converter/xt_usb/keymap_jis.c new file mode 100644 index 00000000..02585150 --- /dev/null +++ b/converter/xt_usb/keymap_jis.c @@ -0,0 +1,34 @@ +/* + * JIS layout Japanese keyboard + */ +#include "keymap_common.h" + +const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* 0: JIS LAYOUT + * ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,-----------. + * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|Slp|Wak| + * `---' `---------------' `---------------' `---------------' `-----------' `-----------' + * ,-----------------------------------------------------------. ,-----------. ,---------------. + * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| JY|Bsp| |Ins|Hom|PgU| |NmL| /| *| -| + * |-----------------------------------------------------------| |-----------| |---------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| Ret | |Del|End|PgD| | 7| 8| 9| | + * |------------------------------------------------------` | `-----------' |-----------| +| + * |CapsLo| A| S| D| F| G| H| J| K| L| ;| :| \| | | 4| 5| 6| | + * |-----------------------------------------------------------| ,---. |---------------| + * |Shift | Z| X| C| V| B| N| M| ,| ,| /| RO|Shift | |Up | | 1| 2| 3| | + * |-----------------------------------------------------------| ,-----------. |-----------|Ent| + * |Ctrl |Gui |Alt |MHEN| Space |HENK|KANA|Alt |Gui |Menu|Ctrl| |Lef|Dow|Rig| | 0| .| | + * `-----------------------------------------------------------' `-----------' `---------------' + */ + KEYMAP_JIS( + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, + GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, JYEN,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, DEL, END, PGDN, P7, P8, P9, + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,BSLS, ENT, P4, P5, P6, PPLS, + LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RO, RSFT, UP, P1, P2, P3, + LCTL,LGUI,LALT, MHEN,SPC, HENK,KANA, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT + ), +}; + +const uint16_t PROGMEM fn_actions[] = { +}; diff --git a/converter/xt_usb/keymap_plain.c b/converter/xt_usb/keymap_plain.c new file mode 100644 index 00000000..51b2fddb --- /dev/null +++ b/converter/xt_usb/keymap_plain.c @@ -0,0 +1,32 @@ +#include "keymap_common.h" + + +const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* 0: default + * ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,-----------. + * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|Slp|Wak| + * `---' `---------------' `---------------' `---------------' `-----------' `-----------' + * ,-----------------------------------------------------------. ,-----------. ,---------------. + * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| |Ins|Hom|PgU| |NmL| /| *| -| + * |-----------------------------------------------------------| |-----------| |---------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | 7| 8| 9| | + * |-----------------------------------------------------------| `-----------' |-----------| +| + * |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return | | 4| 5| 6| | + * |-----------------------------------------------------------| ,---. |---------------| + * |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shift | |Up | | 1| 2| 3| | + * |-----------------------------------------------------------| ,-----------. |-----------|Ent| + * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| |Lef|Dow|Rig| | 0| .| | + * `-----------------------------------------------------------' `-----------' `---------------' + */ + KEYMAP( + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, + GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, PPLS, + LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, + LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT + ), +}; + +const uint16_t PROGMEM fn_actions[] = { +}; diff --git a/converter/xt_usb/keymap_spacefn.c b/converter/xt_usb/keymap_spacefn.c new file mode 100644 index 00000000..bffd2bc6 --- /dev/null +++ b/converter/xt_usb/keymap_spacefn.c @@ -0,0 +1,61 @@ +/* + * SpaceFN layout + * http://geekhack.org/index.php?topic=51069.0 + */ +#include "keymap_common.h" + + +const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* 0: default + * ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,-----------. + * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|Slp|Wak| + * `---' `---------------' `---------------' `---------------' `-----------' `-----------' + * ,-----------------------------------------------------------. ,-----------. ,---------------. + * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| |Ins|Hom|PgU| |NmL| /| *| -| + * |-----------------------------------------------------------| |-----------| |---------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | 7| 8| 9| | + * |-----------------------------------------------------------| `-----------' |-----------| +| + * |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return | | 4| 5| 6| | + * |-----------------------------------------------------------| ,---. |---------------| + * |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shift | |Up | | 1| 2| 3| | + * |-----------------------------------------------------------| ,-----------. |-----------|Ent| + * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| |Lef|Dow|Rig| | 0| .| | + * `-----------------------------------------------------------' `-----------' `---------------' + */ + KEYMAP( + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, PPLS, + LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, + LCTL,LGUI,LALT, FN0, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT + ), + + /* 1: SpaceFN + * ,-----------------------------------------------------------. + * |` | F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | + * |-----------------------------------------------------------| + * | | | |Esc| | | |Hom|Up |End|Psc|Slk|Pau|Ins | + * |-----------------------------------------------------------| + * | | | | | | |PgU|Lef|Dow|Rig| | | | + * |-----------------------------------------------------------| + * | | | | | |Spc|PgD|` |~ | |Men| | + * |-----------------------------------------------------------| + * | | | | | | | | | + * `-----------------------------------------------------------' + */ + KEYMAP( + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, + GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, + TRNS,TRNS,TRNS,ESC, TRNS,TRNS,TRNS,HOME,UP, END, PSCR,SLCK,PAUS,INS, DEL, END, PGDN, P7, P8, P9, + TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PGUP,LEFT,DOWN,RGHT,TRNS,TRNS, TRNS, P4, P5, P6, PPLS, + TRNS,TRNS,TRNS,TRNS,TRNS,SPC, PGDN,GRV, FN1, TRNS,APP, TRNS, UP, P1, P2, P3, + TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, LEFT,DOWN,RGHT, P0, PDOT,PENT + ), +}; + +const uint16_t PROGMEM fn_actions[] = { + [0] = ACTION_LAYER_TAP_KEY(1, KC_SPACE), + [1] = ACTION_MODS_KEY(MOD_LSFT, KC_GRV), // tilde +}; + diff --git a/converter/xt_usb/led.c b/converter/xt_usb/led.c new file mode 100644 index 00000000..8eaa88bd --- /dev/null +++ b/converter/xt_usb/led.c @@ -0,0 +1,20 @@ +/* +Copyright 2016 Ethan Apodaca + +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 . +*/ + +void led_set(uint8_t usb_led) { + //XT Keyboards do not have LEDs, nothing to do. +} diff --git a/converter/xt_usb/matrix.c b/converter/xt_usb/matrix.c new file mode 100644 index 00000000..4218e39b --- /dev/null +++ b/converter/xt_usb/matrix.c @@ -0,0 +1,382 @@ +/* +Copyright 2011 Jun Wako +Copyright 2016 Ethan Apodaca + +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 . +*/ + +#include +#include +#include "action.h" +#include "print.h" +#include "util.h" +#include "debug.h" +#include "xt.h" +#include "matrix.h" + + +static void matrix_make(uint8_t code); +static void matrix_break(uint8_t code); +static void matrix_clear(void); +#ifdef MATRIX_HAS_GHOST +static bool matrix_has_ghost_in_row(uint8_t row); +#endif + +static uint8_t matrix[MATRIX_ROWS]; +#define ROW(code) (code>>3) +#define COL(code) (code&0x07) + +// matrix positions for exceptional keys +#define PRINT_SCREEN (0x7C) +#define PAUSE (0x7D) + +static bool is_modified = false; + + +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; + xt_host_init(); + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; + + return; +} + +static uint8_t move_codes(uint8_t code) { + switch(code) { + case 0x10: + code += 0x5E; + break; + case 0x19: + code += 0x41; + break; + case 0x1C: + case 0x1D: + code += 0x38; + break; + case 0x20: + case 0x21: + case 0x22: + case 0x24: + code += 0x40; + break; + case 0x2E: + case 0x30: + case 0x32: + code += 0x44; + break; + case 0x35: + case 0x38: + code += 0x21; + break; + case 0x47: + case 0x48: + case 0x49: + case 0x4B: + case 0x4D: + case 0x4F: + case 0x50: + case 0x51: + case 0x52: + case 0x53: + code += 0x28; + break; + } + return code; +} + +uint8_t matrix_scan(void) +{ + + // scan code reading states + static enum { + INIT, + E0, + E0_2A, + E0_2A_E0, + E0_B7, + E0_B7_E0, + + // print screen + E1, + E1_1D, + E1_1D_45, + E1_1D_45_E1, + E1_1D_45_E1_9D, + // pause + } state = INIT; + + + is_modified = false; + + // 'pseudo break code' hack + if (matrix_is_on(ROW(PAUSE), COL(PAUSE))) { + matrix_break(PAUSE); + } + + uint8_t code = xt_host_recv(); + if (code) xprintf("%X\r\n", code); + switch (state) { + case INIT: + switch (code) { + case 0xE0: + state = E0; + break; + case 0xE1: + state = E1; + break; + case 0x00: + break; + default: // normal key make + if (code < 0x80) { + xprintf("make: %X\r\n", code); + matrix_make(code); + } else if (code > 0x80 && code < 0xFF) { + xprintf("break %X\r\n", code); + matrix_break(code - 0x80); + } else { + matrix_clear(); + clear_keyboard(); + xprintf("unexpected scan code at INIT: %02X\n", code); + } + state = INIT; + } + break; + case E0: // E0-Prefixed + switch (code) { //move these codes to unused places on the matrix + case 0x2A: + state = E0_2A; + break; + case 0xB7: + state = E0_B7; + break; + case 0x00: + state = INIT; + break; + default: + if (code < 0x80) { + matrix_make(move_codes(code)); + } else if (code > 0x80 && code < 0xFF) { + matrix_break(move_codes(code - 0x80)); + } else { + matrix_clear(); + clear_keyboard(); + xprintf("unexpected scan code at E0: %02X\n", code); + } + state = INIT; + } + break; + case E0_2A: + switch (code) { + case 0xE0: + state = E0_2A_E0; + break; + default: + state = INIT; + } + break; + case E0_2A_E0: + switch (code) { + case 0x37: + matrix_make(PRINT_SCREEN); + break; + default: + state = INIT; + } + break; + case E0_B7: + switch (code) { + case 0xE0: + state = E0_B7; + break; + default: + state = INIT; + } + break; + case E0_B7_E0: + switch (code) { + case 0xAA: + matrix_break(PRINT_SCREEN); + break; + default: + state = INIT; + } + break; + case E1: + switch (code) { + case 0x1D: + state = E1_1D; + break; + default: + state = INIT; + } + break; + case E1_1D: + switch (code) { + case 0x45: + state = E1_1D_45; + break; + default: + state = INIT; + } + break; + case E1_1D_45: + switch (code) { + case 0xE1: + state = E1_1D_45_E1; + break; + default: + state = INIT; + } + break; + case E1_1D_45_E1: + switch (code) { + case 0x9D: + state = E1_1D_45_E1_9D; + break; + default: + state = INIT; + } + break; + case E1_1D_45_E1_9D: + switch (code) { + case 0xC5: + matrix_make(PAUSE); + break; + default: + state = INIT; + } + break; + default: + state = INIT; + } + + // TODO: request RESEND when error occurs? +/* + if (PS2_IS_FAILED(ps2_error)) { + uint8_t ret = ps2_host_send(PS2_RESEND); + xprintf("Resend: %02X\n", ret); + } +*/ + return 1; +} + +bool matrix_is_modified(void) +{ + return is_modified; +} + +inline +bool matrix_has_ghost(void) +{ +#ifdef MATRIX_HAS_GHOST + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + if (matrix_has_ghost_in_row(i)) + return true; + } +#endif + return false; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & (1< #include #include +#include "pbuff.h" #include "ps2.h" #include "ps2_io.h" #include "print.h" @@ -57,13 +58,6 @@ POSSIBILITY OF SUCH DAMAGE. uint8_t ps2_error = PS2_ERR_NONE; - -static inline uint8_t pbuf_dequeue(void); -static inline void pbuf_enqueue(uint8_t data); -static inline bool pbuf_has_data(void); -static inline void pbuf_clear(void); - - void ps2_host_init(void) { idle(); @@ -225,55 +219,3 @@ void ps2_host_set_led(uint8_t led) ps2_host_send(0xED); ps2_host_send(led); } - - -/*-------------------------------------------------------------------- - * Ring buffer to store scan codes from keyboard - *------------------------------------------------------------------*/ -#define PBUF_SIZE 32 -static uint8_t pbuf[PBUF_SIZE]; -static uint8_t pbuf_head = 0; -static uint8_t pbuf_tail = 0; -static inline void pbuf_enqueue(uint8_t data) -{ - uint8_t sreg = SREG; - cli(); - uint8_t next = (pbuf_head + 1) % PBUF_SIZE; - if (next != pbuf_tail) { - pbuf[pbuf_head] = data; - pbuf_head = next; - } else { - print("pbuf: full\n"); - } - SREG = sreg; -} -static inline uint8_t pbuf_dequeue(void) -{ - uint8_t val = 0; - - uint8_t sreg = SREG; - cli(); - if (pbuf_head != pbuf_tail) { - val = pbuf[pbuf_tail]; - pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE; - } - SREG = sreg; - - return val; -} -static inline bool pbuf_has_data(void) -{ - uint8_t sreg = SREG; - cli(); - bool has_data = (pbuf_head != pbuf_tail); - SREG = sreg; - return has_data; -} -static inline void pbuf_clear(void) -{ - uint8_t sreg = SREG; - cli(); - pbuf_head = pbuf_tail = 0; - SREG = sreg; -} - diff --git a/tmk_core/protocol/xt.h b/tmk_core/protocol/xt.h new file mode 100644 index 00000000..55efd75d --- /dev/null +++ b/tmk_core/protocol/xt.h @@ -0,0 +1,75 @@ +/* +Copyright 2010,2011,2012,2013 Jun WAKO +Copyright 2016 Ethan Apodaca + +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. +*/ + +#ifndef XT_H +#define XT_H + +#include +#include "wait.h" +#include "xt_io.h" +#include "print.h" + +void xt_host_init(void); +uint8_t xt_host_recv(void); + + +/*-------------------------------------------------------------------- + * static functions + *------------------------------------------------------------------*/ +static inline uint16_t wait_clock_lo(uint16_t us) +{ + while (clock_in() && us) { asm(""); wait_us(1); us--; } + return us; +} +static inline uint16_t wait_clock_hi(uint16_t us) +{ + while (!clock_in() && us) { asm(""); wait_us(1); us--; } + return us; +} +static inline uint16_t wait_data_lo(uint16_t us) +{ + while (data_in() && us) { asm(""); wait_us(1); us--; } + return us; +} +static inline uint16_t wait_data_hi(uint16_t us) +{ + while (!data_in() && us) { asm(""); wait_us(1); us--; } + return us; +} + +#endif diff --git a/tmk_core/protocol/xt_interrupt.c b/tmk_core/protocol/xt_interrupt.c new file mode 100644 index 00000000..2a351c5b --- /dev/null +++ b/tmk_core/protocol/xt_interrupt.c @@ -0,0 +1,113 @@ +/* +Copyright 2010,2011,2012,2013 Jun WAKO + +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. +*/ + +/* + * PS/2 protocol Pin interrupt version + */ + +#include +#include +#include +#include "pbuff.h" +#include "xt.h" +#include "xt_io.h" +#include "wait.h" +#include "print.h" + +void xt_host_init(void) +{ + XT_INT_INIT(); + XT_INT_ON(); +} + +/* get data received by interrupt */ +uint8_t xt_host_recv(void) +{ + if (pbuf_has_data()) { + return pbuf_dequeue(); + } else { + return 0; + } +} + +ISR(XT_INT_VECT) +{ + static enum { + INIT, + BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, + STOP, + } state = INIT; + static uint8_t data = 0; + // wait for clock falling edge + if(state != INIT) + wait_clock_lo(70); + + switch (state) { + case INIT: + if (data_in()) + state++; + break; + case BIT0: + case BIT1: + case BIT2: + case BIT3: + case BIT4: + case BIT5: + case BIT6: + case BIT7: + state++; + data >>= 1; + if (data_in()) { + data |= 0x80; + } + break; + case STOP: + if (!data_in()) + goto DONE; + pbuf_enqueue(data); + goto DONE; + break; + default: + goto DONE; + } + goto RETURN; +DONE: + state = INIT; + data = 0; +RETURN: + return; +} diff --git a/tmk_core/protocol/xt_io.h b/tmk_core/protocol/xt_io.h new file mode 100644 index 00000000..2e5f31b2 --- /dev/null +++ b/tmk_core/protocol/xt_io.h @@ -0,0 +1,7 @@ +#ifndef XT_IO_H +#define XT_IO_H + +bool clock_in(void); +bool data_in(void); + +#endif diff --git a/tmk_core/protocol/xt_io_avr.c b/tmk_core/protocol/xt_io_avr.c new file mode 100644 index 00000000..6cd153a1 --- /dev/null +++ b/tmk_core/protocol/xt_io_avr.c @@ -0,0 +1,34 @@ +#include +#include +#include + +/* Check port settings for clock and data line */ +#if !(defined(XT_CLOCK_PORT) && \ + defined(XT_CLOCK_PIN) && \ + defined(XT_CLOCK_DDR) && \ + defined(XT_CLOCK_BIT)) +# error "XT clock port setting is required in config.h" +#endif + +#if !(defined(XT_DATA_PORT) && \ + defined(XT_DATA_PIN) && \ + defined(XT_DATA_DDR) && \ + defined(XT_DATA_BIT)) +# error "XT data port setting is required in config.h" +#endif + +bool clock_in(void) +{ + XT_CLOCK_DDR &= ~(1<