stm32f4xx_ll_dma2d.c 24 KB

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