fsl_lpspi.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_LPSPI_H_
  31. #define _FSL_LPSPI_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup lpspi_driver
  35. * @{
  36. */
  37. /**********************************************************************************************************************
  38. * Definitions
  39. *********************************************************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. /*! @brief LPSPI driver version 2.0.1. */
  43. #define FSL_LPSPI_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
  44. /*@}*/
  45. #ifndef LPSPI_DUMMY_DATA
  46. /*! @brief LPSPI dummy data if no Tx data.*/
  47. #define LPSPI_DUMMY_DATA (0x00U) /*!< Dummy data used for tx if there is not txData. */
  48. #endif
  49. /*! @brief Status for the LPSPI driver.*/
  50. enum _lpspi_status
  51. {
  52. kStatus_LPSPI_Busy = MAKE_STATUS(kStatusGroup_LPSPI, 0), /*!< LPSPI transfer is busy.*/
  53. kStatus_LPSPI_Error = MAKE_STATUS(kStatusGroup_LPSPI, 1), /*!< LPSPI driver error. */
  54. kStatus_LPSPI_Idle = MAKE_STATUS(kStatusGroup_LPSPI, 2), /*!< LPSPI is idle.*/
  55. kStatus_LPSPI_OutOfRange = MAKE_STATUS(kStatusGroup_LPSPI, 3) /*!< LPSPI transfer out Of range. */
  56. };
  57. /*! @brief LPSPI status flags in SPIx_SR register.*/
  58. enum _lpspi_flags
  59. {
  60. kLPSPI_TxDataRequestFlag = LPSPI_SR_TDF_MASK, /*!< Transmit data flag */
  61. kLPSPI_RxDataReadyFlag = LPSPI_SR_RDF_MASK, /*!< Receive data flag */
  62. kLPSPI_WordCompleteFlag = LPSPI_SR_WCF_MASK, /*!< Word Complete flag */
  63. kLPSPI_FrameCompleteFlag = LPSPI_SR_FCF_MASK, /*!< Frame Complete flag */
  64. kLPSPI_TransferCompleteFlag = LPSPI_SR_TCF_MASK, /*!< Transfer Complete flag */
  65. kLPSPI_TransmitErrorFlag = LPSPI_SR_TEF_MASK, /*!< Transmit Error flag (FIFO underrun) */
  66. kLPSPI_ReceiveErrorFlag = LPSPI_SR_REF_MASK, /*!< Receive Error flag (FIFO overrun) */
  67. kLPSPI_DataMatchFlag = LPSPI_SR_DMF_MASK, /*!< Data Match flag */
  68. kLPSPI_ModuleBusyFlag = LPSPI_SR_MBF_MASK, /*!< Module Busy flag */
  69. kLPSPI_AllStatusFlag = (LPSPI_SR_TDF_MASK | LPSPI_SR_RDF_MASK | LPSPI_SR_WCF_MASK | LPSPI_SR_FCF_MASK |
  70. LPSPI_SR_TCF_MASK | LPSPI_SR_TEF_MASK | LPSPI_SR_REF_MASK | LPSPI_SR_DMF_MASK |
  71. LPSPI_SR_MBF_MASK) /*!< Used for clearing all w1c status flags */
  72. };
  73. /*! @brief LPSPI interrupt source.*/
  74. enum _lpspi_interrupt_enable
  75. {
  76. kLPSPI_TxInterruptEnable = LPSPI_IER_TDIE_MASK, /*!< Transmit data interrupt enable */
  77. kLPSPI_RxInterruptEnable = LPSPI_IER_RDIE_MASK, /*!< Receive data interrupt enable */
  78. kLPSPI_WordCompleteInterruptEnable = LPSPI_IER_WCIE_MASK, /*!< Word complete interrupt enable */
  79. kLPSPI_FrameCompleteInterruptEnable = LPSPI_IER_FCIE_MASK, /*!< Frame complete interrupt enable */
  80. kLPSPI_TransferCompleteInterruptEnable = LPSPI_IER_TCIE_MASK, /*!< Transfer complete interrupt enable */
  81. kLPSPI_TransmitErrorInterruptEnable = LPSPI_IER_TEIE_MASK, /*!< Transmit error interrupt enable(FIFO underrun)*/
  82. kLPSPI_ReceiveErrorInterruptEnable = LPSPI_IER_REIE_MASK, /*!< Receive Error interrupt enable (FIFO overrun) */
  83. kLPSPI_DataMatchInterruptEnable = LPSPI_IER_DMIE_MASK, /*!< Data Match interrupt enable */
  84. kLPSPI_AllInterruptEnable =
  85. (LPSPI_IER_TDIE_MASK | LPSPI_IER_RDIE_MASK | LPSPI_IER_WCIE_MASK | LPSPI_IER_FCIE_MASK | LPSPI_IER_TCIE_MASK |
  86. LPSPI_IER_TEIE_MASK | LPSPI_IER_REIE_MASK | LPSPI_IER_DMIE_MASK) /*!< All above interrupts enable.*/
  87. };
  88. /*! @brief LPSPI DMA source.*/
  89. enum _lpspi_dma_enable
  90. {
  91. kLPSPI_TxDmaEnable = LPSPI_DER_TDDE_MASK, /*!< Transmit data DMA enable */
  92. kLPSPI_RxDmaEnable = LPSPI_DER_RDDE_MASK /*!< Receive data DMA enable */
  93. };
  94. /*! @brief LPSPI master or slave mode configuration.*/
  95. typedef enum _lpspi_master_slave_mode
  96. {
  97. kLPSPI_Master = 1U, /*!< LPSPI peripheral operates in master mode.*/
  98. kLPSPI_Slave = 0U /*!< LPSPI peripheral operates in slave mode.*/
  99. } lpspi_master_slave_mode_t;
  100. /*! @brief LPSPI Peripheral Chip Select (PCS) configuration (which PCS to configure).*/
  101. typedef enum _lpspi_which_pcs_config
  102. {
  103. kLPSPI_Pcs0 = 0U, /*!< PCS[0] */
  104. kLPSPI_Pcs1 = 1U, /*!< PCS[1] */
  105. kLPSPI_Pcs2 = 2U, /*!< PCS[2] */
  106. kLPSPI_Pcs3 = 3U /*!< PCS[3] */
  107. } lpspi_which_pcs_t;
  108. /*! @brief LPSPI Peripheral Chip Select (PCS) Polarity configuration.*/
  109. typedef enum _lpspi_pcs_polarity_config
  110. {
  111. kLPSPI_PcsActiveHigh = 1U, /*!< PCS Active High (idles low) */
  112. kLPSPI_PcsActiveLow = 0U /*!< PCS Active Low (idles high) */
  113. } lpspi_pcs_polarity_config_t;
  114. /*! @brief LPSPI Peripheral Chip Select (PCS) Polarity.*/
  115. enum _lpspi_pcs_polarity
  116. {
  117. kLPSPI_Pcs0ActiveLow = 1U << 0, /*!< Pcs0 Active Low (idles high). */
  118. kLPSPI_Pcs1ActiveLow = 1U << 1, /*!< Pcs1 Active Low (idles high). */
  119. kLPSPI_Pcs2ActiveLow = 1U << 2, /*!< Pcs2 Active Low (idles high). */
  120. kLPSPI_Pcs3ActiveLow = 1U << 3, /*!< Pcs3 Active Low (idles high). */
  121. kLPSPI_PcsAllActiveLow = 0xFU /*!< Pcs0 to Pcs5 Active Low (idles high). */
  122. };
  123. /*! @brief LPSPI clock polarity configuration.*/
  124. typedef enum _lpspi_clock_polarity
  125. {
  126. kLPSPI_ClockPolarityActiveHigh = 0U, /*!< CPOL=0. Active-high LPSPI clock (idles low)*/
  127. kLPSPI_ClockPolarityActiveLow = 1U /*!< CPOL=1. Active-low LPSPI clock (idles high)*/
  128. } lpspi_clock_polarity_t;
  129. /*! @brief LPSPI clock phase configuration.*/
  130. typedef enum _lpspi_clock_phase
  131. {
  132. kLPSPI_ClockPhaseFirstEdge = 0U, /*!< CPHA=0. Data is captured on the leading edge of the SCK and changed on the
  133. following edge.*/
  134. kLPSPI_ClockPhaseSecondEdge = 1U /*!< CPHA=1. Data is changed on the leading edge of the SCK and captured on the
  135. following edge.*/
  136. } lpspi_clock_phase_t;
  137. /*! @brief LPSPI data shifter direction options.*/
  138. typedef enum _lpspi_shift_direction
  139. {
  140. kLPSPI_MsbFirst = 0U, /*!< Data transfers start with most significant bit.*/
  141. kLPSPI_LsbFirst = 1U /*!< Data transfers start with least significant bit.*/
  142. } lpspi_shift_direction_t;
  143. /*! @brief LPSPI Host Request select configuration. */
  144. typedef enum _lpspi_host_request_select
  145. {
  146. kLPSPI_HostReqExtPin = 0U, /*!< Host Request is an ext pin. */
  147. kLPSPI_HostReqInternalTrigger = 1U /*!< Host Request is an internal trigger. */
  148. } lpspi_host_request_select_t;
  149. /*! @brief LPSPI Match configuration options. */
  150. typedef enum _lpspi_match_config
  151. {
  152. kLPSI_MatchDisabled = 0x0U, /*!< LPSPI Match Disabled. */
  153. kLPSI_1stWordEqualsM0orM1 = 0x2U, /*!< LPSPI Match Enabled. */
  154. kLPSI_AnyWordEqualsM0orM1 = 0x3U, /*!< LPSPI Match Enabled. */
  155. kLPSI_1stWordEqualsM0and2ndWordEqualsM1 = 0x4U, /*!< LPSPI Match Enabled. */
  156. kLPSI_AnyWordEqualsM0andNxtWordEqualsM1 = 0x5U, /*!< LPSPI Match Enabled. */
  157. kLPSI_1stWordAndM1EqualsM0andM1 = 0x6U, /*!< LPSPI Match Enabled. */
  158. kLPSI_AnyWordAndM1EqualsM0andM1 = 0x7U, /*!< LPSPI Match Enabled. */
  159. } lpspi_match_config_t;
  160. /*! @brief LPSPI pin (SDO and SDI) configuration. */
  161. typedef enum _lpspi_pin_config
  162. {
  163. kLPSPI_SdiInSdoOut = 0U, /*!< LPSPI SDI input, SDO output. */
  164. kLPSPI_SdiInSdiOut = 1U, /*!< LPSPI SDI input, SDI output. */
  165. kLPSPI_SdoInSdoOut = 2U, /*!< LPSPI SDO input, SDO output. */
  166. kLPSPI_SdoInSdiOut = 3U /*!< LPSPI SDO input, SDI output. */
  167. } lpspi_pin_config_t;
  168. /*! @brief LPSPI data output configuration. */
  169. typedef enum _lpspi_data_out_config
  170. {
  171. kLpspiDataOutRetained = 0U, /*!< Data out retains last value when chip select is de-asserted */
  172. kLpspiDataOutTristate = 1U /*!< Data out is tristated when chip select is de-asserted */
  173. } lpspi_data_out_config_t;
  174. /*! @brief LPSPI transfer width configuration. */
  175. typedef enum _lpspi_transfer_width
  176. {
  177. kLPSPI_SingleBitXfer = 0U, /*!< 1-bit shift at a time, data out on SDO, in on SDI (normal mode) */
  178. kLPSPI_TwoBitXfer = 1U, /*!< 2-bits shift out on SDO/SDI and in on SDO/SDI */
  179. kLPSPI_FourBitXfer = 2U /*!< 4-bits shift out on SDO/SDI/PCS[3:2] and in on SDO/SDI/PCS[3:2] */
  180. } lpspi_transfer_width_t;
  181. /*! @brief LPSPI delay type selection.*/
  182. typedef enum _lpspi_delay_type
  183. {
  184. kLPSPI_PcsToSck = 1U, /*!< PCS-to-SCK delay. */
  185. kLPSPI_LastSckToPcs, /*!< Last SCK edge to PCS delay. */
  186. kLPSPI_BetweenTransfer /*!< Delay between transfers. */
  187. } lpspi_delay_type_t;
  188. #define LPSPI_MASTER_PCS_SHIFT (4U) /*!< LPSPI master PCS shift macro , internal used. */
  189. #define LPSPI_MASTER_PCS_MASK (0xF0U) /*!< LPSPI master PCS shift macro , internal used. */
  190. /*! @brief Use this enumeration for LPSPI master transfer configFlags. */
  191. enum _lpspi_transfer_config_flag_for_master
  192. {
  193. kLPSPI_MasterPcs0 = 0U << LPSPI_MASTER_PCS_SHIFT, /*!< LPSPI master transfer use PCS0 signal */
  194. kLPSPI_MasterPcs1 = 1U << LPSPI_MASTER_PCS_SHIFT, /*!< LPSPI master transfer use PCS1 signal */
  195. kLPSPI_MasterPcs2 = 2U << LPSPI_MASTER_PCS_SHIFT, /*!< LPSPI master transfer use PCS2 signal */
  196. kLPSPI_MasterPcs3 = 3U << LPSPI_MASTER_PCS_SHIFT, /*!< LPSPI master transfer use PCS3 signal */
  197. kLPSPI_MasterPcsContinuous = 1U << 20, /*!< Is PCS signal continuous */
  198. kLPSPI_MasterByteSwap =
  199. 1U << 22 /*!< Is master swap the byte.
  200. * For example, when want to send data 1 2 3 4 5 6 7 8 (suppose you set
  201. * lpspi_shift_direction_t to MSB).
  202. * 1. If you set bitPerFrame = 8 , no matter the kLPSPI_MasterByteSwapyou flag is used
  203. * or not, the waveform is 1 2 3 4 5 6 7 8.
  204. * 2. If you set bitPerFrame = 16 :
  205. * (1) the waveform is 2 1 4 3 6 5 8 7 if you do not use the kLPSPI_MasterByteSwap flag.
  206. * (2) the waveform is 1 2 3 4 5 6 7 8 if you use the kLPSPI_MasterByteSwap flag.
  207. * 3. If you set bitPerFrame = 32 :
  208. * (1) the waveform is 4 3 2 1 8 7 6 5 if you do not use the kLPSPI_MasterByteSwap flag.
  209. * (2) the waveform is 1 2 3 4 5 6 7 8 if you use the kLPSPI_MasterByteSwap flag.
  210. */
  211. };
  212. #define LPSPI_SLAVE_PCS_SHIFT (4U) /*!< LPSPI slave PCS shift macro , internal used. */
  213. #define LPSPI_SLAVE_PCS_MASK (0xF0U) /*!< LPSPI slave PCS shift macro , internal used. */
  214. /*! @brief Use this enumeration for LPSPI slave transfer configFlags. */
  215. enum _lpspi_transfer_config_flag_for_slave
  216. {
  217. kLPSPI_SlavePcs0 = 0U << LPSPI_SLAVE_PCS_SHIFT, /*!< LPSPI slave transfer use PCS0 signal */
  218. kLPSPI_SlavePcs1 = 1U << LPSPI_SLAVE_PCS_SHIFT, /*!< LPSPI slave transfer use PCS1 signal */
  219. kLPSPI_SlavePcs2 = 2U << LPSPI_SLAVE_PCS_SHIFT, /*!< LPSPI slave transfer use PCS2 signal */
  220. kLPSPI_SlavePcs3 = 3U << LPSPI_SLAVE_PCS_SHIFT, /*!< LPSPI slave transfer use PCS3 signal */
  221. kLPSPI_SlaveByteSwap =
  222. 1U << 22 /*!< Is slave swap the byte.
  223. * For example, when want to send data 1 2 3 4 5 6 7 8 (suppose you set
  224. * lpspi_shift_direction_t to MSB).
  225. * 1. If you set bitPerFrame = 8 , no matter the kLPSPI_SlaveByteSwap flag is used
  226. * or not, the waveform is 1 2 3 4 5 6 7 8.
  227. * 2. If you set bitPerFrame = 16 :
  228. * (1) the waveform is 2 1 4 3 6 5 8 7 if you do not use the kLPSPI_SlaveByteSwap flag.
  229. * (2) the waveform is 1 2 3 4 5 6 7 8 if you use the kLPSPI_SlaveByteSwap flag.
  230. * 3. If you set bitPerFrame = 32 :
  231. * (1) the waveform is 4 3 2 1 8 7 6 5 if you do not use the kLPSPI_SlaveByteSwap flag.
  232. * (2) the waveform is 1 2 3 4 5 6 7 8 if you use the kLPSPI_SlaveByteSwap flag.
  233. */
  234. };
  235. /*! @brief LPSPI transfer state, which is used for LPSPI transactional API state machine. */
  236. enum _lpspi_transfer_state
  237. {
  238. kLPSPI_Idle = 0x0U, /*!< Nothing in the transmitter/receiver. */
  239. kLPSPI_Busy, /*!< Transfer queue is not finished. */
  240. kLPSPI_Error /*!< Transfer error. */
  241. };
  242. /*! @brief LPSPI master configuration structure.*/
  243. typedef struct _lpspi_master_config
  244. {
  245. uint32_t baudRate; /*!< Baud Rate for LPSPI. */
  246. uint32_t bitsPerFrame; /*!< Bits per frame, minimum 8, maximum 4096.*/
  247. lpspi_clock_polarity_t cpol; /*!< Clock polarity. */
  248. lpspi_clock_phase_t cpha; /*!< Clock phase. */
  249. lpspi_shift_direction_t direction; /*!< MSB or LSB data shift direction. */
  250. uint32_t pcsToSckDelayInNanoSec; /*!< PCS to SCK delay time in nanoseconds, setting to 0 sets the minimum delay.
  251. It sets the boundary value if out of range.*/
  252. uint32_t lastSckToPcsDelayInNanoSec; /*!< Last SCK to PCS delay time in nanoseconds, setting to 0 sets the minimum
  253. delay. It sets the boundary value if out of range.*/
  254. uint32_t
  255. betweenTransferDelayInNanoSec; /*!< After the SCK delay time with nanoseconds, setting to 0 sets the minimum
  256. delay. It sets the boundary value if out of range.*/
  257. lpspi_which_pcs_t whichPcs; /*!< Desired Peripheral Chip Select (PCS). */
  258. lpspi_pcs_polarity_config_t pcsActiveHighOrLow; /*!< Desired PCS active high or low */
  259. lpspi_pin_config_t pinCfg; /*!< Configures which pins are used for input and output data
  260. *during single bit transfers.*/
  261. lpspi_data_out_config_t dataOutConfig; /*!< Configures if the output data is tristated
  262. * between accesses (LPSPI_PCS is negated). */
  263. } lpspi_master_config_t;
  264. /*! @brief LPSPI slave configuration structure.*/
  265. typedef struct _lpspi_slave_config
  266. {
  267. uint32_t bitsPerFrame; /*!< Bits per frame, minimum 8, maximum 4096.*/
  268. lpspi_clock_polarity_t cpol; /*!< Clock polarity. */
  269. lpspi_clock_phase_t cpha; /*!< Clock phase. */
  270. lpspi_shift_direction_t direction; /*!< MSB or LSB data shift direction. */
  271. lpspi_which_pcs_t whichPcs; /*!< Desired Peripheral Chip Select (pcs) */
  272. lpspi_pcs_polarity_config_t pcsActiveHighOrLow; /*!< Desired PCS active high or low */
  273. lpspi_pin_config_t pinCfg; /*!< Configures which pins are used for input and output data
  274. *during single bit transfers.*/
  275. lpspi_data_out_config_t dataOutConfig; /*!< Configures if the output data is tristated
  276. * between accesses (LPSPI_PCS is negated). */
  277. } lpspi_slave_config_t;
  278. /*!
  279. * @brief Forward declaration of the _lpspi_master_handle typedefs.
  280. */
  281. typedef struct _lpspi_master_handle lpspi_master_handle_t;
  282. /*!
  283. * @brief Forward declaration of the _lpspi_slave_handle typedefs.
  284. */
  285. typedef struct _lpspi_slave_handle lpspi_slave_handle_t;
  286. /*!
  287. * @brief Master completion callback function pointer type.
  288. *
  289. * @param base LPSPI peripheral address.
  290. * @param handle Pointer to the handle for the LPSPI master.
  291. * @param status Success or error code describing whether the transfer is completed.
  292. * @param userData Arbitrary pointer-dataSized value passed from the application.
  293. */
  294. typedef void (*lpspi_master_transfer_callback_t)(LPSPI_Type *base,
  295. lpspi_master_handle_t *handle,
  296. status_t status,
  297. void *userData);
  298. /*!
  299. * @brief Slave completion callback function pointer type.
  300. *
  301. * @param base LPSPI peripheral address.
  302. * @param handle Pointer to the handle for the LPSPI slave.
  303. * @param status Success or error code describing whether the transfer is completed.
  304. * @param userData Arbitrary pointer-dataSized value passed from the application.
  305. */
  306. typedef void (*lpspi_slave_transfer_callback_t)(LPSPI_Type *base,
  307. lpspi_slave_handle_t *handle,
  308. status_t status,
  309. void *userData);
  310. /*! @brief LPSPI master/slave transfer structure.*/
  311. typedef struct _lpspi_transfer
  312. {
  313. uint8_t *txData; /*!< Send buffer. */
  314. uint8_t *rxData; /*!< Receive buffer. */
  315. volatile size_t dataSize; /*!< Transfer bytes. */
  316. uint32_t
  317. configFlags; /*!< Transfer transfer configuration flags. Set from _lpspi_transfer_config_flag_for_master if the
  318. transfer is used for master or _lpspi_transfer_config_flag_for_slave enumeration if the transfer
  319. is used for slave.*/
  320. } lpspi_transfer_t;
  321. /*! @brief LPSPI master transfer handle structure used for transactional API. */
  322. struct _lpspi_master_handle
  323. {
  324. volatile bool isPcsContinuous; /*!< Is PCS continuous in transfer. */
  325. volatile bool writeTcrInIsr; /*!< A flag that whether should write TCR in ISR. */
  326. volatile bool isByteSwap; /*!< A flag that whether should byte swap. */
  327. volatile uint8_t fifoSize; /*!< FIFO dataSize. */
  328. volatile uint8_t rxWatermark; /*!< Rx watermark. */
  329. volatile uint8_t bytesEachWrite; /*!< Bytes for each write TDR . */
  330. volatile uint8_t bytesEachRead; /*!< Bytes for each read RDR . */
  331. uint8_t *volatile txData; /*!< Send buffer. */
  332. uint8_t *volatile rxData; /*!< Receive buffer. */
  333. volatile size_t txRemainingByteCount; /*!< Number of bytes remaining to send.*/
  334. volatile size_t rxRemainingByteCount; /*!< Number of bytes remaining to receive.*/
  335. volatile uint32_t writeRegRemainingTimes; /*!< Write TDR register remaining times . */
  336. volatile uint32_t readRegRemainingTimes; /*!< Read RDR register remaining times . */
  337. uint32_t totalByteCount; /*!< Number of transfer bytes*/
  338. uint32_t txBuffIfNull; /*!< Used if the txData is NULL. */
  339. volatile uint8_t state; /*!< LPSPI transfer state , _lpspi_transfer_state.*/
  340. lpspi_master_transfer_callback_t callback; /*!< Completion callback. */
  341. void *userData; /*!< Callback user data. */
  342. };
  343. /*! @brief LPSPI slave transfer handle structure used for transactional API. */
  344. struct _lpspi_slave_handle
  345. {
  346. volatile bool isByteSwap; /*!< A flag that whether should byte swap. */
  347. volatile uint8_t fifoSize; /*!< FIFO dataSize. */
  348. volatile uint8_t rxWatermark; /*!< Rx watermark. */
  349. volatile uint8_t bytesEachWrite; /*!< Bytes for each write TDR . */
  350. volatile uint8_t bytesEachRead; /*!< Bytes for each read RDR . */
  351. uint8_t *volatile txData; /*!< Send buffer. */
  352. uint8_t *volatile rxData; /*!< Receive buffer. */
  353. volatile size_t txRemainingByteCount; /*!< Number of bytes remaining to send.*/
  354. volatile size_t rxRemainingByteCount; /*!< Number of bytes remaining to receive.*/
  355. volatile uint32_t writeRegRemainingTimes; /*!< Write TDR register remaining times . */
  356. volatile uint32_t readRegRemainingTimes; /*!< Read RDR register remaining times . */
  357. uint32_t totalByteCount; /*!< Number of transfer bytes*/
  358. volatile uint8_t state; /*!< LPSPI transfer state , _lpspi_transfer_state.*/
  359. volatile uint32_t errorCount; /*!< Error count for slave transfer.*/
  360. lpspi_slave_transfer_callback_t callback; /*!< Completion callback. */
  361. void *userData; /*!< Callback user data. */
  362. };
  363. /**********************************************************************************************************************
  364. * API
  365. *********************************************************************************************************************/
  366. #if defined(__cplusplus)
  367. extern "C" {
  368. #endif /*_cplusplus*/
  369. /*!
  370. * @name Initialization and deinitialization
  371. * @{
  372. */
  373. /*!
  374. * @brief Initializes the LPSPI master.
  375. *
  376. * @param base LPSPI peripheral address.
  377. * @param masterConfig Pointer to structure lpspi_master_config_t.
  378. * @param srcClock_Hz Module source input clock in Hertz
  379. */
  380. void LPSPI_MasterInit(LPSPI_Type *base, const lpspi_master_config_t *masterConfig, uint32_t srcClock_Hz);
  381. /*!
  382. * @brief Sets the lpspi_master_config_t structure to default values.
  383. *
  384. * This API initializes the configuration structure for LPSPI_MasterInit().
  385. * The initialized structure can remain unchanged in LPSPI_MasterInit(), or can be modified
  386. * before calling the LPSPI_MasterInit().
  387. * Example:
  388. * @code
  389. * lpspi_master_config_t masterConfig;
  390. * LPSPI_MasterGetDefaultConfig(&masterConfig);
  391. * @endcode
  392. * @param masterConfig pointer to lpspi_master_config_t structure
  393. */
  394. void LPSPI_MasterGetDefaultConfig(lpspi_master_config_t *masterConfig);
  395. /*!
  396. * @brief LPSPI slave configuration.
  397. *
  398. * @param base LPSPI peripheral address.
  399. * @param slaveConfig Pointer to a structure lpspi_slave_config_t.
  400. */
  401. void LPSPI_SlaveInit(LPSPI_Type *base, const lpspi_slave_config_t *slaveConfig);
  402. /*!
  403. * @brief Sets the lpspi_slave_config_t structure to default values.
  404. *
  405. * This API initializes the configuration structure for LPSPI_SlaveInit().
  406. * The initialized structure can remain unchanged in LPSPI_SlaveInit() or can be modified
  407. * before calling the LPSPI_SlaveInit().
  408. * Example:
  409. * @code
  410. * lpspi_slave_config_t slaveConfig;
  411. * LPSPI_SlaveGetDefaultConfig(&slaveConfig);
  412. * @endcode
  413. * @param slaveConfig pointer to lpspi_slave_config_t structure.
  414. */
  415. void LPSPI_SlaveGetDefaultConfig(lpspi_slave_config_t *slaveConfig);
  416. /*!
  417. * @brief De-initializes the LPSPI peripheral. Call this API to disable the LPSPI clock.
  418. * @param base LPSPI peripheral address.
  419. */
  420. void LPSPI_Deinit(LPSPI_Type *base);
  421. /*!
  422. * @brief Restores the LPSPI peripheral to reset state. Note that this function
  423. * sets all registers to reset state. As a result, the LPSPI module can't work after calling
  424. * this API.
  425. * @param base LPSPI peripheral address.
  426. */
  427. void LPSPI_Reset(LPSPI_Type *base);
  428. /*!
  429. * @brief Enables the LPSPI peripheral and sets the MCR MDIS to 0.
  430. *
  431. * @param base LPSPI peripheral address.
  432. * @param enable Pass true to enable module, false to disable module.
  433. */
  434. static inline void LPSPI_Enable(LPSPI_Type *base, bool enable)
  435. {
  436. if (enable)
  437. {
  438. base->CR |= LPSPI_CR_MEN_MASK;
  439. }
  440. else
  441. {
  442. base->CR &= ~LPSPI_CR_MEN_MASK;
  443. }
  444. }
  445. /*!
  446. *@}
  447. */
  448. /*!
  449. * @name Status
  450. * @{
  451. */
  452. /*!
  453. * @brief Gets the LPSPI status flag state.
  454. * @param base LPSPI peripheral address.
  455. * @return The LPSPI status(in SR register).
  456. */
  457. static inline uint32_t LPSPI_GetStatusFlags(LPSPI_Type *base)
  458. {
  459. return (base->SR);
  460. }
  461. /*!
  462. * @brief Gets the LPSPI Tx FIFO size.
  463. * @param base LPSPI peripheral address.
  464. * @return The LPSPI Tx FIFO size.
  465. */
  466. static inline uint32_t LPSPI_GetTxFifoSize(LPSPI_Type *base)
  467. {
  468. return (1U << ((base->PARAM & LPSPI_PARAM_TXFIFO_MASK) >> LPSPI_PARAM_TXFIFO_SHIFT));
  469. }
  470. /*!
  471. * @brief Gets the LPSPI Rx FIFO size.
  472. * @param base LPSPI peripheral address.
  473. * @return The LPSPI Rx FIFO size.
  474. */
  475. static inline uint32_t LPSPI_GetRxFifoSize(LPSPI_Type *base)
  476. {
  477. return (1U << ((base->PARAM & LPSPI_PARAM_RXFIFO_MASK) >> LPSPI_PARAM_RXFIFO_SHIFT));
  478. }
  479. /*!
  480. * @brief Gets the LPSPI Tx FIFO count.
  481. * @param base LPSPI peripheral address.
  482. * @return The number of words in the transmit FIFO.
  483. */
  484. static inline uint32_t LPSPI_GetTxFifoCount(LPSPI_Type *base)
  485. {
  486. return ((base->FSR & LPSPI_FSR_TXCOUNT_MASK) >> LPSPI_FSR_TXCOUNT_SHIFT);
  487. }
  488. /*!
  489. * @brief Gets the LPSPI Rx FIFO count.
  490. * @param base LPSPI peripheral address.
  491. * @return The number of words in the receive FIFO.
  492. */
  493. static inline uint32_t LPSPI_GetRxFifoCount(LPSPI_Type *base)
  494. {
  495. return ((base->FSR & LPSPI_FSR_RXCOUNT_MASK) >> LPSPI_FSR_RXCOUNT_SHIFT);
  496. }
  497. /*!
  498. * @brief Clears the LPSPI status flag.
  499. *
  500. * This function clears the desired status bit by using a write-1-to-clear. The user passes in the base and the
  501. * desired status flag bit to clear. The list of status flags is defined in the _lpspi_flags.
  502. * Example usage:
  503. * @code
  504. * LPSPI_ClearStatusFlags(base, kLPSPI_TxDataRequestFlag|kLPSPI_RxDataReadyFlag);
  505. * @endcode
  506. *
  507. * @param base LPSPI peripheral address.
  508. * @param statusFlags The status flag used from type _lpspi_flags.
  509. */
  510. static inline void LPSPI_ClearStatusFlags(LPSPI_Type *base, uint32_t statusFlags)
  511. {
  512. base->SR = statusFlags; /*!< The status flags are cleared by writing 1 (w1c).*/
  513. }
  514. /*!
  515. *@}
  516. */
  517. /*!
  518. * @name Interrupts
  519. * @{
  520. */
  521. /*!
  522. * @brief Enables the LPSPI interrupts.
  523. *
  524. * This function configures the various interrupt masks of the LPSPI. The parameters are base and an interrupt mask.
  525. * Note that, for Tx fill and Rx FIFO drain requests, enabling the interrupt request disables the DMA request.
  526. *
  527. * @code
  528. * LPSPI_EnableInterrupts(base, kLPSPI_TxInterruptEnable | kLPSPI_RxInterruptEnable );
  529. * @endcode
  530. *
  531. * @param base LPSPI peripheral address.
  532. * @param mask The interrupt mask; Use the enum _lpspi_interrupt_enable.
  533. */
  534. static inline void LPSPI_EnableInterrupts(LPSPI_Type *base, uint32_t mask)
  535. {
  536. base->IER |= mask;
  537. }
  538. /*!
  539. * @brief Disables the LPSPI interrupts.
  540. *
  541. * @code
  542. * LPSPI_DisableInterrupts(base, kLPSPI_TxInterruptEnable | kLPSPI_RxInterruptEnable );
  543. * @endcode
  544. *
  545. * @param base LPSPI peripheral address.
  546. * @param mask The interrupt mask; Use the enum _lpspi_interrupt_enable.
  547. */
  548. static inline void LPSPI_DisableInterrupts(LPSPI_Type *base, uint32_t mask)
  549. {
  550. base->IER &= ~mask;
  551. }
  552. /*!
  553. *@}
  554. */
  555. /*!
  556. * @name DMA Control
  557. * @{
  558. */
  559. /*!
  560. * @brief Enables the LPSPI DMA request.
  561. *
  562. * This function configures the Rx and Tx DMA mask of the LPSPI. The parameters are base and a DMA mask.
  563. * @code
  564. * LPSPI_EnableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);
  565. * @endcode
  566. *
  567. * @param base LPSPI peripheral address.
  568. * @param mask The interrupt mask; Use the enum _lpspi_dma_enable.
  569. */
  570. static inline void LPSPI_EnableDMA(LPSPI_Type *base, uint32_t mask)
  571. {
  572. base->DER |= mask;
  573. }
  574. /*!
  575. * @brief Disables the LPSPI DMA request.
  576. *
  577. * This function configures the Rx and Tx DMA mask of the LPSPI. The parameters are base and a DMA mask.
  578. * @code
  579. * SPI_DisableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);
  580. * @endcode
  581. *
  582. * @param base LPSPI peripheral address.
  583. * @param mask The interrupt mask; Use the enum _lpspi_dma_enable.
  584. */
  585. static inline void LPSPI_DisableDMA(LPSPI_Type *base, uint32_t mask)
  586. {
  587. base->DER &= ~mask;
  588. }
  589. /*!
  590. * @brief Gets the LPSPI Transmit Data Register address for a DMA operation.
  591. *
  592. * This function gets the LPSPI Transmit Data Register address because this value is needed
  593. * for the DMA operation.
  594. * This function can be used for either master or slave mode.
  595. *
  596. * @param base LPSPI peripheral address.
  597. * @return The LPSPI Transmit Data Register address.
  598. */
  599. static inline uint32_t LPSPI_GetTxRegisterAddress(LPSPI_Type *base)
  600. {
  601. return (uint32_t) & (base->TDR);
  602. }
  603. /*!
  604. * @brief Gets the LPSPI Receive Data Register address for a DMA operation.
  605. *
  606. * This function gets the LPSPI Receive Data Register address because this value is needed
  607. * for the DMA operation.
  608. * This function can be used for either master or slave mode.
  609. *
  610. * @param base LPSPI peripheral address.
  611. * @return The LPSPI Receive Data Register address.
  612. */
  613. static inline uint32_t LPSPI_GetRxRegisterAddress(LPSPI_Type *base)
  614. {
  615. return (uint32_t) & (base->RDR);
  616. }
  617. /*!
  618. *@}
  619. */
  620. /*!
  621. * @name Bus Operations
  622. * @{
  623. */
  624. /*!
  625. * @brief Configures the LPSPI for either master or slave.
  626. *
  627. * Note that the CFGR1 should only be written when the LPSPI is disabled (LPSPIx_CR_MEN = 0).
  628. *
  629. * @param base LPSPI peripheral address.
  630. * @param mode Mode setting (master or slave) of type lpspi_master_slave_mode_t.
  631. */
  632. static inline void LPSPI_SetMasterSlaveMode(LPSPI_Type *base, lpspi_master_slave_mode_t mode)
  633. {
  634. base->CFGR1 = (base->CFGR1 & (~LPSPI_CFGR1_MASTER_MASK)) | LPSPI_CFGR1_MASTER(mode);
  635. }
  636. /*!
  637. * @brief Returns whether the LPSPI module is in master mode.
  638. *
  639. * @param base LPSPI peripheral address.
  640. * @return Returns true if the module is in master mode or false if the module is in slave mode.
  641. */
  642. static inline bool LPSPI_IsMaster(LPSPI_Type *base)
  643. {
  644. return (bool)((base->CFGR1) & LPSPI_CFGR1_MASTER_MASK);
  645. }
  646. /*!
  647. * @brief Flushes the LPSPI FIFOs.
  648. *
  649. * @param base LPSPI peripheral address.
  650. * @param flushTxFifo Flushes (true) the Tx FIFO, else do not flush (false) the Tx FIFO.
  651. * @param flushRxFifo Flushes (true) the Rx FIFO, else do not flush (false) the Rx FIFO.
  652. */
  653. static inline void LPSPI_FlushFifo(LPSPI_Type *base, bool flushTxFifo, bool flushRxFifo)
  654. {
  655. base->CR |= ((uint32_t)flushTxFifo << LPSPI_CR_RTF_SHIFT) | ((uint32_t)flushRxFifo << LPSPI_CR_RRF_SHIFT);
  656. }
  657. /*!
  658. * @brief Sets the transmit and receive FIFO watermark values.
  659. *
  660. * This function allows the user to set the receive and transmit FIFO watermarks. The function
  661. * does not compare the watermark settings to the FIFO size. The FIFO watermark should not be
  662. * equal to or greater than the FIFO size. It is up to the higher level driver to make this check.
  663. *
  664. * @param base LPSPI peripheral address.
  665. * @param txWater The TX FIFO watermark value. Writing a value equal or greater than the FIFO size is truncated.
  666. * @param rxWater The RX FIFO watermark value. Writing a value equal or greater than the FIFO size is truncated.
  667. */
  668. static inline void LPSPI_SetFifoWatermarks(LPSPI_Type *base, uint32_t txWater, uint32_t rxWater)
  669. {
  670. base->FCR = LPSPI_FCR_TXWATER(txWater) | LPSPI_FCR_RXWATER(rxWater);
  671. }
  672. /*!
  673. * @brief Configures all LPSPI peripheral chip select polarities simultaneously.
  674. *
  675. * Note that the CFGR1 should only be written when the LPSPI is disabled (LPSPIx_CR_MEN = 0).
  676. *
  677. * This is an example: PCS0 and PCS1 set to active low and other PCSs set to active high. Note that the number of
  678. * PCS is device-specific.
  679. * @code
  680. * LPSPI_SetAllPcsPolarity(base, kLPSPI_Pcs0ActiveLow | kLPSPI_Pcs1ActiveLow);
  681. * @endcode
  682. *
  683. * @param base LPSPI peripheral address.
  684. * @param mask The PCS polarity mask; Use the enum _lpspi_pcs_polarity.
  685. */
  686. static inline void LPSPI_SetAllPcsPolarity(LPSPI_Type *base, uint32_t mask)
  687. {
  688. base->CFGR1 = (base->CFGR1 & ~LPSPI_CFGR1_PCSPOL_MASK) | LPSPI_CFGR1_PCSPOL(~mask);
  689. }
  690. /*!
  691. * @brief Configures the frame size.
  692. *
  693. * The minimum frame size is 8-bits and the maximum frame size is 4096-bits. If the frame size is less than or equal
  694. * to 32-bits, the word size and frame size are identical. If the frame size is greater than 32-bits, the word
  695. * size is 32-bits for each word except the last (the last word contains the remainder bits if the frame size is not
  696. * divisible by 32). The minimum word size is 2-bits. A frame size of 33-bits (or similar) is not supported.
  697. *
  698. * Note 1 : The transmit command register should be initialized before enabling the LPSPI in slave mode, although
  699. * the command register does not update until after the LPSPI is enabled. After it is enabled, the transmit command
  700. * register
  701. * should only be changed if the LPSPI is idle.
  702. *
  703. * Note 2 : The transmit and command FIFO is a combined FIFO that includes both transmit data and command words. That
  704. * means the TCR register should be written to when the Tx FIFO is not full.
  705. *
  706. * @param base LPSPI peripheral address.
  707. * @param frameSize The frame size in number of bits.
  708. */
  709. static inline void LPSPI_SetFrameSize(LPSPI_Type *base, uint32_t frameSize)
  710. {
  711. base->TCR = (base->TCR & ~LPSPI_TCR_FRAMESZ_MASK) | LPSPI_TCR_FRAMESZ(frameSize - 1);
  712. }
  713. /*!
  714. * @brief Sets the LPSPI baud rate in bits per second.
  715. *
  716. * This function takes in the desired bitsPerSec (baud rate) and calculates the nearest
  717. * possible baud rate without exceeding the desired baud rate and returns the
  718. * calculated baud rate in bits-per-second. It requires the caller to provide
  719. * the frequency of the module source clock (in Hertz). Note that the baud rate
  720. * does not go into effect until the Transmit Control Register (TCR) is programmed
  721. * with the prescale value. Hence, this function returns the prescale tcrPrescaleValue
  722. * parameter for later programming in the TCR. The higher level
  723. * peripheral driver should alert the user of an out of range baud rate input.
  724. *
  725. * Note that the LPSPI module must first be disabled before configuring this.
  726. * Note that the LPSPI module must be configured for master mode before configuring this.
  727. *
  728. * @param base LPSPI peripheral address.
  729. * @param baudRate_Bps The desired baud rate in bits per second.
  730. * @param srcClock_Hz Module source input clock in Hertz.
  731. * @param tcrPrescaleValue The TCR prescale value needed to program the TCR.
  732. * @return The actual calculated baud rate. This function may also return a "0" if the
  733. * LPSPI is not configured for master mode or if the LPSPI module is not disabled.
  734. */
  735. uint32_t LPSPI_MasterSetBaudRate(LPSPI_Type *base,
  736. uint32_t baudRate_Bps,
  737. uint32_t srcClock_Hz,
  738. uint32_t *tcrPrescaleValue);
  739. /*!
  740. * @brief Manually configures a specific LPSPI delay parameter (module must be disabled to
  741. * change the delay values).
  742. *
  743. * This function configures the following:
  744. * SCK to PCS delay, or
  745. * PCS to SCK delay, or
  746. * The configurations must occur between the transfer delay.
  747. *
  748. * The delay names are available in type lpspi_delay_type_t.
  749. *
  750. * The user passes the desired delay along with the delay value.
  751. * This allows the user to directly set the delay values if they have
  752. * pre-calculated them or if they simply wish to manually increment the value.
  753. *
  754. * Note that the LPSPI module must first be disabled before configuring this.
  755. * Note that the LPSPI module must be configured for master mode before configuring this.
  756. *
  757. * @param base LPSPI peripheral address.
  758. * @param scaler The 8-bit delay value 0x00 to 0xFF (255).
  759. * @param whichDelay The desired delay to configure, must be of type lpspi_delay_type_t.
  760. */
  761. void LPSPI_MasterSetDelayScaler(LPSPI_Type *base, uint32_t scaler, lpspi_delay_type_t whichDelay);
  762. /*!
  763. * @brief Calculates the delay based on the desired delay input in nanoseconds (module must be
  764. * disabled to change the delay values).
  765. *
  766. * This function calculates the values for the following:
  767. * SCK to PCS delay, or
  768. * PCS to SCK delay, or
  769. * The configurations must occur between the transfer delay.
  770. *
  771. * The delay names are available in type lpspi_delay_type_t.
  772. *
  773. * The user passes the desired delay and the desired delay value in
  774. * nano-seconds. The function calculates the value needed for the desired delay parameter
  775. * and returns the actual calculated delay because an exact delay match may not be possible. In this
  776. * case, the closest match is calculated without going below the desired delay value input.
  777. * It is possible to input a very large delay value that exceeds the capability of the part, in
  778. * which case the maximum supported delay is returned. It is up to the higher level
  779. * peripheral driver to alert the user of an out of range delay input.
  780. *
  781. * Note that the LPSPI module must be configured for master mode before configuring this. And note that
  782. * the delayTime = LPSPI_clockSource / (PRESCALE * Delay_scaler).
  783. *
  784. * @param base LPSPI peripheral address.
  785. * @param delayTimeInNanoSec The desired delay value in nano-seconds.
  786. * @param whichDelay The desired delay to configuration, which must be of type lpspi_delay_type_t.
  787. * @param srcClock_Hz Module source input clock in Hertz.
  788. * @return actual Calculated delay value in nano-seconds.
  789. */
  790. uint32_t LPSPI_MasterSetDelayTimes(LPSPI_Type *base,
  791. uint32_t delayTimeInNanoSec,
  792. lpspi_delay_type_t whichDelay,
  793. uint32_t srcClock_Hz);
  794. /*!
  795. * @brief Writes data into the transmit data buffer.
  796. *
  797. * This function writes data passed in by the user to the Transmit Data Register (TDR).
  798. * The user can pass up to 32-bits of data to load into the TDR. If the frame size exceeds 32-bits,
  799. * the user has to manage sending the data one 32-bit word at a time.
  800. * Any writes to the TDR result in an immediate push to the transmit FIFO.
  801. * This function can be used for either master or slave modes.
  802. *
  803. * @param base LPSPI peripheral address.
  804. * @param data The data word to be sent.
  805. */
  806. static inline void LPSPI_WriteData(LPSPI_Type *base, uint32_t data)
  807. {
  808. base->TDR = data;
  809. }
  810. /*!
  811. * @brief Reads data from the data buffer.
  812. *
  813. * This function reads the data from the Receive Data Register (RDR).
  814. * This function can be used for either master or slave mode.
  815. *
  816. * @param base LPSPI peripheral address.
  817. * @return The data read from the data buffer.
  818. */
  819. static inline uint32_t LPSPI_ReadData(LPSPI_Type *base)
  820. {
  821. return (base->RDR);
  822. }
  823. /*!
  824. * @brief Set up the dummy data.
  825. *
  826. * @param base LPSPI peripheral address.
  827. * @param dummyData Data to be transferred when tx buffer is NULL.
  828. * Note:
  829. * This API has no effect when LPSPI in slave interrupt mode, because driver
  830. * will set the TXMSK bit to 1 if txData is NULL, no data is loaded from transmit
  831. * FIFO and output pin is tristated.
  832. */
  833. void LPSPI_SetDummyData(LPSPI_Type *base, uint8_t dummyData);
  834. /*!
  835. *@}
  836. */
  837. /*!
  838. * @name Transactional
  839. * @{
  840. */
  841. /*Transactional APIs*/
  842. /*!
  843. * @brief Initializes the LPSPI master handle.
  844. *
  845. * This function initializes the LPSPI handle, which can be used for other LPSPI transactional APIs. Usually, for a
  846. * specified LPSPI instance, call this API once to get the initialized handle.
  847. * @param base LPSPI peripheral address.
  848. * @param handle LPSPI handle pointer to lpspi_master_handle_t.
  849. * @param callback DSPI callback.
  850. * @param userData callback function parameter.
  851. */
  852. void LPSPI_MasterTransferCreateHandle(LPSPI_Type *base,
  853. lpspi_master_handle_t *handle,
  854. lpspi_master_transfer_callback_t callback,
  855. void *userData);
  856. /*!
  857. * @brief LPSPI master transfer data using a polling method.
  858. *
  859. * This function transfers data using a polling method. This is a blocking function, which does not return until all
  860. * transfers have been
  861. * completed.
  862. *
  863. * Note:
  864. * The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4.
  865. * For bytesPerFrame greater than 4:
  866. * The transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not integer multiples of 4.
  867. * Otherwise, the transfer data size can be an integer multiple of bytesPerFrame.
  868. *
  869. * @param base LPSPI peripheral address.
  870. * @param transfer pointer to lpspi_transfer_t structure.
  871. * @return status of status_t.
  872. */
  873. status_t LPSPI_MasterTransferBlocking(LPSPI_Type *base, lpspi_transfer_t *transfer);
  874. /*!
  875. * @brief LPSPI master transfer data using an interrupt method.
  876. *
  877. * This function transfers data using an interrupt method. This is a non-blocking function, which returns right away.
  878. * When all data
  879. * is transferred, the callback function is called.
  880. *
  881. * Note:
  882. * The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4.
  883. * For bytesPerFrame greater than 4:
  884. * The transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not integer multiples of 4.
  885. * Otherwise, the transfer data size can be an integer multiple of bytesPerFrame.
  886. *
  887. * @param base LPSPI peripheral address.
  888. * @param handle pointer to lpspi_master_handle_t structure which stores the transfer state.
  889. * @param transfer pointer to lpspi_transfer_t structure.
  890. * @return status of status_t.
  891. */
  892. status_t LPSPI_MasterTransferNonBlocking(LPSPI_Type *base, lpspi_master_handle_t *handle, lpspi_transfer_t *transfer);
  893. /*!
  894. * @brief Gets the master transfer remaining bytes.
  895. *
  896. * This function gets the master transfer remaining bytes.
  897. *
  898. * @param base LPSPI peripheral address.
  899. * @param handle pointer to lpspi_master_handle_t structure which stores the transfer state.
  900. * @param count Number of bytes transferred so far by the non-blocking transaction.
  901. * @return status of status_t.
  902. */
  903. status_t LPSPI_MasterTransferGetCount(LPSPI_Type *base, lpspi_master_handle_t *handle, size_t *count);
  904. /*!
  905. * @brief LPSPI master abort transfer which uses an interrupt method.
  906. *
  907. * This function aborts a transfer which uses an interrupt method.
  908. *
  909. * @param base LPSPI peripheral address.
  910. * @param handle pointer to lpspi_master_handle_t structure which stores the transfer state.
  911. */
  912. void LPSPI_MasterTransferAbort(LPSPI_Type *base, lpspi_master_handle_t *handle);
  913. /*!
  914. * @brief LPSPI Master IRQ handler function.
  915. *
  916. * This function processes the LPSPI transmit and receive IRQ.
  917. *
  918. * @param base LPSPI peripheral address.
  919. * @param handle pointer to lpspi_master_handle_t structure which stores the transfer state.
  920. */
  921. void LPSPI_MasterTransferHandleIRQ(LPSPI_Type *base, lpspi_master_handle_t *handle);
  922. /*!
  923. * @brief Initializes the LPSPI slave handle.
  924. *
  925. * This function initializes the LPSPI handle, which can be used for other LPSPI transactional APIs. Usually, for a
  926. * specified LPSPI instance, call this API once to get the initialized handle.
  927. *
  928. * @param base LPSPI peripheral address.
  929. * @param handle LPSPI handle pointer to lpspi_slave_handle_t.
  930. * @param callback DSPI callback.
  931. * @param userData callback function parameter.
  932. */
  933. void LPSPI_SlaveTransferCreateHandle(LPSPI_Type *base,
  934. lpspi_slave_handle_t *handle,
  935. lpspi_slave_transfer_callback_t callback,
  936. void *userData);
  937. /*!
  938. * @brief LPSPI slave transfer data using an interrupt method.
  939. *
  940. * This function transfer data using an interrupt method. This is a non-blocking function, which returns right away.
  941. * When all data
  942. * is transferred, the callback function is called.
  943. *
  944. * Note:
  945. * The transfer data size should be integer multiples of bytesPerFrame if bytesPerFrame is less than or equal to 4.
  946. * For bytesPerFrame greater than 4:
  947. * The transfer data size should be equal to bytesPerFrame if the bytesPerFrame is not an integer multiple of 4.
  948. * Otherwise, the transfer data size can be an integer multiple of bytesPerFrame.
  949. *
  950. * @param base LPSPI peripheral address.
  951. * @param handle pointer to lpspi_slave_handle_t structure which stores the transfer state.
  952. * @param transfer pointer to lpspi_transfer_t structure.
  953. * @return status of status_t.
  954. */
  955. status_t LPSPI_SlaveTransferNonBlocking(LPSPI_Type *base, lpspi_slave_handle_t *handle, lpspi_transfer_t *transfer);
  956. /*!
  957. * @brief Gets the slave transfer remaining bytes.
  958. *
  959. * This function gets the slave transfer remaining bytes.
  960. *
  961. * @param base LPSPI peripheral address.
  962. * @param handle pointer to lpspi_slave_handle_t structure which stores the transfer state.
  963. * @param count Number of bytes transferred so far by the non-blocking transaction.
  964. * @return status of status_t.
  965. */
  966. status_t LPSPI_SlaveTransferGetCount(LPSPI_Type *base, lpspi_slave_handle_t *handle, size_t *count);
  967. /*!
  968. * @brief LPSPI slave aborts a transfer which uses an interrupt method.
  969. *
  970. * This function aborts a transfer which uses an interrupt method.
  971. *
  972. * @param base LPSPI peripheral address.
  973. * @param handle pointer to lpspi_slave_handle_t structure which stores the transfer state.
  974. */
  975. void LPSPI_SlaveTransferAbort(LPSPI_Type *base, lpspi_slave_handle_t *handle);
  976. /*!
  977. * @brief LPSPI Slave IRQ handler function.
  978. *
  979. * This function processes the LPSPI transmit and receives an IRQ.
  980. *
  981. * @param base LPSPI peripheral address.
  982. * @param handle pointer to lpspi_slave_handle_t structure which stores the transfer state.
  983. */
  984. void LPSPI_SlaveTransferHandleIRQ(LPSPI_Type *base, lpspi_slave_handle_t *handle);
  985. /*!
  986. *@}
  987. */
  988. #if defined(__cplusplus)
  989. }
  990. #endif /*_cplusplus*/
  991. /*!
  992. *@}
  993. */
  994. #endif /*_FSL_LPSPI_H_*/