Naze32 clone with Frysky receiver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

spi.h 964B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 D2
  10. #define SCK_on PORTD |= PD2
  11. #define SCK_off PORTD &= ~(PD2)
  12. // Arduino D4
  13. #define MO_on PORTD |= PD4
  14. #define MO_off PORTD &= ~(PD4)
  15. // Arduino D7
  16. #define CS_on PORTD |= PD7
  17. #define CS_off PORTD &= ~(PD7)
  18. // Arduino D8
  19. #define MI_1 (PINB & PB0) == PB0
  20. #define MI_0 (PINB & PB0) != PB0
  21. // Arduino D12
  22. #define GDO_1 (PINB & PB4) == PB4
  23. #define GDO_0 (PINB & PB4) != PB4
  24. #else
  25. #define SCK_on PORTB |= PB4
  26. #define SCK_off PORTB &= ~(PB4)
  27. #define MO_on PORTB |= PB3
  28. #define MO_off PORTB &= ~(PB3)
  29. #define CS_on PORTB |= PB1
  30. #define CS_off PORTB &= ~(PB1)
  31. #define MI_1 (PINB & PB2) == PB2
  32. #define MI_0 (PINB & PB2) != PB2
  33. #define GDO_1 (PINB & PB0) == PB0
  34. #define GDO_0 (PINB & PB0) != PB0
  35. #endif
  36. #define NOP() __asm__ __volatile__("nop")
  37. void spiInit(void);
  38. void spiWrite(uint8_t command);
  39. uint8_t spiRead(void);
  40. #endif