Naze32 clone with Frysky receiver
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

spi.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Bit-Banged SPI routines
  3. */
  4. #ifndef _AVR_SPI_H
  5. #define _AVR_SPI_H
  6. #include <avr/io.h>
  7. #ifdef DEBUG
  8. // Arduino D3 = PD3
  9. #define SCK_on PORTD |= (1 << PD3)
  10. #define SCK_off PORTD &= ~(1 << PD3)
  11. #define SCK_dir DDRD |= (1 << PD3)
  12. // Arduino D7 = PD7
  13. #define MO_on PORTD |= (1 << PD7)
  14. #define MO_off PORTD &= ~(1 << PD7)
  15. #define MO_dir DDRD |= (1 << PD7)
  16. // Arduino D8 = PB0
  17. #define CS_on PORTB |= (1 << PB0)
  18. #define CS_off PORTB &= ~(1 << PB0)
  19. #define CS_dir DDRB |= (1 << PB0)
  20. // Arduino D2 = PD2
  21. #define MI_1 (PIND & (1 << PD2)) != 0
  22. #define MI_0 (PIND & (1 << PD2)) == 0
  23. #define MI_dir DDRD &= ~(1 << PD2); PORTD |= (1 << PD2)
  24. // Arduino D9 = PB1
  25. #define GDO_1 (PINB & (1 << PB1)) != 0
  26. #define GDO_0 (PINB & (1 << PB1)) == 0
  27. #define GDO_dir DDRB &= ~(1 << PB1); PORTB |= (1 << PB1)
  28. #else
  29. #define SCK_on PORTB |= (1 << PB4)
  30. #define SCK_off PORTB &= ~(1 << PB4)
  31. #define SCK_dir DDRB |= (1 << PB4)
  32. #define MO_on PORTB |= (1 << PB2)
  33. #define MO_off PORTB &= ~(1 << PB2)
  34. #define MO_dir DDRB |= (1 << PB2)
  35. #define CS_on PORTB |= (1 << PB1)
  36. #define CS_off PORTB &= ~(1 << PB1)
  37. #define CS_dir DDRB |= (1 << PB1)
  38. #define MI_1 (PINB & (1 << PB3)) != 0
  39. #define MI_0 (PINB & (1 << PB3)) == 0
  40. #define MI_dir DDRB &= ~(1 << PB3); PORTB |= (1 << PB3)
  41. #define GDO_1 (PINB & (1 << PB0)) != 0
  42. #define GDO_0 (PINB & (1 << PB0)) == 0
  43. #define GDO_dir DDRB &= ~(1 << PB0); PORTB |= (1 << PB0)
  44. #endif
  45. #define NOP() __asm__ __volatile__("nop")
  46. #endif