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.

57 lines
1.8 KiB

  1. /* Copyright 2020
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include "quantum.h"
  18. typedef int16_t spi_status_t;
  19. // Hardware SS pin is defined in the header so that user code can refer to it
  20. #if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
  21. # define SPI_SS_PIN B0
  22. #elif defined(__AVR_ATmega32A__)
  23. # define SPI_SS_PIN B4
  24. #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
  25. # define SPI_SS_PIN B2
  26. #endif
  27. #define SPI_STATUS_SUCCESS (0)
  28. #define SPI_STATUS_ERROR (-1)
  29. #define SPI_STATUS_TIMEOUT (-2)
  30. #define SPI_TIMEOUT_IMMEDIATE (0)
  31. #define SPI_TIMEOUT_INFINITE (0xFFFF)
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. void spi_init(void);
  36. bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor);
  37. spi_status_t spi_write(uint8_t data);
  38. spi_status_t spi_read(void);
  39. spi_status_t spi_transmit(const uint8_t *data, uint16_t length);
  40. spi_status_t spi_receive(uint8_t *data, uint16_t length);
  41. void spi_stop(void);
  42. #ifdef __cplusplus
  43. }
  44. #endif