spi.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2013 Semtech
  8. Description: Implements the generic SPI driver
  9. License: Revised BSD License, see LICENSE.TXT file include in the project
  10. Maintainer: Miguel Luis and Gregory Cristian
  11. */
  12. #ifndef __SPI_H__
  13. #define __SPI_H__
  14. #include "spi-board.h"
  15. /*!
  16. * SPI object type definition
  17. */
  18. typedef struct Spi_s Spi_t;
  19. /*!
  20. * \brief Initializes the SPI object and MCU peripheral
  21. *
  22. * \remark When NSS pin is software controlled set the pin name to NC otherwise
  23. * set the pin name to be used.
  24. *
  25. * \param [IN] obj SPI object
  26. * \param [IN] mosi SPI MOSI pin name to be used
  27. * \param [IN] miso SPI MISO pin name to be used
  28. * \param [IN] sclk SPI SCLK pin name to be used
  29. * \param [IN] nss SPI NSS pin name to be used
  30. */
  31. void SpiInit( Spi_t *obj, PinNames mosi, PinNames miso, PinNames sclk, PinNames nss );
  32. /*!
  33. * \brief De-initializes the SPI object and MCU peripheral
  34. *
  35. * \param [IN] obj SPI object
  36. */
  37. void SpiDeInit( Spi_t *obj );
  38. /*!
  39. * \brief Configures the SPI peripheral
  40. *
  41. * \remark Slave mode isn't currently handled
  42. *
  43. * \param [IN] obj SPI object
  44. * \param [IN] bits Number of bits to be used. [8 or 16]
  45. * \param [IN] cpol Clock polarity
  46. * \param [IN] cpha Clock phase
  47. * \param [IN] slave When set the peripheral acts in slave mode
  48. */
  49. void SpiFormat( Spi_t *obj, int8_t bits, int8_t cpol, int8_t cpha, int8_t slave );
  50. /*!
  51. * \brief Sets the SPI speed
  52. *
  53. * \param [IN] obj SPI object
  54. * \param [IN] hz SPI clock frequency in hz
  55. */
  56. void SpiFrequency( Spi_t *obj, uint32_t hz );
  57. /*!
  58. * \brief Sends outData and receives inData
  59. *
  60. * \param [IN] obj SPI object
  61. * \param [IN] outData Byte to be sent
  62. * \retval inData Received byte.
  63. */
  64. uint16_t SpiInOut( Spi_t *obj, uint16_t outData );
  65. #endif // __SPI_H__