Skip to content

Instantly share code, notes, and snippets.

@glegrain
Created August 4, 2020 09:20
Show Gist options
  • Save glegrain/4327385c2307ad7a2580a3f4c9a015c4 to your computer and use it in GitHub Desktop.
Save glegrain/4327385c2307ad7a2580a3f4c9a015c4 to your computer and use it in GitHub Desktop.
DMA2D Pixel format conversion
/* Private variables -------------------------------------------------------- */
DMA2D_HandleTypeDef hdma2d;
/* Private function prototypes ---------------------------------------------- */
static void DMA2D_Init(void);
static void DMA2D_Convert(void);
void DMA2D_Init(void)
{
HAL_StatusTypeDef status;
hdma2d.Instance = DMA2D;
hdma2d.Init.Mode = DMA2D_M2M_PFC;
hdma2d.Init.ColorMode = DMA2D_OUTPUT_RGB8888 ;
hdma2d.Init.OutputOffset = 0U;
hdma2d.Init.AlphaInverted = DMA2D_REGULAR_ALPHA;
hdma2d.Init.RedBlueSwap = DMA2D_RB_REGULAR;
hdma2d.Init.BytesSwap = DMA2D_BYTES_REGULAR;
hdma2d.Init.LineOffsetMode = DMA2D_LOM_PIXELS;
status = HAL_DMA2D_Init(&hdma2d);
if (status != HAL_OK) {
Error_Handler();
}
hdma2d.LayerCfg[1].InputOffset = 0x0;
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_RGB565;
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
hdma2d.LayerCfg[1].InputAlpha = 0xFF;
hdma2d.LayerCfg[1].AlphaInverted = DMA2D_REGULAR_ALPHA;
hdma2d.LayerCfg[1].RedBlueSwap = DMA2D_RB_REGULAR;
hdma2d.LayerCfg[1].ChromaSubSampling = DMA2D_NO_CSS;
status = HAL_DMA2D_ConfigLayer(&hdma2d, 1);
if (status != HAL_OK) {
Error_Handler();
}
}
void DMA2D_Convert(void)
{
HAL_StatusTypeDef status;
status = HAL_DMA2D_Start(&hdma2d, (uint32_t)pImgData_rgb565,
(uint32_t)pImgData_rgb8888, 320, 240);
if (status != HAL_OK) {
Error_Handler();
}
status = HAL_DMA2D_PollForTransfer(&hdma2d, 1000);
if (status != HAL_OK) {
Error_Handler();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment