spi_interface.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef SPI_INTERFACE_H_
  2. #define SPI_INTERFACE_H_
  3. #include <util/crc16.h>
  4. /* Button coprocessor wire protocol */
  5. enum spi_commands {
  6. /* No operation */
  7. SPI_CONTROL_NOP,
  8. /* Application identification */
  9. SPI_CONTROL_TESTAPP,
  10. /* Data fetch commands */
  11. SPI_CONTROL_GETLOW,
  12. SPI_CONTROL_GETHIGH,
  13. SPI_CONTROL_GETENC,
  14. SPI_CONTROL_GETSUM,
  15. /* Bootloader related commands */
  16. SPI_CONTROL_ENTERBOOT = 0xA0, /* Enter the bootloader */
  17. SPI_CONTROL_ENTERBOOT2, /* Enter the bootloader (second stage) */
  18. SPI_CONTROL_ENTERAPP, /* Enter the application */
  19. SPI_CONTROL_STARTFLASH, /* Begin flashing sequence */
  20. };
  21. enum spi_result {
  22. SPI_RESULT_OK = 0xFA,
  23. SPI_RESULT_FAIL = 0x8A,
  24. };
  25. #define SPI_SLAVE_TRANSIRQ_DDR DDRB
  26. #define SPI_SLAVE_TRANSIRQ_PORT PORTB
  27. #define SPI_SLAVE_TRANSIRQ_PIN PINB
  28. #define SPI_SLAVE_TRANSIRQ_BIT 6
  29. #define SPI_MASTER_TRANSIRQ_DDR DDRD
  30. #define SPI_MASTER_TRANSIRQ_PORT PORTD
  31. #define SPI_MASTER_TRANSIRQ_PIN PIND
  32. #define SPI_MASTER_TRANSIRQ_BIT 2
  33. #define SPI_MASTER_TRANSIRQ_INT INT0
  34. #define SPI_MASTER_TRANSIRQ_INTF INTF0
  35. #define SPI_MASTER_TRANSIRQ_VECT INT0_vect
  36. static inline uint8_t spi_crc8(uint8_t crc, uint8_t data)
  37. {
  38. return _crc_ibutton_update(crc, data);
  39. }
  40. #endif /* SPI_INTERFACE_H_ */