spi.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* sd2iec - SD/MMC to Commodore serial bus interface/controller
  2. Copyright (C) 2007-2010 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. /* Low speed 400kHz for init, fast speed <=20MHz (MMC limit) */
  23. typedef enum { SPI_SPEED_FAST, SPI_SPEED_SLOW, SPI_SPEED_FPGA_FAST, SPI_SPEED_FPGA_SLOW } spi_speed_t;
  24. /* Pre-Initialize SPI interface (PCLK divider before PLL setup) */
  25. void spi_preinit(void);
  26. /* Initialize SPI interface */
  27. void spi_init(spi_speed_t speed);
  28. /* Transmit a single byte */
  29. void spi_tx_byte(uint8_t data);
  30. /* Transmit a single byte and return received data */
  31. uint8_t spi_txrx_byte(uint8_t data);
  32. /* Transmit a data block */
  33. void spi_tx_block(const void *data, unsigned int length);
  34. /* Receive a single byte */
  35. uint8_t spi_rx_byte(void);
  36. /* Receive a data block */
  37. void spi_rx_block(void *data, unsigned int length);
  38. /* Switch speed of SPI interface */
  39. void spi_set_speed(spi_speed_t speed);
  40. /* wait for SPI TX FIFO to become empty */
  41. void spi_tx_sync(void);
  42. #endif