/*
-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.
#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)
-void xt_host_init(void);
-uint8_t xt_host_recv(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))
-/*--------------------------------------------------------------------
- * 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;
-}
+#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);
#endif