From acbea7fb15c7d2bbfce7261e7e8acb110438a9e5 Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 2 Mar 2018 13:56:46 +0900 Subject: [PATCH] xt_usb: Replace functions with macros --- converter/xt_usb/Makefile | 1 - tmk_core/protocol/xt.h | 15 ----------- tmk_core/protocol/xt_interrupt.c | 13 ++++++--- tmk_core/protocol/xt_io.h | 27 ++++++++++++++++--- tmk_core/protocol/xt_io_avr.c | 46 -------------------------------- 5 files changed, 32 insertions(+), 70 deletions(-) delete mode 100644 tmk_core/protocol/xt_io_avr.c diff --git a/converter/xt_usb/Makefile b/converter/xt_usb/Makefile index e7fb6c8a..0cbf3b56 100644 --- a/converter/xt_usb/Makefile +++ b/converter/xt_usb/Makefile @@ -12,7 +12,6 @@ TARGET_DIR = . # project specific files SRC = protocol/xt_interrupt.c \ - protocol/xt_io_avr.c \ matrix.c \ led.c diff --git a/tmk_core/protocol/xt.h b/tmk_core/protocol/xt.h index ef1bbfaf..e689109c 100644 --- a/tmk_core/protocol/xt.h +++ b/tmk_core/protocol/xt.h @@ -39,22 +39,7 @@ 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; -} - #endif diff --git a/tmk_core/protocol/xt_interrupt.c b/tmk_core/protocol/xt_interrupt.c index 05afefd3..97e93a5a 100644 --- a/tmk_core/protocol/xt_interrupt.c +++ b/tmk_core/protocol/xt_interrupt.c @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. void xt_host_init(void) { XT_INT_INIT(); + XT_INT_OFF(); /* hard reset */ #ifdef XT_RESET @@ -58,10 +59,14 @@ void xt_host_init(void) #endif /* soft reset: pull clock line down for 20ms */ - XT_INT_OFF(); - data_lo(); clock_lo(); + XT_DATA_LO(); + XT_CLOCK_LO(); _delay_ms(20); - data_in(); clock_in(); + + /* input mode with pullup */ + XT_CLOCK_IN(); + XT_DATA_IN(); + XT_INT_ON(); } @@ -93,7 +98,7 @@ ISR(XT_INT_VECT) } state = START; static uint8_t data = 0; - uint8_t dbit = data_in(); + uint8_t dbit = XT_DATA_READ(); // This is needed if using PCINT which can be called on both falling and rising edge //if (clock_in()) return; diff --git a/tmk_core/protocol/xt_io.h b/tmk_core/protocol/xt_io.h index 4198e655..8252e1cf 100644 --- a/tmk_core/protocol/xt_io.h +++ b/tmk_core/protocol/xt_io.h @@ -1,10 +1,29 @@ #ifndef XT_IO_H #define XT_IO_H -bool clock_in(void); -bool data_in(void); +#define XT_DATA_IN() do { \ + XT_DATA_DDR &= ~(1< -#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<