Lab4 DMA2D Embedded Systems
Dependencies: BSP_DISCO_F746NG mbed
main.cpp
- Committer:
- codebreaker7
- Date:
- 2017-10-21
- Revision:
- 0:919da762f527
- Child:
- 1:751d3c9544ea
File content as of revision 0:919da762f527:
//#include "mbed.h" /** ****************************************************************************** * @file main.c * @author Ac6 * @version V1.0 * @date 01-December-2013 * @brief Default main function. ****************************************************************************** */ #include "stm32f7xx.h" #include "stm32746g_discovery.h" #include "stm32746g_discovery_lcd.h" #include "stm32f7xx_hal_dma2d.h" #include "ARGB4444_150x150.h" #define LCD_MEM_ADDR (LCD_FB_START_ADDRESS + (480 * 272) * 4) void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; HAL_StatusTypeDef ret = HAL_OK; /* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 400; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 8; ret = HAL_RCC_OscConfig(&RCC_OscInitStruct); if(ret != HAL_OK) { while(1) { ; } } /* Activate the OverDrive to reach the 200 MHz Frequency */ ret = HAL_PWREx_EnableOverDrive(); if(ret != HAL_OK) { while(1) { ; } } /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6); if(ret != HAL_OK) { while(1) { ; } } } DMA2D_HandleTypeDef hdma2d; void DMA2D_Config(void); uint32_t ramBuffer[(150 * 150 * 2) / 4]; uint32_t offset = ((272 - 150) / 2 * 480 + (480 - 150) / 2) * 4; int main(void) { int xpos_offset = 0; HAL_Init(); //SystemClock_Config(); BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_Clear(LCD_COLOR_BLACK); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_SetFont(&Font16); DMA2D_Config(); HAL_DMA2D_Start(&hdma2d, (uint32_t)&ARGB4444_150x150, (uint32_t)&ramBuffer, 150, 150); while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); hdma2d.Init.Mode = DMA2D_M2M_PFC; hdma2d.Init.ColorMode = DMA2D_ARGB8888; hdma2d.Init.OutputOffset = 480 - 150; hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hdma2d.LayerCfg[1].InputAlpha = 0xff; hdma2d.LayerCfg[1].InputColorMode = CM_ARGB4444; hdma2d.LayerCfg[1].InputOffset = 0; HAL_DMA2D_Init(&hdma2d); HAL_DMA2D_ConfigLayer(&hdma2d, 1); HAL_DMA2D_Start(&hdma2d, (uint32_t)&ramBuffer, LCD_FB_START_ADDRESS + offset, 150, 150); while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); for(;;){ // fill the previous position of image hdma2d.Init.Mode = DMA2D_R2M; HAL_DMA2D_Init(&hdma2d); //HAL_DMA2D_Start(&hdma2d, 0x00000000, LCD_FB_START_ADDRESS + offset + xpos_offset, 150, 150); HAL_DMA2D_Start(&hdma2d, 0x00000000, LCD_MEM_ADDR, 480, 272); while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); // and move to the next xpos_offset += 4; if (xpos_offset == 300) xpos_offset = 0; hdma2d.Init.Mode = DMA2D_M2M_PFC; hdma2d.Init.ColorMode = DMA2D_ARGB8888; hdma2d.Init.OutputOffset = 480 - 150; hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hdma2d.LayerCfg[1].InputAlpha = 0xff; hdma2d.LayerCfg[1].InputColorMode = CM_ARGB4444; hdma2d.LayerCfg[1].InputOffset = 0; HAL_DMA2D_Init(&hdma2d); HAL_DMA2D_ConfigLayer(&hdma2d, 1); //HAL_DMA2D_Start(&hdma2d, (uint32_t)&ramBuffer, LCD_FB_START_ADDRESS + offset + xpos_offset, 150, 150); HAL_DMA2D_Start(&hdma2d, (uint32_t)&ramBuffer, LCD_MEM_ADDR + offset + xpos_offset, 150, 150); while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); hdma2d.Init.OutputOffset = 0; hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hdma2d.LayerCfg[1].InputAlpha = 0xff; hdma2d.LayerCfg[1].InputColorMode = CM_ARGB8888; hdma2d.LayerCfg[1].InputOffset = 0; HAL_DMA2D_Init(&hdma2d); HAL_DMA2D_ConfigLayer(&hdma2d, 1); HAL_DMA2D_Start(&hdma2d, LCD_MEM_ADDR, LCD_FB_START_ADDRESS, 480, 272); while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); HAL_Delay(50); } } void DMA2D_Config(void) { hdma2d.Init.Mode = DMA2D_M2M; hdma2d.Init.OutputOffset = 0; hdma2d.Init.ColorMode = DMA2D_ARGB4444; hdma2d.Instance = DMA2D; hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hdma2d.LayerCfg[1].InputAlpha = 0xff; hdma2d.LayerCfg[1].InputOffset = 0; hdma2d.LayerCfg[1].InputColorMode = CM_ARGB4444; HAL_DMA2D_Init(&hdma2d); HAL_DMA2D_ConfigLayer(&hdma2d, 1); }