Merge branch 'xt_rev2'
commit
ec49ce3be6
|
|
@ -11,7 +11,8 @@ TMK_DIR = ../../tmk_core
|
|||
TARGET_DIR = .
|
||||
|
||||
# project specific files
|
||||
SRC = matrix.c \
|
||||
SRC = protocol/xt_interrupt.c \
|
||||
matrix.c \
|
||||
led.c
|
||||
|
||||
ifdef KEYMAP
|
||||
|
|
@ -61,7 +62,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*
|
||||
|
|
@ -71,6 +72,7 @@ F_USB = $(F_CPU)
|
|||
# LUFA bootloader 4096
|
||||
# USBaspLoader 2048
|
||||
OPT_DEFS += -DBOOTLOADER_SIZE=512
|
||||
#OPT_DEFS += -DBOOTLOADER_SIZE=4096
|
||||
|
||||
|
||||
# Build Options
|
||||
|
|
@ -84,11 +86,6 @@ COMMAND_ENABLE = yes # Commands for debug and configuration
|
|||
NKRO_ENABLE = yes # USB Nkey Rollover
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -45,8 +45,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
/*
|
||||
* 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
|
||||
|
|
@ -55,17 +53,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#define XT_DATA_PIN PIND
|
||||
#define XT_DATA_DDR DDRD
|
||||
#define XT_DATA_BIT 0
|
||||
#define XT_RST_PORT PORTB
|
||||
#define XT_RST_PIN PINB
|
||||
#define XT_RST_DDR DDRB
|
||||
#define XT_RST_BIT 7
|
||||
|
||||
/* hard reset: low pulse for 500ms and after that HiZ for safety */
|
||||
#define XT_RESET() do { \
|
||||
XT_RST_PORT &= ~(1<<XT_RST_BIT); \
|
||||
XT_RST_DDR |= (1<<XT_RST_BIT); \
|
||||
_delay_ms(500); \
|
||||
XT_RST_DDR &= ~(1<<XT_RST_BIT); \
|
||||
} while (0)
|
||||
|
||||
/* INT1 for falling edge of clock line */
|
||||
#define XT_INT_INIT() do { \
|
||||
EICRA |= ((1<<ISC11) | \
|
||||
(1<<ISC10)); \
|
||||
(0<<ISC10)); \
|
||||
} while (0)
|
||||
/* clears flag and enables interrupt */
|
||||
#define XT_INT_ON() do { \
|
||||
EIFR |= (1<<INTF1); \
|
||||
EIMSK |= (1<<INT1); \
|
||||
} while (0)
|
||||
#define XT_INT_OFF() do { \
|
||||
EIMSK &= ~(1<<INT1); \
|
||||
} while (0)
|
||||
#define XT_INT_VECT INT1_vect
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ uint8_t matrix_scan(void)
|
|||
}
|
||||
|
||||
uint8_t code = xt_host_recv();
|
||||
if (code) xprintf("%02X ", code);
|
||||
switch (state) {
|
||||
case INIT:
|
||||
switch (code) {
|
||||
|
|
@ -131,10 +132,8 @@ uint8_t matrix_scan(void)
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -26,13 +26,6 @@ ifeq (yes,$(strip $(PS2_USE_USART)))
|
|||
endif
|
||||
|
||||
|
||||
ifeq (yes,$(strip $(XT_USE_INT)))
|
||||
SRC += protocol/xt_interrupt.c
|
||||
SRC += protocol/xt_io_avr.c
|
||||
OPT_DEFS += -DXT_USE_INT
|
||||
endif
|
||||
|
||||
|
||||
ifeq (yes,$(strip $(SERIAL_MOUSE_MICROSOFT_ENABLE)))
|
||||
SRC += $(PROTOCOL_DIR)/serial_mouse_microsoft.c
|
||||
OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MICROSOFT \
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2010,2011,2012,2013 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2018 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2016 Ethan Apodaca <papodaca@gmail.com>
|
||||
|
||||
This software is licensed with a Modified BSD License.
|
||||
|
|
@ -39,22 +39,33 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#ifndef XT_H
|
||||
#define XT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "wait.h"
|
||||
#include "xt_io.h"
|
||||
#include "print.h"
|
||||
#define XT_DATA_IN() do { \
|
||||
XT_DATA_DDR &= ~(1<<XT_DATA_BIT); \
|
||||
XT_DATA_PORT |= (1<<XT_DATA_BIT); \
|
||||
} while (0)
|
||||
|
||||
#define XT_DATA_READ() (XT_DATA_PIN&(1<<XT_DATA_BIT))
|
||||
|
||||
#define XT_DATA_LO() do { \
|
||||
XT_DATA_PORT &= ~(1<<XT_DATA_BIT); \
|
||||
XT_DATA_DDR |= (1<<XT_DATA_BIT); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define XT_CLOCK_IN() do { \
|
||||
XT_CLOCK_DDR &= ~(1<<XT_CLOCK_BIT); \
|
||||
XT_CLOCK_PORT |= (1<<XT_CLOCK_BIT); \
|
||||
} while (0)
|
||||
|
||||
#define XT_CLOCK_READ() (XT_CLOCK_PIN&(1<<XT_CLOCK_BIT))
|
||||
|
||||
#define XT_CLOCK_LO() do { \
|
||||
XT_CLOCK_PORT &= ~(1<<XT_CLOCK_BIT); \
|
||||
XT_CLOCK_DDR |= (1<<XT_CLOCK_BIT); \
|
||||
} while (0)
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2010,2011,2012,2013 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2018 Jun WAKO <wakojun@gmail.com>
|
||||
Copyright 2016 Ethan Apodaca <papodaca@gmail.com>
|
||||
|
||||
This software is licensed with a Modified BSD License.
|
||||
All of this is supposed to be Free Software, Open Source, DFSG-free,
|
||||
|
|
@ -35,22 +36,33 @@ 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_OFF();
|
||||
|
||||
/* hard reset */
|
||||
#ifdef XT_RESET
|
||||
XT_RESET();
|
||||
#endif
|
||||
|
||||
/* soft reset: pull clock line down for 20ms */
|
||||
XT_DATA_LO();
|
||||
XT_CLOCK_LO();
|
||||
_delay_ms(20);
|
||||
|
||||
/* input mode with pullup */
|
||||
XT_CLOCK_IN();
|
||||
XT_DATA_IN();
|
||||
|
||||
XT_INT_ON();
|
||||
}
|
||||
|
||||
|
|
@ -66,29 +78,42 @@ uint8_t xt_host_recv(void)
|
|||
|
||||
ISR(XT_INT_VECT)
|
||||
{
|
||||
static uint8_t state = 0;
|
||||
/*
|
||||
* XT signal format consits of 10 or 9 clocks and sends start bits and 8-bit data,
|
||||
* which should be read on falling edge of clock.
|
||||
*
|
||||
* start(0), start(1), bit0, bit1, bit2, bit3, bit4, bit5, bit6, bit7
|
||||
*
|
||||
* Original IBM XT keyboard sends start(0) bit while some of clones don't.
|
||||
* Start(0) bit is read as low on data line while start(1) as high.
|
||||
*
|
||||
* https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-XT-Keyboard-Protocol
|
||||
*/
|
||||
static enum {
|
||||
START, BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7
|
||||
} state = START;
|
||||
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;
|
||||
uint8_t dbit = XT_DATA_READ();
|
||||
|
||||
// This is needed if using PCINT which can be called on both falling and rising edge
|
||||
//if (XT_CLOCK_READ()) return;
|
||||
|
||||
switch (state) {
|
||||
case START:
|
||||
// ignore start(0) bit
|
||||
if (!dbit) return;
|
||||
break;
|
||||
case BIT0 ... BIT7:
|
||||
data >>= 1;
|
||||
if (dbit)
|
||||
data |= 0x80;
|
||||
break;
|
||||
}
|
||||
if (state++ == BIT7) {
|
||||
pbuf_enqueue(data);
|
||||
state = START;
|
||||
data = 0;
|
||||
}
|
||||
goto RETURN;
|
||||
END:
|
||||
pbuf_enqueue(data);
|
||||
DONE:
|
||||
state = 0;
|
||||
data = 0;
|
||||
RETURN:
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
#ifndef XT_IO_H
|
||||
#define XT_IO_H
|
||||
|
||||
bool clock_in(void);
|
||||
bool data_in(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#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);
|
||||
}
|
||||
Loading…
Reference in New Issue