Naze32 clone with Frysky receiver
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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