py32f0xx_ll_spi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_ll_spi.c
  4. * @author MCU Application Team
  5. * @brief SPI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. #if defined(USE_FULL_LL_DRIVER)
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "py32f0xx_ll_spi.h"
  33. #include "py32f0xx_ll_bus.h"
  34. #include "py32f0xx_ll_rcc.h"
  35. #ifdef USE_FULL_ASSERT
  36. #include "py32_assert.h"
  37. #else
  38. #define assert_param(expr) ((void)0U)
  39. #endif /* USE_FULL_ASSERT */
  40. /** @addtogroup PY32F0xx_LL_Driver
  41. * @{
  42. */
  43. #if defined (SPI1) || defined (SPI2)
  44. /** @addtogroup SPI_LL
  45. * @{
  46. */
  47. /* Private types -------------------------------------------------------------*/
  48. /* Private variables ---------------------------------------------------------*/
  49. /* Private constants ---------------------------------------------------------*/
  50. /** @defgroup SPI_LL_Private_Constants SPI Private Constants
  51. * @{
  52. */
  53. /* SPI registers Masks */
  54. #define SPI_CR1_CLEAR_MASK (SPI_CR1_CPHA | SPI_CR1_CPOL | SPI_CR1_MSTR | \
  55. SPI_CR1_BR | SPI_CR1_LSBFIRST | SPI_CR1_SSI | \
  56. SPI_CR1_SSM | SPI_CR1_RXONLY | SPI_CR1_BIDIOE | \
  57. SPI_CR1_BIDIMODE)
  58. /**
  59. * @}
  60. */
  61. /* Private macros ------------------------------------------------------------*/
  62. /** @defgroup SPI_LL_Private_Macros SPI Private Macros
  63. * @{
  64. */
  65. #define IS_LL_SPI_TRANSFER_DIRECTION(__VALUE__) (((__VALUE__) == LL_SPI_FULL_DUPLEX) \
  66. || ((__VALUE__) == LL_SPI_SIMPLEX_RX) \
  67. || ((__VALUE__) == LL_SPI_HALF_DUPLEX_RX) \
  68. || ((__VALUE__) == LL_SPI_HALF_DUPLEX_TX))
  69. #define IS_LL_SPI_MODE(__VALUE__) (((__VALUE__) == LL_SPI_MODE_MASTER) \
  70. || ((__VALUE__) == LL_SPI_MODE_SLAVE))
  71. #define IS_LL_SPI_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_SPI_DATAWIDTH_8BIT) \
  72. || ((__VALUE__) == LL_SPI_DATAWIDTH_16BIT))
  73. #define IS_LL_SPI_POLARITY(__VALUE__) (((__VALUE__) == LL_SPI_POLARITY_LOW) \
  74. || ((__VALUE__) == LL_SPI_POLARITY_HIGH))
  75. #define IS_LL_SPI_PHASE(__VALUE__) (((__VALUE__) == LL_SPI_PHASE_1EDGE) \
  76. || ((__VALUE__) == LL_SPI_PHASE_2EDGE))
  77. #define IS_LL_SPI_NSS(__VALUE__) (((__VALUE__) == LL_SPI_NSS_SOFT) \
  78. || ((__VALUE__) == LL_SPI_NSS_HARD_INPUT) \
  79. || ((__VALUE__) == LL_SPI_NSS_HARD_OUTPUT))
  80. #define IS_LL_SPI_BAUDRATE(__VALUE__) (((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV2) \
  81. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV4) \
  82. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV8) \
  83. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV16) \
  84. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV32) \
  85. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV64) \
  86. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV128) \
  87. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV256))
  88. #define IS_LL_SPI_BITORDER(__VALUE__) (((__VALUE__) == LL_SPI_LSB_FIRST) \
  89. || ((__VALUE__) == LL_SPI_MSB_FIRST))
  90. #define IS_LL_SPI_SLAVE_SPEED_MODE(__VALUE__) (((__VALUE__) == LL_SPI_SLAVE_SPEED_NORMAL) \
  91. || ((__VALUE__) == LL_SPI_SLAVE_SPEED_FAST))
  92. /**
  93. * @}
  94. */
  95. /* Private function prototypes -----------------------------------------------*/
  96. /* Exported functions --------------------------------------------------------*/
  97. /** @addtogroup SPI_LL_Exported_Functions
  98. * @{
  99. */
  100. /** @addtogroup SPI_LL_EF_Init
  101. * @{
  102. */
  103. /**
  104. * @brief De-initialize the SPI registers to their default reset values.
  105. * @param SPIx SPI Instance
  106. * @retval An ErrorStatus enumeration value:
  107. * - SUCCESS: SPI registers are de-initialized
  108. * - ERROR: SPI registers are not de-initialized
  109. */
  110. ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx)
  111. {
  112. ErrorStatus status = ERROR;
  113. /* Check the parameters */
  114. assert_param(IS_SPI_ALL_INSTANCE(SPIx));
  115. if (SPIx == SPI1)
  116. {
  117. /* Force reset of SPI clock */
  118. LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SPI1);
  119. /* Release reset of SPI clock */
  120. LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SPI1);
  121. status = SUCCESS;
  122. }
  123. #if defined(SPI2)
  124. if (SPIx == SPI2)
  125. {
  126. /* Force reset of SPI clock */
  127. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2);
  128. /* Release reset of SPI clock */
  129. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2);
  130. status = SUCCESS;
  131. }
  132. #endif
  133. return status;
  134. }
  135. /**
  136. * @brief Initialize the SPI registers according to the specified parameters in SPI_InitStruct.
  137. * @note As some bits in SPI configuration registers can only be written when the SPI is disabled (SPI_CR1_SPE bit =0),
  138. * SPI peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
  139. * @param SPIx SPI Instance
  140. * @param SPI_InitStruct pointer to a @ref LL_SPI_InitTypeDef structure
  141. * @retval An ErrorStatus enumeration value. (Return always SUCCESS)
  142. */
  143. ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct)
  144. {
  145. ErrorStatus status = ERROR;
  146. /* Check the SPI Instance SPIx*/
  147. assert_param(IS_SPI_ALL_INSTANCE(SPIx));
  148. /* Check the SPI parameters from SPI_InitStruct*/
  149. assert_param(IS_LL_SPI_TRANSFER_DIRECTION(SPI_InitStruct->TransferDirection));
  150. assert_param(IS_LL_SPI_MODE(SPI_InitStruct->Mode));
  151. assert_param(IS_LL_SPI_DATAWIDTH(SPI_InitStruct->DataWidth));
  152. assert_param(IS_LL_SPI_POLARITY(SPI_InitStruct->ClockPolarity));
  153. assert_param(IS_LL_SPI_PHASE(SPI_InitStruct->ClockPhase));
  154. assert_param(IS_LL_SPI_NSS(SPI_InitStruct->NSS));
  155. assert_param(IS_LL_SPI_BAUDRATE(SPI_InitStruct->BaudRate));
  156. assert_param(IS_LL_SPI_BITORDER(SPI_InitStruct->BitOrder));
  157. assert_param(IS_LL_SPI_SLAVE_SPEED_MODE(SPI_InitStruct->SlaveSpeedMode));
  158. if (LL_SPI_IsEnabled(SPIx) == 0x00000000U)
  159. {
  160. /*---------------------------- SPIx CR1 Configuration ------------------------
  161. * Configure SPIx CR1 with parameters:
  162. * - TransferDirection: SPI_CR1_BIDIMODE, SPI_CR1_BIDIOE and SPI_CR1_RXONLY bits
  163. * - Master/Slave Mode: SPI_CR1_MSTR bit
  164. * - ClockPolarity: SPI_CR1_CPOL bit
  165. * - ClockPhase: SPI_CR1_CPHA bit
  166. * - NSS management: SPI_CR1_SSM bit
  167. * - BaudRate prescaler: SPI_CR1_BR[2:0] bits
  168. * - BitOrder: SPI_CR1_LSBFIRST bit
  169. * - CRCCalculation: SPI_CR1_CRCEN bit
  170. */
  171. MODIFY_REG(SPIx->CR1,
  172. SPI_CR1_CLEAR_MASK,
  173. SPI_InitStruct->TransferDirection | SPI_InitStruct->Mode |
  174. SPI_InitStruct->ClockPolarity | SPI_InitStruct->ClockPhase |
  175. (SPI_InitStruct->NSS & SPI_CR1_SSM) | SPI_InitStruct->BaudRate |
  176. SPI_InitStruct->BitOrder);
  177. /*---------------------------- SPIx CR2 Configuration ------------------------
  178. * Configure SPIx CR2 with parameters:
  179. * - DataWidth: DS[3:0] bits
  180. * - NSS management: SSOE bit
  181. */
  182. MODIFY_REG(SPIx->CR2,
  183. (SPI_CR2_DS | SPI_CR2_SSOE | SPI_CR2_SLVFM),
  184. (SPI_InitStruct->DataWidth | ((SPI_InitStruct->NSS >> 16U) & SPI_CR2_SSOE) | SPI_InitStruct->SlaveSpeedMode));
  185. /* Set Rx FIFO to Quarter (1 Byte) in case of 8 Bits mode. No DataPacking by default */
  186. if (SPI_InitStruct->DataWidth == LL_SPI_DATAWIDTH_8BIT)
  187. {
  188. LL_SPI_SetRxFIFOThreshold(SPIx, LL_SPI_RX_FIFO_TH_QUARTER);
  189. }
  190. else
  191. {
  192. LL_SPI_SetRxFIFOThreshold(SPIx, LL_SPI_RX_FIFO_TH_HALF);
  193. }
  194. status = SUCCESS;
  195. }
  196. return status;
  197. }
  198. /**
  199. * @brief Set each @ref LL_SPI_InitTypeDef field to default value.
  200. * @param SPI_InitStruct pointer to a @ref LL_SPI_InitTypeDef structure
  201. * whose fields will be set to default values.
  202. * @retval None
  203. */
  204. void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct)
  205. {
  206. /* Set SPI_InitStruct fields to default values */
  207. SPI_InitStruct->TransferDirection = LL_SPI_FULL_DUPLEX;
  208. SPI_InitStruct->Mode = LL_SPI_MODE_SLAVE;
  209. SPI_InitStruct->DataWidth = LL_SPI_DATAWIDTH_8BIT;
  210. SPI_InitStruct->ClockPolarity = LL_SPI_POLARITY_LOW;
  211. SPI_InitStruct->ClockPhase = LL_SPI_PHASE_1EDGE;
  212. SPI_InitStruct->NSS = LL_SPI_NSS_HARD_INPUT;
  213. SPI_InitStruct->BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
  214. SPI_InitStruct->BitOrder = LL_SPI_MSB_FIRST;
  215. SPI_InitStruct->SlaveSpeedMode = LL_SPI_SLAVE_SPEED_NORMAL;
  216. }
  217. /**
  218. * @}
  219. */
  220. /**
  221. * @}
  222. */
  223. /**
  224. * @}
  225. */
  226. #if defined(SPI_I2S_SUPPORT)
  227. /** @addtogroup I2S_LL
  228. * @{
  229. */
  230. /* Private types -------------------------------------------------------------*/
  231. /* Private variables ---------------------------------------------------------*/
  232. /* Private constants ---------------------------------------------------------*/
  233. /** @defgroup I2S_LL_Private_Constants I2S Private Constants
  234. * @{
  235. */
  236. /* I2S registers Masks */
  237. #define I2S_I2SCFGR_CLEAR_MASK (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN | \
  238. SPI_I2SCFGR_CKPOL | SPI_I2SCFGR_I2SSTD | \
  239. SPI_I2SCFGR_I2SCFG | SPI_I2SCFGR_I2SMOD )
  240. #define I2S_I2SPR_CLEAR_MASK 0x0002U
  241. /**
  242. * @}
  243. */
  244. /* Private macros ------------------------------------------------------------*/
  245. /** @defgroup I2S_LL_Private_Macros I2S Private Macros
  246. * @{
  247. */
  248. #define IS_LL_I2S_DATAFORMAT(__VALUE__) (((__VALUE__) == LL_I2S_DATAFORMAT_16B) \
  249. || ((__VALUE__) == LL_I2S_DATAFORMAT_16B_EXTENDED) \
  250. || ((__VALUE__) == LL_I2S_DATAFORMAT_24B) \
  251. || ((__VALUE__) == LL_I2S_DATAFORMAT_32B))
  252. #define IS_LL_I2S_CPOL(__VALUE__) (((__VALUE__) == LL_I2S_POLARITY_LOW) \
  253. || ((__VALUE__) == LL_I2S_POLARITY_HIGH))
  254. #define IS_LL_I2S_STANDARD(__VALUE__) (((__VALUE__) == LL_I2S_STANDARD_PHILIPS) \
  255. || ((__VALUE__) == LL_I2S_STANDARD_MSB) \
  256. || ((__VALUE__) == LL_I2S_STANDARD_LSB) \
  257. || ((__VALUE__) == LL_I2S_STANDARD_PCM_SHORT) \
  258. || ((__VALUE__) == LL_I2S_STANDARD_PCM_LONG))
  259. #define IS_LL_I2S_MODE(__VALUE__) (((__VALUE__) == LL_I2S_MODE_SLAVE_TX) \
  260. || ((__VALUE__) == LL_I2S_MODE_SLAVE_RX) \
  261. || ((__VALUE__) == LL_I2S_MODE_MASTER_TX) \
  262. || ((__VALUE__) == LL_I2S_MODE_MASTER_RX))
  263. #define IS_LL_I2S_MCLK_OUTPUT(__VALUE__) (((__VALUE__) == LL_I2S_MCLK_OUTPUT_ENABLE) \
  264. || ((__VALUE__) == LL_I2S_MCLK_OUTPUT_DISABLE))
  265. #define IS_LL_I2S_AUDIO_FREQ(__VALUE__) ((((__VALUE__) >= LL_I2S_AUDIOFREQ_8K) \
  266. && ((__VALUE__) <= LL_I2S_AUDIOFREQ_96K)) \
  267. || ((__VALUE__) == LL_I2S_AUDIOFREQ_DEFAULT))
  268. #define IS_LL_I2S_PRESCALER_LINEAR(__VALUE__) ((__VALUE__) >= 0x2U)
  269. #define IS_LL_I2S_PRESCALER_PARITY(__VALUE__) (((__VALUE__) == LL_I2S_PRESCALER_PARITY_EVEN) \
  270. || ((__VALUE__) == LL_I2S_PRESCALER_PARITY_ODD))
  271. /**
  272. * @}
  273. */
  274. /* Private function prototypes -----------------------------------------------*/
  275. /* Exported functions --------------------------------------------------------*/
  276. /** @addtogroup I2S_LL_Exported_Functions
  277. * @{
  278. */
  279. /** @addtogroup I2S_LL_EF_Init
  280. * @{
  281. */
  282. /**
  283. * @brief De-initialize the SPI/I2S registers to their default reset values.
  284. * @param SPIx SPI Instance
  285. * @retval An ErrorStatus enumeration value:
  286. * - SUCCESS: SPI registers are de-initialized
  287. * - ERROR: SPI registers are not de-initialized
  288. */
  289. ErrorStatus LL_I2S_DeInit(SPI_TypeDef *SPIx)
  290. {
  291. return LL_SPI_DeInit(SPIx);
  292. }
  293. /**
  294. * @brief Initializes the SPI/I2S registers according to the specified parameters in I2S_InitStruct.
  295. * @note As some bits in SPI configuration registers can only be written when the SPI is disabled (SPI_CR1_SPE bit =0),
  296. * SPI peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
  297. * @param SPIx SPI Instance
  298. * @param I2S_InitStruct pointer to a @ref LL_I2S_InitTypeDef structure
  299. * @retval An ErrorStatus enumeration value:
  300. * - SUCCESS: SPI registers are Initialized
  301. * - ERROR: SPI registers are not Initialized
  302. */
  303. ErrorStatus LL_I2S_Init(SPI_TypeDef *SPIx, LL_I2S_InitTypeDef *I2S_InitStruct)
  304. {
  305. uint32_t i2sdiv = 2U;
  306. uint32_t i2sodd = 0U;
  307. uint32_t packetlength = 1U;
  308. uint32_t tmp;
  309. LL_RCC_ClocksTypeDef rcc_clocks;
  310. uint32_t sourceclock;
  311. ErrorStatus status = ERROR;
  312. /* Check the I2S parameters */
  313. assert_param(IS_I2S_ALL_INSTANCE(SPIx));
  314. assert_param(IS_LL_I2S_MODE(I2S_InitStruct->Mode));
  315. assert_param(IS_LL_I2S_STANDARD(I2S_InitStruct->Standard));
  316. assert_param(IS_LL_I2S_DATAFORMAT(I2S_InitStruct->DataFormat));
  317. assert_param(IS_LL_I2S_MCLK_OUTPUT(I2S_InitStruct->MCLKOutput));
  318. assert_param(IS_LL_I2S_AUDIO_FREQ(I2S_InitStruct->AudioFreq));
  319. assert_param(IS_LL_I2S_CPOL(I2S_InitStruct->ClockPolarity));
  320. if (LL_I2S_IsEnabled(SPIx) == 0x00000000U)
  321. {
  322. /*---------------------------- SPIx I2SCFGR Configuration --------------------
  323. * Configure SPIx I2SCFGR with parameters:
  324. * - Mode: SPI_I2SCFGR_I2SCFG[1:0] bit
  325. * - Standard: SPI_I2SCFGR_I2SSTD[1:0] and SPI_I2SCFGR_PCMSYNC bits
  326. * - DataFormat: SPI_I2SCFGR_CHLEN and SPI_I2SCFGR_DATLEN bits
  327. * - ClockPolarity: SPI_I2SCFGR_CKPOL bit
  328. */
  329. /* Write to SPIx I2SCFGR */
  330. MODIFY_REG(SPIx->I2SCFGR,
  331. I2S_I2SCFGR_CLEAR_MASK,
  332. I2S_InitStruct->Mode | I2S_InitStruct->Standard |
  333. I2S_InitStruct->DataFormat | I2S_InitStruct->ClockPolarity |
  334. SPI_I2SCFGR_I2SMOD);
  335. /*---------------------------- SPIx I2SPR Configuration ----------------------
  336. * Configure SPIx I2SPR with parameters:
  337. * - MCLKOutput: SPI_I2SPR_MCKOE bit
  338. * - AudioFreq: SPI_I2SPR_I2SDIV[7:0] and SPI_I2SPR_ODD bits
  339. */
  340. /* If the requested audio frequency is not the default, compute the prescaler (i2sodd, i2sdiv)
  341. * else, default values are used: i2sodd = 0U, i2sdiv = 2U.
  342. */
  343. if (I2S_InitStruct->AudioFreq != LL_I2S_AUDIOFREQ_DEFAULT)
  344. {
  345. /* Check the frame length (For the Prescaler computing)
  346. * Default value: LL_I2S_DATAFORMAT_16B (packetlength = 1U).
  347. */
  348. if (I2S_InitStruct->DataFormat != LL_I2S_DATAFORMAT_16B)
  349. {
  350. /* Packet length is 32 bits */
  351. packetlength = 2U;
  352. }
  353. /* I2S Clock source is System clock: Get System Clock frequency */
  354. LL_RCC_GetSystemClocksFreq(&rcc_clocks);
  355. /* Get the source clock value: based on System Clock value */
  356. sourceclock = rcc_clocks.SYSCLK_Frequency;
  357. /* Compute the Real divider depending on the MCLK output state with a floating point */
  358. if (I2S_InitStruct->MCLKOutput == LL_I2S_MCLK_OUTPUT_ENABLE)
  359. {
  360. /* MCLK output is enabled */
  361. tmp = (((((sourceclock / 256U) * 10U) / I2S_InitStruct->AudioFreq)) + 5U);
  362. }
  363. else
  364. {
  365. /* MCLK output is disabled */
  366. tmp = (((((sourceclock / (32U * packetlength)) * 10U) / I2S_InitStruct->AudioFreq)) + 5U);
  367. }
  368. /* Remove the floating point */
  369. tmp = tmp / 10U;
  370. /* Check the parity of the divider */
  371. i2sodd = (tmp & (uint16_t)0x0001U);
  372. /* Compute the i2sdiv prescaler */
  373. i2sdiv = ((tmp - i2sodd) / 2U);
  374. /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
  375. i2sodd = (i2sodd << 8U);
  376. }
  377. /* Test if the divider is 1 or 0 or greater than 0xFF */
  378. if ((i2sdiv < 2U) || (i2sdiv > 0xFFU))
  379. {
  380. /* Set the default values */
  381. i2sdiv = 2U;
  382. i2sodd = 0U;
  383. }
  384. /* Write to SPIx I2SPR register the computed value */
  385. WRITE_REG(SPIx->I2SPR, i2sdiv | i2sodd | I2S_InitStruct->MCLKOutput);
  386. status = SUCCESS;
  387. }
  388. return status;
  389. }
  390. /**
  391. * @brief Set each @ref LL_I2S_InitTypeDef field to default value.
  392. * @param I2S_InitStruct pointer to a @ref LL_I2S_InitTypeDef structure
  393. * whose fields will be set to default values.
  394. * @retval None
  395. */
  396. void LL_I2S_StructInit(LL_I2S_InitTypeDef *I2S_InitStruct)
  397. {
  398. /*--------------- Reset I2S init structure parameters values -----------------*/
  399. I2S_InitStruct->Mode = LL_I2S_MODE_SLAVE_TX;
  400. I2S_InitStruct->Standard = LL_I2S_STANDARD_PHILIPS;
  401. I2S_InitStruct->DataFormat = LL_I2S_DATAFORMAT_16B;
  402. I2S_InitStruct->MCLKOutput = LL_I2S_MCLK_OUTPUT_DISABLE;
  403. I2S_InitStruct->AudioFreq = LL_I2S_AUDIOFREQ_DEFAULT;
  404. I2S_InitStruct->ClockPolarity = LL_I2S_POLARITY_LOW;
  405. }
  406. /**
  407. * @brief Set linear and parity prescaler.
  408. * @note To calculate value of PrescalerLinear(I2SDIV[7:0] bits) and PrescalerParity(ODD bit)\n
  409. * Check Audio frequency table and formulas inside Reference Manual (SPI/I2S).
  410. * @param SPIx SPI Instance
  411. * @param PrescalerLinear value Min_Data=0x02 and Max_Data=0xFF.
  412. * @param PrescalerParity This parameter can be one of the following values:
  413. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  414. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  415. * @retval None
  416. */
  417. void LL_I2S_ConfigPrescaler(SPI_TypeDef *SPIx, uint32_t PrescalerLinear, uint32_t PrescalerParity)
  418. {
  419. /* Check the I2S parameters */
  420. assert_param(IS_I2S_ALL_INSTANCE(SPIx));
  421. assert_param(IS_LL_I2S_PRESCALER_LINEAR(PrescalerLinear));
  422. assert_param(IS_LL_I2S_PRESCALER_PARITY(PrescalerParity));
  423. /* Write to SPIx I2SPR */
  424. MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_I2SDIV | SPI_I2SPR_ODD, PrescalerLinear | (PrescalerParity << 8U));
  425. }
  426. /**
  427. * @}
  428. */
  429. /**
  430. * @}
  431. */
  432. /**
  433. * @}
  434. */
  435. #endif /* SPI_I2S_SUPPORT */
  436. #endif /* defined (SPI1) || defined (SPI2) */
  437. /**
  438. * @}
  439. */
  440. #endif /* USE_FULL_LL_DRIVER */
  441. /************************ (C) COPYRIGHT Puya *****END OF FILE****/