Add converter for XT keyboards, fixes #309master
*~ | *~ | ||||
build/ | build/ | ||||
*.bak | *.bak | ||||
.DS_Store |
# | |||||
# 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 |
XT to USB keyboard converter | |||||
============================== | |||||
This firmware converts XT keyboard protocol to USB.(It supports Scan Code Set 1.) | |||||
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) | |||||
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 `xt_usb_lufa.hex` in current directory. | |||||
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_<name>.c` and see keymap document(you can find in README.md of top directory) and existent keymap files. | |||||
/* | |||||
Copyright 2012 Jun Wako <[email protected]> | |||||
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 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<<ISC11) | \ | |||||
(1<<ISC10)); \ | |||||
} while (0) | |||||
#define XT_INT_ON() do { \ | |||||
EIMSK |= (1<<INT1); \ | |||||
} while (0) | |||||
#define XT_INT_OFF() do { \ | |||||
EIMSK &= ~(1<<INT1); \ | |||||
} while (0) | |||||
#define XT_INT_VECT INT1_vect | |||||
#endif | |||||
#endif |
/* | |||||
Copyright 2011,2012,2013 Jun Wako <[email protected]> | |||||
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" | |||||
#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)]) }; | |||||
} |
/* | |||||
Copyright 2011,2012,2013 Jun Wako <[email protected]> | |||||
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 "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 |
/* | |||||
* 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[] = { | |||||
}; |
#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[] = { | |||||
}; |
/* | |||||
* 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 | |||||
}; | |||||
/* | |||||
Copyright 2016 Ethan Apodaca <[email protected]> | |||||
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/>. | |||||
*/ | |||||
void led_set(uint8_t usb_led) { | |||||
//XT Keyboards do not have LEDs, nothing to do. | |||||
} |
/* | |||||
Copyright 2011 Jun Wako <[email protected]> | |||||
Copyright 2016 Ethan Apodaca <[email protected]> | |||||
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 "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(); | |||||
switch (state) { | |||||
case INIT: | |||||
switch (code) { | |||||
case 0xE0: | |||||
state = E0; | |||||
break; | |||||
case 0xE1: | |||||
state = E1; | |||||
break; | |||||
default: // normal key make | |||||
if (code < 0x80 && code != 0x00) { | |||||
xprintf("make: %X\r\n", code); | |||||
matrix_make(code); | |||||
} else if (code > 0x80 && code < 0xFF && code != 0x00) { | |||||
xprintf("break %X\r\n", code); | |||||
matrix_break(code - 0x80); | |||||
} | |||||
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; | |||||
default: | |||||
if (code < 0x80 && code != 0x00) { | |||||
matrix_make(move_codes(code)); | |||||
} else if (code > 0x80 && code < 0xFF && code != 0x00) { | |||||
matrix_break(move_codes(code - 0x80)); | |||||
} | |||||
state = INIT; | |||||
} | |||||
break; | |||||
case E0_2A: | |||||
if(code == 0xE0) | |||||
state = E0_2A_E0; | |||||
else | |||||
state = INIT; | |||||
break; | |||||
case E0_2A_E0: | |||||
if(code == 0x37) | |||||
matrix_make(PRINT_SCREEN); | |||||
else | |||||
state = INIT; | |||||
break; | |||||
case E0_B7: | |||||
if(code == 0xE0) | |||||
state = E0_B7; | |||||
else | |||||
state = INIT; | |||||
break; | |||||
case E0_B7_E0: | |||||
if(code == 0xAA) | |||||
matrix_break(PRINT_SCREEN); | |||||
else | |||||
state = INIT; | |||||
break; | |||||
case E1: | |||||
if (code == 0x1D) | |||||
state = E1_1D; | |||||
else | |||||
state = INIT; | |||||
break; | |||||
case E1_1D: | |||||
if(code == 0x45) | |||||
state = E1_1D_45; | |||||
else | |||||
state = INIT; | |||||
break; | |||||
case E1_1D_45: | |||||
if(code == 0xE1) | |||||
state = E1_1D_45_E1; | |||||
else | |||||
state = INIT; | |||||
break; | |||||
case E1_1D_45_E1: | |||||
if(code == 0x9D) | |||||
state = E1_1D_45_E1_9D; | |||||
else | |||||
state = INIT; | |||||
break; | |||||
case E1_1D_45_E1_9D: | |||||
if(code == 0xC5) | |||||
matrix_make(PAUSE); | |||||
else | |||||
state = INIT; | |||||
break; | |||||
default: | |||||
state = INIT; | |||||
} | |||||
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<<col)); | |||||
} | |||||
inline | |||||
uint8_t matrix_get_row(uint8_t row) | |||||
{ | |||||
return matrix[row]; | |||||
} | |||||
void matrix_print(void) | |||||
{ | |||||
print("\nr/c 01234567\n"); | |||||
for (uint8_t row = 0; row < matrix_rows(); row++) { | |||||
phex(row); print(": "); | |||||
pbin_reverse(matrix_get_row(row)); | |||||
#ifdef MATRIX_HAS_GHOST | |||||
if (matrix_has_ghost_in_row(row)) { | |||||
print(" <ghost"); | |||||
} | |||||
#endif | |||||
print("\n"); | |||||
} | |||||
} | |||||
uint8_t matrix_key_count(void) | |||||
{ | |||||
uint8_t count = 0; | |||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | |||||
count += bitpop(matrix[i]); | |||||
} | |||||
return count; | |||||
} | |||||
#ifdef MATRIX_HAS_GHOST | |||||
inline | |||||
static bool matrix_has_ghost_in_row(uint8_t row) | |||||
{ | |||||
// no ghost exists in case less than 2 keys on | |||||
if (((matrix[row] - 1) & matrix[row]) == 0) | |||||
return false; | |||||
// ghost exists in case same state as other row | |||||
for (uint8_t i=0; i < MATRIX_ROWS; i++) { | |||||
if (i != row && (matrix[i] & matrix[row]) == matrix[row]) | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
#endif | |||||
inline | |||||
static void matrix_make(uint8_t code) | |||||
{ | |||||
if (!matrix_is_on(ROW(code), COL(code))) { | |||||
matrix[ROW(code)] |= 1<<COL(code); | |||||
is_modified = true; | |||||
} | |||||
} | |||||
inline | |||||
static void matrix_break(uint8_t code) | |||||
{ | |||||
if (matrix_is_on(ROW(code), COL(code))) { | |||||
matrix[ROW(code)] &= ~(1<<COL(code)); | |||||
is_modified = true; | |||||
} | |||||
} | |||||
inline | |||||
static void matrix_clear(void) | |||||
{ | |||||
for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; | |||||
} |
endif | endif | ||||
ifdef XT_USE_INT | |||||
SRC += protocol/xt_interrupt.c | |||||
SRC += protocol/xt_io_avr.c | |||||
OPT_DEFS += -DXT_USE_INT | |||||
endif | |||||
ifdef SERIAL_MOUSE_MICROSOFT_ENABLE | ifdef SERIAL_MOUSE_MICROSOFT_ENABLE | ||||
SRC += $(PROTOCOL_DIR)/serial_mouse_microsoft.c | SRC += $(PROTOCOL_DIR)/serial_mouse_microsoft.c | ||||
OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MICROSOFT \ | OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MICROSOFT \ |
/*-------------------------------------------------------------------- | |||||
* Ring buffer to store scan codes from keyboard | |||||
*------------------------------------------------------------------*/ | |||||
#ifndef PBUFF_H | |||||
#define PBUFF_H | |||||
#include "print.h" | |||||
#define PBUF_SIZE 32 | |||||
static uint16_t pbuf[PBUF_SIZE]; | |||||
static uint16_t pbuf_head = 0; | |||||
static uint16_t pbuf_tail = 0; | |||||
static inline void pbuf_enqueue(uint16_t data) | |||||
{ | |||||
uint8_t sreg = SREG; | |||||
cli(); | |||||
uint16_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 uint16_t pbuf_dequeue(void) | |||||
{ | |||||
uint16_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; | |||||
} | |||||
#endif |
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <avr/interrupt.h> | #include <avr/interrupt.h> | ||||
#include <util/delay.h> | #include <util/delay.h> | ||||
#include "pbuff.h" | |||||
#include "ps2.h" | #include "ps2.h" | ||||
#include "ps2_io.h" | #include "ps2_io.h" | ||||
#include "print.h" | #include "print.h" | ||||
uint8_t ps2_error = PS2_ERR_NONE; | 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) | void ps2_host_init(void) | ||||
{ | { | ||||
idle(); | idle(); | ||||
ps2_host_send(0xED); | ps2_host_send(0xED); | ||||
ps2_host_send(led); | 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; | |||||
} | |||||
/* | |||||
Copyright 2010,2011,2012,2013 Jun WAKO <[email protected]> | |||||
Copyright 2016 Ethan Apodaca <[email protected]> | |||||
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 <stdbool.h> | |||||
#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 |
/* | |||||
Copyright 2010,2011,2012,2013 Jun WAKO <[email protected]> | |||||
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 <stdbool.h> | |||||
#include <avr/interrupt.h> | |||||
#include <util/delay.h> | |||||
#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 uint8_t state = 0; | |||||
static uint8_t data = 0; | |||||
if (state == 0) { | |||||
if (data_in()) | |||||
state++; | |||||
} else if (state >= 1 && state <= 8) { | |||||
wait_clock_lo(20); | |||||
data >>= 1; | |||||
if (data_in()) | |||||
data |= 0x80; | |||||
if (state == 8) | |||||
goto END; | |||||
state++; | |||||
} else { | |||||
goto DONE; | |||||
} | |||||
goto RETURN; | |||||
END: | |||||
pbuf_enqueue(data); | |||||
DONE: | |||||
state = 0; | |||||
data = 0; | |||||
RETURN: | |||||
return; | |||||
} |
#ifndef XT_IO_H | |||||
#define XT_IO_H | |||||
bool clock_in(void); | |||||
bool data_in(void); | |||||
#endif |
#include <stdbool.h> | |||||
#include <avr/io.h> | |||||
#include <util/delay.h> | |||||
/* 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<<XT_CLOCK_BIT); | |||||
XT_CLOCK_PORT |= (1<<XT_CLOCK_BIT); | |||||
_delay_us(1); | |||||
return XT_CLOCK_PIN&(1<<XT_CLOCK_BIT); | |||||
} | |||||
bool data_in(void) | |||||
{ | |||||
XT_DATA_DDR &= ~(1<<XT_DATA_BIT); | |||||
XT_DATA_PORT |= (1<<XT_DATA_BIT); | |||||
_delay_us(1); | |||||
return XT_DATA_PIN&(1<<XT_DATA_BIT); | |||||
} |