spi.h 2.5 KB

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