]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
xt_usb: Replace functions with macros
authortmk <hasu@tmk-kbd.com>
Fri, 2 Mar 2018 04:56:46 +0000 (13:56 +0900)
committertmk <hasu@tmk-kbd.com>
Wed, 14 Mar 2018 12:32:22 +0000 (21:32 +0900)
converter/xt_usb/Makefile
tmk_core/protocol/xt.h
tmk_core/protocol/xt_interrupt.c
tmk_core/protocol/xt_io.h
tmk_core/protocol/xt_io_avr.c [deleted file]

index e7fb6c8adc2e62db48eb78115302b35337902293..0cbf3b563419ee098a7be8b8c10c984372b378ab 100644 (file)
@@ -12,7 +12,6 @@ TARGET_DIR = .
 
 # project specific files
 SRC =  protocol/xt_interrupt.c \
-       protocol/xt_io_avr.c \
        matrix.c \
        led.c
 
index ef1bbfaf972161d4dccdce347955863118a44e50..e689109c6d6f305a074e35ad65ca8fc4669948f6 100644 (file)
@@ -39,22 +39,7 @@ 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;
-}
-
 #endif
index 05afefd36017ffdd30d5716857a16f2ded695d2a..97e93a5a22f0594f26b7c35ae030f1435adf76fd 100644 (file)
@@ -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;
index 4198e6557f7b9c4f0d63805d1705bd1c1157783d..8252e1cf78138a2e65eb0496cbfa0430f5274771 100644 (file)
@@ -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<<XT_DATA_BIT); \
+    XT_DATA_PORT |=  (1<<XT_DATA_BIT); \
+} while (0)
 
-void clock_lo(void);
-void data_lo(void);
+#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)
 
 #endif
diff --git a/tmk_core/protocol/xt_io_avr.c b/tmk_core/protocol/xt_io_avr.c
deleted file mode 100644 (file)
index 7775be7..0000000
+++ /dev/null
@@ -1,46 +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);
-}
-
-void clock_lo(void)
-{
-    XT_CLOCK_PORT &= ~(1<<XT_CLOCK_BIT);
-    XT_CLOCK_DDR  |=  (1<<XT_CLOCK_BIT);
-}
-
-void data_lo(void)
-{
-    XT_DATA_PORT &= ~(1<<XT_DATA_BIT);
-    XT_DATA_DDR  |=  (1<<XT_DATA_BIT);
-}