stm32f4xx_hal_dsi.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_dsi.c
  4. * @author MCD Application Team
  5. * @version V1.4.3
  6. * @date 11-December-2015
  7. * @brief DSI HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the DSI peripheral:
  10. * + Initialization and de-initialization functions
  11. * + IO operation functions
  12. * + Peripheral Control functions
  13. * + Peripheral State and Errors functions
  14. ******************************************************************************
  15. * @attention
  16. *
  17. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  18. *
  19. * Redistribution and use in source and binary forms, with or without modification,
  20. * are permitted provided that the following conditions are met:
  21. * 1. Redistributions of source code must retain the above copyright notice,
  22. * this list of conditions and the following disclaimer.
  23. * 2. Redistributions in binary form must reproduce the above copyright notice,
  24. * this list of conditions and the following disclaimer in the documentation
  25. * and/or other materials provided with the distribution.
  26. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  27. * may be used to endorse or promote products derived from this software
  28. * without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  34. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  36. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  37. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  38. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ******************************************************************************
  42. */
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f4xx_hal.h"
  45. /** @addtogroup STM32F4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup DSI
  49. * @{
  50. */
  51. #ifdef HAL_DSI_MODULE_ENABLED
  52. #if defined(STM32F469xx) || defined(STM32F479xx)
  53. /* Private types -------------------------------------------------------------*/
  54. /* Private defines -----------------------------------------------------------*/
  55. /** @addtogroup DSI_Private_Constants
  56. * @{
  57. */
  58. #define DSI_TIMEOUT_VALUE ((uint32_t)1000) /* 1s */
  59. #define DSI_ERROR_ACK_MASK (DSI_ISR0_AE0 | DSI_ISR0_AE1 | DSI_ISR0_AE2 | DSI_ISR0_AE3 | \
  60. DSI_ISR0_AE4 | DSI_ISR0_AE5 | DSI_ISR0_AE6 | DSI_ISR0_AE7 | \
  61. DSI_ISR0_AE8 | DSI_ISR0_AE9 | DSI_ISR0_AE10 | DSI_ISR0_AE11 | \
  62. DSI_ISR0_AE12 | DSI_ISR0_AE13 | DSI_ISR0_AE14 | DSI_ISR0_AE15)
  63. #define DSI_ERROR_PHY_MASK (DSI_ISR0_PE0 | DSI_ISR0_PE1 | DSI_ISR0_PE2 | DSI_ISR0_PE3 | DSI_ISR0_PE4)
  64. #define DSI_ERROR_TX_MASK DSI_ISR1_TOHSTX
  65. #define DSI_ERROR_RX_MASK DSI_ISR1_TOLPRX
  66. #define DSI_ERROR_ECC_MASK (DSI_ISR1_ECCSE | DSI_ISR1_ECCME)
  67. #define DSI_ERROR_CRC_MASK DSI_ISR1_CRCE
  68. #define DSI_ERROR_PSE_MASK DSI_ISR1_PSE
  69. #define DSI_ERROR_EOT_MASK DSI_ISR1_EOTPE
  70. #define DSI_ERROR_OVF_MASK DSI_ISR1_LPWRE
  71. #define DSI_ERROR_GEN_MASK (DSI_ISR1_GCWRE | DSI_ISR1_GPWRE | DSI_ISR1_GPTXE | DSI_ISR1_GPRDE | DSI_ISR1_GPRXE)
  72. /**
  73. * @}
  74. */
  75. /* Private variables ---------------------------------------------------------*/
  76. /* Private constants ---------------------------------------------------------*/
  77. /* Private macros ------------------------------------------------------------*/
  78. /* Private function prototypes -----------------------------------------------*/
  79. static void DSI_ConfigPacketHeader(DSI_TypeDef *DSIx, uint32_t ChannelID, uint32_t DataType, uint32_t Data0, uint32_t Data1);
  80. /* Private functions ---------------------------------------------------------*/
  81. /**
  82. * @brief Generic DSI packet header configuration
  83. * @param DSIx: Pointer to DSI register base
  84. * @param ChannelID: Virtual channel ID of the header packet
  85. * @param DataType: Packet data type of the header packet
  86. * This parameter can be any value of :
  87. * @ref DSI_SHORT_WRITE_PKT_Data_Type
  88. * or @ref DSI_LONG_WRITE_PKT_Data_Type
  89. * or @ref DSI_SHORT_READ_PKT_Data_Type
  90. * or DSI_MAX_RETURN_PKT_SIZE
  91. * @param Data0: Word count LSB
  92. * @param Data1: Word count MSB
  93. * @retval None
  94. */
  95. static void DSI_ConfigPacketHeader(DSI_TypeDef *DSIx,
  96. uint32_t ChannelID,
  97. uint32_t DataType,
  98. uint32_t Data0,
  99. uint32_t Data1)
  100. {
  101. /* Update the DSI packet header with new information */
  102. DSIx->GHCR = (DataType | (ChannelID<<6) | (Data0<<8) | (Data1<<16));
  103. }
  104. /* Exported functions --------------------------------------------------------*/
  105. /** @addtogroup DSI_Exported_Functions
  106. * @{
  107. */
  108. /** @defgroup DSI_Group1 Initialization and Configuration functions
  109. * @brief Initialization and Configuration functions
  110. *
  111. @verbatim
  112. ===============================================================================
  113. ##### Initialization and Configuration functions #####
  114. ===============================================================================
  115. [..] This section provides functions allowing to:
  116. (+) Initialize and configure the DSI
  117. (+) De-initialize the DSI
  118. @endverbatim
  119. * @{
  120. */
  121. /**
  122. * @brief Initializes the DSI according to the specified
  123. * parameters in the DSI_InitTypeDef and create the associated handle.
  124. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  125. * the configuration information for the DSI.
  126. * @param PLLInit: pointer to a DSI_PLLInitTypeDef structure that contains
  127. * the PLL Clock structure definition for the DSI.
  128. * @retval HAL status
  129. */
  130. HAL_StatusTypeDef HAL_DSI_Init(DSI_HandleTypeDef *hdsi, DSI_PLLInitTypeDef *PLLInit)
  131. {
  132. uint32_t tickstart = 0;
  133. uint32_t unitIntervalx4 = 0;
  134. uint32_t tempIDF = 0;
  135. /* Check the DSI handle allocation */
  136. if(hdsi == NULL)
  137. {
  138. return HAL_ERROR;
  139. }
  140. /* Check function parameters */
  141. assert_param(IS_DSI_PLL_NDIV(PLLInit->PLLNDIV));
  142. assert_param(IS_DSI_PLL_IDF(PLLInit->PLLIDF));
  143. assert_param(IS_DSI_PLL_ODF(PLLInit->PLLODF));
  144. assert_param(IS_DSI_AUTO_CLKLANE_CONTROL(hdsi->Init.AutomaticClockLaneControl));
  145. assert_param(IS_DSI_NUMBER_OF_LANES(hdsi->Init.NumberOfLanes));
  146. if(hdsi->State == HAL_DSI_STATE_RESET)
  147. {
  148. /* Initialize the low level hardware */
  149. HAL_DSI_MspInit(hdsi);
  150. }
  151. /* Change DSI peripheral state */
  152. hdsi->State = HAL_DSI_STATE_BUSY;
  153. /**************** Turn on the regulator and enable the DSI PLL ****************/
  154. /* Enable the regulator */
  155. __HAL_DSI_REG_ENABLE(hdsi);
  156. /* Get tick */
  157. tickstart = HAL_GetTick();
  158. /* Wait until the regulator is ready */
  159. while(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_RRS) == RESET)
  160. {
  161. /* Check for the Timeout */
  162. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  163. {
  164. return HAL_TIMEOUT;
  165. }
  166. }
  167. /* Set the PLL division factors */
  168. hdsi->Instance->WRPCR &= ~(DSI_WRPCR_PLL_NDIV | DSI_WRPCR_PLL_IDF | DSI_WRPCR_PLL_ODF);
  169. hdsi->Instance->WRPCR |= (((PLLInit->PLLNDIV)<<2) | ((PLLInit->PLLIDF)<<11) | ((PLLInit->PLLODF)<<16));
  170. /* Enable the DSI PLL */
  171. __HAL_DSI_PLL_ENABLE(hdsi);
  172. /* Get tick */
  173. tickstart = HAL_GetTick();
  174. /* Wait for the lock of the PLL */
  175. while(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_PLLLS) == RESET)
  176. {
  177. /* Check for the Timeout */
  178. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  179. {
  180. return HAL_TIMEOUT;
  181. }
  182. }
  183. /*************************** Set the PHY parameters ***************************/
  184. /* D-PHY clock and digital enable*/
  185. hdsi->Instance->PCTLR |= (DSI_PCTLR_CKE | DSI_PCTLR_DEN);
  186. /* Clock lane configuration */
  187. hdsi->Instance->CLCR &= ~(DSI_CLCR_DPCC | DSI_CLCR_ACR);
  188. hdsi->Instance->CLCR |= (DSI_CLCR_DPCC | hdsi->Init.AutomaticClockLaneControl);
  189. /* Configure the number of active data lanes */
  190. hdsi->Instance->PCONFR &= ~DSI_PCONFR_NL;
  191. hdsi->Instance->PCONFR |= hdsi->Init.NumberOfLanes;
  192. /************************ Set the DSI clock parameters ************************/
  193. /* Set the TX escape clock division factor */
  194. hdsi->Instance->CCR &= ~DSI_CCR_TXECKDIV;
  195. hdsi->Instance->CCR = hdsi->Init.TXEscapeCkdiv;
  196. /* Calculate the bit period in high-speed mode in unit of 0.25 ns (UIX4) */
  197. /* The equation is : UIX4 = IntegerPart( (1000/F_PHY_Mhz) * 4 ) */
  198. /* Where : F_PHY_Mhz = (NDIV * HSE_Mhz) / (IDF * ODF) */
  199. tempIDF = (PLLInit->PLLIDF > 0) ? PLLInit->PLLIDF : 1;
  200. unitIntervalx4 = (4000000 * tempIDF * (1 << PLLInit->PLLODF)) / ((HSE_VALUE/1000) * PLLInit->PLLNDIV);
  201. /* Set the bit period in high-speed mode */
  202. hdsi->Instance->WPCR[0] &= ~DSI_WPCR0_UIX4;
  203. hdsi->Instance->WPCR[0] |= unitIntervalx4;
  204. /****************************** Error management *****************************/
  205. /* Disable all error interrupts and reset the Error Mask */
  206. hdsi->Instance->IER[0] = 0;
  207. hdsi->Instance->IER[1] = 0;
  208. hdsi->ErrorMsk = 0;
  209. /* Initialise the error code */
  210. hdsi->ErrorCode = HAL_DSI_ERROR_NONE;
  211. /* Initialize the DSI state*/
  212. hdsi->State = HAL_DSI_STATE_READY;
  213. return HAL_OK;
  214. }
  215. /**
  216. * @brief De-initializes the DSI peripheral registers to their default reset
  217. * values.
  218. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  219. * the configuration information for the DSI.
  220. * @retval HAL status
  221. */
  222. HAL_StatusTypeDef HAL_DSI_DeInit(DSI_HandleTypeDef *hdsi)
  223. {
  224. /* Check the DSI handle allocation */
  225. if(hdsi == NULL)
  226. {
  227. return HAL_ERROR;
  228. }
  229. /* Change DSI peripheral state */
  230. hdsi->State = HAL_DSI_STATE_BUSY;
  231. /* Disable the DSI wrapper */
  232. __HAL_DSI_WRAPPER_DISABLE(hdsi);
  233. /* Disable the DSI host */
  234. __HAL_DSI_DISABLE(hdsi);
  235. /* D-PHY clock and digital disable */
  236. hdsi->Instance->PCTLR &= ~(DSI_PCTLR_CKE | DSI_PCTLR_DEN);
  237. /* Turn off the DSI PLL */
  238. __HAL_DSI_PLL_DISABLE(hdsi);
  239. /* Disable the regulator */
  240. __HAL_DSI_REG_DISABLE(hdsi);
  241. /* DeInit the low level hardware */
  242. HAL_DSI_MspDeInit(hdsi);
  243. /* Initialise the error code */
  244. hdsi->ErrorCode = HAL_DSI_ERROR_NONE;
  245. /* Initialize the DSI state*/
  246. hdsi->State = HAL_DSI_STATE_RESET;
  247. /* Release Lock */
  248. __HAL_UNLOCK(hdsi);
  249. return HAL_OK;
  250. }
  251. /**
  252. * @brief Return the DSI error code
  253. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  254. * the configuration information for the DSI.
  255. * @retval DSI Error Code
  256. */
  257. uint32_t HAL_DSI_GetError(DSI_HandleTypeDef *hdsi)
  258. {
  259. /* Get the error code */
  260. return hdsi->ErrorCode;
  261. }
  262. /**
  263. * @brief Enable the error monitor flags
  264. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  265. * the configuration information for the DSI.
  266. * @param ActiveErrors: indicates which error interrupts will be enabled.
  267. * This parameter can be any combination of @ref DSI_Error_Data_Type.
  268. * @retval HAL status
  269. */
  270. HAL_StatusTypeDef HAL_DSI_ConfigErrorMonitor(DSI_HandleTypeDef *hdsi, uint32_t ActiveErrors)
  271. {
  272. /* Process locked */
  273. __HAL_LOCK(hdsi);
  274. hdsi->Instance->IER[0] = 0;
  275. hdsi->Instance->IER[1] = 0;
  276. /* Store active errors to the handle */
  277. hdsi->ErrorMsk = ActiveErrors;
  278. if(ActiveErrors & HAL_DSI_ERROR_ACK)
  279. {
  280. /* Enable the interrupt generation on selected errors */
  281. hdsi->Instance->IER[0] |= DSI_ERROR_ACK_MASK;
  282. }
  283. if(ActiveErrors & HAL_DSI_ERROR_PHY)
  284. {
  285. /* Enable the interrupt generation on selected errors */
  286. hdsi->Instance->IER[0] |= DSI_ERROR_PHY_MASK;
  287. }
  288. if(ActiveErrors & HAL_DSI_ERROR_TX)
  289. {
  290. /* Enable the interrupt generation on selected errors */
  291. hdsi->Instance->IER[1] |= DSI_ERROR_TX_MASK;
  292. }
  293. if(ActiveErrors & HAL_DSI_ERROR_RX)
  294. {
  295. /* Enable the interrupt generation on selected errors */
  296. hdsi->Instance->IER[1] |= DSI_ERROR_RX_MASK;
  297. }
  298. if(ActiveErrors & HAL_DSI_ERROR_ECC)
  299. {
  300. /* Enable the interrupt generation on selected errors */
  301. hdsi->Instance->IER[1] |= DSI_ERROR_ECC_MASK;
  302. }
  303. if(ActiveErrors & HAL_DSI_ERROR_CRC)
  304. {
  305. /* Enable the interrupt generation on selected errors */
  306. hdsi->Instance->IER[1] |= DSI_ERROR_CRC_MASK;
  307. }
  308. if(ActiveErrors & HAL_DSI_ERROR_PSE)
  309. {
  310. /* Enable the interrupt generation on selected errors */
  311. hdsi->Instance->IER[1] |= DSI_ERROR_PSE_MASK;
  312. }
  313. if(ActiveErrors & HAL_DSI_ERROR_EOT)
  314. {
  315. /* Enable the interrupt generation on selected errors */
  316. hdsi->Instance->IER[1] |= DSI_ERROR_EOT_MASK;
  317. }
  318. if(ActiveErrors & HAL_DSI_ERROR_OVF)
  319. {
  320. /* Enable the interrupt generation on selected errors */
  321. hdsi->Instance->IER[1] |= DSI_ERROR_OVF_MASK;
  322. }
  323. if(ActiveErrors & HAL_DSI_ERROR_GEN)
  324. {
  325. /* Enable the interrupt generation on selected errors */
  326. hdsi->Instance->IER[1] |= DSI_ERROR_GEN_MASK;
  327. }
  328. /* Process Unlocked */
  329. __HAL_UNLOCK(hdsi);
  330. return HAL_OK;
  331. }
  332. /**
  333. * @brief Initializes the DSI MSP.
  334. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  335. * the configuration information for the DSI.
  336. * @retval None
  337. */
  338. __weak void HAL_DSI_MspInit(DSI_HandleTypeDef* hdsi)
  339. {
  340. /* Prevent unused argument(s) compilation warning */
  341. UNUSED(hdsi);
  342. /* NOTE : This function Should not be modified, when the callback is needed,
  343. the HAL_DSI_MspInit could be implemented in the user file
  344. */
  345. }
  346. /**
  347. * @brief De-initializes the DSI MSP.
  348. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  349. * the configuration information for the DSI.
  350. * @retval None
  351. */
  352. __weak void HAL_DSI_MspDeInit(DSI_HandleTypeDef* hdsi)
  353. {
  354. /* Prevent unused argument(s) compilation warning */
  355. UNUSED(hdsi);
  356. /* NOTE : This function Should not be modified, when the callback is needed,
  357. the HAL_DSI_MspDeInit could be implemented in the user file
  358. */
  359. }
  360. /**
  361. * @}
  362. */
  363. /** @defgroup DSI_Group2 IO operation functions
  364. * @brief IO operation functions
  365. *
  366. @verbatim
  367. ===============================================================================
  368. ##### IO operation functions #####
  369. ===============================================================================
  370. [..] This section provides function allowing to:
  371. (+) Handle DSI interrupt request
  372. @endverbatim
  373. * @{
  374. */
  375. /**
  376. * @brief Handles DSI interrupt request.
  377. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  378. * the configuration information for the DSI.
  379. * @retval HAL status
  380. */
  381. void HAL_DSI_IRQHandler(DSI_HandleTypeDef *hdsi)
  382. {
  383. uint32_t ErrorStatus0, ErrorStatus1;
  384. /* Tearing Effect Interrupt management ***************************************/
  385. if(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_TE) != RESET)
  386. {
  387. if(__HAL_DSI_GET_IT_SOURCE(hdsi, DSI_IT_TE) != RESET)
  388. {
  389. /* Clear the Tearing Effect Interrupt Flag */
  390. __HAL_DSI_CLEAR_FLAG(hdsi, DSI_FLAG_TE);
  391. /* Tearing Effect Callback */
  392. HAL_DSI_TearingEffectCallback(hdsi);
  393. }
  394. }
  395. /* End of Refresh Interrupt management ***************************************/
  396. if(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_ER) != RESET)
  397. {
  398. if(__HAL_DSI_GET_IT_SOURCE(hdsi, DSI_IT_ER) != RESET)
  399. {
  400. /* Clear the End of Refresh Interrupt Flag */
  401. __HAL_DSI_CLEAR_FLAG(hdsi, DSI_FLAG_ER);
  402. /* End of Refresh Callback */
  403. HAL_DSI_EndOfRefreshCallback(hdsi);
  404. }
  405. }
  406. /* Error Interrupts management ***********************************************/
  407. if(hdsi->ErrorMsk != 0)
  408. {
  409. ErrorStatus0 = hdsi->Instance->ISR[0];
  410. ErrorStatus0 &= hdsi->Instance->IER[0];
  411. ErrorStatus1 = hdsi->Instance->ISR[1];
  412. ErrorStatus1 &= hdsi->Instance->IER[1];
  413. if(ErrorStatus0 & DSI_ERROR_ACK_MASK)
  414. {
  415. hdsi->ErrorCode |= HAL_DSI_ERROR_ACK;
  416. }
  417. if(ErrorStatus0 & DSI_ERROR_PHY_MASK)
  418. {
  419. hdsi->ErrorCode |= HAL_DSI_ERROR_PHY;
  420. }
  421. if(ErrorStatus1 & DSI_ERROR_TX_MASK)
  422. {
  423. hdsi->ErrorCode |= HAL_DSI_ERROR_TX;
  424. }
  425. if(ErrorStatus1 & DSI_ERROR_RX_MASK)
  426. {
  427. hdsi->ErrorCode |= HAL_DSI_ERROR_RX;
  428. }
  429. if(ErrorStatus1 & DSI_ERROR_ECC_MASK)
  430. {
  431. hdsi->ErrorCode |= HAL_DSI_ERROR_ECC;
  432. }
  433. if(ErrorStatus1 & DSI_ERROR_CRC_MASK)
  434. {
  435. hdsi->ErrorCode |= HAL_DSI_ERROR_CRC;
  436. }
  437. if(ErrorStatus1 & DSI_ERROR_PSE_MASK)
  438. {
  439. hdsi->ErrorCode |= HAL_DSI_ERROR_PSE;
  440. }
  441. if(ErrorStatus1 & DSI_ERROR_EOT_MASK)
  442. {
  443. hdsi->ErrorCode |= HAL_DSI_ERROR_EOT;
  444. }
  445. if(ErrorStatus1 & DSI_ERROR_OVF_MASK)
  446. {
  447. hdsi->ErrorCode |= HAL_DSI_ERROR_OVF;
  448. }
  449. if(ErrorStatus1 & DSI_ERROR_GEN_MASK)
  450. {
  451. hdsi->ErrorCode |= HAL_DSI_ERROR_GEN;
  452. }
  453. /* Check only selected errors */
  454. if(hdsi->ErrorCode != HAL_DSI_ERROR_NONE)
  455. {
  456. /* DSI error interrupt user callback */
  457. HAL_DSI_ErrorCallback(hdsi);
  458. }
  459. }
  460. }
  461. /**
  462. * @brief Tearing Effect DSI callback.
  463. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  464. * the configuration information for the DSI.
  465. * @retval None
  466. */
  467. __weak void HAL_DSI_TearingEffectCallback(DSI_HandleTypeDef *hdsi)
  468. {
  469. /* Prevent unused argument(s) compilation warning */
  470. UNUSED(hdsi);
  471. /* NOTE : This function Should not be modified, when the callback is needed,
  472. the HAL_DSI_TearingEffectCallback could be implemented in the user file
  473. */
  474. }
  475. /**
  476. * @brief End of Refresh DSI callback.
  477. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  478. * the configuration information for the DSI.
  479. * @retval None
  480. */
  481. __weak void HAL_DSI_EndOfRefreshCallback(DSI_HandleTypeDef *hdsi)
  482. {
  483. /* Prevent unused argument(s) compilation warning */
  484. UNUSED(hdsi);
  485. /* NOTE : This function Should not be modified, when the callback is needed,
  486. the HAL_DSI_EndOfRefreshCallback could be implemented in the user file
  487. */
  488. }
  489. /**
  490. * @brief Operation Error DSI callback.
  491. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  492. * the configuration information for the DSI.
  493. * @retval None
  494. */
  495. __weak void HAL_DSI_ErrorCallback(DSI_HandleTypeDef *hdsi)
  496. {
  497. /* Prevent unused argument(s) compilation warning */
  498. UNUSED(hdsi);
  499. /* NOTE : This function Should not be modified, when the callback is needed,
  500. the HAL_DSI_ErrorCallback could be implemented in the user file
  501. */
  502. }
  503. /**
  504. * @}
  505. */
  506. /** @defgroup DSI_Group3 Peripheral Control functions
  507. * @brief Peripheral Control functions
  508. *
  509. @verbatim
  510. ===============================================================================
  511. ##### Peripheral Control functions #####
  512. ===============================================================================
  513. [..] This section provides functions allowing to:
  514. (+)
  515. (+)
  516. (+)
  517. @endverbatim
  518. * @{
  519. */
  520. /**
  521. * @brief Configure the Generic interface read-back Virtual Channel ID.
  522. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  523. * the configuration information for the DSI.
  524. * @param VirtualChannelID: Virtual channel ID
  525. * @retval HAL status
  526. */
  527. HAL_StatusTypeDef HAL_DSI_SetGenericVCID(DSI_HandleTypeDef *hdsi, uint32_t VirtualChannelID)
  528. {
  529. /* Process locked */
  530. __HAL_LOCK(hdsi);
  531. /* Update the GVCID register */
  532. hdsi->Instance->GVCIDR &= ~DSI_GVCIDR_VCID;
  533. hdsi->Instance->GVCIDR |= VirtualChannelID;
  534. /* Process unlocked */
  535. __HAL_UNLOCK(hdsi);
  536. return HAL_OK;
  537. }
  538. /**
  539. * @brief Select video mode and configure the corresponding parameters
  540. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  541. * the configuration information for the DSI.
  542. * @param VidCfg: pointer to a DSI_VidCfgTypeDef structure that contains
  543. * the DSI video mode configuration parameters
  544. * @retval HAL status
  545. */
  546. HAL_StatusTypeDef HAL_DSI_ConfigVideoMode(DSI_HandleTypeDef *hdsi, DSI_VidCfgTypeDef *VidCfg)
  547. {
  548. /* Process locked */
  549. __HAL_LOCK(hdsi);
  550. /* Check the parameters */
  551. assert_param(IS_DSI_COLOR_CODING(VidCfg->ColorCoding));
  552. assert_param(IS_DSI_VIDEO_MODE_TYPE(VidCfg->Mode));
  553. assert_param(IS_DSI_LP_COMMAND(VidCfg->LPCommandEnable));
  554. assert_param(IS_DSI_LP_HFP(VidCfg->LPHorizontalFrontPorchEnable));
  555. assert_param(IS_DSI_LP_HBP(VidCfg->LPHorizontalBackPorchEnable));
  556. assert_param(IS_DSI_LP_VACTIVE(VidCfg->LPVerticalActiveEnable));
  557. assert_param(IS_DSI_LP_VFP(VidCfg->LPVerticalFrontPorchEnable));
  558. assert_param(IS_DSI_LP_VBP(VidCfg->LPVerticalBackPorchEnable));
  559. assert_param(IS_DSI_LP_VSYNC(VidCfg->LPVerticalSyncActiveEnable));
  560. assert_param(IS_DSI_FBTAA(VidCfg->FrameBTAAcknowledgeEnable));
  561. assert_param(IS_DSI_DE_POLARITY(VidCfg->DEPolarity));
  562. assert_param(IS_DSI_VSYNC_POLARITY(VidCfg->VSPolarity));
  563. assert_param(IS_DSI_HSYNC_POLARITY(VidCfg->HSPolarity));
  564. /* Check the LooselyPacked variant only in 18-bit mode */
  565. if(VidCfg->ColorCoding == DSI_RGB666)
  566. {
  567. assert_param(IS_DSI_LOOSELY_PACKED(VidCfg->LooselyPacked));
  568. }
  569. /* Select video mode by resetting CMDM and DSIM bits */
  570. hdsi->Instance->MCR &= ~DSI_MCR_CMDM;
  571. hdsi->Instance->WCFGR &= ~DSI_WCFGR_DSIM;
  572. /* Configure the video mode transmission type */
  573. hdsi->Instance->VMCR &= ~DSI_VMCR_VMT;
  574. hdsi->Instance->VMCR |= VidCfg->Mode;
  575. /* Configure the video packet size */
  576. hdsi->Instance->VPCR &= ~DSI_VPCR_VPSIZE;
  577. hdsi->Instance->VPCR |= VidCfg->PacketSize;
  578. /* Set the chunks number to be transmitted through the DSI link */
  579. hdsi->Instance->VCCR &= ~DSI_VCCR_NUMC;
  580. hdsi->Instance->VCCR |= VidCfg->NumberOfChunks;
  581. /* Set the size of the null packet */
  582. hdsi->Instance->VNPCR &= ~DSI_VNPCR_NPSIZE;
  583. hdsi->Instance->VNPCR |= VidCfg->NullPacketSize;
  584. /* Select the virtual channel for the LTDC interface traffic */
  585. hdsi->Instance->LVCIDR &= ~DSI_LVCIDR_VCID;
  586. hdsi->Instance->LVCIDR |= VidCfg->VirtualChannelID;
  587. /* Configure the polarity of control signals */
  588. hdsi->Instance->LPCR &= ~(DSI_LPCR_DEP | DSI_LPCR_VSP | DSI_LPCR_HSP);
  589. hdsi->Instance->LPCR |= (VidCfg->DEPolarity | VidCfg->VSPolarity | VidCfg->HSPolarity);
  590. /* Select the color coding for the host */
  591. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_COLC;
  592. hdsi->Instance->LCOLCR |= VidCfg->ColorCoding;
  593. /* Select the color coding for the wrapper */
  594. hdsi->Instance->WCFGR &= ~DSI_WCFGR_COLMUX;
  595. hdsi->Instance->WCFGR |= ((VidCfg->ColorCoding)<<1);
  596. /* Enable/disable the loosely packed variant to 18-bit configuration */
  597. if(VidCfg->ColorCoding == DSI_RGB666)
  598. {
  599. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_LPE;
  600. hdsi->Instance->LCOLCR |= VidCfg->LooselyPacked;
  601. }
  602. /* Set the Horizontal Synchronization Active (HSA) in lane byte clock cycles */
  603. hdsi->Instance->VHSACR &= ~DSI_VHSACR_HSA;
  604. hdsi->Instance->VHSACR |= VidCfg->HorizontalSyncActive;
  605. /* Set the Horizontal Back Porch (HBP) in lane byte clock cycles */
  606. hdsi->Instance->VHBPCR &= ~DSI_VHBPCR_HBP;
  607. hdsi->Instance->VHBPCR |= VidCfg->HorizontalBackPorch;
  608. /* Set the total line time (HLINE=HSA+HBP+HACT+HFP) in lane byte clock cycles */
  609. hdsi->Instance->VLCR &= ~DSI_VLCR_HLINE;
  610. hdsi->Instance->VLCR |= VidCfg->HorizontalLine;
  611. /* Set the Vertical Synchronization Active (VSA) */
  612. hdsi->Instance->VVSACR &= ~DSI_VVSACR_VSA;
  613. hdsi->Instance->VVSACR |= VidCfg->VerticalSyncActive;
  614. /* Set the Vertical Back Porch (VBP)*/
  615. hdsi->Instance->VVBPCR &= ~DSI_VVBPCR_VBP;
  616. hdsi->Instance->VVBPCR |= VidCfg->VerticalBackPorch;
  617. /* Set the Vertical Front Porch (VFP)*/
  618. hdsi->Instance->VVFPCR &= ~DSI_VVFPCR_VFP;
  619. hdsi->Instance->VVFPCR |= VidCfg->VerticalFrontPorch;
  620. /* Set the Vertical Active period*/
  621. hdsi->Instance->VVACR &= ~DSI_VVACR_VA;
  622. hdsi->Instance->VVACR |= VidCfg->VerticalActive;
  623. /* Configure the command transmission mode */
  624. hdsi->Instance->VMCR &= ~DSI_VMCR_LPCE;
  625. hdsi->Instance->VMCR |= VidCfg->LPCommandEnable;
  626. /* Low power largest packet size */
  627. hdsi->Instance->LPMCR &= ~DSI_LPMCR_LPSIZE;
  628. hdsi->Instance->LPMCR |= ((VidCfg->LPLargestPacketSize)<<16);
  629. /* Low power VACT largest packet size */
  630. hdsi->Instance->LPMCR &= ~DSI_LPMCR_VLPSIZE;
  631. hdsi->Instance->LPMCR |= VidCfg->LPVACTLargestPacketSize;
  632. /* Enable LP transition in HFP period */
  633. hdsi->Instance->VMCR &= ~DSI_VMCR_LPHFPE;
  634. hdsi->Instance->VMCR |= VidCfg->LPHorizontalFrontPorchEnable;
  635. /* Enable LP transition in HBP period */
  636. hdsi->Instance->VMCR &= ~DSI_VMCR_LPHBPE;
  637. hdsi->Instance->VMCR |= VidCfg->LPHorizontalBackPorchEnable;
  638. /* Enable LP transition in VACT period */
  639. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVAE;
  640. hdsi->Instance->VMCR |= VidCfg->LPVerticalActiveEnable;
  641. /* Enable LP transition in VFP period */
  642. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVFPE;
  643. hdsi->Instance->VMCR |= VidCfg->LPVerticalFrontPorchEnable;
  644. /* Enable LP transition in VBP period */
  645. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVBPE;
  646. hdsi->Instance->VMCR |= VidCfg->LPVerticalBackPorchEnable;
  647. /* Enable LP transition in vertical sync period */
  648. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVSAE;
  649. hdsi->Instance->VMCR |= VidCfg->LPVerticalSyncActiveEnable;
  650. /* Enable the request for an acknowledge response at the end of a frame */
  651. hdsi->Instance->VMCR &= ~DSI_VMCR_FBTAAE;
  652. hdsi->Instance->VMCR |= VidCfg->FrameBTAAcknowledgeEnable;
  653. /* Process unlocked */
  654. __HAL_UNLOCK(hdsi);
  655. return HAL_OK;
  656. }
  657. /**
  658. * @brief Select adapted command mode and configure the corresponding parameters
  659. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  660. * the configuration information for the DSI.
  661. * @param CmdCfg: pointer to a DSI_CmdCfgTypeDef structure that contains
  662. * the DSI command mode configuration parameters
  663. * @retval HAL status
  664. */
  665. HAL_StatusTypeDef HAL_DSI_ConfigAdaptedCommandMode(DSI_HandleTypeDef *hdsi, DSI_CmdCfgTypeDef *CmdCfg)
  666. {
  667. /* Process locked */
  668. __HAL_LOCK(hdsi);
  669. /* Check the parameters */
  670. assert_param(IS_DSI_COLOR_CODING(CmdCfg->ColorCoding));
  671. assert_param(IS_DSI_TE_SOURCE(CmdCfg->TearingEffectSource));
  672. assert_param(IS_DSI_TE_POLARITY(CmdCfg->TearingEffectPolarity));
  673. assert_param(IS_DSI_AUTOMATIC_REFRESH(CmdCfg->AutomaticRefresh));
  674. assert_param(IS_DSI_VS_POLARITY(CmdCfg->VSyncPol));
  675. assert_param(IS_DSI_TE_ACK_REQUEST(CmdCfg->TEAcknowledgeRequest));
  676. assert_param(IS_DSI_DE_POLARITY(CmdCfg->DEPolarity));
  677. assert_param(IS_DSI_VSYNC_POLARITY(CmdCfg->VSPolarity));
  678. assert_param(IS_DSI_HSYNC_POLARITY(CmdCfg->HSPolarity));
  679. /* Select command mode by setting CMDM and DSIM bits */
  680. hdsi->Instance->MCR |= DSI_MCR_CMDM;
  681. hdsi->Instance->WCFGR &= ~DSI_WCFGR_DSIM;
  682. hdsi->Instance->WCFGR |= DSI_WCFGR_DSIM;
  683. /* Select the virtual channel for the LTDC interface traffic */
  684. hdsi->Instance->LVCIDR &= ~DSI_LVCIDR_VCID;
  685. hdsi->Instance->LVCIDR |= CmdCfg->VirtualChannelID;
  686. /* Configure the polarity of control signals */
  687. hdsi->Instance->LPCR &= ~(DSI_LPCR_DEP | DSI_LPCR_VSP | DSI_LPCR_HSP);
  688. hdsi->Instance->LPCR |= (CmdCfg->DEPolarity | CmdCfg->VSPolarity | CmdCfg->HSPolarity);
  689. /* Select the color coding for the host */
  690. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_COLC;
  691. hdsi->Instance->LCOLCR |= CmdCfg->ColorCoding;
  692. /* Select the color coding for the wrapper */
  693. hdsi->Instance->WCFGR &= ~DSI_WCFGR_COLMUX;
  694. hdsi->Instance->WCFGR |= ((CmdCfg->ColorCoding)<<1);
  695. /* Configure the maximum allowed size for write memory command */
  696. hdsi->Instance->LCCR &= ~DSI_LCCR_CMDSIZE;
  697. hdsi->Instance->LCCR |= CmdCfg->CommandSize;
  698. /* Configure the tearing effect source and polarity and select the refresh mode */
  699. hdsi->Instance->WCFGR &= ~(DSI_WCFGR_TESRC | DSI_WCFGR_TEPOL | DSI_WCFGR_AR | DSI_WCFGR_VSPOL);
  700. hdsi->Instance->WCFGR |= (CmdCfg->TearingEffectSource | CmdCfg->TearingEffectPolarity | CmdCfg->AutomaticRefresh | CmdCfg->VSyncPol);
  701. /* Configure the tearing effect acknowledge request */
  702. hdsi->Instance->CMCR &= ~DSI_CMCR_TEARE;
  703. hdsi->Instance->CMCR |= CmdCfg->TEAcknowledgeRequest;
  704. /* Enable the Tearing Effect interrupt */
  705. __HAL_DSI_ENABLE_IT(hdsi, DSI_IT_TE);
  706. /* Enable the End of Refresh interrupt */
  707. __HAL_DSI_ENABLE_IT(hdsi, DSI_IT_ER);
  708. /* Process unlocked */
  709. __HAL_UNLOCK(hdsi);
  710. return HAL_OK;
  711. }
  712. /**
  713. * @brief Configure command transmission mode: High-speed or Low-power
  714. * and enable/disable acknowledge request after packet transmission
  715. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  716. * the configuration information for the DSI.
  717. * @param LPCmd: pointer to a DSI_LPCmdTypeDef structure that contains
  718. * the DSI command transmission mode configuration parameters
  719. * @retval HAL status
  720. */
  721. HAL_StatusTypeDef HAL_DSI_ConfigCommand(DSI_HandleTypeDef *hdsi, DSI_LPCmdTypeDef *LPCmd)
  722. {
  723. /* Process locked */
  724. __HAL_LOCK(hdsi);
  725. assert_param(IS_DSI_LP_GSW0P(LPCmd->LPGenShortWriteNoP));
  726. assert_param(IS_DSI_LP_GSW1P(LPCmd->LPGenShortWriteOneP));
  727. assert_param(IS_DSI_LP_GSW2P(LPCmd->LPGenShortWriteTwoP));
  728. assert_param(IS_DSI_LP_GSR0P(LPCmd->LPGenShortReadNoP));
  729. assert_param(IS_DSI_LP_GSR1P(LPCmd->LPGenShortReadOneP));
  730. assert_param(IS_DSI_LP_GSR2P(LPCmd->LPGenShortReadTwoP));
  731. assert_param(IS_DSI_LP_GLW(LPCmd->LPGenLongWrite));
  732. assert_param(IS_DSI_LP_DSW0P(LPCmd->LPDcsShortWriteNoP));
  733. assert_param(IS_DSI_LP_DSW1P(LPCmd->LPDcsShortWriteOneP));
  734. assert_param(IS_DSI_LP_DSR0P(LPCmd->LPDcsShortReadNoP));
  735. assert_param(IS_DSI_LP_DLW(LPCmd->LPDcsLongWrite));
  736. assert_param(IS_DSI_LP_MRDP(LPCmd->LPMaxReadPacket));
  737. assert_param(IS_DSI_ACK_REQUEST(LPCmd->AcknowledgeRequest));
  738. /* Select High-speed or Low-power for command transmission */
  739. hdsi->Instance->CMCR &= ~(DSI_CMCR_GSW0TX |\
  740. DSI_CMCR_GSW1TX |\
  741. DSI_CMCR_GSW2TX |\
  742. DSI_CMCR_GSR0TX |\
  743. DSI_CMCR_GSR1TX |\
  744. DSI_CMCR_GSR2TX |\
  745. DSI_CMCR_GLWTX |\
  746. DSI_CMCR_DSW0TX |\
  747. DSI_CMCR_DSW1TX |\
  748. DSI_CMCR_DSR0TX |\
  749. DSI_CMCR_DLWTX |\
  750. DSI_CMCR_MRDPS);
  751. hdsi->Instance->CMCR |= (LPCmd->LPGenShortWriteNoP |\
  752. LPCmd->LPGenShortWriteOneP |\
  753. LPCmd->LPGenShortWriteTwoP |\
  754. LPCmd->LPGenShortReadNoP |\
  755. LPCmd->LPGenShortReadOneP |\
  756. LPCmd->LPGenShortReadTwoP |\
  757. LPCmd->LPGenLongWrite |\
  758. LPCmd->LPDcsShortWriteNoP |\
  759. LPCmd->LPDcsShortWriteOneP |\
  760. LPCmd->LPDcsShortReadNoP |\
  761. LPCmd->LPDcsLongWrite |\
  762. LPCmd->LPMaxReadPacket);
  763. /* Configure the acknowledge request after each packet transmission */
  764. hdsi->Instance->CMCR &= ~DSI_CMCR_ARE;
  765. hdsi->Instance->CMCR |= LPCmd->AcknowledgeRequest;
  766. /* Process unlocked */
  767. __HAL_UNLOCK(hdsi);
  768. return HAL_OK;
  769. }
  770. /**
  771. * @brief Configure the flow control parameters
  772. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  773. * the configuration information for the DSI.
  774. * @param FlowControl: flow control feature(s) to be enabled.
  775. * This parameter can be any combination of @ref DSI_FlowControl.
  776. * @retval HAL status
  777. */
  778. HAL_StatusTypeDef HAL_DSI_ConfigFlowControl(DSI_HandleTypeDef *hdsi, uint32_t FlowControl)
  779. {
  780. /* Process locked */
  781. __HAL_LOCK(hdsi);
  782. /* Check the parameters */
  783. assert_param(IS_DSI_FLOW_CONTROL(FlowControl));
  784. /* Set the DSI Host Protocol Configuration Register */
  785. hdsi->Instance->PCR &= ~DSI_FLOW_CONTROL_ALL;
  786. hdsi->Instance->PCR |= FlowControl;
  787. /* Process unlocked */
  788. __HAL_UNLOCK(hdsi);
  789. return HAL_OK;
  790. }
  791. /**
  792. * @brief Configure the DSI PHY timer parameters
  793. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  794. * the configuration information for the DSI.
  795. * @param PhyTimers: DSI_PHY_TimerTypeDef structure that contains
  796. * the DSI PHY timing parameters
  797. * @retval HAL status
  798. */
  799. HAL_StatusTypeDef HAL_DSI_ConfigPhyTimer(DSI_HandleTypeDef *hdsi, DSI_PHY_TimerTypeDef *PhyTimers)
  800. {
  801. uint32_t maxTime;
  802. /* Process locked */
  803. __HAL_LOCK(hdsi);
  804. maxTime = (PhyTimers->ClockLaneLP2HSTime > PhyTimers->ClockLaneHS2LPTime)? PhyTimers->ClockLaneLP2HSTime: PhyTimers->ClockLaneHS2LPTime;
  805. /* Clock lane timer configuration */
  806. /* In Automatic Clock Lane control mode, the DSI Host can turn off the clock lane between two
  807. High-Speed transmission.
  808. To do so, the DSI Host calculates the time required for the clock lane to change from HighSpeed
  809. to Low-Power and from Low-Power to High-Speed.
  810. This timings are configured by the HS2LP_TIME and LP2HS_TIME in the DSI Host Clock Lane Timer Configuration Register (DSI_CLTCR).
  811. But the DSI Host is not calculating LP2HS_TIME + HS2LP_TIME but 2 x HS2LP_TIME.
  812. Workaround : Configure HS2LP_TIME and LP2HS_TIME with the same value being the max of HS2LP_TIME or LP2HS_TIME.
  813. */
  814. hdsi->Instance->CLTCR &= ~(DSI_CLTCR_LP2HS_TIME | DSI_CLTCR_HS2LP_TIME);
  815. hdsi->Instance->CLTCR |= (maxTime | ((maxTime)<<16));
  816. /* Data lane timer configuration */
  817. hdsi->Instance->DLTCR &= ~(DSI_DLTCR_MRD_TIME | DSI_DLTCR_LP2HS_TIME | DSI_DLTCR_HS2LP_TIME);
  818. hdsi->Instance->DLTCR |= (PhyTimers->DataLaneMaxReadTime | ((PhyTimers->DataLaneLP2HSTime)<<16) | ((PhyTimers->DataLaneHS2LPTime)<<24));
  819. /* Configure the wait period to request HS transmission after a stop state */
  820. hdsi->Instance->PCONFR &= ~DSI_PCONFR_SW_TIME;
  821. hdsi->Instance->PCONFR |= ((PhyTimers->StopWaitTime)<<8);
  822. /* Process unlocked */
  823. __HAL_UNLOCK(hdsi);
  824. return HAL_OK;
  825. }
  826. /**
  827. * @brief Configure the DSI HOST timeout parameters
  828. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  829. * the configuration information for the DSI.
  830. * @param HostTimeouts: DSI_HOST_TimeoutTypeDef structure that contains
  831. * the DSI host timeout parameters
  832. * @retval HAL status
  833. */
  834. HAL_StatusTypeDef HAL_DSI_ConfigHostTimeouts(DSI_HandleTypeDef *hdsi, DSI_HOST_TimeoutTypeDef *HostTimeouts)
  835. {
  836. /* Process locked */
  837. __HAL_LOCK(hdsi);
  838. /* Set the timeout clock division factor */
  839. hdsi->Instance->CCR &= ~DSI_CCR_TOCKDIV;
  840. hdsi->Instance->CCR = ((HostTimeouts->TimeoutCkdiv)<<8);
  841. /* High-speed transmission timeout */
  842. hdsi->Instance->TCCR[0] &= ~DSI_TCCR0_HSTX_TOCNT;
  843. hdsi->Instance->TCCR[0] |= ((HostTimeouts->HighSpeedTransmissionTimeout)<<16);
  844. /* Low-power reception timeout */
  845. hdsi->Instance->TCCR[0] &= ~DSI_TCCR0_LPRX_TOCNT;
  846. hdsi->Instance->TCCR[0] |= HostTimeouts->LowPowerReceptionTimeout;
  847. /* High-speed read timeout */
  848. hdsi->Instance->TCCR[1] &= ~DSI_TCCR1_HSRD_TOCNT;
  849. hdsi->Instance->TCCR[1] |= HostTimeouts->HighSpeedReadTimeout;
  850. /* Low-power read timeout */
  851. hdsi->Instance->TCCR[2] &= ~DSI_TCCR2_LPRD_TOCNT;
  852. hdsi->Instance->TCCR[2] |= HostTimeouts->LowPowerReadTimeout;
  853. /* High-speed write timeout */
  854. hdsi->Instance->TCCR[3] &= ~DSI_TCCR3_HSWR_TOCNT;
  855. hdsi->Instance->TCCR[3] |= HostTimeouts->HighSpeedWriteTimeout;
  856. /* High-speed write presp mode */
  857. hdsi->Instance->TCCR[3] &= ~DSI_TCCR3_PM;
  858. hdsi->Instance->TCCR[3] |= HostTimeouts->HighSpeedWritePrespMode;
  859. /* Low-speed write timeout */
  860. hdsi->Instance->TCCR[4] &= ~DSI_TCCR4_LPWR_TOCNT;
  861. hdsi->Instance->TCCR[4] |= HostTimeouts->LowPowerWriteTimeout;
  862. /* BTA timeout */
  863. hdsi->Instance->TCCR[5] &= ~DSI_TCCR5_BTA_TOCNT;
  864. hdsi->Instance->TCCR[5] |= HostTimeouts->BTATimeout;
  865. /* Process unlocked */
  866. __HAL_UNLOCK(hdsi);
  867. return HAL_OK;
  868. }
  869. /**
  870. * @brief Start the DSI module
  871. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  872. * the configuration information for the DSI.
  873. * @retval HAL status
  874. */
  875. HAL_StatusTypeDef HAL_DSI_Start(DSI_HandleTypeDef *hdsi)
  876. {
  877. /* Process locked */
  878. __HAL_LOCK(hdsi);
  879. /* Enable the DSI host */
  880. __HAL_DSI_ENABLE(hdsi);
  881. /* Enable the DSI wrapper */
  882. __HAL_DSI_WRAPPER_ENABLE(hdsi);
  883. /* Process unlocked */
  884. __HAL_UNLOCK(hdsi);
  885. return HAL_OK;
  886. }
  887. /**
  888. * @brief Stop the DSI module
  889. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  890. * the configuration information for the DSI.
  891. * @retval HAL status
  892. */
  893. HAL_StatusTypeDef HAL_DSI_Stop(DSI_HandleTypeDef *hdsi)
  894. {
  895. /* Process locked */
  896. __HAL_LOCK(hdsi);
  897. /* Disable the DSI host */
  898. __HAL_DSI_DISABLE(hdsi);
  899. /* Disable the DSI wrapper */
  900. __HAL_DSI_WRAPPER_DISABLE(hdsi);
  901. /* Process unlocked */
  902. __HAL_UNLOCK(hdsi);
  903. return HAL_OK;
  904. }
  905. /**
  906. * @brief Refresh the display in command mode
  907. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  908. * the configuration information for the DSI.
  909. * @retval HAL status
  910. */
  911. HAL_StatusTypeDef HAL_DSI_Refresh(DSI_HandleTypeDef *hdsi)
  912. {
  913. /* Process locked */
  914. __HAL_LOCK(hdsi);
  915. /* Update the display */
  916. hdsi->Instance->WCR |= DSI_WCR_LTDCEN;
  917. /* Process unlocked */
  918. __HAL_UNLOCK(hdsi);
  919. return HAL_OK;
  920. }
  921. /**
  922. * @brief Controls the display color mode in Video mode
  923. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  924. * the configuration information for the DSI.
  925. * @param ColorMode: Color mode (full or 8-colors).
  926. * This parameter can be any value of @ref DSI_Color_Mode
  927. * @retval HAL status
  928. */
  929. HAL_StatusTypeDef HAL_DSI_ColorMode(DSI_HandleTypeDef *hdsi, uint32_t ColorMode)
  930. {
  931. /* Process locked */
  932. __HAL_LOCK(hdsi);
  933. /* Check the parameters */
  934. assert_param(IS_DSI_COLOR_MODE(ColorMode));
  935. /* Update the display color mode */
  936. hdsi->Instance->WCR &= ~DSI_WCR_COLM;
  937. hdsi->Instance->WCR |= ColorMode;
  938. /* Process unlocked */
  939. __HAL_UNLOCK(hdsi);
  940. return HAL_OK;
  941. }
  942. /**
  943. * @brief Control the display shutdown in Video mode
  944. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  945. * the configuration information for the DSI.
  946. * @param Shutdown: Shut-down (Display-ON or Display-OFF).
  947. * This parameter can be any value of @ref DSI_ShutDown
  948. * @retval HAL status
  949. */
  950. HAL_StatusTypeDef HAL_DSI_Shutdown(DSI_HandleTypeDef *hdsi, uint32_t Shutdown)
  951. {
  952. /* Process locked */
  953. __HAL_LOCK(hdsi);
  954. /* Check the parameters */
  955. assert_param(IS_DSI_SHUT_DOWN(Shutdown));
  956. /* Update the display Shutdown */
  957. hdsi->Instance->WCR &= ~DSI_WCR_SHTDN;
  958. hdsi->Instance->WCR |= Shutdown;
  959. /* Process unlocked */
  960. __HAL_UNLOCK(hdsi);
  961. return HAL_OK;
  962. }
  963. /**
  964. * @brief DCS or Generic short write command
  965. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  966. * the configuration information for the DSI.
  967. * @param ChannelID: Virtual channel ID.
  968. * @param Mode: DSI short packet data type.
  969. * This parameter can be any value of @ref DSI_SHORT_WRITE_PKT_Data_Type.
  970. * @param Param1: DSC command or first generic parameter.
  971. * This parameter can be any value of @ref DSI_DCS_Command or a
  972. * generic command code.
  973. * @param Param2: DSC parameter or second generic parameter.
  974. * @retval HAL status
  975. */
  976. HAL_StatusTypeDef HAL_DSI_ShortWrite(DSI_HandleTypeDef *hdsi,
  977. uint32_t ChannelID,
  978. uint32_t Mode,
  979. uint32_t Param1,
  980. uint32_t Param2)
  981. {
  982. uint32_t tickstart = 0;
  983. /* Process locked */
  984. __HAL_LOCK(hdsi);
  985. /* Check the parameters */
  986. assert_param(IS_DSI_SHORT_WRITE_PACKET_TYPE(Mode));
  987. /* Get tick */
  988. tickstart = HAL_GetTick();
  989. /* Wait for Command FIFO Empty */
  990. while((hdsi->Instance->GPSR & DSI_GPSR_CMDFE) == 0)
  991. {
  992. /* Check for the Timeout */
  993. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  994. {
  995. /* Process Unlocked */
  996. __HAL_UNLOCK(hdsi);
  997. return HAL_TIMEOUT;
  998. }
  999. }
  1000. /* Configure the packet to send a short DCS command with 0 or 1 parameter */
  1001. DSI_ConfigPacketHeader(hdsi->Instance,
  1002. ChannelID,
  1003. Mode,
  1004. Param1,
  1005. Param2);
  1006. /* Process unlocked */
  1007. __HAL_UNLOCK(hdsi);
  1008. return HAL_OK;
  1009. }
  1010. /**
  1011. * @brief DCS or Generic long write command
  1012. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1013. * the configuration information for the DSI.
  1014. * @param ChannelID: Virtual channel ID.
  1015. * @param Mode: DSI long packet data type.
  1016. * This parameter can be any value of @ref DSI_LONG_WRITE_PKT_Data_Type.
  1017. * @param NbParams: Number of parameters.
  1018. * @param Param1: DSC command or first generic parameter.
  1019. * This parameter can be any value of @ref DSI_DCS_Command or a
  1020. * generic command code
  1021. * @param ParametersTable: Pointer to parameter values table.
  1022. * @retval HAL status
  1023. */
  1024. HAL_StatusTypeDef HAL_DSI_LongWrite(DSI_HandleTypeDef *hdsi,
  1025. uint32_t ChannelID,
  1026. uint32_t Mode,
  1027. uint32_t NbParams,
  1028. uint32_t Param1,
  1029. uint8_t* ParametersTable)
  1030. {
  1031. uint32_t uicounter = 0;
  1032. uint32_t tickstart = 0;
  1033. /* Process locked */
  1034. __HAL_LOCK(hdsi);
  1035. /* Check the parameters */
  1036. assert_param(IS_DSI_LONG_WRITE_PACKET_TYPE(Mode));
  1037. /* Get tick */
  1038. tickstart = HAL_GetTick();
  1039. /* Wait for Command FIFO Empty */
  1040. while((hdsi->Instance->GPSR & DSI_GPSR_CMDFE) == RESET)
  1041. {
  1042. /* Check for the Timeout */
  1043. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1044. {
  1045. /* Process Unlocked */
  1046. __HAL_UNLOCK(hdsi);
  1047. return HAL_TIMEOUT;
  1048. }
  1049. }
  1050. /* Set the DCS code hexadecimal on payload byte 1, and the other parameters on the write FIFO command*/
  1051. while(uicounter < NbParams)
  1052. {
  1053. if(uicounter == 0x00)
  1054. {
  1055. hdsi->Instance->GPDR=(Param1 | \
  1056. ((*(ParametersTable+uicounter))<<8) | \
  1057. ((*(ParametersTable+uicounter+1))<<16) | \
  1058. ((*(ParametersTable+uicounter+2))<<24));
  1059. uicounter += 3;
  1060. }
  1061. else
  1062. {
  1063. hdsi->Instance->GPDR=((*(ParametersTable+uicounter)) | \
  1064. ((*(ParametersTable+uicounter+1))<<8) | \
  1065. ((*(ParametersTable+uicounter+2))<<16) | \
  1066. ((*(ParametersTable+uicounter+3))<<24));
  1067. uicounter+=4;
  1068. }
  1069. }
  1070. /* Configure the packet to send a long DCS command */
  1071. DSI_ConfigPacketHeader(hdsi->Instance,
  1072. ChannelID,
  1073. Mode,
  1074. ((NbParams+1)&0x00FF),
  1075. (((NbParams+1)&0xFF00)>>8));
  1076. /* Process unlocked */
  1077. __HAL_UNLOCK(hdsi);
  1078. return HAL_OK;
  1079. }
  1080. /**
  1081. * @brief Read command (DCS or generic)
  1082. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1083. * the configuration information for the DSI.
  1084. * @param ChannelNbr: Virtual channel ID
  1085. * @param Array: pointer to a buffer to store the payload of a read back operation.
  1086. * @param Size: Data size to be read (in byte).
  1087. * @param Mode: DSI read packet data type.
  1088. * This parameter can be any value of @ref DSI_SHORT_READ_PKT_Data_Type.
  1089. * @param DCSCmd: DCS get/read command.
  1090. * @param ParametersTable: Pointer to parameter values table.
  1091. * @retval HAL status
  1092. */
  1093. HAL_StatusTypeDef HAL_DSI_Read(DSI_HandleTypeDef *hdsi,
  1094. uint32_t ChannelNbr,
  1095. uint8_t* Array,
  1096. uint32_t Size,
  1097. uint32_t Mode,
  1098. uint32_t DCSCmd,
  1099. uint8_t* ParametersTable)
  1100. {
  1101. uint32_t tickstart = 0;
  1102. /* Process locked */
  1103. __HAL_LOCK(hdsi);
  1104. /* Check the parameters */
  1105. assert_param(IS_DSI_READ_PACKET_TYPE(Mode));
  1106. if(Size > 2)
  1107. {
  1108. /* set max return packet size */
  1109. HAL_DSI_ShortWrite(hdsi, ChannelNbr, DSI_MAX_RETURN_PKT_SIZE, ((Size)&0xFF), (((Size)>>8)&0xFF));
  1110. }
  1111. /* Configure the packet to read command */
  1112. if (Mode == DSI_DCS_SHORT_PKT_READ)
  1113. {
  1114. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, DCSCmd, 0);
  1115. }
  1116. else if (Mode == DSI_GEN_SHORT_PKT_READ_P0)
  1117. {
  1118. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, 0, 0);
  1119. }
  1120. else if (Mode == DSI_GEN_SHORT_PKT_READ_P1)
  1121. {
  1122. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, ParametersTable[0], 0);
  1123. }
  1124. else if (Mode == DSI_GEN_SHORT_PKT_READ_P2)
  1125. {
  1126. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, ParametersTable[0], ParametersTable[1]);
  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] |= 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] |= (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] |= (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] |= (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] |= (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] |= (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] |= (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] |= (State<<27);
  1636. if(State)
  1637. {
  1638. /* Set custom value */
  1639. hdsi->Instance->WPCR[4] &= ~DSI_WPCR4_TCLKPOST;
  1640. hdsi->Instance->WPCR[4] |= Value;
  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] |= (State<<26);
  1647. if(State)
  1648. {
  1649. /* Set custom value */
  1650. hdsi->Instance->WPCR[3] &= ~DSI_WPCR3_TLPXC;
  1651. hdsi->Instance->WPCR[3] |= Value;
  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] |= (State<<25);
  1658. if(State)
  1659. {
  1660. /* Set custom value */
  1661. hdsi->Instance->WPCR[3] &= ~DSI_WPCR3_THSEXIT;
  1662. hdsi->Instance->WPCR[3] |= Value;
  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] |= (State<<24);
  1669. if(State)
  1670. {
  1671. /* Set custom value */
  1672. hdsi->Instance->WPCR[3] &= ~DSI_WPCR3_TLPXD;
  1673. hdsi->Instance->WPCR[3] |= Value;
  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] |= (State<<23);
  1680. if(State)
  1681. {
  1682. /* Set custom value */
  1683. hdsi->Instance->WPCR[3] &= ~DSI_WPCR3_THSZERO;
  1684. hdsi->Instance->WPCR[3] |= Value;
  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] |= (State<<22);
  1691. if(State)
  1692. {
  1693. /* Set custom value */
  1694. hdsi->Instance->WPCR[2] &= ~DSI_WPCR2_THSTRAIL;
  1695. hdsi->Instance->WPCR[2] |= Value;
  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] |= (State<<21);
  1702. if(State)
  1703. {
  1704. /* Set custom value */
  1705. hdsi->Instance->WPCR[2] &= ~DSI_WPCR2_THSPREP;
  1706. hdsi->Instance->WPCR[2] |= Value;
  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] |= (State<<20);
  1713. if(State)
  1714. {
  1715. /* Set custom value */
  1716. hdsi->Instance->WPCR[2] &= ~DSI_WPCR2_TCLKZERO;
  1717. hdsi->Instance->WPCR[2] |= Value;
  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] |= (State<<19);
  1724. if(State)
  1725. {
  1726. /* Set custom value */
  1727. hdsi->Instance->WPCR[2] &= ~DSI_WPCR2_TCLKPREP;
  1728. hdsi->Instance->WPCR[2] |= Value;
  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] |= (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] |= (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] |= 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] |= 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] |= 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] |= 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 /* STM32F469xx || STM32F479xx */
  1884. #endif /* HAL_DSI_MODULE_ENABLED */
  1885. /**
  1886. * @}
  1887. */
  1888. /**
  1889. * @}
  1890. */
  1891. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/