1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- /*
- * Bit-Banged SPI routines
- */
-
- #ifndef _SPI_H
- #define _SPI_H
-
- #include <stdint.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")
-
- void spiInit(void);
- uint8_t spiReadWrite(uint8_t command);
-
- #define spiWrite(x) spiReadWrite(x)
- #define spiRead() spiReadWrite(0)
-
- #endif
|