stm32l4xx_hal_dsi.c 96 KB

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