81 lines
1.8 KiB
C
81 lines
1.8 KiB
C
#ifndef _TABBY_AVR_H
|
|
#define _TABBY_AVR_H
|
|
|
|
/*
|
|
* So like, we're abusing pins here. So badly, it's beyond. So here's
|
|
* what's going down: We want to retain the same physical I/O connections
|
|
* between both the sending and receiving flavors of the whole Game Boy
|
|
* Printer endeavor, and that mean/s that we must absolutely bit bang MOSI
|
|
* and MISO opposite from their ordinary roles. The reason being: There is
|
|
* no notion of MISO or MOSI from the Game Boy's (nor its peripherals')
|
|
* point of view. The SI and SO pins over a link cable are crossed over, so
|
|
* SI on one end always connects to SO on the other, and vice-versa. The SI
|
|
* and SO pins do not switch roles based on role, unlike on AVR SPI
|
|
* implementations.
|
|
*/
|
|
|
|
#define SPI_PULSE_USEC 61
|
|
|
|
/*
|
|
* SC -- Serial Clock
|
|
*/
|
|
#define SC_DDR DDRB
|
|
#define SC_DDB DDB5
|
|
#define SC_PORT PORTB
|
|
#define SC_PORT_PIN PORTB5
|
|
|
|
#define SC_INPUT() \
|
|
(SC_DDR |= ~(1 << SC_DDB))
|
|
|
|
#define SC_OUTPUT() \
|
|
(SC_DDR |= (1 << SC_DDB))
|
|
|
|
#define SC_HIGH() \
|
|
(SC_PORT |= (1 << SC_PORT_PIN))
|
|
|
|
#define SC_LOW() \
|
|
(SC_PORT &= ~(1 << SC_PORT_PIN))
|
|
|
|
/*
|
|
* SI -- Serial In
|
|
*/
|
|
#define SI_DDR DDRB
|
|
#define SI_DDB DDB3
|
|
#define SI_PIN_REG PINB
|
|
#define SI_PIN PINB3
|
|
#define SI_PORT PORTB
|
|
#define SI_PORT_PIN PORTB3
|
|
|
|
#define SI_INPUT() \
|
|
(SI_DDR &= ~(1 << SI_DDB))
|
|
|
|
#define SI_PULLUP() \
|
|
(SI_PORT |= (1 << SI_PORT_PIN))
|
|
|
|
#define SI_IS_HIGH() \
|
|
(SI_PIN_REG & (1 << SI_PIN))
|
|
|
|
/*
|
|
* SO -- Serial Out
|
|
*/
|
|
#define SO_DDR DDRB
|
|
#define SO_DDB DDB4
|
|
#define SO_PORT PORTB
|
|
#define SO_PORT_PIN PORTB4
|
|
|
|
#define SO_OUTPUT() \
|
|
(SO_DDR |= (1 << SO_DDB))
|
|
|
|
#define SO_HIGH() \
|
|
(SO_PORT |= (1 << SO_PORT_PIN))
|
|
|
|
#define SO_LOW() \
|
|
(SO_PORT &= ~(1 << SO_PORT_PIN))
|
|
|
|
#define SS_DDR DDRB
|
|
#define SS_DDB DDB2
|
|
|
|
#define SS_INPUT() \
|
|
(SS_DDR &= ~(1 << SS_DDB))
|
|
|
|
#endif /* _TABBY_AVR_H */
|