stm32f4xx_hal_dsi.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_dsi.c
  4. * @author MCD Application Team
  5. * @version V1.6.0
  6. * @date 04-November-2016
  7. * @brief DSI HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the DSI peripheral:
  10. * + Initialization and de-initialization functions
  11. * + IO operation functions
  12. * + Peripheral Control functions
  13. * + Peripheral State and Errors functions
  14. ******************************************************************************
  15. * @attention
  16. *
  17. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  18. *
  19. * Redistribution and use in source and binary forms, with or without modification,
  20. * are permitted provided that the following conditions are met:
  21. * 1. Redistributions of source code must retain the above copyright notice,
  22. * this list of conditions and the following disclaimer.
  23. * 2. Redistributions in binary form must reproduce the above copyright notice,
  24. * this list of conditions and the following disclaimer in the documentation
  25. * and/or other materials provided with the distribution.
  26. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  27. * may be used to endorse or promote products derived from this software
  28. * without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  34. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  36. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  37. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  38. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ******************************************************************************
  42. */
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f4xx_hal.h"
  45. /** @addtogroup STM32F4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup DSI
  49. * @{
  50. */
  51. #ifdef HAL_DSI_MODULE_ENABLED
  52. #if defined(STM32F469xx) || defined(STM32F479xx)
  53. /* Private types -------------------------------------------------------------*/
  54. /* Private defines -----------------------------------------------------------*/
  55. /** @addtogroup DSI_Private_Constants
  56. * @{
  57. */
  58. #define DSI_TIMEOUT_VALUE ((uint32_t)1000U) /* 1s */
  59. #define DSI_ERROR_ACK_MASK (DSI_ISR0_AE0 | DSI_ISR0_AE1 | DSI_ISR0_AE2 | DSI_ISR0_AE3 | \
  60. DSI_ISR0_AE4 | DSI_ISR0_AE5 | DSI_ISR0_AE6 | DSI_ISR0_AE7 | \
  61. DSI_ISR0_AE8 | DSI_ISR0_AE9 | DSI_ISR0_AE10 | DSI_ISR0_AE11 | \
  62. DSI_ISR0_AE12 | DSI_ISR0_AE13 | DSI_ISR0_AE14 | DSI_ISR0_AE15)
  63. #define DSI_ERROR_PHY_MASK (DSI_ISR0_PE0 | DSI_ISR0_PE1 | DSI_ISR0_PE2 | DSI_ISR0_PE3 | DSI_ISR0_PE4)
  64. #define DSI_ERROR_TX_MASK DSI_ISR1_TOHSTX
  65. #define DSI_ERROR_RX_MASK DSI_ISR1_TOLPRX
  66. #define DSI_ERROR_ECC_MASK (DSI_ISR1_ECCSE | DSI_ISR1_ECCME)
  67. #define DSI_ERROR_CRC_MASK DSI_ISR1_CRCE
  68. #define DSI_ERROR_PSE_MASK DSI_ISR1_PSE
  69. #define DSI_ERROR_EOT_MASK DSI_ISR1_EOTPE
  70. #define DSI_ERROR_OVF_MASK DSI_ISR1_LPWRE
  71. #define DSI_ERROR_GEN_MASK (DSI_ISR1_GCWRE | DSI_ISR1_GPWRE | DSI_ISR1_GPTXE | DSI_ISR1_GPRDE | DSI_ISR1_GPRXE)
  72. /**
  73. * @}
  74. */
  75. /* Private variables ---------------------------------------------------------*/
  76. /* Private constants ---------------------------------------------------------*/
  77. /* Private macros ------------------------------------------------------------*/
  78. /* Private function prototypes -----------------------------------------------*/
  79. static void DSI_ConfigPacketHeader(DSI_TypeDef *DSIx, uint32_t ChannelID, uint32_t DataType, uint32_t Data0, uint32_t Data1);
  80. /* Private functions ---------------------------------------------------------*/
  81. /**
  82. * @brief Generic DSI packet header configuration
  83. * @param DSIx: Pointer to DSI register base
  84. * @param ChannelID: Virtual channel ID of the header packet
  85. * @param DataType: Packet data type of the header packet
  86. * This parameter can be any value of :
  87. * @ref DSI_SHORT_WRITE_PKT_Data_Type
  88. * or @ref DSI_LONG_WRITE_PKT_Data_Type
  89. * or @ref DSI_SHORT_READ_PKT_Data_Type
  90. * or DSI_MAX_RETURN_PKT_SIZE
  91. * @param Data0: Word count LSB
  92. * @param Data1: Word count MSB
  93. * @retval None
  94. */
  95. static void DSI_ConfigPacketHeader(DSI_TypeDef *DSIx,
  96. uint32_t ChannelID,
  97. uint32_t DataType,
  98. uint32_t Data0,
  99. uint32_t Data1)
  100. {
  101. /* Update the DSI packet header with new information */
  102. DSIx->GHCR = (DataType | (ChannelID<<6U) | (Data0<<8U) | (Data1<<16U));
  103. }
  104. /* Exported functions --------------------------------------------------------*/
  105. /** @addtogroup DSI_Exported_Functions
  106. * @{
  107. */
  108. /** @defgroup DSI_Group1 Initialization and Configuration functions
  109. * @brief Initialization and Configuration functions
  110. *
  111. @verbatim
  112. ===============================================================================
  113. ##### Initialization and Configuration functions #####
  114. ===============================================================================
  115. [..] This section provides functions allowing to:
  116. (+) Initialize and configure the DSI
  117. (+) De-initialize the DSI
  118. @endverbatim
  119. * @{
  120. */
  121. /**
  122. * @brief Initializes the DSI according to the specified
  123. * parameters in the DSI_InitTypeDef and create the associated handle.
  124. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  125. * the configuration information for the DSI.
  126. * @param PLLInit: pointer to a DSI_PLLInitTypeDef structure that contains
  127. * the PLL Clock structure definition for the DSI.
  128. * @retval HAL status
  129. */
  130. HAL_StatusTypeDef HAL_DSI_Init(DSI_HandleTypeDef *hdsi, DSI_PLLInitTypeDef *PLLInit)
  131. {
  132. uint32_t tickstart = 0U;
  133. uint32_t unitIntervalx4 = 0U;
  134. uint32_t tempIDF = 0U;
  135. /* Check the DSI handle allocation */
  136. if(hdsi == NULL)
  137. {
  138. return HAL_ERROR;
  139. }
  140. /* Check function parameters */
  141. assert_param(IS_DSI_PLL_NDIV(PLLInit->PLLNDIV));
  142. assert_param(IS_DSI_PLL_IDF(PLLInit->PLLIDF));
  143. assert_param(IS_DSI_PLL_ODF(PLLInit->PLLODF));
  144. assert_param(IS_DSI_AUTO_CLKLANE_CONTROL(hdsi->Init.AutomaticClockLaneControl));
  145. assert_param(IS_DSI_NUMBER_OF_LANES(hdsi->Init.NumberOfLanes));
  146. if(hdsi->State == HAL_DSI_STATE_RESET)
  147. {
  148. /* Initialize the low level hardware */
  149. HAL_DSI_MspInit(hdsi);
  150. }
  151. /* Change DSI peripheral state */
  152. hdsi->State = HAL_DSI_STATE_BUSY;
  153. /**************** Turn on the regulator and enable the DSI PLL ****************/
  154. /* Enable the regulator */
  155. __HAL_DSI_REG_ENABLE(hdsi);
  156. /* Get tick */
  157. tickstart = HAL_GetTick();
  158. /* Wait until the regulator is ready */
  159. while(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_RRS) == RESET)
  160. {
  161. /* Check for the Timeout */
  162. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  163. {
  164. return HAL_TIMEOUT;
  165. }
  166. }
  167. /* Set the PLL division factors */
  168. hdsi->Instance->WRPCR &= ~(DSI_WRPCR_PLL_NDIV | DSI_WRPCR_PLL_IDF | DSI_WRPCR_PLL_ODF);
  169. hdsi->Instance->WRPCR |= (((PLLInit->PLLNDIV)<<2U) | ((PLLInit->PLLIDF)<<11U) | ((PLLInit->PLLODF)<<16U));
  170. /* Enable the DSI PLL */
  171. __HAL_DSI_PLL_ENABLE(hdsi);
  172. /* Get tick */
  173. tickstart = HAL_GetTick();
  174. /* Wait for the lock of the PLL */
  175. while(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_PLLLS) == RESET)
  176. {
  177. /* Check for the Timeout */
  178. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  179. {
  180. return HAL_TIMEOUT;
  181. }
  182. }
  183. /*************************** Set the PHY parameters ***************************/
  184. /* D-PHY clock and digital enable*/
  185. hdsi->Instance->PCTLR |= (DSI_PCTLR_CKE | DSI_PCTLR_DEN);
  186. /* Clock lane configuration */
  187. hdsi->Instance->CLCR &= ~(DSI_CLCR_DPCC | DSI_CLCR_ACR);
  188. hdsi->Instance->CLCR |= (DSI_CLCR_DPCC | hdsi->Init.AutomaticClockLaneControl);
  189. /* Configure the number of active data lanes */
  190. hdsi->Instance->PCONFR &= ~DSI_PCONFR_NL;
  191. hdsi->Instance->PCONFR |= hdsi->Init.NumberOfLanes;
  192. /************************ Set the DSI clock parameters ************************/
  193. /* Set the TX escape clock division factor */
  194. hdsi->Instance->CCR &= ~DSI_CCR_TXECKDIV;
  195. hdsi->Instance->CCR |= hdsi->Init.TXEscapeCkdiv;
  196. /* Calculate the bit period in high-speed mode in unit of 0.25 ns (UIX4) */
  197. /* The equation is : UIX4 = IntegerPart( (1000/F_PHY_Mhz) * 4 ) */
  198. /* Where : F_PHY_Mhz = (NDIV * HSE_Mhz) / (IDF * ODF) */
  199. tempIDF = (PLLInit->PLLIDF > 0U) ? PLLInit->PLLIDF : 1U;
  200. unitIntervalx4 = (4000000U * tempIDF * (1U << PLLInit->PLLODF)) / ((HSE_VALUE/1000U) * PLLInit->PLLNDIV);
  201. /* Set the bit period in high-speed mode */
  202. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_UIX4;
  203. hdsi->Instance->WPCR[0U] |= unitIntervalx4;
  204. /****************************** Error management *****************************/
  205. /* Disable all error interrupts and reset the Error Mask */
  206. hdsi->Instance->IER[0U] = 0U;
  207. hdsi->Instance->IER[1U] = 0U;
  208. hdsi->ErrorMsk = 0U;
  209. /* Initialise the error code */
  210. hdsi->ErrorCode = HAL_DSI_ERROR_NONE;
  211. /* Initialize the DSI state*/
  212. hdsi->State = HAL_DSI_STATE_READY;
  213. return HAL_OK;
  214. }
  215. /**
  216. * @brief De-initializes the DSI peripheral registers to their default reset
  217. * values.
  218. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  219. * the configuration information for the DSI.
  220. * @retval HAL status
  221. */
  222. HAL_StatusTypeDef HAL_DSI_DeInit(DSI_HandleTypeDef *hdsi)
  223. {
  224. /* Check the DSI handle allocation */
  225. if(hdsi == NULL)
  226. {
  227. return HAL_ERROR;
  228. }
  229. /* Change DSI peripheral state */
  230. hdsi->State = HAL_DSI_STATE_BUSY;
  231. /* Disable the DSI wrapper */
  232. __HAL_DSI_WRAPPER_DISABLE(hdsi);
  233. /* Disable the DSI host */
  234. __HAL_DSI_DISABLE(hdsi);
  235. /* D-PHY clock and digital disable */
  236. hdsi->Instance->PCTLR &= ~(DSI_PCTLR_CKE | DSI_PCTLR_DEN);
  237. /* Turn off the DSI PLL */
  238. __HAL_DSI_PLL_DISABLE(hdsi);
  239. /* Disable the regulator */
  240. __HAL_DSI_REG_DISABLE(hdsi);
  241. /* DeInit the low level hardware */
  242. HAL_DSI_MspDeInit(hdsi);
  243. /* Initialise the error code */
  244. hdsi->ErrorCode = HAL_DSI_ERROR_NONE;
  245. /* Initialize the DSI state*/
  246. hdsi->State = HAL_DSI_STATE_RESET;
  247. /* Release Lock */
  248. __HAL_UNLOCK(hdsi);
  249. return HAL_OK;
  250. }
  251. /**
  252. * @brief Return the DSI error code
  253. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  254. * the configuration information for the DSI.
  255. * @retval DSI Error Code
  256. */
  257. uint32_t HAL_DSI_GetError(DSI_HandleTypeDef *hdsi)
  258. {
  259. /* Get the error code */
  260. return hdsi->ErrorCode;
  261. }
  262. /**
  263. * @brief Enable the error monitor flags
  264. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  265. * the configuration information for the DSI.
  266. * @param ActiveErrors: indicates which error interrupts will be enabled.
  267. * This parameter can be any combination of @ref DSI_Error_Data_Type.
  268. * @retval HAL status
  269. */
  270. HAL_StatusTypeDef HAL_DSI_ConfigErrorMonitor(DSI_HandleTypeDef *hdsi, uint32_t ActiveErrors)
  271. {
  272. /* Process locked */
  273. __HAL_LOCK(hdsi);
  274. hdsi->Instance->IER[0U] = 0U;
  275. hdsi->Instance->IER[1U] = 0U;
  276. /* Store active errors to the handle */
  277. hdsi->ErrorMsk = ActiveErrors;
  278. if((ActiveErrors & HAL_DSI_ERROR_ACK) != RESET)
  279. {
  280. /* Enable the interrupt generation on selected errors */
  281. hdsi->Instance->IER[0U] |= DSI_ERROR_ACK_MASK;
  282. }
  283. if((ActiveErrors & HAL_DSI_ERROR_PHY) != RESET)
  284. {
  285. /* Enable the interrupt generation on selected errors */
  286. hdsi->Instance->IER[0U] |= DSI_ERROR_PHY_MASK;
  287. }
  288. if((ActiveErrors & HAL_DSI_ERROR_TX) != RESET)
  289. {
  290. /* Enable the interrupt generation on selected errors */
  291. hdsi->Instance->IER[1U] |= DSI_ERROR_TX_MASK;
  292. }
  293. if((ActiveErrors & HAL_DSI_ERROR_RX) != RESET)
  294. {
  295. /* Enable the interrupt generation on selected errors */
  296. hdsi->Instance->IER[1U] |= DSI_ERROR_RX_MASK;
  297. }
  298. if((ActiveErrors & HAL_DSI_ERROR_ECC) != RESET)
  299. {
  300. /* Enable the interrupt generation on selected errors */
  301. hdsi->Instance->IER[1U] |= DSI_ERROR_ECC_MASK;
  302. }
  303. if((ActiveErrors & HAL_DSI_ERROR_CRC) != RESET)
  304. {
  305. /* Enable the interrupt generation on selected errors */
  306. hdsi->Instance->IER[1U] |= DSI_ERROR_CRC_MASK;
  307. }
  308. if((ActiveErrors & HAL_DSI_ERROR_PSE) != RESET)
  309. {
  310. /* Enable the interrupt generation on selected errors */
  311. hdsi->Instance->IER[1U] |= DSI_ERROR_PSE_MASK;
  312. }
  313. if((ActiveErrors & HAL_DSI_ERROR_EOT) != RESET)
  314. {
  315. /* Enable the interrupt generation on selected errors */
  316. hdsi->Instance->IER[1U] |= DSI_ERROR_EOT_MASK;
  317. }
  318. if((ActiveErrors & HAL_DSI_ERROR_OVF) != RESET)
  319. {
  320. /* Enable the interrupt generation on selected errors */
  321. hdsi->Instance->IER[1U] |= DSI_ERROR_OVF_MASK;
  322. }
  323. if((ActiveErrors & HAL_DSI_ERROR_GEN) != RESET)
  324. {
  325. /* Enable the interrupt generation on selected errors */
  326. hdsi->Instance->IER[1U] |= DSI_ERROR_GEN_MASK;
  327. }
  328. /* Process Unlocked */
  329. __HAL_UNLOCK(hdsi);
  330. return HAL_OK;
  331. }
  332. /**
  333. * @brief Initializes the DSI MSP.
  334. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  335. * the configuration information for the DSI.
  336. * @retval None
  337. */
  338. __weak void HAL_DSI_MspInit(DSI_HandleTypeDef* hdsi)
  339. {
  340. /* Prevent unused argument(s) compilation warning */
  341. UNUSED(hdsi);
  342. /* NOTE : This function Should not be modified, when the callback is needed,
  343. the HAL_DSI_MspInit could be implemented in the user file
  344. */
  345. }
  346. /**
  347. * @brief De-initializes the DSI MSP.
  348. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  349. * the configuration information for the DSI.
  350. * @retval None
  351. */
  352. __weak void HAL_DSI_MspDeInit(DSI_HandleTypeDef* hdsi)
  353. {
  354. /* Prevent unused argument(s) compilation warning */
  355. UNUSED(hdsi);
  356. /* NOTE : This function Should not be modified, when the callback is needed,
  357. the HAL_DSI_MspDeInit could be implemented in the user file
  358. */
  359. }
  360. /**
  361. * @}
  362. */
  363. /** @defgroup DSI_Group2 IO operation functions
  364. * @brief IO operation functions
  365. *
  366. @verbatim
  367. ===============================================================================
  368. ##### IO operation functions #####
  369. ===============================================================================
  370. [..] This section provides function allowing to:
  371. (+) Handle DSI interrupt request
  372. @endverbatim
  373. * @{
  374. */
  375. /**
  376. * @brief Handles DSI interrupt request.
  377. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  378. * the configuration information for the DSI.
  379. * @retval HAL status
  380. */
  381. void HAL_DSI_IRQHandler(DSI_HandleTypeDef *hdsi)
  382. {
  383. uint32_t ErrorStatus0, ErrorStatus1;
  384. /* Tearing Effect Interrupt management ***************************************/
  385. if(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_TE) != RESET)
  386. {
  387. if(__HAL_DSI_GET_IT_SOURCE(hdsi, DSI_IT_TE) != RESET)
  388. {
  389. /* Clear the Tearing Effect Interrupt Flag */
  390. __HAL_DSI_CLEAR_FLAG(hdsi, DSI_FLAG_TE);
  391. /* Tearing Effect Callback */
  392. HAL_DSI_TearingEffectCallback(hdsi);
  393. }
  394. }
  395. /* End of Refresh Interrupt management ***************************************/
  396. if(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_ER) != RESET)
  397. {
  398. if(__HAL_DSI_GET_IT_SOURCE(hdsi, DSI_IT_ER) != RESET)
  399. {
  400. /* Clear the End of Refresh Interrupt Flag */
  401. __HAL_DSI_CLEAR_FLAG(hdsi, DSI_FLAG_ER);
  402. /* End of Refresh Callback */
  403. HAL_DSI_EndOfRefreshCallback(hdsi);
  404. }
  405. }
  406. /* Error Interrupts management ***********************************************/
  407. if(hdsi->ErrorMsk != 0U)
  408. {
  409. ErrorStatus0 = hdsi->Instance->ISR[0U];
  410. ErrorStatus0 &= hdsi->Instance->IER[0U];
  411. ErrorStatus1 = hdsi->Instance->ISR[1U];
  412. ErrorStatus1 &= hdsi->Instance->IER[1U];
  413. if((ErrorStatus0 & DSI_ERROR_ACK_MASK) != RESET)
  414. {
  415. hdsi->ErrorCode |= HAL_DSI_ERROR_ACK;
  416. }
  417. if((ErrorStatus0 & DSI_ERROR_PHY_MASK) != RESET)
  418. {
  419. hdsi->ErrorCode |= HAL_DSI_ERROR_PHY;
  420. }
  421. if((ErrorStatus1 & DSI_ERROR_TX_MASK) != RESET)
  422. {
  423. hdsi->ErrorCode |= HAL_DSI_ERROR_TX;
  424. }
  425. if((ErrorStatus1 & DSI_ERROR_RX_MASK) != RESET)
  426. {
  427. hdsi->ErrorCode |= HAL_DSI_ERROR_RX;
  428. }
  429. if((ErrorStatus1 & DSI_ERROR_ECC_MASK) != RESET)
  430. {
  431. hdsi->ErrorCode |= HAL_DSI_ERROR_ECC;
  432. }
  433. if((ErrorStatus1 & DSI_ERROR_CRC_MASK) != RESET)
  434. {
  435. hdsi->ErrorCode |= HAL_DSI_ERROR_CRC;
  436. }
  437. if((ErrorStatus1 & DSI_ERROR_PSE_MASK) != RESET)
  438. {
  439. hdsi->ErrorCode |= HAL_DSI_ERROR_PSE;
  440. }
  441. if((ErrorStatus1 & DSI_ERROR_EOT_MASK) != RESET)
  442. {
  443. hdsi->ErrorCode |= HAL_DSI_ERROR_EOT;
  444. }
  445. if((ErrorStatus1 & DSI_ERROR_OVF_MASK) != RESET)
  446. {
  447. hdsi->ErrorCode |= HAL_DSI_ERROR_OVF;
  448. }
  449. if((ErrorStatus1 & DSI_ERROR_GEN_MASK) != RESET)
  450. {
  451. hdsi->ErrorCode |= HAL_DSI_ERROR_GEN;
  452. }
  453. /* Check only selected errors */
  454. if(hdsi->ErrorCode != HAL_DSI_ERROR_NONE)
  455. {
  456. /* DSI error interrupt user callback */
  457. HAL_DSI_ErrorCallback(hdsi);
  458. }
  459. }
  460. }
  461. /**
  462. * @brief Tearing Effect DSI callback.
  463. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  464. * the configuration information for the DSI.
  465. * @retval None
  466. */
  467. __weak void HAL_DSI_TearingEffectCallback(DSI_HandleTypeDef *hdsi)
  468. {
  469. /* Prevent unused argument(s) compilation warning */
  470. UNUSED(hdsi);
  471. /* NOTE : This function Should not be modified, when the callback is needed,
  472. the HAL_DSI_TearingEffectCallback could be implemented in the user file
  473. */
  474. }
  475. /**
  476. * @brief End of Refresh DSI callback.
  477. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  478. * the configuration information for the DSI.
  479. * @retval None
  480. */
  481. __weak void HAL_DSI_EndOfRefreshCallback(DSI_HandleTypeDef *hdsi)
  482. {
  483. /* Prevent unused argument(s) compilation warning */
  484. UNUSED(hdsi);
  485. /* NOTE : This function Should not be modified, when the callback is needed,
  486. the HAL_DSI_EndOfRefreshCallback could be implemented in the user file
  487. */
  488. }
  489. /**
  490. * @brief Operation Error DSI callback.
  491. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  492. * the configuration information for the DSI.
  493. * @retval None
  494. */
  495. __weak void HAL_DSI_ErrorCallback(DSI_HandleTypeDef *hdsi)
  496. {
  497. /* Prevent unused argument(s) compilation warning */
  498. UNUSED(hdsi);
  499. /* NOTE : This function Should not be modified, when the callback is needed,
  500. the HAL_DSI_ErrorCallback could be implemented in the user file
  501. */
  502. }
  503. /**
  504. * @}
  505. */
  506. /** @defgroup DSI_Group3 Peripheral Control functions
  507. * @brief Peripheral Control functions
  508. *
  509. @verbatim
  510. ===============================================================================
  511. ##### Peripheral Control functions #####
  512. ===============================================================================
  513. [..] This section provides functions allowing to:
  514. (+)
  515. (+)
  516. (+)
  517. @endverbatim
  518. * @{
  519. */
  520. /**
  521. * @brief Configure the Generic interface read-back Virtual Channel ID.
  522. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  523. * the configuration information for the DSI.
  524. * @param VirtualChannelID: Virtual channel ID
  525. * @retval HAL status
  526. */
  527. HAL_StatusTypeDef HAL_DSI_SetGenericVCID(DSI_HandleTypeDef *hdsi, uint32_t VirtualChannelID)
  528. {
  529. /* Process locked */
  530. __HAL_LOCK(hdsi);
  531. /* Update the GVCID register */
  532. hdsi->Instance->GVCIDR &= ~DSI_GVCIDR_VCID;
  533. hdsi->Instance->GVCIDR |= VirtualChannelID;
  534. /* Process unlocked */
  535. __HAL_UNLOCK(hdsi);
  536. return HAL_OK;
  537. }
  538. /**
  539. * @brief Select video mode and configure the corresponding parameters
  540. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  541. * the configuration information for the DSI.
  542. * @param VidCfg: pointer to a DSI_VidCfgTypeDef structure that contains
  543. * the DSI video mode configuration parameters
  544. * @retval HAL status
  545. */
  546. HAL_StatusTypeDef HAL_DSI_ConfigVideoMode(DSI_HandleTypeDef *hdsi, DSI_VidCfgTypeDef *VidCfg)
  547. {
  548. /* Process locked */
  549. __HAL_LOCK(hdsi);
  550. /* Check the parameters */
  551. assert_param(IS_DSI_COLOR_CODING(VidCfg->ColorCoding));
  552. assert_param(IS_DSI_VIDEO_MODE_TYPE(VidCfg->Mode));
  553. assert_param(IS_DSI_LP_COMMAND(VidCfg->LPCommandEnable));
  554. assert_param(IS_DSI_LP_HFP(VidCfg->LPHorizontalFrontPorchEnable));
  555. assert_param(IS_DSI_LP_HBP(VidCfg->LPHorizontalBackPorchEnable));
  556. assert_param(IS_DSI_LP_VACTIVE(VidCfg->LPVerticalActiveEnable));
  557. assert_param(IS_DSI_LP_VFP(VidCfg->LPVerticalFrontPorchEnable));
  558. assert_param(IS_DSI_LP_VBP(VidCfg->LPVerticalBackPorchEnable));
  559. assert_param(IS_DSI_LP_VSYNC(VidCfg->LPVerticalSyncActiveEnable));
  560. assert_param(IS_DSI_FBTAA(VidCfg->FrameBTAAcknowledgeEnable));
  561. assert_param(IS_DSI_DE_POLARITY(VidCfg->DEPolarity));
  562. assert_param(IS_DSI_VSYNC_POLARITY(VidCfg->VSPolarity));
  563. assert_param(IS_DSI_HSYNC_POLARITY(VidCfg->HSPolarity));
  564. /* Check the LooselyPacked variant only in 18-bit mode */
  565. if(VidCfg->ColorCoding == DSI_RGB666)
  566. {
  567. assert_param(IS_DSI_LOOSELY_PACKED(VidCfg->LooselyPacked));
  568. }
  569. /* Select video mode by resetting CMDM and DSIM bits */
  570. hdsi->Instance->MCR &= ~DSI_MCR_CMDM;
  571. hdsi->Instance->WCFGR &= ~DSI_WCFGR_DSIM;
  572. /* Configure the video mode transmission type */
  573. hdsi->Instance->VMCR &= ~DSI_VMCR_VMT;
  574. hdsi->Instance->VMCR |= VidCfg->Mode;
  575. /* Configure the video packet size */
  576. hdsi->Instance->VPCR &= ~DSI_VPCR_VPSIZE;
  577. hdsi->Instance->VPCR |= VidCfg->PacketSize;
  578. /* Set the chunks number to be transmitted through the DSI link */
  579. hdsi->Instance->VCCR &= ~DSI_VCCR_NUMC;
  580. hdsi->Instance->VCCR |= VidCfg->NumberOfChunks;
  581. /* Set the size of the null packet */
  582. hdsi->Instance->VNPCR &= ~DSI_VNPCR_NPSIZE;
  583. hdsi->Instance->VNPCR |= VidCfg->NullPacketSize;
  584. /* Select the virtual channel for the LTDC interface traffic */
  585. hdsi->Instance->LVCIDR &= ~DSI_LVCIDR_VCID;
  586. hdsi->Instance->LVCIDR |= VidCfg->VirtualChannelID;
  587. /* Configure the polarity of control signals */
  588. hdsi->Instance->LPCR &= ~(DSI_LPCR_DEP | DSI_LPCR_VSP | DSI_LPCR_HSP);
  589. hdsi->Instance->LPCR |= (VidCfg->DEPolarity | VidCfg->VSPolarity | VidCfg->HSPolarity);
  590. /* Select the color coding for the host */
  591. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_COLC;
  592. hdsi->Instance->LCOLCR |= VidCfg->ColorCoding;
  593. /* Select the color coding for the wrapper */
  594. hdsi->Instance->WCFGR &= ~DSI_WCFGR_COLMUX;
  595. hdsi->Instance->WCFGR |= ((VidCfg->ColorCoding)<<1U);
  596. /* Enable/disable the loosely packed variant to 18-bit configuration */
  597. if(VidCfg->ColorCoding == DSI_RGB666)
  598. {
  599. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_LPE;
  600. hdsi->Instance->LCOLCR |= VidCfg->LooselyPacked;
  601. }
  602. /* Set the Horizontal Synchronization Active (HSA) in lane byte clock cycles */
  603. hdsi->Instance->VHSACR &= ~DSI_VHSACR_HSA;
  604. hdsi->Instance->VHSACR |= VidCfg->HorizontalSyncActive;
  605. /* Set the Horizontal Back Porch (HBP) in lane byte clock cycles */
  606. hdsi->Instance->VHBPCR &= ~DSI_VHBPCR_HBP;
  607. hdsi->Instance->VHBPCR |= VidCfg->HorizontalBackPorch;
  608. /* Set the total line time (HLINE=HSA+HBP+HACT+HFP) in lane byte clock cycles */
  609. hdsi->Instance->VLCR &= ~DSI_VLCR_HLINE;
  610. hdsi->Instance->VLCR |= VidCfg->HorizontalLine;
  611. /* Set the Vertical Synchronization Active (VSA) */
  612. hdsi->Instance->VVSACR &= ~DSI_VVSACR_VSA;
  613. hdsi->Instance->VVSACR |= VidCfg->VerticalSyncActive;
  614. /* Set the Vertical Back Porch (VBP)*/
  615. hdsi->Instance->VVBPCR &= ~DSI_VVBPCR_VBP;
  616. hdsi->Instance->VVBPCR |= VidCfg->VerticalBackPorch;
  617. /* Set the Vertical Front Porch (VFP)*/
  618. hdsi->Instance->VVFPCR &= ~DSI_VVFPCR_VFP;
  619. hdsi->Instance->VVFPCR |= VidCfg->VerticalFrontPorch;
  620. /* Set the Vertical Active period*/
  621. hdsi->Instance->VVACR &= ~DSI_VVACR_VA;
  622. hdsi->Instance->VVACR |= VidCfg->VerticalActive;
  623. /* Configure the command transmission mode */
  624. hdsi->Instance->VMCR &= ~DSI_VMCR_LPCE;
  625. hdsi->Instance->VMCR |= VidCfg->LPCommandEnable;
  626. /* Low power largest packet size */
  627. hdsi->Instance->LPMCR &= ~DSI_LPMCR_LPSIZE;
  628. hdsi->Instance->LPMCR |= ((VidCfg->LPLargestPacketSize)<<16U);
  629. /* Low power VACT largest packet size */
  630. hdsi->Instance->LPMCR &= ~DSI_LPMCR_VLPSIZE;
  631. hdsi->Instance->LPMCR |= VidCfg->LPVACTLargestPacketSize;
  632. /* Enable LP transition in HFP period */
  633. hdsi->Instance->VMCR &= ~DSI_VMCR_LPHFPE;
  634. hdsi->Instance->VMCR |= VidCfg->LPHorizontalFrontPorchEnable;
  635. /* Enable LP transition in HBP period */
  636. hdsi->Instance->VMCR &= ~DSI_VMCR_LPHBPE;
  637. hdsi->Instance->VMCR |= VidCfg->LPHorizontalBackPorchEnable;
  638. /* Enable LP transition in VACT period */
  639. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVAE;
  640. hdsi->Instance->VMCR |= VidCfg->LPVerticalActiveEnable;
  641. /* Enable LP transition in VFP period */
  642. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVFPE;
  643. hdsi->Instance->VMCR |= VidCfg->LPVerticalFrontPorchEnable;
  644. /* Enable LP transition in VBP period */
  645. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVBPE;
  646. hdsi->Instance->VMCR |= VidCfg->LPVerticalBackPorchEnable;
  647. /* Enable LP transition in vertical sync period */
  648. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVSAE;
  649. hdsi->Instance->VMCR |= VidCfg->LPVerticalSyncActiveEnable;
  650. /* Enable the request for an acknowledge response at the end of a frame */
  651. hdsi->Instance->VMCR &= ~DSI_VMCR_FBTAAE;
  652. hdsi->Instance->VMCR |= VidCfg->FrameBTAAcknowledgeEnable;
  653. /* Process unlocked */
  654. __HAL_UNLOCK(hdsi);
  655. return HAL_OK;
  656. }
  657. /**
  658. * @brief Select adapted command mode and configure the corresponding parameters
  659. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  660. * the configuration information for the DSI.
  661. * @param CmdCfg: pointer to a DSI_CmdCfgTypeDef structure that contains
  662. * the DSI command mode configuration parameters
  663. * @retval HAL status
  664. */
  665. HAL_StatusTypeDef HAL_DSI_ConfigAdaptedCommandMode(DSI_HandleTypeDef *hdsi, DSI_CmdCfgTypeDef *CmdCfg)
  666. {
  667. /* Process locked */
  668. __HAL_LOCK(hdsi);
  669. /* Check the parameters */
  670. assert_param(IS_DSI_COLOR_CODING(CmdCfg->ColorCoding));
  671. assert_param(IS_DSI_TE_SOURCE(CmdCfg->TearingEffectSource));
  672. assert_param(IS_DSI_TE_POLARITY(CmdCfg->TearingEffectPolarity));
  673. assert_param(IS_DSI_AUTOMATIC_REFRESH(CmdCfg->AutomaticRefresh));
  674. assert_param(IS_DSI_VS_POLARITY(CmdCfg->VSyncPol));
  675. assert_param(IS_DSI_TE_ACK_REQUEST(CmdCfg->TEAcknowledgeRequest));
  676. assert_param(IS_DSI_DE_POLARITY(CmdCfg->DEPolarity));
  677. assert_param(IS_DSI_VSYNC_POLARITY(CmdCfg->VSPolarity));
  678. assert_param(IS_DSI_HSYNC_POLARITY(CmdCfg->HSPolarity));
  679. /* Select command mode by setting CMDM and DSIM bits */
  680. hdsi->Instance->MCR |= DSI_MCR_CMDM;
  681. hdsi->Instance->WCFGR &= ~DSI_WCFGR_DSIM;
  682. hdsi->Instance->WCFGR |= DSI_WCFGR_DSIM;
  683. /* Select the virtual channel for the LTDC interface traffic */
  684. hdsi->Instance->LVCIDR &= ~DSI_LVCIDR_VCID;
  685. hdsi->Instance->LVCIDR |= CmdCfg->VirtualChannelID;
  686. /* Configure the polarity of control signals */
  687. hdsi->Instance->LPCR &= ~(DSI_LPCR_DEP | DSI_LPCR_VSP | DSI_LPCR_HSP);
  688. hdsi->Instance->LPCR |= (CmdCfg->DEPolarity | CmdCfg->VSPolarity | CmdCfg->HSPolarity);
  689. /* Select the color coding for the host */
  690. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_COLC;
  691. hdsi->Instance->LCOLCR |= CmdCfg->ColorCoding;
  692. /* Select the color coding for the wrapper */
  693. hdsi->Instance->WCFGR &= ~DSI_WCFGR_COLMUX;
  694. hdsi->Instance->WCFGR |= ((CmdCfg->ColorCoding)<<1U);
  695. /* Configure the maximum allowed size for write memory command */
  696. hdsi->Instance->LCCR &= ~DSI_LCCR_CMDSIZE;
  697. hdsi->Instance->LCCR |= CmdCfg->CommandSize;
  698. /* Configure the tearing effect source and polarity and select the refresh mode */
  699. hdsi->Instance->WCFGR &= ~(DSI_WCFGR_TESRC | DSI_WCFGR_TEPOL | DSI_WCFGR_AR | DSI_WCFGR_VSPOL);
  700. hdsi->Instance->WCFGR |= (CmdCfg->TearingEffectSource | CmdCfg->TearingEffectPolarity | CmdCfg->AutomaticRefresh | CmdCfg->VSyncPol);
  701. /* Configure the tearing effect acknowledge request */
  702. hdsi->Instance->CMCR &= ~DSI_CMCR_TEARE;
  703. hdsi->Instance->CMCR |= CmdCfg->TEAcknowledgeRequest;
  704. /* Enable the Tearing Effect interrupt */
  705. __HAL_DSI_ENABLE_IT(hdsi, DSI_IT_TE);
  706. /* Enable the End of Refresh interrupt */
  707. __HAL_DSI_ENABLE_IT(hdsi, DSI_IT_ER);
  708. /* Process unlocked */
  709. __HAL_UNLOCK(hdsi);
  710. return HAL_OK;
  711. }
  712. /**
  713. * @brief Configure command transmission mode: High-speed or Low-power
  714. * and enable/disable acknowledge request after packet transmission
  715. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  716. * the configuration information for the DSI.
  717. * @param LPCmd: pointer to a DSI_LPCmdTypeDef structure that contains
  718. * the DSI command transmission mode configuration parameters
  719. * @retval HAL status
  720. */
  721. HAL_StatusTypeDef HAL_DSI_ConfigCommand(DSI_HandleTypeDef *hdsi, DSI_LPCmdTypeDef *LPCmd)
  722. {
  723. /* Process locked */
  724. __HAL_LOCK(hdsi);
  725. assert_param(IS_DSI_LP_GSW0P(LPCmd->LPGenShortWriteNoP));
  726. assert_param(IS_DSI_LP_GSW1P(LPCmd->LPGenShortWriteOneP));
  727. assert_param(IS_DSI_LP_GSW2P(LPCmd->LPGenShortWriteTwoP));
  728. assert_param(IS_DSI_LP_GSR0P(LPCmd->LPGenShortReadNoP));
  729. assert_param(IS_DSI_LP_GSR1P(LPCmd->LPGenShortReadOneP));
  730. assert_param(IS_DSI_LP_GSR2P(LPCmd->LPGenShortReadTwoP));
  731. assert_param(IS_DSI_LP_GLW(LPCmd->LPGenLongWrite));
  732. assert_param(IS_DSI_LP_DSW0P(LPCmd->LPDcsShortWriteNoP));
  733. assert_param(IS_DSI_LP_DSW1P(LPCmd->LPDcsShortWriteOneP));
  734. assert_param(IS_DSI_LP_DSR0P(LPCmd->LPDcsShortReadNoP));
  735. assert_param(IS_DSI_LP_DLW(LPCmd->LPDcsLongWrite));
  736. assert_param(IS_DSI_LP_MRDP(LPCmd->LPMaxReadPacket));
  737. assert_param(IS_DSI_ACK_REQUEST(LPCmd->AcknowledgeRequest));
  738. /* Select High-speed or Low-power for command transmission */
  739. hdsi->Instance->CMCR &= ~(DSI_CMCR_GSW0TX |\
  740. DSI_CMCR_GSW1TX |\
  741. DSI_CMCR_GSW2TX |\
  742. DSI_CMCR_GSR0TX |\
  743. DSI_CMCR_GSR1TX |\
  744. DSI_CMCR_GSR2TX |\
  745. DSI_CMCR_GLWTX |\
  746. DSI_CMCR_DSW0TX |\
  747. DSI_CMCR_DSW1TX |\
  748. DSI_CMCR_DSR0TX |\
  749. DSI_CMCR_DLWTX |\
  750. DSI_CMCR_MRDPS);
  751. hdsi->Instance->CMCR |= (LPCmd->LPGenShortWriteNoP |\
  752. LPCmd->LPGenShortWriteOneP |\
  753. LPCmd->LPGenShortWriteTwoP |\
  754. LPCmd->LPGenShortReadNoP |\
  755. LPCmd->LPGenShortReadOneP |\
  756. LPCmd->LPGenShortReadTwoP |\
  757. LPCmd->LPGenLongWrite |\
  758. LPCmd->LPDcsShortWriteNoP |\
  759. LPCmd->LPDcsShortWriteOneP |\
  760. LPCmd->LPDcsShortReadNoP |\
  761. LPCmd->LPDcsLongWrite |\
  762. LPCmd->LPMaxReadPacket);
  763. /* Configure the acknowledge request after each packet transmission */
  764. hdsi->Instance->CMCR &= ~DSI_CMCR_ARE;
  765. hdsi->Instance->CMCR |= LPCmd->AcknowledgeRequest;
  766. /* Process unlocked */
  767. __HAL_UNLOCK(hdsi);
  768. return HAL_OK;
  769. }
  770. /**
  771. * @brief Configure the flow control parameters
  772. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  773. * the configuration information for the DSI.
  774. * @param FlowControl: flow control feature(s) to be enabled.
  775. * This parameter can be any combination of @ref DSI_FlowControl.
  776. * @retval HAL status
  777. */
  778. HAL_StatusTypeDef HAL_DSI_ConfigFlowControl(DSI_HandleTypeDef *hdsi, uint32_t FlowControl)
  779. {
  780. /* Process locked */
  781. __HAL_LOCK(hdsi);
  782. /* Check the parameters */
  783. assert_param(IS_DSI_FLOW_CONTROL(FlowControl));
  784. /* Set the DSI Host Protocol Configuration Register */
  785. hdsi->Instance->PCR &= ~DSI_FLOW_CONTROL_ALL;
  786. hdsi->Instance->PCR |= FlowControl;
  787. /* Process unlocked */
  788. __HAL_UNLOCK(hdsi);
  789. return HAL_OK;
  790. }
  791. /**
  792. * @brief Configure the DSI PHY timer parameters
  793. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  794. * the configuration information for the DSI.
  795. * @param PhyTimers: DSI_PHY_TimerTypeDef structure that contains
  796. * the DSI PHY timing parameters
  797. * @retval HAL status
  798. */
  799. HAL_StatusTypeDef HAL_DSI_ConfigPhyTimer(DSI_HandleTypeDef *hdsi, DSI_PHY_TimerTypeDef *PhyTimers)
  800. {
  801. uint32_t maxTime;
  802. /* Process locked */
  803. __HAL_LOCK(hdsi);
  804. maxTime = (PhyTimers->ClockLaneLP2HSTime > PhyTimers->ClockLaneHS2LPTime)? PhyTimers->ClockLaneLP2HSTime: PhyTimers->ClockLaneHS2LPTime;
  805. /* Clock lane timer configuration */
  806. /* In Automatic Clock Lane control mode, the DSI Host can turn off the clock lane between two
  807. High-Speed transmission.
  808. To do so, the DSI Host calculates the time required for the clock lane to change from HighSpeed
  809. to Low-Power and from Low-Power to High-Speed.
  810. This timings are configured by the HS2LP_TIME and LP2HS_TIME in the DSI Host Clock Lane Timer Configuration Register (DSI_CLTCR).
  811. But the DSI Host is not calculating LP2HS_TIME + HS2LP_TIME but 2 x HS2LP_TIME.
  812. Workaround : Configure HS2LP_TIME and LP2HS_TIME with the same value being the max of HS2LP_TIME or LP2HS_TIME.
  813. */
  814. hdsi->Instance->CLTCR &= ~(DSI_CLTCR_LP2HS_TIME | DSI_CLTCR_HS2LP_TIME);
  815. hdsi->Instance->CLTCR |= (maxTime | ((maxTime)<<16U));
  816. /* Data lane timer configuration */
  817. hdsi->Instance->DLTCR &= ~(DSI_DLTCR_MRD_TIME | DSI_DLTCR_LP2HS_TIME | DSI_DLTCR_HS2LP_TIME);
  818. hdsi->Instance->DLTCR |= (PhyTimers->DataLaneMaxReadTime | ((PhyTimers->DataLaneLP2HSTime)<<16U) | ((PhyTimers->DataLaneHS2LPTime)<<24U));
  819. /* Configure the wait period to request HS transmission after a stop state */
  820. hdsi->Instance->PCONFR &= ~DSI_PCONFR_SW_TIME;
  821. hdsi->Instance->PCONFR |= ((PhyTimers->StopWaitTime)<<8U);
  822. /* Process unlocked */
  823. __HAL_UNLOCK(hdsi);
  824. return HAL_OK;
  825. }
  826. /**
  827. * @brief Configure the DSI HOST timeout parameters
  828. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  829. * the configuration information for the DSI.
  830. * @param HostTimeouts: DSI_HOST_TimeoutTypeDef structure that contains
  831. * the DSI host timeout parameters
  832. * @retval HAL status
  833. */
  834. HAL_StatusTypeDef HAL_DSI_ConfigHostTimeouts(DSI_HandleTypeDef *hdsi, DSI_HOST_TimeoutTypeDef *HostTimeouts)
  835. {
  836. /* Process locked */
  837. __HAL_LOCK(hdsi);
  838. /* Set the timeout clock division factor */
  839. hdsi->Instance->CCR &= ~DSI_CCR_TOCKDIV;
  840. hdsi->Instance->CCR |= ((HostTimeouts->TimeoutCkdiv)<<8U);
  841. /* High-speed transmission timeout */
  842. hdsi->Instance->TCCR[0U] &= ~DSI_TCCR0_HSTX_TOCNT;
  843. hdsi->Instance->TCCR[0U] |= ((HostTimeouts->HighSpeedTransmissionTimeout)<<16U);
  844. /* Low-power reception timeout */
  845. hdsi->Instance->TCCR[0U] &= ~DSI_TCCR0_LPRX_TOCNT;
  846. hdsi->Instance->TCCR[0U] |= HostTimeouts->LowPowerReceptionTimeout;
  847. /* High-speed read timeout */
  848. hdsi->Instance->TCCR[1U] &= ~DSI_TCCR1_HSRD_TOCNT;
  849. hdsi->Instance->TCCR[1U] |= HostTimeouts->HighSpeedReadTimeout;
  850. /* Low-power read timeout */
  851. hdsi->Instance->TCCR[2U] &= ~DSI_TCCR2_LPRD_TOCNT;
  852. hdsi->Instance->TCCR[2U] |= HostTimeouts->LowPowerReadTimeout;
  853. /* High-speed write timeout */
  854. hdsi->Instance->TCCR[3U] &= ~DSI_TCCR3_HSWR_TOCNT;
  855. hdsi->Instance->TCCR[3U] |= HostTimeouts->HighSpeedWriteTimeout;
  856. /* High-speed write presp mode */
  857. hdsi->Instance->TCCR[3U] &= ~DSI_TCCR3_PM;
  858. hdsi->Instance->TCCR[3U] |= HostTimeouts->HighSpeedWritePrespMode;
  859. /* Low-speed write timeout */
  860. hdsi->Instance->TCCR[4U] &= ~DSI_TCCR4_LPWR_TOCNT;
  861. hdsi->Instance->TCCR[4U] |= HostTimeouts->LowPowerWriteTimeout;
  862. /* BTA timeout */
  863. hdsi->Instance->TCCR[5U] &= ~DSI_TCCR5_BTA_TOCNT;
  864. hdsi->Instance->TCCR[5U] |= HostTimeouts->BTATimeout;
  865. /* Process unlocked */
  866. __HAL_UNLOCK(hdsi);
  867. return HAL_OK;
  868. }
  869. /**
  870. * @brief Start the DSI module
  871. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  872. * the configuration information for the DSI.
  873. * @retval HAL status
  874. */
  875. HAL_StatusTypeDef HAL_DSI_Start(DSI_HandleTypeDef *hdsi)
  876. {
  877. /* Process locked */
  878. __HAL_LOCK(hdsi);
  879. /* Enable the DSI host */
  880. __HAL_DSI_ENABLE(hdsi);
  881. /* Enable the DSI wrapper */
  882. __HAL_DSI_WRAPPER_ENABLE(hdsi);
  883. /* Process unlocked */
  884. __HAL_UNLOCK(hdsi);
  885. return HAL_OK;
  886. }
  887. /**
  888. * @brief Stop the DSI module
  889. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  890. * the configuration information for the DSI.
  891. * @retval HAL status
  892. */
  893. HAL_StatusTypeDef HAL_DSI_Stop(DSI_HandleTypeDef *hdsi)
  894. {
  895. /* Process locked */
  896. __HAL_LOCK(hdsi);
  897. /* Disable the DSI host */
  898. __HAL_DSI_DISABLE(hdsi);
  899. /* Disable the DSI wrapper */
  900. __HAL_DSI_WRAPPER_DISABLE(hdsi);
  901. /* Process unlocked */
  902. __HAL_UNLOCK(hdsi);
  903. return HAL_OK;
  904. }
  905. /**
  906. * @brief Refresh the display in command mode
  907. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  908. * the configuration information for the DSI.
  909. * @retval HAL status
  910. */
  911. HAL_StatusTypeDef HAL_DSI_Refresh(DSI_HandleTypeDef *hdsi)
  912. {
  913. /* Process locked */
  914. __HAL_LOCK(hdsi);
  915. /* Update the display */
  916. hdsi->Instance->WCR |= DSI_WCR_LTDCEN;
  917. /* Process unlocked */
  918. __HAL_UNLOCK(hdsi);
  919. return HAL_OK;
  920. }
  921. /**
  922. * @brief Controls the display color mode in Video mode
  923. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  924. * the configuration information for the DSI.
  925. * @param ColorMode: Color mode (full or 8-colors).
  926. * This parameter can be any value of @ref DSI_Color_Mode
  927. * @retval HAL status
  928. */
  929. HAL_StatusTypeDef HAL_DSI_ColorMode(DSI_HandleTypeDef *hdsi, uint32_t ColorMode)
  930. {
  931. /* Process locked */
  932. __HAL_LOCK(hdsi);
  933. /* Check the parameters */
  934. assert_param(IS_DSI_COLOR_MODE(ColorMode));
  935. /* Update the display color mode */
  936. hdsi->Instance->WCR &= ~DSI_WCR_COLM;
  937. hdsi->Instance->WCR |= ColorMode;
  938. /* Process unlocked */
  939. __HAL_UNLOCK(hdsi);
  940. return HAL_OK;
  941. }
  942. /**
  943. * @brief Control the display shutdown in Video mode
  944. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  945. * the configuration information for the DSI.
  946. * @param Shutdown: Shut-down (Display-ON or Display-OFF).
  947. * This parameter can be any value of @ref DSI_ShutDown
  948. * @retval HAL status
  949. */
  950. HAL_StatusTypeDef HAL_DSI_Shutdown(DSI_HandleTypeDef *hdsi, uint32_t Shutdown)
  951. {
  952. /* Process locked */
  953. __HAL_LOCK(hdsi);
  954. /* Check the parameters */
  955. assert_param(IS_DSI_SHUT_DOWN(Shutdown));
  956. /* Update the display Shutdown */
  957. hdsi->Instance->WCR &= ~DSI_WCR_SHTDN;
  958. hdsi->Instance->WCR |= Shutdown;
  959. /* Process unlocked */
  960. __HAL_UNLOCK(hdsi);
  961. return HAL_OK;
  962. }
  963. /**
  964. * @brief DCS or Generic short write command
  965. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  966. * the configuration information for the DSI.
  967. * @param ChannelID: Virtual channel ID.
  968. * @param Mode: DSI short packet data type.
  969. * This parameter can be any value of @ref DSI_SHORT_WRITE_PKT_Data_Type.
  970. * @param Param1: DSC command or first generic parameter.
  971. * This parameter can be any value of @ref DSI_DCS_Command or a
  972. * generic command code.
  973. * @param Param2: DSC parameter or second generic parameter.
  974. * @retval HAL status
  975. */
  976. HAL_StatusTypeDef HAL_DSI_ShortWrite(DSI_HandleTypeDef *hdsi,
  977. uint32_t ChannelID,
  978. uint32_t Mode,
  979. uint32_t Param1,
  980. uint32_t Param2)
  981. {
  982. uint32_t tickstart = 0U;
  983. /* Process locked */
  984. __HAL_LOCK(hdsi);
  985. /* Check the parameters */
  986. assert_param(IS_DSI_SHORT_WRITE_PACKET_TYPE(Mode));
  987. /* Get tick */
  988. tickstart = HAL_GetTick();
  989. /* Wait for Command FIFO Empty */
  990. while((hdsi->Instance->GPSR & DSI_GPSR_CMDFE) == 0U)
  991. {
  992. /* Check for the Timeout */
  993. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  994. {
  995. /* Process Unlocked */
  996. __HAL_UNLOCK(hdsi);
  997. return HAL_TIMEOUT;
  998. }
  999. }
  1000. /* Configure the packet to send a short DCS command with 0 or 1 parameter */
  1001. DSI_ConfigPacketHeader(hdsi->Instance,
  1002. ChannelID,
  1003. Mode,
  1004. Param1,
  1005. Param2);
  1006. /* Process unlocked */
  1007. __HAL_UNLOCK(hdsi);
  1008. return HAL_OK;
  1009. }
  1010. /**
  1011. * @brief DCS or Generic long write command
  1012. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1013. * the configuration information for the DSI.
  1014. * @param ChannelID: Virtual channel ID.
  1015. * @param Mode: DSI long packet data type.
  1016. * This parameter can be any value of @ref DSI_LONG_WRITE_PKT_Data_Type.
  1017. * @param NbParams: Number of parameters.
  1018. * @param Param1: DSC command or first generic parameter.
  1019. * This parameter can be any value of @ref DSI_DCS_Command or a
  1020. * generic command code
  1021. * @param ParametersTable: Pointer to parameter values table.
  1022. * @retval HAL status
  1023. */
  1024. HAL_StatusTypeDef HAL_DSI_LongWrite(DSI_HandleTypeDef *hdsi,
  1025. uint32_t ChannelID,
  1026. uint32_t Mode,
  1027. uint32_t NbParams,
  1028. uint32_t Param1,
  1029. uint8_t* ParametersTable)
  1030. {
  1031. uint32_t uicounter = 0U;
  1032. uint32_t tickstart = 0U;
  1033. /* Process locked */
  1034. __HAL_LOCK(hdsi);
  1035. /* Check the parameters */
  1036. assert_param(IS_DSI_LONG_WRITE_PACKET_TYPE(Mode));
  1037. /* Get tick */
  1038. tickstart = HAL_GetTick();
  1039. /* Wait for Command FIFO Empty */
  1040. while((hdsi->Instance->GPSR & DSI_GPSR_CMDFE) == RESET)
  1041. {
  1042. /* Check for the Timeout */
  1043. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1044. {
  1045. /* Process Unlocked */
  1046. __HAL_UNLOCK(hdsi);
  1047. return HAL_TIMEOUT;
  1048. }
  1049. }
  1050. /* Set the DCS code hexadecimal on payload byte 1, and the other parameters on the write FIFO command*/
  1051. while(uicounter < NbParams)
  1052. {
  1053. if(uicounter == 0x00U)
  1054. {
  1055. hdsi->Instance->GPDR=(Param1 | \
  1056. ((uint32_t)(*(ParametersTable + uicounter)) << 8U) | \
  1057. ((uint32_t)(*(ParametersTable + uicounter+1U))<<16U) | \
  1058. ((uint32_t)(*(ParametersTable + uicounter+2U))<<24U));
  1059. uicounter+=3U;
  1060. }
  1061. else
  1062. {
  1063. hdsi->Instance->GPDR=((uint32_t)(*(ParametersTable + uicounter)) | \
  1064. ((uint32_t)(*(ParametersTable + uicounter+1U)) << 8U) | \
  1065. ((uint32_t)(*(ParametersTable + uicounter+2U)) << 16U) | \
  1066. ((uint32_t)(*(ParametersTable + uicounter+3U)) << 24U));
  1067. uicounter+=4U;
  1068. }
  1069. }
  1070. /* Configure the packet to send a long DCS command */
  1071. DSI_ConfigPacketHeader(hdsi->Instance,
  1072. ChannelID,
  1073. Mode,
  1074. ((NbParams+1U)&0x00FFU),
  1075. (((NbParams+1U)&0xFF00U)>>8U));
  1076. /* Process unlocked */
  1077. __HAL_UNLOCK(hdsi);
  1078. return HAL_OK;
  1079. }
  1080. /**
  1081. * @brief Read command (DCS or generic)
  1082. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1083. * the configuration information for the DSI.
  1084. * @param ChannelNbr: Virtual channel ID
  1085. * @param Array: pointer to a buffer to store the payload of a read back operation.
  1086. * @param Size: Data size to be read (in byte).
  1087. * @param Mode: DSI read packet data type.
  1088. * This parameter can be any value of @ref DSI_SHORT_READ_PKT_Data_Type.
  1089. * @param DCSCmd: DCS get/read command.
  1090. * @param ParametersTable: Pointer to parameter values table.
  1091. * @retval HAL status
  1092. */
  1093. HAL_StatusTypeDef HAL_DSI_Read(DSI_HandleTypeDef *hdsi,
  1094. uint32_t ChannelNbr,
  1095. uint8_t* Array,
  1096. uint32_t Size,
  1097. uint32_t Mode,
  1098. uint32_t DCSCmd,
  1099. uint8_t* ParametersTable)
  1100. {
  1101. uint32_t tickstart = 0U;
  1102. /* Process locked */
  1103. __HAL_LOCK(hdsi);
  1104. /* Check the parameters */
  1105. assert_param(IS_DSI_READ_PACKET_TYPE(Mode));
  1106. if(Size > 2U)
  1107. {
  1108. /* set max return packet size */
  1109. HAL_DSI_ShortWrite(hdsi, ChannelNbr, DSI_MAX_RETURN_PKT_SIZE, ((Size)&0xFFU), (((Size)>>8U)&0xFFU));
  1110. }
  1111. /* Configure the packet to read command */
  1112. if (Mode == DSI_DCS_SHORT_PKT_READ)
  1113. {
  1114. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, DCSCmd, 0U);
  1115. }
  1116. else if (Mode == DSI_GEN_SHORT_PKT_READ_P0)
  1117. {
  1118. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, 0U, 0U);
  1119. }
  1120. else if (Mode == DSI_GEN_SHORT_PKT_READ_P1)
  1121. {
  1122. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, ParametersTable[0U], 0U);
  1123. }
  1124. else if (Mode == DSI_GEN_SHORT_PKT_READ_P2)
  1125. {
  1126. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, ParametersTable[0U], ParametersTable[1U]);
  1127. }
  1128. else
  1129. {
  1130. /* Process Unlocked */
  1131. __HAL_UNLOCK(hdsi);
  1132. return HAL_ERROR;
  1133. }
  1134. /* Get tick */
  1135. tickstart = HAL_GetTick();
  1136. /* Check that the payload read FIFO is not empty */
  1137. while((hdsi->Instance->GPSR & DSI_GPSR_PRDFE) == DSI_GPSR_PRDFE)
  1138. {
  1139. /* Check for the Timeout */
  1140. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1141. {
  1142. /* Process Unlocked */
  1143. __HAL_UNLOCK(hdsi);
  1144. return HAL_TIMEOUT;
  1145. }
  1146. }
  1147. /* Get the first byte */
  1148. *((uint32_t *)Array) = (hdsi->Instance->GPDR);
  1149. if (Size > 4U)
  1150. {
  1151. Size -= 4U;
  1152. Array += 4U;
  1153. }
  1154. else
  1155. {
  1156. /* Process unlocked */
  1157. __HAL_UNLOCK(hdsi);
  1158. return HAL_OK;
  1159. }
  1160. /* Get tick */
  1161. tickstart = HAL_GetTick();
  1162. /* Get the remaining bytes if any */
  1163. while(((int)(Size)) > 0U)
  1164. {
  1165. if((hdsi->Instance->GPSR & DSI_GPSR_PRDFE) == 0U)
  1166. {
  1167. *((uint32_t *)Array) = (hdsi->Instance->GPDR);
  1168. Size -= 4U;
  1169. Array += 4U;
  1170. }
  1171. /* Check for the Timeout */
  1172. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1173. {
  1174. /* Process Unlocked */
  1175. __HAL_UNLOCK(hdsi);
  1176. return HAL_TIMEOUT;
  1177. }
  1178. }
  1179. /* Process unlocked */
  1180. __HAL_UNLOCK(hdsi);
  1181. return HAL_OK;
  1182. }
  1183. /**
  1184. * @brief Enter the ULPM (Ultra Low Power Mode) with the D-PHY PLL running
  1185. * (only data lanes are in ULPM)
  1186. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1187. * the configuration information for the DSI.
  1188. * @retval HAL status
  1189. */
  1190. HAL_StatusTypeDef HAL_DSI_EnterULPMData(DSI_HandleTypeDef *hdsi)
  1191. {
  1192. uint32_t tickstart = 0U;
  1193. /* Process locked */
  1194. __HAL_LOCK(hdsi);
  1195. /* ULPS Request on Data Lanes */
  1196. hdsi->Instance->PUCR |= DSI_PUCR_URDL;
  1197. /* Get tick */
  1198. tickstart = HAL_GetTick();
  1199. /* Wait until the D-PHY active lanes enter into ULPM */
  1200. if((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE)
  1201. {
  1202. while((hdsi->Instance->PSR & DSI_PSR_UAN0) != RESET)
  1203. {
  1204. /* Check for the Timeout */
  1205. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1206. {
  1207. /* Process Unlocked */
  1208. __HAL_UNLOCK(hdsi);
  1209. return HAL_TIMEOUT;
  1210. }
  1211. }
  1212. }
  1213. else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES)
  1214. {
  1215. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1)) != RESET)
  1216. {
  1217. /* Check for the Timeout */
  1218. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1219. {
  1220. /* Process Unlocked */
  1221. __HAL_UNLOCK(hdsi);
  1222. return HAL_TIMEOUT;
  1223. }
  1224. }
  1225. }
  1226. /* Process unlocked */
  1227. __HAL_UNLOCK(hdsi);
  1228. return HAL_OK;
  1229. }
  1230. /**
  1231. * @brief Exit the ULPM (Ultra Low Power Mode) with the D-PHY PLL running
  1232. * (only data lanes are in ULPM)
  1233. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1234. * the configuration information for the DSI.
  1235. * @retval HAL status
  1236. */
  1237. HAL_StatusTypeDef HAL_DSI_ExitULPMData(DSI_HandleTypeDef *hdsi)
  1238. {
  1239. uint32_t tickstart = 0U;
  1240. /* Process locked */
  1241. __HAL_LOCK(hdsi);
  1242. /* Exit ULPS on Data Lanes */
  1243. hdsi->Instance->PUCR |= DSI_PUCR_UEDL;
  1244. /* Get tick */
  1245. tickstart = HAL_GetTick();
  1246. /* Wait until all active lanes exit ULPM */
  1247. if((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE)
  1248. {
  1249. while((hdsi->Instance->PSR & DSI_PSR_UAN0) != DSI_PSR_UAN0)
  1250. {
  1251. /* Check for the Timeout */
  1252. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1253. {
  1254. /* Process Unlocked */
  1255. __HAL_UNLOCK(hdsi);
  1256. return HAL_TIMEOUT;
  1257. }
  1258. }
  1259. }
  1260. else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES)
  1261. {
  1262. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1)) != (DSI_PSR_UAN0 | DSI_PSR_UAN1))
  1263. {
  1264. /* Check for the Timeout */
  1265. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1266. {
  1267. /* Process Unlocked */
  1268. __HAL_UNLOCK(hdsi);
  1269. return HAL_TIMEOUT;
  1270. }
  1271. }
  1272. }
  1273. /* De-assert the ULPM requests and the ULPM exit bits */
  1274. hdsi->Instance->PUCR = 0U;
  1275. /* Process unlocked */
  1276. __HAL_UNLOCK(hdsi);
  1277. return HAL_OK;
  1278. }
  1279. /**
  1280. * @brief Enter the ULPM (Ultra Low Power Mode) with the D-PHY PLL turned off
  1281. * (both data and clock lanes are in ULPM)
  1282. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1283. * the configuration information for the DSI.
  1284. * @retval HAL status
  1285. */
  1286. HAL_StatusTypeDef HAL_DSI_EnterULPM(DSI_HandleTypeDef *hdsi)
  1287. {
  1288. uint32_t tickstart = 0U;
  1289. /* Process locked */
  1290. __HAL_LOCK(hdsi);
  1291. /* Clock lane configuration: no more HS request */
  1292. hdsi->Instance->CLCR &= ~DSI_CLCR_DPCC;
  1293. /* Use system PLL as byte lane clock source before stopping DSIPHY clock source */
  1294. __HAL_RCC_DSI_CONFIG(RCC_DSICLKSOURCE_PLLR);
  1295. /* ULPS Request on Clock and Data Lanes */
  1296. hdsi->Instance->PUCR |= (DSI_PUCR_URCL | DSI_PUCR_URDL);
  1297. /* Get tick */
  1298. tickstart = HAL_GetTick();
  1299. /* Wait until all active lanes exit ULPM */
  1300. if((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE)
  1301. {
  1302. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UANC)) != RESET)
  1303. {
  1304. /* Check for the Timeout */
  1305. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1306. {
  1307. /* Process Unlocked */
  1308. __HAL_UNLOCK(hdsi);
  1309. return HAL_TIMEOUT;
  1310. }
  1311. }
  1312. }
  1313. else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES)
  1314. {
  1315. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1 | DSI_PSR_UANC)) != RESET)
  1316. {
  1317. /* Check for the Timeout */
  1318. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1319. {
  1320. /* Process Unlocked */
  1321. __HAL_UNLOCK(hdsi);
  1322. return HAL_TIMEOUT;
  1323. }
  1324. }
  1325. }
  1326. /* Turn off the DSI PLL */
  1327. __HAL_DSI_PLL_DISABLE(hdsi);
  1328. /* Process unlocked */
  1329. __HAL_UNLOCK(hdsi);
  1330. return HAL_OK;
  1331. }
  1332. /**
  1333. * @brief Exit the ULPM (Ultra Low Power Mode) with the D-PHY PLL turned off
  1334. * (both data and clock lanes are in ULPM)
  1335. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1336. * the configuration information for the DSI.
  1337. * @retval HAL status
  1338. */
  1339. HAL_StatusTypeDef HAL_DSI_ExitULPM(DSI_HandleTypeDef *hdsi)
  1340. {
  1341. uint32_t tickstart = 0U;
  1342. /* Process locked */
  1343. __HAL_LOCK(hdsi);
  1344. /* Turn on the DSI PLL */
  1345. __HAL_DSI_PLL_ENABLE(hdsi);
  1346. /* Get tick */
  1347. tickstart = HAL_GetTick();
  1348. /* Wait for the lock of the PLL */
  1349. while(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_PLLLS) == RESET)
  1350. {
  1351. /* Check for the Timeout */
  1352. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1353. {
  1354. /* Process Unlocked */
  1355. __HAL_UNLOCK(hdsi);
  1356. return HAL_TIMEOUT;
  1357. }
  1358. }
  1359. /* Exit ULPS on Clock and Data Lanes */
  1360. hdsi->Instance->PUCR |= (DSI_PUCR_UECL | DSI_PUCR_UEDL);
  1361. /* Get tick */
  1362. tickstart = HAL_GetTick();
  1363. /* Wait until all active lanes exit ULPM */
  1364. if((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE)
  1365. {
  1366. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UANC)) != (DSI_PSR_UAN0 | DSI_PSR_UANC))
  1367. {
  1368. /* Check for the Timeout */
  1369. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1370. {
  1371. /* Process Unlocked */
  1372. __HAL_UNLOCK(hdsi);
  1373. return HAL_TIMEOUT;
  1374. }
  1375. }
  1376. }
  1377. else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES)
  1378. {
  1379. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1 | DSI_PSR_UANC)) != (DSI_PSR_UAN0 | DSI_PSR_UAN1 | DSI_PSR_UANC))
  1380. {
  1381. /* Check for the Timeout */
  1382. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1383. {
  1384. /* Process Unlocked */
  1385. __HAL_UNLOCK(hdsi);
  1386. return HAL_TIMEOUT;
  1387. }
  1388. }
  1389. }
  1390. /* De-assert the ULPM requests and the ULPM exit bits */
  1391. hdsi->Instance->PUCR = 0U;
  1392. /* Switch the lanbyteclock source in the RCC from system PLL to D-PHY */
  1393. __HAL_RCC_DSI_CONFIG(RCC_DSICLKSOURCE_DSIPHY);
  1394. /* Restore clock lane configuration to HS */
  1395. hdsi->Instance->CLCR |= DSI_CLCR_DPCC;
  1396. /* Process unlocked */
  1397. __HAL_UNLOCK(hdsi);
  1398. return HAL_OK;
  1399. }
  1400. /**
  1401. * @brief Start test pattern generation
  1402. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1403. * the configuration information for the DSI.
  1404. * @param Mode: Pattern generator mode
  1405. * This parameter can be one of the following values:
  1406. * 0 : Color bars (horizontal or vertical)
  1407. * 1 : BER pattern (vertical only)
  1408. * @param Orientation: Pattern generator orientation
  1409. * This parameter can be one of the following values:
  1410. * 0 : Vertical color bars
  1411. * 1 : Horizontal color bars
  1412. * @retval HAL status
  1413. */
  1414. HAL_StatusTypeDef HAL_DSI_PatternGeneratorStart(DSI_HandleTypeDef *hdsi, uint32_t Mode, uint32_t Orientation)
  1415. {
  1416. /* Process locked */
  1417. __HAL_LOCK(hdsi);
  1418. /* Configure pattern generator mode and orientation */
  1419. hdsi->Instance->VMCR &= ~(DSI_VMCR_PGM | DSI_VMCR_PGO);
  1420. hdsi->Instance->VMCR |= ((Mode<<20U) | (Orientation<<24U));
  1421. /* Enable pattern generator by setting PGE bit */
  1422. hdsi->Instance->VMCR |= DSI_VMCR_PGE;
  1423. /* Process unlocked */
  1424. __HAL_UNLOCK(hdsi);
  1425. return HAL_OK;
  1426. }
  1427. /**
  1428. * @brief Stop test pattern generation
  1429. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1430. * the configuration information for the DSI.
  1431. * @retval HAL status
  1432. */
  1433. HAL_StatusTypeDef HAL_DSI_PatternGeneratorStop(DSI_HandleTypeDef *hdsi)
  1434. {
  1435. /* Process locked */
  1436. __HAL_LOCK(hdsi);
  1437. /* Disable pattern generator by clearing PGE bit */
  1438. hdsi->Instance->VMCR &= ~DSI_VMCR_PGE;
  1439. /* Process unlocked */
  1440. __HAL_UNLOCK(hdsi);
  1441. return HAL_OK;
  1442. }
  1443. /**
  1444. * @brief Set Slew-Rate And Delay Tuning
  1445. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1446. * the configuration information for the DSI.
  1447. * @param CommDelay: Communication delay to be adjusted.
  1448. * This parameter can be any value of @ref DSI_Communication_Delay
  1449. * @param Lane: select between clock or data lanes.
  1450. * This parameter can be any value of @ref DSI_Lane_Group
  1451. * @param Value: Custom value of the slew-rate or delay
  1452. * @retval HAL status
  1453. */
  1454. HAL_StatusTypeDef HAL_DSI_SetSlewRateAndDelayTuning(DSI_HandleTypeDef *hdsi, uint32_t CommDelay, uint32_t Lane, uint32_t Value)
  1455. {
  1456. /* Process locked */
  1457. __HAL_LOCK(hdsi);
  1458. /* Check function parameters */
  1459. assert_param(IS_DSI_COMMUNICATION_DELAY(CommDelay));
  1460. assert_param(IS_DSI_LANE_GROUP(Lane));
  1461. switch(CommDelay)
  1462. {
  1463. case DSI_SLEW_RATE_HSTX:
  1464. if(Lane == DSI_CLOCK_LANE)
  1465. {
  1466. /* High-Speed Transmission Slew Rate Control on Clock Lane */
  1467. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXSRCCL;
  1468. hdsi->Instance->WPCR[1U] |= Value<<16U;
  1469. }
  1470. else if(Lane == DSI_DATA_LANES)
  1471. {
  1472. /* High-Speed Transmission Slew Rate Control on Data Lanes */
  1473. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXSRCDL;
  1474. hdsi->Instance->WPCR[1U] |= Value<<18U;
  1475. }
  1476. break;
  1477. case DSI_SLEW_RATE_LPTX:
  1478. if(Lane == DSI_CLOCK_LANE)
  1479. {
  1480. /* Low-Power transmission Slew Rate Compensation on Clock Lane */
  1481. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPSRCCL;
  1482. hdsi->Instance->WPCR[1U] |= Value<<6U;
  1483. }
  1484. else if(Lane == DSI_DATA_LANES)
  1485. {
  1486. /* Low-Power transmission Slew Rate Compensation on Data Lanes */
  1487. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPSRCDL;
  1488. hdsi->Instance->WPCR[1U] |= Value<<8U;
  1489. }
  1490. break;
  1491. case DSI_HS_DELAY:
  1492. if(Lane == DSI_CLOCK_LANE)
  1493. {
  1494. /* High-Speed Transmission Delay on Clock Lane */
  1495. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXDCL;
  1496. hdsi->Instance->WPCR[1U] |= Value;
  1497. }
  1498. else if(Lane == DSI_DATA_LANES)
  1499. {
  1500. /* High-Speed Transmission Delay on Data Lanes */
  1501. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXDDL;
  1502. hdsi->Instance->WPCR[1U] |= Value<<2U;
  1503. }
  1504. break;
  1505. default:
  1506. break;
  1507. }
  1508. /* Process unlocked */
  1509. __HAL_UNLOCK(hdsi);
  1510. return HAL_OK;
  1511. }
  1512. /**
  1513. * @brief Low-Power Reception Filter Tuning
  1514. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1515. * the configuration information for the DSI.
  1516. * @param Frequency: cutoff frequency of low-pass filter at the input of LPRX
  1517. * @retval HAL status
  1518. */
  1519. HAL_StatusTypeDef HAL_DSI_SetLowPowerRXFilter(DSI_HandleTypeDef *hdsi, uint32_t Frequency)
  1520. {
  1521. /* Process locked */
  1522. __HAL_LOCK(hdsi);
  1523. /* Low-Power RX low-pass Filtering Tuning */
  1524. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPRXFT;
  1525. hdsi->Instance->WPCR[1U] |= Frequency<<25U;
  1526. /* Process unlocked */
  1527. __HAL_UNLOCK(hdsi);
  1528. return HAL_OK;
  1529. }
  1530. /**
  1531. * @brief Activate an additional current path on all lanes to meet the SDDTx parameter
  1532. * defined in the MIPI D-PHY specification
  1533. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1534. * the configuration information for the DSI.
  1535. * @param State: ENABLE or DISABLE
  1536. * @retval HAL status
  1537. */
  1538. HAL_StatusTypeDef HAL_DSI_SetSDD(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1539. {
  1540. /* Process locked */
  1541. __HAL_LOCK(hdsi);
  1542. /* Check function parameters */
  1543. assert_param(IS_FUNCTIONAL_STATE(State));
  1544. /* Activate/Disactivate additional current path on all lanes */
  1545. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_SDDC;
  1546. hdsi->Instance->WPCR[1U] |= ((uint32_t)State << 12U);
  1547. /* Process unlocked */
  1548. __HAL_UNLOCK(hdsi);
  1549. return HAL_OK;
  1550. }
  1551. /**
  1552. * @brief Custom lane pins configuration
  1553. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1554. * the configuration information for the DSI.
  1555. * @param CustomLane: Function to be applyed on selected lane.
  1556. * This parameter can be any value of @ref DSI_CustomLane
  1557. * @param Lane: select between clock or data lane 0 or data lane 1.
  1558. * This parameter can be any value of @ref DSI_Lane_Select
  1559. * @param State: ENABLE or DISABLE
  1560. * @retval HAL status
  1561. */
  1562. HAL_StatusTypeDef HAL_DSI_SetLanePinsConfiguration(DSI_HandleTypeDef *hdsi, uint32_t CustomLane, uint32_t Lane, FunctionalState State)
  1563. {
  1564. /* Process locked */
  1565. __HAL_LOCK(hdsi);
  1566. /* Check function parameters */
  1567. assert_param(IS_DSI_CUSTOM_LANE(CustomLane));
  1568. assert_param(IS_DSI_LANE(Lane));
  1569. assert_param(IS_FUNCTIONAL_STATE(State));
  1570. switch(CustomLane)
  1571. {
  1572. case DSI_SWAP_LANE_PINS:
  1573. if(Lane == DSI_CLOCK_LANE)
  1574. {
  1575. /* Swap pins on clock lane */
  1576. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWCL;
  1577. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 6U);
  1578. }
  1579. else if(Lane == DSI_DATA_LANE0)
  1580. {
  1581. /* Swap pins on data lane 0 */
  1582. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWDL0;
  1583. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 7U);
  1584. }
  1585. else if(Lane == DSI_DATA_LANE1)
  1586. {
  1587. /* Swap pins on data lane 1 */
  1588. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWDL1;
  1589. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 8U);
  1590. }
  1591. break;
  1592. case DSI_INVERT_HS_SIGNAL:
  1593. if(Lane == DSI_CLOCK_LANE)
  1594. {
  1595. /* Invert HS signal on clock lane */
  1596. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSICL;
  1597. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 9U);
  1598. }
  1599. else if(Lane == DSI_DATA_LANE0)
  1600. {
  1601. /* Invert HS signal on data lane 0 */
  1602. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSIDL0;
  1603. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 10U);
  1604. }
  1605. else if(Lane == DSI_DATA_LANE1)
  1606. {
  1607. /* Invert HS signal on data lane 1 */
  1608. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSIDL1;
  1609. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 11U);
  1610. }
  1611. break;
  1612. default:
  1613. break;
  1614. }
  1615. /* Process unlocked */
  1616. __HAL_UNLOCK(hdsi);
  1617. return HAL_OK;
  1618. }
  1619. /**
  1620. * @brief Set custom timing for the PHY
  1621. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1622. * the configuration information for the DSI.
  1623. * @param Timing: PHY timing to be adjusted.
  1624. * This parameter can be any value of @ref DSI_PHY_Timing
  1625. * @param State: ENABLE or DISABLE
  1626. * @param Value: Custom value of the timing
  1627. * @retval HAL status
  1628. */
  1629. HAL_StatusTypeDef HAL_DSI_SetPHYTimings(DSI_HandleTypeDef *hdsi, uint32_t Timing, FunctionalState State, uint32_t Value)
  1630. {
  1631. /* Process locked */
  1632. __HAL_LOCK(hdsi);
  1633. /* Check function parameters */
  1634. assert_param(IS_DSI_PHY_TIMING(Timing));
  1635. assert_param(IS_FUNCTIONAL_STATE(State));
  1636. switch(Timing)
  1637. {
  1638. case DSI_TCLK_POST:
  1639. /* Enable/Disable custom timing setting */
  1640. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKPOSTEN;
  1641. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 27U);
  1642. if(State)
  1643. {
  1644. /* Set custom value */
  1645. hdsi->Instance->WPCR[4U] &= ~DSI_WPCR4_TCLKPOST;
  1646. hdsi->Instance->WPCR[4U] |= Value & DSI_WPCR4_TCLKPOST;
  1647. }
  1648. break;
  1649. case DSI_TLPX_CLK:
  1650. /* Enable/Disable custom timing setting */
  1651. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TLPXCEN;
  1652. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 26U);
  1653. if(State)
  1654. {
  1655. /* Set custom value */
  1656. hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_TLPXC;
  1657. hdsi->Instance->WPCR[3U] |= (Value << 24U) & DSI_WPCR3_TLPXC;
  1658. }
  1659. break;
  1660. case DSI_THS_EXIT:
  1661. /* Enable/Disable custom timing setting */
  1662. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSEXITEN;
  1663. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 25U);
  1664. if(State)
  1665. {
  1666. /* Set custom value */
  1667. hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_THSEXIT;
  1668. hdsi->Instance->WPCR[3U] |= (Value << 16U) & DSI_WPCR3_THSEXIT;
  1669. }
  1670. break;
  1671. case DSI_TLPX_DATA:
  1672. /* Enable/Disable custom timing setting */
  1673. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TLPXDEN;
  1674. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 24U);
  1675. if(State)
  1676. {
  1677. /* Set custom value */
  1678. hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_TLPXD;
  1679. hdsi->Instance->WPCR[3U] |= (Value << 8U) & DSI_WPCR3_TLPXD;
  1680. }
  1681. break;
  1682. case DSI_THS_ZERO:
  1683. /* Enable/Disable custom timing setting */
  1684. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSZEROEN;
  1685. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 23U);
  1686. if(State)
  1687. {
  1688. /* Set custom value */
  1689. hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_THSZERO;
  1690. hdsi->Instance->WPCR[3U] |= Value & DSI_WPCR3_THSZERO;
  1691. }
  1692. break;
  1693. case DSI_THS_TRAIL:
  1694. /* Enable/Disable custom timing setting */
  1695. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSTRAILEN;
  1696. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 22U);
  1697. if(State)
  1698. {
  1699. /* Set custom value */
  1700. hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_THSTRAIL;
  1701. hdsi->Instance->WPCR[2U] |= (Value << 24U) & DSI_WPCR2_THSTRAIL;
  1702. }
  1703. break;
  1704. case DSI_THS_PREPARE:
  1705. /* Enable/Disable custom timing setting */
  1706. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSPREPEN;
  1707. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 21U);
  1708. if(State)
  1709. {
  1710. /* Set custom value */
  1711. hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_THSPREP;
  1712. hdsi->Instance->WPCR[2U] |= (Value << 16U) & DSI_WPCR2_THSPREP;
  1713. }
  1714. break;
  1715. case DSI_TCLK_ZERO:
  1716. /* Enable/Disable custom timing setting */
  1717. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKZEROEN;
  1718. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 20U);
  1719. if(State)
  1720. {
  1721. /* Set custom value */
  1722. hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_TCLKZERO;
  1723. hdsi->Instance->WPCR[2U] |= (Value << 8U) & DSI_WPCR2_TCLKZERO;
  1724. }
  1725. break;
  1726. case DSI_TCLK_PREPARE:
  1727. /* Enable/Disable custom timing setting */
  1728. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKPREPEN;
  1729. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 19U);
  1730. if(State)
  1731. {
  1732. /* Set custom value */
  1733. hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_TCLKPREP;
  1734. hdsi->Instance->WPCR[2U] |= Value & DSI_WPCR2_TCLKPREP;
  1735. }
  1736. break;
  1737. default:
  1738. break;
  1739. }
  1740. /* Process unlocked */
  1741. __HAL_UNLOCK(hdsi);
  1742. return HAL_OK;
  1743. }
  1744. /**
  1745. * @brief Force the Clock/Data Lane in TX Stop Mode
  1746. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1747. * the configuration information for the DSI.
  1748. * @param Lane: select between clock or data lanes.
  1749. * This parameter can be any value of @ref DSI_Lane_Group
  1750. * @param State: ENABLE or DISABLE
  1751. * @retval HAL status
  1752. */
  1753. HAL_StatusTypeDef HAL_DSI_ForceTXStopMode(DSI_HandleTypeDef *hdsi, uint32_t Lane, FunctionalState State)
  1754. {
  1755. /* Process locked */
  1756. __HAL_LOCK(hdsi);
  1757. /* Check function parameters */
  1758. assert_param(IS_DSI_LANE_GROUP(Lane));
  1759. assert_param(IS_FUNCTIONAL_STATE(State));
  1760. if(Lane == DSI_CLOCK_LANE)
  1761. {
  1762. /* Force/Unforce the Clock Lane in TX Stop Mode */
  1763. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_FTXSMCL;
  1764. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 12U);
  1765. }
  1766. else if(Lane == DSI_DATA_LANES)
  1767. {
  1768. /* Force/Unforce the Data Lanes in TX Stop Mode */
  1769. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_FTXSMDL;
  1770. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 13U);
  1771. }
  1772. /* Process unlocked */
  1773. __HAL_UNLOCK(hdsi);
  1774. return HAL_OK;
  1775. }
  1776. /**
  1777. * @brief Forces LP Receiver in Low-Power Mode
  1778. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1779. * the configuration information for the DSI.
  1780. * @param State: ENABLE or DISABLE
  1781. * @retval HAL status
  1782. */
  1783. HAL_StatusTypeDef HAL_DSI_ForceRXLowPower(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1784. {
  1785. /* Process locked */
  1786. __HAL_LOCK(hdsi);
  1787. /* Check function parameters */
  1788. assert_param(IS_FUNCTIONAL_STATE(State));
  1789. /* Force/Unforce LP Receiver in Low-Power Mode */
  1790. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_FLPRXLPM;
  1791. hdsi->Instance->WPCR[1U] |= ((uint32_t)State << 22U);
  1792. /* Process unlocked */
  1793. __HAL_UNLOCK(hdsi);
  1794. return HAL_OK;
  1795. }
  1796. /**
  1797. * @brief Force Data Lanes in RX Mode after a BTA
  1798. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1799. * the configuration information for the DSI.
  1800. * @param State: ENABLE or DISABLE
  1801. * @retval HAL status
  1802. */
  1803. HAL_StatusTypeDef HAL_DSI_ForceDataLanesInRX(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1804. {
  1805. /* Process locked */
  1806. __HAL_LOCK(hdsi);
  1807. /* Check function parameters */
  1808. assert_param(IS_FUNCTIONAL_STATE(State));
  1809. /* Force Data Lanes in RX Mode */
  1810. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TDDL;
  1811. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 16U);
  1812. /* Process unlocked */
  1813. __HAL_UNLOCK(hdsi);
  1814. return HAL_OK;
  1815. }
  1816. /**
  1817. * @brief Enable a pull-down on the lanes to prevent from floating states when unused
  1818. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1819. * the configuration information for the DSI.
  1820. * @param State: ENABLE or DISABLE
  1821. * @retval HAL status
  1822. */
  1823. HAL_StatusTypeDef HAL_DSI_SetPullDown(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1824. {
  1825. /* Process locked */
  1826. __HAL_LOCK(hdsi);
  1827. /* Check function parameters */
  1828. assert_param(IS_FUNCTIONAL_STATE(State));
  1829. /* Enable/Disable pull-down on lanes */
  1830. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_PDEN;
  1831. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 18U);
  1832. /* Process unlocked */
  1833. __HAL_UNLOCK(hdsi);
  1834. return HAL_OK;
  1835. }
  1836. /**
  1837. * @brief Switch off the contention detection on data lanes
  1838. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1839. * the configuration information for the DSI.
  1840. * @param State: ENABLE or DISABLE
  1841. * @retval HAL status
  1842. */
  1843. HAL_StatusTypeDef HAL_DSI_SetContentionDetectionOff(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1844. {
  1845. /* Process locked */
  1846. __HAL_LOCK(hdsi);
  1847. /* Check function parameters */
  1848. assert_param(IS_FUNCTIONAL_STATE(State));
  1849. /* Contention Detection on Data Lanes OFF */
  1850. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_CDOFFDL;
  1851. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 14U);
  1852. /* Process unlocked */
  1853. __HAL_UNLOCK(hdsi);
  1854. return HAL_OK;
  1855. }
  1856. /**
  1857. * @}
  1858. */
  1859. /** @defgroup DSI_Group4 Peripheral State and Errors functions
  1860. * @brief Peripheral State and Errors functions
  1861. *
  1862. @verbatim
  1863. ===============================================================================
  1864. ##### Peripheral State and Errors functions #####
  1865. ===============================================================================
  1866. [..]
  1867. This subsection provides functions allowing to
  1868. (+) Check the DSI state.
  1869. (+) Get error code.
  1870. @endverbatim
  1871. * @{
  1872. */
  1873. /**
  1874. * @brief Return the DSI state
  1875. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1876. * the configuration information for the DSI.
  1877. * @retval HAL state
  1878. */
  1879. HAL_DSI_StateTypeDef HAL_DSI_GetState(DSI_HandleTypeDef *hdsi)
  1880. {
  1881. return hdsi->State;
  1882. }
  1883. /**
  1884. * @}
  1885. */
  1886. /**
  1887. * @}
  1888. */
  1889. #endif /* STM32F469xx || STM32F479xx */
  1890. #endif /* HAL_DSI_MODULE_ENABLED */
  1891. /**
  1892. * @}
  1893. */
  1894. /**
  1895. * @}
  1896. */
  1897. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/