spi.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* sd2iec - SD/MMC to Commodore serial bus interface/controller
  2. Copyright (C) 2007-2009 Ingo Korb <ingo@akana.de>
  3. Inspiration and low-level SD/MMC access based on code from MMC2IEC
  4. by Lars Pontoppidan et al., see sdcard.c|h and config.h.
  5. FAT filesystem access based on code from ChaN and Jim Brain, see ff.c|h.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; version 2 of the License only.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. spi.h: Definitions for the low-level SPI routines
  17. Based on original code by Lars Pontoppidan et al., see spi.c
  18. for full copyright details.
  19. */
  20. #ifndef SPI_H
  21. #define SPI_H
  22. // function prototypes
  23. // SPI interface initializer
  24. void spiInit(void);
  25. // spiTransferByte(u08 data) waits until the SPI interface is ready
  26. // and then sends a single byte over the SPI port. The function also
  27. // returns the byte that was received during transmission.
  28. uint8_t spiTransferByte(uint8_t data);
  29. // spiTransferLong(u08 data) waits until the SPI interface is ready
  30. // and then sends the long with MSB first over the SPI port.
  31. uint32_t spiTransferLong(uint32_t data);
  32. // Macros for setting slave select:
  33. #ifdef CONFIG_TWINSD
  34. # define SPI_SS_HIGH(card) do { \
  35. if (card == 0) { \
  36. SPI_PORT |= SPI_SS; \
  37. } else { \
  38. SD2_PORT |= SD2_CS; \
  39. } \
  40. } while (0)
  41. #define SPI_SS_LOW(card) do { \
  42. if (card == 0) { \
  43. SPI_PORT &= (uint8_t)~SPI_SS; \
  44. } else { \
  45. SD2_PORT &= (uint8_t)~SD2_CS; \
  46. } \
  47. } while (0)
  48. #else
  49. # define SPI_SS_HIGH(card) SPI_PORT |= SPI_SS
  50. # define SPI_SS_LOW(card) SPI_PORT &= (uint8_t)~SPI_SS
  51. #endif
  52. #endif