stm32f4xx_hal_dsi.c 85 KB

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