/* * Bit-Banged SPI routines */ #ifndef _SPI_H #define _SPI_H #include #include #ifdef DEBUG // Arduino D3 = PD3 #define SCK_on PORTD |= PD3 #define SCK_off PORTD &= ~(PD3) #define SCK_dir DDRD |= (1 << PD3) // Arduino D2 = PD2 #define MO_on PORTD |= PD2 #define MO_off PORTD &= ~(PD2) #define MO_dir DDRD &= ~(1 << PD2) // Arduino D8 = PB0 #define CS_on PORTB |= PB0 #define CS_off PORTB &= ~(PB0) #define CS_dir DDRB |= (1 << PB0) // Arduino D7 = PD7 #define MI_1 (PIND & PD7) == PD7 #define MI_0 (PIND & PD7) != PD7 #define MI_dir DDRD |= (1 << PD7) // Arduino D9 = PB1 #define GDO_1 (PINB & PB1) == PB1 #define GDO_0 (PINB & PB1) != PB1 #define GDO_dir DDRB &= ~(1 << PB1) #else #define SCK_on PORTB |= PB4 #define SCK_off PORTB &= ~(PB4) #define SCK_dir DDRB |= (1 << PB4) #define MO_on PORTB |= PB3 #define MO_off PORTB &= ~(PB3) #define MO_dir DDRB &= ~(1 << PB3) #define CS_on PORTB |= PB1 #define CS_off PORTB &= ~(PB1) #define CS_dir DDRB |= (1 << PB1) #define MI_1 (PINB & PB2) == PB2 #define MI_0 (PINB & PB2) != PB2 #define MI_dir DDRB |= (1 << PB2) #define GDO_1 (PINB & PB0) == PB0 #define GDO_0 (PINB & PB0) != PB0 #define GDO_dir DDRB &= ~(1 << PB0) #endif #define NOP() __asm__ __volatile__("nop") void spiInit(void); void spiWrite(uint8_t command); uint8_t spiRead(void); #endif