stm32f7xx_hal_dsi.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260
  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****/