spi17y.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. * @file spi17y.h
  3. * @brief Serial Peripheral Interface (SPI17Y) function prototypes and data types.
  4. */
  5. /* ****************************************************************************
  6. * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
  22. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Except as contained in this notice, the name of Maxim Integrated
  27. * Products, Inc. shall not be used except as stated in the Maxim Integrated
  28. * Products, Inc. Branding Policy.
  29. *
  30. * The mere transfer of this software does not imply any licenses
  31. * of trade secrets, proprietary technology, copyrights, patents,
  32. * trademarks, maskwork rights, or any other form of intellectual
  33. * property whatsoever. Maxim Integrated Products, Inc. retains all
  34. * ownership rights.
  35. *
  36. * $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
  37. * $Revision: 40072 $
  38. *
  39. *************************************************************************** */
  40. /* Define to prevent redundant inclusion */
  41. #ifndef _SPI17Y_H_
  42. #define _SPI17Y_H_
  43. /* **** Includes **** */
  44. #include "mxc_config.h"
  45. #include "spi17y_regs.h"
  46. #include "mxc_sys.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * @defgroup spi17y SPI17Y
  52. * @ingroup spi
  53. * @{
  54. */
  55. /* **** Definitions **** */
  56. /**
  57. * Enumeration type for setting the number data lines to use for communication.
  58. */
  59. typedef enum {
  60. SPI17Y_WIDTH_1 = 0, /**< 1 Data Line. */
  61. SPI17Y_WIDTH_2 = 1, /**< 2 Data Lines (x2). */
  62. SPI17Y_WIDTH_4 = 2 /**< 4 Data Lines (x4). */
  63. } spi17y_width_t;
  64. /**
  65. * Enumeration type for setting the polarity of ss lines.
  66. */
  67. typedef enum {
  68. SPI17Y_POL_LOW = 0, /**< Polarity Low. */
  69. SPI17Y_POL_HIGH = 1 /**< Polarity High. */
  70. } spi17y_sspol_t;
  71. /**
  72. * Structure type representing a SPI17Y Master Transaction request.
  73. */
  74. typedef struct spi17y_req spi17y_req_t;
  75. /**
  76. * @brief Callback function type used in asynchronous SPI Master communication requests.
  77. * @details The function declaration for the SPI Master callback is:
  78. * @code
  79. * void callback(spi17y_req_t * req, int error_code);
  80. * @endcode
  81. * | | |
  82. * | -----: | :----------------------------------------- |
  83. * | \p req | Pointer to a #spi_req object representing the active SPI Master active transaction. |
  84. * | \p error_code | An error code if the active transaction had a failure or #E_NO_ERROR if successful. |
  85. * @note Callback will execute in interrupt context
  86. * @addtogroup spi_async
  87. */
  88. typedef void (*spi17y_callback_fn)(spi17y_req_t * req, int error_code);
  89. /**
  90. * @brief Structure definition for an SPI Master Transaction request.
  91. * @note When using this structure for an asynchronous operation, the
  92. * structure must remain allocated until the callback is completed.
  93. * @addtogroup spi_async
  94. */
  95. struct spi17y_req {
  96. uint8_t ssel; /**< Slave select line to use. (Master only, ignored in slave mode) */
  97. uint8_t deass; /**< Non-zero to de-assert slave select after transaction. (Master only, ignored in slave mode)*/
  98. spi17y_sspol_t ssel_pol; /**< Slave select line polarity. */
  99. const void *tx_data; /**< Pointer to a buffer to transmit data from. NULL if undesired. */
  100. void *rx_data; /**< Pointer to a buffer to store data received. NULL if undesired.*/
  101. spi17y_width_t width; /**< Number of data lines to use, see #spi17y_width_t. */
  102. unsigned len; /**< Number of transfer units to send from the \p tx_data buffer. */
  103. unsigned bits; /**< Number of bits in transfer unit (e.g. 8 for byte, 16 for short) */
  104. unsigned rx_num; /**< Number of bytes actually read into the \p rx_data buffer. */
  105. unsigned tx_num; /**< Number of bytes actually sent from the \p tx_data buffer */
  106. spi17y_callback_fn callback; /**< Callback function if desired, NULL otherwise */
  107. };
  108. /* **** Function Prototypes **** */
  109. /**
  110. * @brief Initialize the spi.
  111. * @param spi Pointer to spi module to initialize.
  112. * @param mode SPI mode for clock phase and polarity.
  113. * @param freq Desired clock frequency.
  114. * @param sys_cfg System configuration object
  115. *
  116. * @return #E_NO_ERROR if successful, @ref
  117. * MXC_Error_Codes "error" if unsuccessful.
  118. */
  119. int SPI17Y_Init(mxc_spi17y_regs_t *spi, unsigned int mode, unsigned int freq, const sys_cfg_spi17y_t* sys_cfg);
  120. /**
  121. * @brief Shutdown SPI module.
  122. * @param spi Pointer to SPI regs.
  123. *
  124. * @return #E_NO_ERROR if successful, @ref
  125. * MXC_Error_Codes "error" if unsuccessful.
  126. */
  127. int SPI17Y_Shutdown(mxc_spi17y_regs_t *spi);
  128. /**
  129. * @brief Processing function for asynchronous SPI operations.
  130. * This function must be called either from the SPI interrupt
  131. * handler or periodically.
  132. *
  133. * @param spi Pointer to spi module.
  134. */
  135. void SPI17Y_Handler(mxc_spi17y_regs_t *spi);
  136. /**
  137. * @brief Execute a master transaction.
  138. * This function will block until the transaction is complete.
  139. * @param spi Pointer to spi module.
  140. * @param req Pointer to spi request
  141. *
  142. * @return #E_NO_ERROR if successful, @ref
  143. * MXC_Error_Codes "error" if unsuccessful.
  144. */
  145. int SPI17Y_MasterTrans(mxc_spi17y_regs_t *spi, spi17y_req_t *req);
  146. /**
  147. * @brief Execute a slave transaction.
  148. * This function will block until the transaction is complete.
  149. * @param spi Pointer to spi module.
  150. * @param req Pointer to spi request
  151. *
  152. * @return #E_NO_ERROR if successful, @ref
  153. * MXC_Error_Codes "error" if unsuccessful.
  154. */
  155. int SPI17Y_SlaveTrans(mxc_spi17y_regs_t *spi, spi17y_req_t *req);
  156. /**
  157. * @brief Asynchronously read/write SPI Master data
  158. *
  159. * @param spi Pointer to spi module
  160. * @param req Pointer to spi request
  161. *
  162. * @return #E_NO_ERROR if successful, @ref
  163. * MXC_Error_Codes "error" if unsuccessful.
  164. */
  165. int SPI17Y_MasterTransAsync(mxc_spi17y_regs_t *spi, spi17y_req_t *req);
  166. /**
  167. * @brief Asynchronously read/write SPI Slave data
  168. *
  169. * @param spi Pointer to spi module
  170. * @param req Pointer to spi request
  171. *
  172. * @return #E_NO_ERROR if successful, @ref
  173. * MXC_Error_Codes "error" if unsuccessful.
  174. */
  175. int SPI17Y_SlaveTransAsync(mxc_spi17y_regs_t *spi, spi17y_req_t *req);
  176. /**
  177. * @brief Aborts an Asynchronous request
  178. *
  179. * @param req Pointer to spi request
  180. * @return #E_NO_ERROR if successful, @ref
  181. * MXC_Error_Codes "error" if unsuccessful.
  182. */
  183. int SPI17Y_AbortAsync(spi17y_req_t *req);
  184. /**
  185. * @brief Enable SPI
  186. * @param spi Pointer to spi module.
  187. *
  188. * @return #E_NO_ERROR if successful, @ref
  189. * MXC_Error_Codes "error" if unsuccessful.
  190. */
  191. void SPI17Y_Enable(mxc_spi17y_regs_t* spi);
  192. /**
  193. * @brief Disable SPI. Any pending asynchronous transactions will not
  194. * complete and their callbacks will not be executed.
  195. * @param spi Pointer to spi module.
  196. *
  197. * @return #E_NO_ERROR if successful, @ref
  198. * MXC_Error_Codes "error" if unsuccessful.
  199. */
  200. void SPI17Y_Disable(mxc_spi17y_regs_t* spi);
  201. /**
  202. * @brief Clear the TX and RX FIFO
  203. * @param spi Pointer to spi module.
  204. *
  205. * @return #E_NO_ERROR if successful, @ref
  206. * MXC_Error_Codes "error" if unsuccessful.
  207. */
  208. void SPI17Y_Clear_fifo(mxc_spi17y_regs_t* spi);
  209. /**@} end of group spi17y */
  210. #ifdef __cplusplus
  211. }
  212. #endif
  213. #endif /* _SPI17Y_H_ */