# project specific files
SRC = protocol/xt_interrupt.c \
- protocol/xt_io_avr.c \
matrix.c \
led.c
#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
void xt_host_init(void)
{
XT_INT_INIT();
+ XT_INT_OFF();
/* hard reset */
#ifdef XT_RESET
#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();
}
} 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;
#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
+++ /dev/null
-#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);
-}