stm32l4xx_ll_dma2d.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_dma2d.c
  4. * @author MCD Application Team
  5. * @brief DMA2D LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. #if defined(USE_FULL_LL_DRIVER)
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32l4xx_ll_dma2d.h"
  38. #include "stm32l4xx_ll_bus.h"
  39. #ifdef USE_FULL_ASSERT
  40. #include "stm32_assert.h"
  41. #else
  42. #define assert_param(expr) ((void)0U)
  43. #endif
  44. /** @addtogroup STM32L4xx_LL_Driver
  45. * @{
  46. */
  47. #if defined (DMA2D)
  48. /** @addtogroup DMA2D_LL
  49. * @{
  50. */
  51. /* Private types -------------------------------------------------------------*/
  52. /* Private variables ---------------------------------------------------------*/
  53. /* Private constants ---------------------------------------------------------*/
  54. /** @addtogroup DMA2D_LL_Private_Constants DMA2D Private Constants
  55. * @{
  56. */
  57. #define LL_DMA2D_COLOR 0xFFU /*!< Maximum output color setting */
  58. #define LL_DMA2D_NUMBEROFLINES DMA2D_NLR_NL /*!< Maximum number of lines */
  59. #define LL_DMA2D_NUMBEROFPIXELS (DMA2D_NLR_PL >> DMA2D_NLR_PL_Pos) /*!< Maximum number of pixels per lines */
  60. #define LL_DMA2D_OFFSET_MAX 0x3FFFU /*!< Maximum output line offset expressed in pixels */
  61. #define LL_DMA2D_CLUTSIZE_MAX 0xFFU /*!< Maximum CLUT size */
  62. /**
  63. * @}
  64. */
  65. /* Private macros ------------------------------------------------------------*/
  66. /** @addtogroup DMA2D_LL_Private_Macros
  67. * @{
  68. */
  69. #if defined(DMA2D_M2M_BLEND_FIXED_COLOR_FG_BG_SUPPORT)
  70. #define IS_LL_DMA2D_MODE(MODE) (((MODE) == LL_DMA2D_MODE_M2M) || \
  71. ((MODE) == LL_DMA2D_MODE_M2M_PFC) || \
  72. ((MODE) == LL_DMA2D_MODE_M2M_BLEND) || \
  73. ((MODE) == LL_DMA2D_MODE_M2M_BLEND_FIXED_COLOR_FG) || \
  74. ((MODE) == LL_DMA2D_MODE_M2M_BLEND_FIXED_COLOR_BG) || \
  75. ((MODE) == LL_DMA2D_MODE_R2M))
  76. #else
  77. #define IS_LL_DMA2D_MODE(MODE) (((MODE) == LL_DMA2D_MODE_M2M) || \
  78. ((MODE) == LL_DMA2D_MODE_M2M_PFC) || \
  79. ((MODE) == LL_DMA2D_MODE_M2M_BLEND) || \
  80. ((MODE) == LL_DMA2D_MODE_R2M))
  81. #endif
  82. #define IS_LL_DMA2D_OCMODE(MODE_ARGB) (((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB8888) || \
  83. ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_RGB888) || \
  84. ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_RGB565) || \
  85. ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB1555) || \
  86. ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB4444))
  87. #define IS_LL_DMA2D_GREEN(GREEN) ((GREEN) <= LL_DMA2D_COLOR)
  88. #define IS_LL_DMA2D_RED(RED) ((RED) <= LL_DMA2D_COLOR)
  89. #define IS_LL_DMA2D_BLUE(BLUE) ((BLUE) <= LL_DMA2D_COLOR)
  90. #define IS_LL_DMA2D_ALPHA(ALPHA) ((ALPHA) <= LL_DMA2D_COLOR)
  91. #if defined(DMA2D_LINE_OFFSET_MODE_SUPPORT)
  92. #define IS_LL_DMA2D_OFFSET_MODE(MODE) (((MODE) == LL_DMA2D_LINE_OFFSET_PIXELS) || \
  93. ((MODE) == LL_DMA2D_LINE_OFFSET_BYTES))
  94. #endif /* DMA2D_LINE_OFFSET_MODE_SUPPORT */
  95. #define IS_LL_DMA2D_OFFSET(OFFSET) ((OFFSET) <= LL_DMA2D_OFFSET_MAX)
  96. #define IS_LL_DMA2D_LINE(LINES) ((LINES) <= LL_DMA2D_NUMBEROFLINES)
  97. #define IS_LL_DMA2D_PIXEL(PIXELS) ((PIXELS) <= LL_DMA2D_NUMBEROFPIXELS)
  98. #if defined(DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT)
  99. #define IS_LL_DMA2D_SWAP_MODE(MODE) (((MODE) == LL_DMA2D_SWAP_MODE_REGULAR) || \
  100. ((MODE) == LL_DMA2D_SWAP_MODE_TWO_BY_TWO))
  101. #endif /* DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT */
  102. #define IS_LL_DMA2D_ALPHAINV(ALPHA) (((ALPHA) == LL_DMA2D_ALPHA_REGULAR) || \
  103. ((ALPHA) == LL_DMA2D_ALPHA_INVERTED))
  104. #define IS_LL_DMA2D_RBSWAP(RBSWAP) (((RBSWAP) == LL_DMA2D_RB_MODE_REGULAR) || \
  105. ((RBSWAP) == LL_DMA2D_RB_MODE_SWAP))
  106. #define IS_LL_DMA2D_LCMODE(MODE_ARGB) (((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB8888) || \
  107. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_RGB888) || \
  108. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_RGB565) || \
  109. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB1555) || \
  110. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB4444) || \
  111. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_L8) || \
  112. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_AL44) || \
  113. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_AL88) || \
  114. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_L4) || \
  115. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_A8) || \
  116. ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_A4))
  117. #define IS_LL_DMA2D_CLUTCMODE(CLUTCMODE) (((CLUTCMODE) == LL_DMA2D_CLUT_COLOR_MODE_ARGB8888) || \
  118. ((CLUTCMODE) == LL_DMA2D_CLUT_COLOR_MODE_RGB888))
  119. #define IS_LL_DMA2D_CLUTSIZE(SIZE) ((SIZE) <= LL_DMA2D_CLUTSIZE_MAX)
  120. #define IS_LL_DMA2D_ALPHAMODE(MODE) (((MODE) == LL_DMA2D_ALPHA_MODE_NO_MODIF) || \
  121. ((MODE) == LL_DMA2D_ALPHA_MODE_REPLACE) || \
  122. ((MODE) == LL_DMA2D_ALPHA_MODE_COMBINE))
  123. /**
  124. * @}
  125. */
  126. /* Private function prototypes -----------------------------------------------*/
  127. /* Exported functions --------------------------------------------------------*/
  128. /** @addtogroup DMA2D_LL_Exported_Functions
  129. * @{
  130. */
  131. /** @addtogroup DMA2D_LL_EF_Init_Functions Initialization and De-initialization Functions
  132. * @{
  133. */
  134. /**
  135. * @brief De-initialize DMA2D registers (registers restored to their default values).
  136. * @param DMA2Dx DMA2D Instance
  137. * @retval An ErrorStatus enumeration value:
  138. * - SUCCESS: DMA2D registers are de-initialized
  139. * - ERROR: DMA2D registers are not de-initialized
  140. */
  141. ErrorStatus LL_DMA2D_DeInit(DMA2D_TypeDef *DMA2Dx)
  142. {
  143. ErrorStatus status = SUCCESS;
  144. /* Check the parameters */
  145. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  146. if (DMA2Dx == DMA2D)
  147. {
  148. /* Force reset of DMA2D clock */
  149. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA2D);
  150. /* Release reset of DMA2D clock */
  151. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA2D);
  152. }
  153. else
  154. {
  155. status = ERROR;
  156. }
  157. return (status);
  158. }
  159. /**
  160. * @brief Initialize DMA2D registers according to the specified parameters in DMA2D_InitStruct.
  161. * @note DMA2D transfers must be disabled to set initialization bits in configuration registers,
  162. * otherwise ERROR result is returned.
  163. * @param DMA2Dx DMA2D Instance
  164. * @param DMA2D_InitStruct: pointer to a LL_DMA2D_InitTypeDef structure
  165. * that contains the configuration information for the specified DMA2D peripheral.
  166. * @retval An ErrorStatus enumeration value:
  167. * - SUCCESS: DMA2D registers are initialized according to DMA2D_InitStruct content
  168. * - ERROR: Issue occurred during DMA2D registers initialization
  169. */
  170. ErrorStatus LL_DMA2D_Init(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_InitTypeDef *DMA2D_InitStruct)
  171. {
  172. ErrorStatus status = ERROR;
  173. LL_DMA2D_ColorTypeDef DMA2D_ColorStruct;
  174. uint32_t tmp = 0U, tmp1 = 0U, tmp2 = 0U;
  175. /* Check the parameters */
  176. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  177. assert_param(IS_LL_DMA2D_MODE(DMA2D_InitStruct->Mode));
  178. assert_param(IS_LL_DMA2D_OCMODE(DMA2D_InitStruct->ColorMode));
  179. assert_param(IS_LL_DMA2D_LINE(DMA2D_InitStruct->NbrOfLines));
  180. assert_param(IS_LL_DMA2D_PIXEL(DMA2D_InitStruct->NbrOfPixelsPerLines));
  181. assert_param(IS_LL_DMA2D_GREEN(DMA2D_InitStruct->OutputGreen));
  182. assert_param(IS_LL_DMA2D_RED(DMA2D_InitStruct->OutputRed));
  183. assert_param(IS_LL_DMA2D_BLUE(DMA2D_InitStruct->OutputBlue));
  184. assert_param(IS_LL_DMA2D_ALPHA(DMA2D_InitStruct->OutputAlpha));
  185. #if defined(DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT)
  186. assert_param(IS_LL_DMA2D_SWAP_MODE(DMA2D_InitStruct->OutputSwapMode));
  187. #endif /* DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT */
  188. #if defined(DMA2D_LINE_OFFSET_MODE_SUPPORT)
  189. assert_param(IS_LL_DMA2D_OFFSET_MODE(DMA2D_InitStruct->LineOffsetMode));
  190. #endif /* DMA2D_LINE_OFFSET_MODE_SUPPORT */
  191. assert_param(IS_LL_DMA2D_OFFSET(DMA2D_InitStruct->LineOffset));
  192. assert_param(IS_LL_DMA2D_ALPHAINV(DMA2D_InitStruct->AlphaInversionMode));
  193. assert_param(IS_LL_DMA2D_RBSWAP(DMA2D_InitStruct->RBSwapMode));
  194. /* DMA2D transfers must be disabled to configure bits in initialization registers */
  195. tmp = LL_DMA2D_IsTransferOngoing(DMA2Dx);
  196. tmp1 = LL_DMA2D_FGND_IsEnabledCLUTLoad(DMA2Dx);
  197. tmp2 = LL_DMA2D_BGND_IsEnabledCLUTLoad(DMA2Dx);
  198. if ((tmp == 0U) && (tmp1 == 0U) && (tmp2 == 0U))
  199. {
  200. /* DMA2D CR register configuration -------------------------------------------*/
  201. #if defined(DMA2D_LINE_OFFSET_MODE_SUPPORT)
  202. MODIFY_REG(DMA2Dx->CR, (DMA2D_CR_MODE | DMA2D_CR_LOM), \
  203. (DMA2D_InitStruct->Mode | DMA2D_InitStruct->LineOffsetMode));
  204. #else
  205. LL_DMA2D_SetMode(DMA2Dx, DMA2D_InitStruct->Mode);
  206. #endif /* DMA2D_LINE_OFFSET_MODE_SUPPORT */
  207. /* DMA2D OPFCCR register configuration ---------------------------------------*/
  208. #if defined(DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT)
  209. MODIFY_REG(DMA2Dx->OPFCCR, (DMA2D_OPFCCR_CM | DMA2D_OPFCCR_SB | DMA2D_OPFCCR_AI | DMA2D_OPFCCR_RBS), \
  210. (DMA2D_InitStruct->ColorMode | DMA2D_InitStruct->OutputSwapMode | DMA2D_InitStruct->AlphaInversionMode | DMA2D_InitStruct->RBSwapMode));
  211. #else
  212. MODIFY_REG(DMA2Dx->OPFCCR, (DMA2D_OPFCCR_CM | DMA2D_OPFCCR_RBS | DMA2D_OPFCCR_AI), \
  213. (DMA2D_InitStruct->ColorMode | DMA2D_InitStruct->AlphaInversionMode | DMA2D_InitStruct->RBSwapMode));
  214. #endif /* DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT */
  215. /* DMA2D OOR register configuration ------------------------------------------*/
  216. LL_DMA2D_SetLineOffset(DMA2Dx, DMA2D_InitStruct->LineOffset);
  217. /* DMA2D NLR register configuration ------------------------------------------*/
  218. LL_DMA2D_ConfigSize(DMA2Dx, DMA2D_InitStruct->NbrOfLines, DMA2D_InitStruct->NbrOfPixelsPerLines);
  219. /* DMA2D OMAR register configuration ------------------------------------------*/
  220. LL_DMA2D_SetOutputMemAddr(DMA2Dx, DMA2D_InitStruct->OutputMemoryAddress);
  221. /* DMA2D OCOLR register configuration ------------------------------------------*/
  222. DMA2D_ColorStruct.ColorMode = DMA2D_InitStruct->ColorMode;
  223. DMA2D_ColorStruct.OutputBlue = DMA2D_InitStruct->OutputBlue;
  224. DMA2D_ColorStruct.OutputGreen = DMA2D_InitStruct->OutputGreen;
  225. DMA2D_ColorStruct.OutputRed = DMA2D_InitStruct->OutputRed;
  226. DMA2D_ColorStruct.OutputAlpha = DMA2D_InitStruct->OutputAlpha;
  227. LL_DMA2D_ConfigOutputColor(DMA2Dx, &DMA2D_ColorStruct);
  228. status = SUCCESS;
  229. }
  230. /* If DMA2D transfers are not disabled, return ERROR */
  231. return (status);
  232. }
  233. /**
  234. * @brief Set each @ref LL_DMA2D_InitTypeDef field to default value.
  235. * @param DMA2D_InitStruct: pointer to a @ref LL_DMA2D_InitTypeDef structure
  236. * whose fields will be set to default values.
  237. * @retval None
  238. */
  239. void LL_DMA2D_StructInit(LL_DMA2D_InitTypeDef *DMA2D_InitStruct)
  240. {
  241. /* Set DMA2D_InitStruct fields to default values */
  242. DMA2D_InitStruct->Mode = LL_DMA2D_MODE_M2M;
  243. DMA2D_InitStruct->ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB8888;
  244. DMA2D_InitStruct->NbrOfLines = 0x0U;
  245. DMA2D_InitStruct->NbrOfPixelsPerLines = 0x0U;
  246. #if defined(DMA2D_LINE_OFFSET_MODE_SUPPORT)
  247. DMA2D_InitStruct->LineOffsetMode = LL_DMA2D_LINE_OFFSET_PIXELS;
  248. #endif /* DMA2D_LINE_OFFSET_MODE_SUPPORT */
  249. DMA2D_InitStruct->LineOffset = 0x0U;
  250. DMA2D_InitStruct->OutputBlue = 0x0U;
  251. DMA2D_InitStruct->OutputGreen = 0x0U;
  252. DMA2D_InitStruct->OutputRed = 0x0U;
  253. DMA2D_InitStruct->OutputAlpha = 0x0U;
  254. DMA2D_InitStruct->OutputMemoryAddress = 0x0U;
  255. #if defined(DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT)
  256. DMA2D_InitStruct->OutputSwapMode = LL_DMA2D_SWAP_MODE_REGULAR;
  257. #endif /* DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT */
  258. DMA2D_InitStruct->AlphaInversionMode = LL_DMA2D_ALPHA_REGULAR;
  259. DMA2D_InitStruct->RBSwapMode = LL_DMA2D_RB_MODE_REGULAR;
  260. }
  261. /**
  262. * @brief Configure the foreground or background according to the specified parameters
  263. * in the LL_DMA2D_LayerCfgTypeDef structure.
  264. * @param DMA2Dx DMA2D Instance
  265. * @param DMA2D_LayerCfg: pointer to a LL_DMA2D_LayerCfgTypeDef structure that contains
  266. * the configuration information for the specified layer.
  267. * @param LayerIdx: DMA2D Layer index.
  268. * This parameter can be one of the following values:
  269. * 0(background) / 1(foreground)
  270. * @retval None
  271. */
  272. void LL_DMA2D_ConfigLayer(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg, uint32_t LayerIdx)
  273. {
  274. /* Check the parameters */
  275. assert_param(IS_LL_DMA2D_OFFSET(DMA2D_LayerCfg->LineOffset));
  276. assert_param(IS_LL_DMA2D_LCMODE(DMA2D_LayerCfg->ColorMode));
  277. assert_param(IS_LL_DMA2D_CLUTCMODE(DMA2D_LayerCfg->CLUTColorMode));
  278. assert_param(IS_LL_DMA2D_CLUTSIZE(DMA2D_LayerCfg->CLUTSize));
  279. assert_param(IS_LL_DMA2D_ALPHAMODE(DMA2D_LayerCfg->AlphaMode));
  280. assert_param(IS_LL_DMA2D_GREEN(DMA2D_LayerCfg->Green));
  281. assert_param(IS_LL_DMA2D_RED(DMA2D_LayerCfg->Red));
  282. assert_param(IS_LL_DMA2D_BLUE(DMA2D_LayerCfg->Blue));
  283. assert_param(IS_LL_DMA2D_ALPHA(DMA2D_LayerCfg->Alpha));
  284. assert_param(IS_LL_DMA2D_ALPHAINV(DMA2D_LayerCfg->AlphaInversionMode));
  285. assert_param(IS_LL_DMA2D_RBSWAP(DMA2D_LayerCfg->RBSwapMode));
  286. if (LayerIdx == 0U)
  287. {
  288. /* Configure the background memory address */
  289. LL_DMA2D_BGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress);
  290. /* Configure the background line offset */
  291. LL_DMA2D_BGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset);
  292. /* Configure the background Alpha value, Alpha mode, RB swap, Alpha inversion
  293. CLUT size, CLUT Color mode and Color mode */
  294. MODIFY_REG(DMA2Dx->BGPFCCR, \
  295. (DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_RBS | DMA2D_BGPFCCR_AI | DMA2D_BGPFCCR_AM | \
  296. DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM | DMA2D_BGPFCCR_CM), \
  297. ((DMA2D_LayerCfg->Alpha << DMA2D_BGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->RBSwapMode | \
  298. DMA2D_LayerCfg->AlphaInversionMode | DMA2D_LayerCfg->AlphaMode | \
  299. (DMA2D_LayerCfg->CLUTSize << DMA2D_BGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
  300. DMA2D_LayerCfg->ColorMode));
  301. /* Configure the background color */
  302. LL_DMA2D_BGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue);
  303. /* Configure the background CLUT memory address */
  304. LL_DMA2D_BGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress);
  305. }
  306. else
  307. {
  308. /* Configure the foreground memory address */
  309. LL_DMA2D_FGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress);
  310. /* Configure the foreground line offset */
  311. LL_DMA2D_FGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset);
  312. /* Configure the foreground Alpha value, Alpha mode, RB swap, Alpha inversion
  313. CLUT size, CLUT Color mode and Color mode */
  314. MODIFY_REG(DMA2Dx->FGPFCCR, \
  315. (DMA2D_FGPFCCR_ALPHA | DMA2D_FGPFCCR_RBS | DMA2D_FGPFCCR_AI | DMA2D_FGPFCCR_AM | \
  316. DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM | DMA2D_FGPFCCR_CM), \
  317. ((DMA2D_LayerCfg->Alpha << DMA2D_FGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->RBSwapMode | \
  318. DMA2D_LayerCfg->AlphaInversionMode | DMA2D_LayerCfg->AlphaMode | \
  319. (DMA2D_LayerCfg->CLUTSize << DMA2D_FGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
  320. DMA2D_LayerCfg->ColorMode));
  321. /* Configure the foreground color */
  322. LL_DMA2D_FGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue);
  323. /* Configure the foreground CLUT memory address */
  324. LL_DMA2D_FGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress);
  325. }
  326. }
  327. /**
  328. * @brief Set each @ref LL_DMA2D_LayerCfgTypeDef field to default value.
  329. * @param DMA2D_LayerCfg: pointer to a @ref LL_DMA2D_LayerCfgTypeDef structure
  330. * whose fields will be set to default values.
  331. * @retval None
  332. */
  333. void LL_DMA2D_LayerCfgStructInit(LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg)
  334. {
  335. /* Set DMA2D_LayerCfg fields to default values */
  336. DMA2D_LayerCfg->MemoryAddress = 0x0U;
  337. DMA2D_LayerCfg->ColorMode = LL_DMA2D_INPUT_MODE_ARGB8888;
  338. DMA2D_LayerCfg->LineOffset = 0x0U;
  339. DMA2D_LayerCfg->CLUTColorMode = LL_DMA2D_CLUT_COLOR_MODE_ARGB8888;
  340. DMA2D_LayerCfg->CLUTSize = 0x0U;
  341. DMA2D_LayerCfg->AlphaMode = LL_DMA2D_ALPHA_MODE_NO_MODIF;
  342. DMA2D_LayerCfg->Alpha = 0x0U;
  343. DMA2D_LayerCfg->Blue = 0x0U;
  344. DMA2D_LayerCfg->Green = 0x0U;
  345. DMA2D_LayerCfg->Red = 0x0U;
  346. DMA2D_LayerCfg->CLUTMemoryAddress = 0x0U;
  347. DMA2D_LayerCfg->AlphaInversionMode = LL_DMA2D_ALPHA_REGULAR;
  348. DMA2D_LayerCfg->RBSwapMode = LL_DMA2D_RB_MODE_REGULAR;
  349. }
  350. /**
  351. * @brief Initialize DMA2D output color register according to the specified parameters
  352. * in DMA2D_ColorStruct.
  353. * @param DMA2Dx DMA2D Instance
  354. * @param DMA2D_ColorStruct: pointer to a LL_DMA2D_ColorTypeDef structure that contains
  355. * the color configuration information for the specified DMA2D peripheral.
  356. * @retval None
  357. */
  358. void LL_DMA2D_ConfigOutputColor(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_ColorTypeDef *DMA2D_ColorStruct)
  359. {
  360. uint32_t outgreen = 0U;
  361. uint32_t outred = 0U;
  362. uint32_t outalpha = 0U;
  363. /* Check the parameters */
  364. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  365. assert_param(IS_LL_DMA2D_OCMODE(DMA2D_ColorStruct->ColorMode));
  366. assert_param(IS_LL_DMA2D_GREEN(DMA2D_ColorStruct->OutputGreen));
  367. assert_param(IS_LL_DMA2D_RED(DMA2D_ColorStruct->OutputRed));
  368. assert_param(IS_LL_DMA2D_BLUE(DMA2D_ColorStruct->OutputBlue));
  369. assert_param(IS_LL_DMA2D_ALPHA(DMA2D_ColorStruct->OutputAlpha));
  370. /* DMA2D OCOLR register configuration ------------------------------------------*/
  371. if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  372. {
  373. outgreen = DMA2D_ColorStruct->OutputGreen << 8U;
  374. outred = DMA2D_ColorStruct->OutputRed << 16U;
  375. outalpha = DMA2D_ColorStruct->OutputAlpha << 24U;
  376. }
  377. else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
  378. {
  379. outgreen = DMA2D_ColorStruct->OutputGreen << 8U;
  380. outred = DMA2D_ColorStruct->OutputRed << 16U;
  381. outalpha = 0x00000000U;
  382. }
  383. else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
  384. {
  385. outgreen = DMA2D_ColorStruct->OutputGreen << 5U;
  386. outred = DMA2D_ColorStruct->OutputRed << 11U;
  387. outalpha = 0x00000000U;
  388. }
  389. else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  390. {
  391. outgreen = DMA2D_ColorStruct->OutputGreen << 5U;
  392. outred = DMA2D_ColorStruct->OutputRed << 10U;
  393. outalpha = DMA2D_ColorStruct->OutputAlpha << 15U;
  394. }
  395. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  396. {
  397. outgreen = DMA2D_ColorStruct->OutputGreen << 4U;
  398. outred = DMA2D_ColorStruct->OutputRed << 8U;
  399. outalpha = DMA2D_ColorStruct->OutputAlpha << 12U;
  400. }
  401. LL_DMA2D_SetOutputColor(DMA2Dx, (outgreen | outred | DMA2D_ColorStruct->OutputBlue | outalpha));
  402. }
  403. /**
  404. * @brief Return DMA2D output Blue color.
  405. * @param DMA2Dx DMA2D Instance.
  406. * @param ColorMode This parameter can be one of the following values:
  407. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
  408. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
  409. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
  410. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
  411. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
  412. * @retval Output Blue color value between Min_Data=0 and Max_Data=0xFF
  413. */
  414. uint32_t LL_DMA2D_GetOutputBlueColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
  415. {
  416. uint32_t color = 0U;
  417. /* Check the parameters */
  418. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  419. assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
  420. /* DMA2D OCOLR register reading ------------------------------------------*/
  421. if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  422. {
  423. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFFU));
  424. }
  425. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
  426. {
  427. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFFU));
  428. }
  429. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
  430. {
  431. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x1FU));
  432. }
  433. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  434. {
  435. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x1FU));
  436. }
  437. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  438. {
  439. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFU));
  440. }
  441. return color;
  442. }
  443. /**
  444. * @brief Return DMA2D output Green color.
  445. * @param DMA2Dx DMA2D Instance.
  446. * @param ColorMode This parameter can be one of the following values:
  447. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
  448. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
  449. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
  450. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
  451. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
  452. * @retval Output Green color value between Min_Data=0 and Max_Data=0xFF
  453. */
  454. uint32_t LL_DMA2D_GetOutputGreenColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
  455. {
  456. uint32_t color = 0U;
  457. /* Check the parameters */
  458. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  459. assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
  460. /* DMA2D OCOLR register reading ------------------------------------------*/
  461. if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  462. {
  463. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF00U) >> 8U);
  464. }
  465. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
  466. {
  467. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF00U) >> 8U);
  468. }
  469. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
  470. {
  471. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x7E0U) >> 5U);
  472. }
  473. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  474. {
  475. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x3E0U) >> 5U);
  476. }
  477. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  478. {
  479. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF0U) >> 4U);
  480. }
  481. return color;
  482. }
  483. /**
  484. * @brief Return DMA2D output Red color.
  485. * @param DMA2Dx DMA2D Instance.
  486. * @param ColorMode This parameter can be one of the following values:
  487. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
  488. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
  489. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
  490. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
  491. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
  492. * @retval Output Red color value between Min_Data=0 and Max_Data=0xFF
  493. */
  494. uint32_t LL_DMA2D_GetOutputRedColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
  495. {
  496. uint32_t color = 0U;
  497. /* Check the parameters */
  498. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  499. assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
  500. /* DMA2D OCOLR register reading ------------------------------------------*/
  501. if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  502. {
  503. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF0000U) >> 16U);
  504. }
  505. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
  506. {
  507. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF0000U) >> 16U);
  508. }
  509. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
  510. {
  511. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF800U) >> 11U);
  512. }
  513. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  514. {
  515. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x7C00U) >> 10U);
  516. }
  517. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  518. {
  519. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF00U) >> 8U);
  520. }
  521. return color;
  522. }
  523. /**
  524. * @brief Return DMA2D output Alpha color.
  525. * @param DMA2Dx DMA2D Instance.
  526. * @param ColorMode This parameter can be one of the following values:
  527. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
  528. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
  529. * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
  530. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
  531. * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
  532. * @retval Output Alpha color value between Min_Data=0 and Max_Data=0xFF
  533. */
  534. uint32_t LL_DMA2D_GetOutputAlphaColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
  535. {
  536. uint32_t color = 0U;
  537. /* Check the parameters */
  538. assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
  539. assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
  540. /* DMA2D OCOLR register reading ------------------------------------------*/
  541. if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
  542. {
  543. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF000000U) >> 24U);
  544. }
  545. else if ((ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888) || (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565))
  546. {
  547. color = 0x0U;
  548. }
  549. else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
  550. {
  551. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x8000U) >> 15U);
  552. }
  553. else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
  554. {
  555. color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF000U) >> 12U);
  556. }
  557. return color;
  558. }
  559. /**
  560. * @brief Configure DMA2D transfer size.
  561. * @param DMA2Dx DMA2D Instance
  562. * @param NbrOfLines Value between Min_Data=0 and Max_Data=0xFFFF
  563. * @param NbrOfPixelsPerLines Value between Min_Data=0 and Max_Data=0x3FFF
  564. * @retval None
  565. */
  566. void LL_DMA2D_ConfigSize(DMA2D_TypeDef *DMA2Dx, uint32_t NbrOfLines, uint32_t NbrOfPixelsPerLines)
  567. {
  568. MODIFY_REG(DMA2Dx->NLR, (DMA2D_NLR_PL | DMA2D_NLR_NL), \
  569. ((NbrOfPixelsPerLines << DMA2D_NLR_PL_Pos) | NbrOfLines));
  570. }
  571. /**
  572. * @}
  573. */
  574. /**
  575. * @}
  576. */
  577. /**
  578. * @}
  579. */
  580. #endif /* defined (DMA2D) */
  581. /**
  582. * @}
  583. */
  584. #endif /* USE_FULL_LL_DRIVER */
  585. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/