stm32f7xx_hal_dsi.c 70 KB

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