You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

600 lines
24 KiB

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