stm32l4xx_hal_dsi.c 95 KB

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