xt_usb: Replace functions with macros
This commit is contained in:
parent
42199c90f8
commit
acbea7fb15
5 changed files with 32 additions and 70 deletions
|
|
@ -12,7 +12,6 @@ TARGET_DIR = .
|
||||||
|
|
||||||
# project specific files
|
# project specific files
|
||||||
SRC = protocol/xt_interrupt.c \
|
SRC = protocol/xt_interrupt.c \
|
||||||
protocol/xt_io_avr.c \
|
|
||||||
matrix.c \
|
matrix.c \
|
||||||
led.c
|
led.c
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,22 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef XT_H
|
#ifndef XT_H
|
||||||
#define XT_H
|
#define XT_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "wait.h"
|
|
||||||
#include "xt_io.h"
|
|
||||||
#include "print.h"
|
|
||||||
|
|
||||||
void xt_host_init(void);
|
void xt_host_init(void);
|
||||||
uint8_t xt_host_recv(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
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
void xt_host_init(void)
|
void xt_host_init(void)
|
||||||
{
|
{
|
||||||
XT_INT_INIT();
|
XT_INT_INIT();
|
||||||
|
XT_INT_OFF();
|
||||||
|
|
||||||
/* hard reset */
|
/* hard reset */
|
||||||
#ifdef XT_RESET
|
#ifdef XT_RESET
|
||||||
|
|
@ -58,10 +59,14 @@ void xt_host_init(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* soft reset: pull clock line down for 20ms */
|
/* soft reset: pull clock line down for 20ms */
|
||||||
XT_INT_OFF();
|
XT_DATA_LO();
|
||||||
data_lo(); clock_lo();
|
XT_CLOCK_LO();
|
||||||
_delay_ms(20);
|
_delay_ms(20);
|
||||||
data_in(); clock_in();
|
|
||||||
|
/* input mode with pullup */
|
||||||
|
XT_CLOCK_IN();
|
||||||
|
XT_DATA_IN();
|
||||||
|
|
||||||
XT_INT_ON();
|
XT_INT_ON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +98,7 @@ ISR(XT_INT_VECT)
|
||||||
} state = START;
|
} state = START;
|
||||||
static uint8_t data = 0;
|
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
|
// This is needed if using PCINT which can be called on both falling and rising edge
|
||||||
//if (clock_in()) return;
|
//if (clock_in()) return;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,29 @@
|
||||||
#ifndef XT_IO_H
|
#ifndef XT_IO_H
|
||||||
#define XT_IO_H
|
#define XT_IO_H
|
||||||
|
|
||||||
bool clock_in(void);
|
#define XT_DATA_IN() do { \
|
||||||
bool data_in(void);
|
XT_DATA_DDR &= ~(1<<XT_DATA_BIT); \
|
||||||
|
XT_DATA_PORT |= (1<<XT_DATA_BIT); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
void clock_lo(void);
|
#define XT_DATA_READ() (XT_DATA_PIN&(1<<XT_DATA_BIT))
|
||||||
void data_lo(void);
|
|
||||||
|
#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
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue