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