stm32f4xx_ll_dma2d.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_dma2d.c
  4. * @author MCD Application Team
  5. * @brief DMA2D LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f4xx_ll_dma2d.h"
  22. #include "stm32f4xx_ll_bus.h"
  23. #ifdef USE_FULL_ASSERT
  24. #include "stm32_assert.h"
  25. #else
  26. #define assert_param(expr) ((void)0U)
  27. #endif
  28. /** @addtogroup STM32F4xx_LL_Driver
  29. * @{
  30. */
  31. #if defined (DMA2D)
  32. /** @addtogroup DMA2D_LL
  33. * @{
  34. */
  35. /* Private types -------------------------------------------------------------*/
  36. /* Private variables ---------------------------------------------------------*/
  37. /* Private constants ---------------------------------------------------------*/
  38. /** @addtogroup DMA2D_LL_Private_Constants DMA2D Private Constants
  39. * @{
  40. */
  41. #define LL_DMA2D_COLOR 0xFFU /*!< Maximum output color setting */
  42. #define LL_DMA2D_NUMBEROFLINES DMA2D_NLR_NL /*!< Maximum number of lines */
  43. #define LL_DMA2D_NUMBEROFPIXELS (DMA2D_NLR_PL >> DMA2D_NLR_PL_Pos) /*!< Maximum number of pixels per lines */
  44. #define LL_DMA2D_OFFSET_MAX 0x3FFFU /*!< Maximum output line offset expressed in pixels */
  45. #define LL_DMA2D_CLUTSIZE_MAX 0xFFU /*!< Maximum CLUT size */
  46. /**
  47. * @}
  48. */
  49. /* Private macros ------------------------------------------------------------*/
  50. /** @addtogroup DMA2D_LL_Private_Macros
  51. * @{
  52. */
  53. #define IS_LL_DMA2D_MODE(MODE) (((MODE) == LL_DMA2D_MODE_M2M) || \
  54. ((MODE) == LL_DMA2D_MODE_M2M_PFC) || \
  55. ((MODE) == LL_DMA2D_MODE_M2M_BLEND) || \
  56. ((MODE) == LL_DMA2D_MODE_R2M))
  57. #define IS_LL_DMA2D_OCMODE(MODE_ARGB) (((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB8888) || \
  58. ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_RGB888) || \
  59. ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_RGB565) || \
  60. ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB1555) || \
  61. ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB4444))
  62. #define IS_LL_DMA2D_GREEN(GREEN) ((GREEN) <= LL_DMA2D_COLOR)
  63. #define IS_LL_DMA2D_RED(RED) ((RED) <= LL_DMA2D_COLOR)
  64. #define IS_LL_DMA2D_BLUE(BLUE) ((BLUE) <= LL_DMA2D_COLOR)
  65. #define IS_LL_DMA2D_ALPHA(ALPHA) ((ALPHA) <= LL_DMA2D_COLOR)
  66. #define IS_LL_DMA2D_OFFSET(OFFSET) ((OFFSET) <= LL_DMA2D_OFFSET_MAX)
  67. #define IS_LL_DMA2D_LINE(LINES) ((LINES) <= LL_DMA2D_NUMBEROFLINES)
  68. #define IS_LL_DMA2D_PIXEL(PIXELS) ((PIXELS) <= LL_DMA2D_NUMBEROFPIXELS)
  69. #define IS_LL_DMA2D_LCMODE(MODE_ARGB) (((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB8888) || \
  70. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_RGB888) || \
  71. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_RGB565) || \
  72. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB1555) || \
  73. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB4444) || \
  74. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_L8) || \
  75. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_AL44) || \
  76. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_AL88) || \
  77. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_L4) || \
  78. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_A8) || \
  79. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_A4))
  80. #define IS_LL_DMA2D_CLUTCMODE(CLUTCMODE) (((CLUTCMODE) == LL_DMA2D_CLUT_COLOR_MODE_ARGB8888) || \
  81. ((CLUTCMODE) == LL_DMA2D_CLUT_COLOR_MODE_RGB888))
  82. #define IS_LL_DMA2D_CLUTSIZE(SIZE) ((SIZE) <= LL_DMA2D_CLUTSIZE_MAX)
  83. #define IS_LL_DMA2D_ALPHAMODE(MODE) (((MODE) == LL_DMA2D_ALPHA_MODE_NO_MODIF) || \
  84. ((MODE) == LL_DMA2D_ALPHA_MODE_REPLACE) || \
  85. ((MODE) == LL_DMA2D_ALPHA_MODE_COMBINE))
  86. /**
  87. * @}
  88. */
  89. /* Private function prototypes -----------------------------------------------*/
  90. /* Exported functions --------------------------------------------------------*/
  91. /** @addtogroup DMA2D_LL_Exported_Functions
  92. * @{
  93. */
  94. /** @addtogroup DMA2D_LL_EF_Init_Functions Initialization and De-initialization Functions
  95. * @{
  96. */
  97. /**
  98. * @brief De-initialize DMA2D registers (registers restored to their default values).
  99. * @param DMA2Dx DMA2D Instance
  100. * @retval An ErrorStatus enumeration value:
  101. * - SUCCESS: DMA2D registers are de-initialized
  102. * - ERROR: DMA2D registers are not de-initialized
  103. */
  104. ErrorStatus LL_DMA2D_DeInit(DMA2D_TypeDef *DMA2Dx)
  105. {
  106. ErrorStatus status = SUCCESS;
  107. /* Check the parameters */
  108. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  109. if (DMA2Dx == DMA2D)
  110. {
  111. /* Force reset of DMA2D clock */
  112. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA2D);
  113. /* Release reset of DMA2D clock */
  114. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA2D);
  115. }
  116. else
  117. {
  118. status = ERROR;
  119. }
  120. return (status);
  121. }
  122. /**
  123. * @brief Initialize DMA2D registers according to the specified parameters in DMA2D_InitStruct.
  124. * @note DMA2D transfers must be disabled to set initialization bits in configuration registers,
  125. * otherwise ERROR result is returned.
  126. * @param DMA2Dx DMA2D Instance
  127. * @param DMA2D_InitStruct pointer to a LL_DMA2D_InitTypeDef structure
  128. * that contains the configuration information for the specified DMA2D peripheral.
  129. * @retval An ErrorStatus enumeration value:
  130. * - SUCCESS: DMA2D registers are initialized according to DMA2D_InitStruct content
  131. * - ERROR: Issue occurred during DMA2D registers initialization
  132. */
  133. ErrorStatus LL_DMA2D_Init(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_InitTypeDef *DMA2D_InitStruct)
  134. {
  135. ErrorStatus status = ERROR;
  136. LL_DMA2D_ColorTypeDef DMA2D_ColorStruct;
  137. uint32_t tmp, tmp1, tmp2;
  138. uint32_t regMask, regValue;
  139. /* Check the parameters */
  140. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  141. assert_param(IS_LL_DMA2D_MODE(DMA2D_InitStruct->Mode));
  142. assert_param(IS_LL_DMA2D_OCMODE(DMA2D_InitStruct->ColorMode));
  143. assert_param(IS_LL_DMA2D_LINE(DMA2D_InitStruct->NbrOfLines));
  144. assert_param(IS_LL_DMA2D_PIXEL(DMA2D_InitStruct->NbrOfPixelsPerLines));
  145. assert_param(IS_LL_DMA2D_GREEN(DMA2D_InitStruct->OutputGreen));
  146. assert_param(IS_LL_DMA2D_RED(DMA2D_InitStruct->OutputRed));
  147. assert_param(IS_LL_DMA2D_BLUE(DMA2D_InitStruct->OutputBlue));
  148. assert_param(IS_LL_DMA2D_ALPHA(DMA2D_InitStruct->OutputAlpha));
  149. assert_param(IS_LL_DMA2D_OFFSET(DMA2D_InitStruct->LineOffset));
  150. /* DMA2D transfers must be disabled to configure bits in initialization registers */
  151. tmp = LL_DMA2D_IsTransferOngoing(DMA2Dx);
  152. tmp1 = LL_DMA2D_FGND_IsEnabledCLUTLoad(DMA2Dx);
  153. tmp2 = LL_DMA2D_BGND_IsEnabledCLUTLoad(DMA2Dx);
  154. if ((tmp == 0U) && (tmp1 == 0U) && (tmp2 == 0U))
  155. {
  156. /* DMA2D CR register configuration -------------------------------------------*/
  157. LL_DMA2D_SetMode(DMA2Dx, DMA2D_InitStruct->Mode);
  158. /* DMA2D OPFCCR register configuration ---------------------------------------*/
  159. regMask = DMA2D_OPFCCR_CM;
  160. regValue = DMA2D_InitStruct->ColorMode;
  161. MODIFY_REG(DMA2Dx->OPFCCR, regMask, regValue);
  162. /* DMA2D OOR register configuration ------------------------------------------*/
  163. LL_DMA2D_SetLineOffset(DMA2Dx, DMA2D_InitStruct->LineOffset);
  164. /* DMA2D NLR register configuration ------------------------------------------*/
  165. LL_DMA2D_ConfigSize(DMA2Dx, DMA2D_InitStruct->NbrOfLines, DMA2D_InitStruct->NbrOfPixelsPerLines);
  166. /* DMA2D OMAR register configuration ------------------------------------------*/
  167. LL_DMA2D_SetOutputMemAddr(DMA2Dx, DMA2D_InitStruct->OutputMemoryAddress);
  168. /* DMA2D OCOLR register configuration ------------------------------------------*/
  169. DMA2D_ColorStruct.ColorMode = DMA2D_InitStruct->ColorMode;
  170. DMA2D_ColorStruct.OutputBlue = DMA2D_InitStruct->OutputBlue;
  171. DMA2D_ColorStruct.OutputGreen = DMA2D_InitStruct->OutputGreen;
  172. DMA2D_ColorStruct.OutputRed = DMA2D_InitStruct->OutputRed;
  173. DMA2D_ColorStruct.OutputAlpha = DMA2D_InitStruct->OutputAlpha;
  174. LL_DMA2D_ConfigOutputColor(DMA2Dx, &DMA2D_ColorStruct);
  175. status = SUCCESS;
  176. }
  177. /* If DMA2D transfers are not disabled, return ERROR */
  178. return (status);
  179. }
  180. /**
  181. * @brief Set each @ref LL_DMA2D_InitTypeDef field to default value.
  182. * @param DMA2D_InitStruct pointer to a @ref LL_DMA2D_InitTypeDef structure
  183. * whose fields will be set to default values.
  184. * @retval None
  185. */
  186. void LL_DMA2D_StructInit(LL_DMA2D_InitTypeDef *DMA2D_InitStruct)
  187. {
  188. /* Set DMA2D_InitStruct fields to default values */
  189. DMA2D_InitStruct->Mode = LL_DMA2D_MODE_M2M;
  190. DMA2D_InitStruct->ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB8888;
  191. DMA2D_InitStruct->NbrOfLines = 0x0U;
  192. DMA2D_InitStruct->NbrOfPixelsPerLines = 0x0U;
  193. DMA2D_InitStruct->LineOffset = 0x0U;
  194. DMA2D_InitStruct->OutputBlue = 0x0U;
  195. DMA2D_InitStruct->OutputGreen = 0x0U;
  196. DMA2D_InitStruct->OutputRed = 0x0U;
  197. DMA2D_InitStruct->OutputAlpha = 0x0U;
  198. DMA2D_InitStruct->OutputMemoryAddress = 0x0U;
  199. }
  200. /**
  201. * @brief Configure the foreground or background according to the specified parameters
  202. * in the LL_DMA2D_LayerCfgTypeDef structure.
  203. * @param DMA2Dx DMA2D Instance
  204. * @param DMA2D_LayerCfg pointer to a LL_DMA2D_LayerCfgTypeDef structure that contains
  205. * the configuration information for the specified layer.
  206. * @param LayerIdx DMA2D Layer index.
  207. * This parameter can be one of the following values:
  208. * 0(background) / 1(foreground)
  209. * @retval None
  210. */
  211. void LL_DMA2D_ConfigLayer(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg, uint32_t LayerIdx)
  212. {
  213. /* Check the parameters */
  214. assert_param(IS_LL_DMA2D_OFFSET(DMA2D_LayerCfg->LineOffset));
  215. assert_param(IS_LL_DMA2D_LCMODE(DMA2D_LayerCfg->ColorMode));
  216. assert_param(IS_LL_DMA2D_CLUTCMODE(DMA2D_LayerCfg->CLUTColorMode));
  217. assert_param(IS_LL_DMA2D_CLUTSIZE(DMA2D_LayerCfg->CLUTSize));
  218. assert_param(IS_LL_DMA2D_ALPHAMODE(DMA2D_LayerCfg->AlphaMode));
  219. assert_param(IS_LL_DMA2D_GREEN(DMA2D_LayerCfg->Green));
  220. assert_param(IS_LL_DMA2D_RED(DMA2D_LayerCfg->Red));
  221. assert_param(IS_LL_DMA2D_BLUE(DMA2D_LayerCfg->Blue));
  222. assert_param(IS_LL_DMA2D_ALPHA(DMA2D_LayerCfg->Alpha));
  223. if (LayerIdx == 0U)
  224. {
  225. /* Configure the background memory address */
  226. LL_DMA2D_BGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress);
  227. /* Configure the background line offset */
  228. LL_DMA2D_BGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset);
  229. /* Configure the background Alpha value, Alpha mode, CLUT size, CLUT Color mode and Color mode */
  230. MODIFY_REG(DMA2Dx->BGPFCCR, \
  231. (DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM | DMA2D_BGPFCCR_CM), \
  232. ((DMA2D_LayerCfg->Alpha << DMA2D_BGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->AlphaMode | \
  233. (DMA2D_LayerCfg->CLUTSize << DMA2D_BGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
  234. DMA2D_LayerCfg->ColorMode));
  235. /* Configure the background color */
  236. LL_DMA2D_BGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue);
  237. /* Configure the background CLUT memory address */
  238. LL_DMA2D_BGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress);
  239. }
  240. else
  241. {
  242. /* Configure the foreground memory address */
  243. LL_DMA2D_FGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress);
  244. /* Configure the foreground line offset */
  245. LL_DMA2D_FGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset);
  246. /* Configure the foreground Alpha value, Alpha mode, CLUT size, CLUT Color mode and Color mode */
  247. MODIFY_REG(DMA2Dx->FGPFCCR, \
  248. (DMA2D_FGPFCCR_ALPHA | DMA2D_FGPFCCR_AM | DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM | DMA2D_FGPFCCR_CM), \
  249. ((DMA2D_LayerCfg->Alpha << DMA2D_FGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->AlphaMode | \
  250. (DMA2D_LayerCfg->CLUTSize << DMA2D_FGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
  251. DMA2D_LayerCfg->ColorMode));
  252. /* Configure the foreground color */
  253. LL_DMA2D_FGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue);
  254. /* Configure the foreground CLUT memory address */
  255. LL_DMA2D_FGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress);
  256. }
  257. }
  258. /**
  259. * @brief Set each @ref LL_DMA2D_LayerCfgTypeDef field to default value.
  260. * @param DMA2D_LayerCfg pointer to a @ref LL_DMA2D_LayerCfgTypeDef structure
  261. * whose fields will be set to default values.
  262. * @retval None
  263. */
  264. void LL_DMA2D_LayerCfgStructInit(LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg)
  265. {
  266. /* Set DMA2D_LayerCfg fields to default values */
  267. DMA2D_LayerCfg->MemoryAddress = 0x0U;
  268. DMA2D_LayerCfg->ColorMode = LL_DMA2D_INPUT_MODE_ARGB8888;
  269. DMA2D_LayerCfg->LineOffset = 0x0U;
  270. DMA2D_LayerCfg->CLUTColorMode = LL_DMA2D_CLUT_COLOR_MODE_ARGB8888;
  271. DMA2D_LayerCfg->CLUTSize = 0x0U;
  272. DMA2D_LayerCfg->AlphaMode = LL_DMA2D_ALPHA_MODE_NO_MODIF;
  273. DMA2D_LayerCfg->Alpha = 0x0U;
  274. DMA2D_LayerCfg->Blue = 0x0U;
  275. DMA2D_LayerCfg->Green = 0x0U;
  276. DMA2D_LayerCfg->Red = 0x0U;
  277. DMA2D_LayerCfg->CLUTMemoryAddress = 0x0U;
  278. }
  279. /**
  280. * @brief Initialize DMA2D output color register according to the specified parameters
  281. * in DMA2D_ColorStruct.
  282. * @param DMA2Dx DMA2D Instance
  283. * @param DMA2D_ColorStruct pointer to a LL_DMA2D_ColorTypeDef structure that contains
  284. * the color configuration information for the specified DMA2D peripheral.
  285. * @retval None
  286. */
  287. void LL_DMA2D_ConfigOutputColor(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_ColorTypeDef *DMA2D_ColorStruct)
  288. {
  289. uint32_t outgreen;
  290. uint32_t outred;
  291. uint32_t outalpha;
  292. /* Check the parameters */
  293. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  294. assert_param(IS_LL_DMA2D_OCMODE(DMA2D_ColorStruct->ColorMode));
  295. assert_param(IS_LL_DMA2D_GREEN(DMA2D_ColorStruct->OutputGreen));
  296. assert_param(IS_LL_DMA2D_RED(DMA2D_ColorStruct->OutputRed));
  297. assert_param(IS_LL_DMA2D_BLUE(DMA2D_ColorStruct->OutputBlue));
  298. assert_param(IS_LL_DMA2D_ALPHA(DMA2D_ColorStruct->OutputAlpha));
  299. /* DMA2D OCOLR register configuration ------------------------------------------*/
  300. if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  301. {
  302. outgreen = DMA2D_ColorStruct->OutputGreen << 8U;
  303. outred = DMA2D_ColorStruct->OutputRed << 16U;
  304. outalpha = DMA2D_ColorStruct->OutputAlpha << 24U;
  305. }
  306. else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
  307. {
  308. outgreen = DMA2D_ColorStruct->OutputGreen << 8U;
  309. outred = DMA2D_ColorStruct->OutputRed << 16U;
  310. outalpha = 0x00000000U;
  311. }
  312. else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
  313. {
  314. outgreen = DMA2D_ColorStruct->OutputGreen << 5U;
  315. outred = DMA2D_ColorStruct->OutputRed << 11U;
  316. outalpha = 0x00000000U;
  317. }
  318. else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  319. {
  320. outgreen = DMA2D_ColorStruct->OutputGreen << 5U;
  321. outred = DMA2D_ColorStruct->OutputRed << 10U;
  322. outalpha = DMA2D_ColorStruct->OutputAlpha << 15U;
  323. }
  324. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  325. {
  326. outgreen = DMA2D_ColorStruct->OutputGreen << 4U;
  327. outred = DMA2D_ColorStruct->OutputRed << 8U;
  328. outalpha = DMA2D_ColorStruct->OutputAlpha << 12U;
  329. }
  330. LL_DMA2D_SetOutputColor(DMA2Dx, (outgreen | outred | DMA2D_ColorStruct->OutputBlue | outalpha));
  331. }
  332. /**
  333. * @brief Return DMA2D output Blue color.
  334. * @param DMA2Dx DMA2D Instance.
  335. * @param ColorMode This parameter can be one of the following values:
  336. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
  337. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
  338. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
  339. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
  340. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
  341. * @retval Output Blue color value between Min_Data=0 and Max_Data=0xFF
  342. */
  343. uint32_t LL_DMA2D_GetOutputBlueColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
  344. {
  345. uint32_t color;
  346. /* Check the parameters */
  347. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  348. assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
  349. /* DMA2D OCOLR register reading ------------------------------------------*/
  350. if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  351. {
  352. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFFU));
  353. }
  354. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
  355. {
  356. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFFU));
  357. }
  358. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
  359. {
  360. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x1FU));
  361. }
  362. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  363. {
  364. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x1FU));
  365. }
  366. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  367. {
  368. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFU));
  369. }
  370. return color;
  371. }
  372. /**
  373. * @brief Return DMA2D output Green color.
  374. * @param DMA2Dx DMA2D Instance.
  375. * @param ColorMode This parameter can be one of the following values:
  376. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
  377. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
  378. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
  379. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
  380. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
  381. * @retval Output Green color value between Min_Data=0 and Max_Data=0xFF
  382. */
  383. uint32_t LL_DMA2D_GetOutputGreenColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
  384. {
  385. uint32_t color;
  386. /* Check the parameters */
  387. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  388. assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
  389. /* DMA2D OCOLR register reading ------------------------------------------*/
  390. if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  391. {
  392. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF00U) >> 8U);
  393. }
  394. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
  395. {
  396. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF00U) >> 8U);
  397. }
  398. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
  399. {
  400. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x7E0U) >> 5U);
  401. }
  402. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  403. {
  404. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x3E0U) >> 5U);
  405. }
  406. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  407. {
  408. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF0U) >> 4U);
  409. }
  410. return color;
  411. }
  412. /**
  413. * @brief Return DMA2D output Red color.
  414. * @param DMA2Dx DMA2D Instance.
  415. * @param ColorMode This parameter can be one of the following values:
  416. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
  417. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
  418. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
  419. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
  420. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
  421. * @retval Output Red color value between Min_Data=0 and Max_Data=0xFF
  422. */
  423. uint32_t LL_DMA2D_GetOutputRedColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
  424. {
  425. uint32_t color;
  426. /* Check the parameters */
  427. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  428. assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
  429. /* DMA2D OCOLR register reading ------------------------------------------*/
  430. if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  431. {
  432. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF0000U) >> 16U);
  433. }
  434. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
  435. {
  436. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF0000U) >> 16U);
  437. }
  438. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
  439. {
  440. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF800U) >> 11U);
  441. }
  442. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  443. {
  444. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x7C00U) >> 10U);
  445. }
  446. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  447. {
  448. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF00U) >> 8U);
  449. }
  450. return color;
  451. }
  452. /**
  453. * @brief Return DMA2D output Alpha color.
  454. * @param DMA2Dx DMA2D Instance.
  455. * @param ColorMode This parameter can be one of the following values:
  456. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
  457. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
  458. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
  459. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
  460. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
  461. * @retval Output Alpha color value between Min_Data=0 and Max_Data=0xFF
  462. */
  463. uint32_t LL_DMA2D_GetOutputAlphaColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
  464. {
  465. uint32_t color;
  466. /* Check the parameters */
  467. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  468. assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
  469. /* DMA2D OCOLR register reading ------------------------------------------*/
  470. if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  471. {
  472. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF000000U) >> 24U);
  473. }
  474. else if ((ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888) || (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565))
  475. {
  476. color = 0x0U;
  477. }
  478. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  479. {
  480. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x8000U) >> 15U);
  481. }
  482. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  483. {
  484. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF000U) >> 12U);
  485. }
  486. return color;
  487. }
  488. /**
  489. * @brief Configure DMA2D transfer size.
  490. * @param DMA2Dx DMA2D Instance
  491. * @param NbrOfLines Value between Min_Data=0 and Max_Data=0xFFFF
  492. * @param NbrOfPixelsPerLines Value between Min_Data=0 and Max_Data=0x3FFF
  493. * @retval None
  494. */
  495. void LL_DMA2D_ConfigSize(DMA2D_TypeDef *DMA2Dx, uint32_t NbrOfLines, uint32_t NbrOfPixelsPerLines)
  496. {
  497. MODIFY_REG(DMA2Dx->NLR, (DMA2D_NLR_PL | DMA2D_NLR_NL), \
  498. ((NbrOfPixelsPerLines << DMA2D_NLR_PL_Pos) | NbrOfLines));
  499. }
  500. /**
  501. * @}
  502. */
  503. /**
  504. * @}
  505. */
  506. /**
  507. * @}
  508. */
  509. #endif /* defined (DMA2D) */
  510. /**
  511. * @}
  512. */
  513. #endif /* USE_FULL_LL_DRIVER */
  514. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/