spi.h 941 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef SPI_CONFIG_H_
  2. #define SPI_CONFIG_H_
  3. #include <avr/io.h>
  4. #include <avr/pgmspace.h>
  5. #include "util.h"
  6. #include "coproc-firmware/spi_interface.h"
  7. /* No async for the bootloader */
  8. #ifdef BOOTLOADER
  9. # define SPI_HAVE_ASYNC 0
  10. #else
  11. # define SPI_HAVE_ASYNC 1
  12. #endif
  13. enum spi_async_flags {
  14. SPI_ASYNC_RUNNING = (1 << 0),
  15. SPI_ASYNC_TXPROGMEM = (1 << 1), /* TX buffer is in progmem */
  16. };
  17. void spi_async_start(void *rxbuf, const void *txbuf,
  18. uint8_t nr_bytes, uint8_t flags, uint8_t wait_ms);
  19. bool spi_async_running(void);
  20. void spi_async_ms_tick(void);
  21. extern void spi_async_done(void);
  22. static inline void spi_slave_select(bool select)
  23. {
  24. if (select)
  25. PORTB = (uint8_t)(PORTB & ~(1u << 4/*SS*/));
  26. else
  27. PORTB = (uint8_t)(PORTB | (1u << 4/*SS*/));
  28. }
  29. uint8_t spi_transfer_sync(uint8_t tx);
  30. uint8_t spi_transfer_slowsync(uint8_t tx);
  31. void spi_lowlevel_exit(void);
  32. void spi_lowlevel_init(void);
  33. #endif /* SPI_CONFIG_H_ */