![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Lab4 DMA2D Embedded Systems
Dependencies: BSP_DISCO_F746NG mbed
main.cpp@2:b4b0e5e08b0a, 2017-10-24 (annotated)
- Committer:
- codebreaker7
- Date:
- Tue Oct 24 06:27:04 2017 +0000
- Revision:
- 2:b4b0e5e08b0a
- Parent:
- 1:751d3c9544ea
- Child:
- 3:ed3e2096b46f
Added example how to draw red square in the specified position and cleaned up some code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
codebreaker7 | 0:919da762f527 | 1 | //#include "mbed.h" |
codebreaker7 | 0:919da762f527 | 2 | |
codebreaker7 | 0:919da762f527 | 3 | #include "stm32f7xx.h" |
codebreaker7 | 0:919da762f527 | 4 | #include "stm32746g_discovery.h" |
codebreaker7 | 0:919da762f527 | 5 | #include "stm32746g_discovery_lcd.h" |
codebreaker7 | 0:919da762f527 | 6 | #include "stm32f7xx_hal_dma2d.h" |
codebreaker7 | 0:919da762f527 | 7 | #include "ARGB4444_150x150.h" |
codebreaker7 | 0:919da762f527 | 8 | |
codebreaker7 | 0:919da762f527 | 9 | #define LCD_MEM_ADDR (LCD_FB_START_ADDRESS + (480 * 272) * 4) |
codebreaker7 | 0:919da762f527 | 10 | |
codebreaker7 | 0:919da762f527 | 11 | DMA2D_HandleTypeDef hdma2d; |
codebreaker7 | 0:919da762f527 | 12 | |
codebreaker7 | 0:919da762f527 | 13 | void DMA2D_Config(void); |
codebreaker7 | 0:919da762f527 | 14 | uint32_t ramBuffer[(150 * 150 * 2) / 4]; |
codebreaker7 | 0:919da762f527 | 15 | uint32_t offset = ((272 - 150) / 2 * 480 + (480 - 150) / 2) * 4; |
codebreaker7 | 0:919da762f527 | 16 | |
codebreaker7 | 0:919da762f527 | 17 | int main(void) |
codebreaker7 | 0:919da762f527 | 18 | { |
codebreaker7 | 0:919da762f527 | 19 | int xpos_offset = 0; |
codebreaker7 | 0:919da762f527 | 20 | HAL_Init(); |
codebreaker7 | 0:919da762f527 | 21 | |
codebreaker7 | 0:919da762f527 | 22 | BSP_LCD_Init(); |
codebreaker7 | 0:919da762f527 | 23 | BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); |
codebreaker7 | 0:919da762f527 | 24 | BSP_LCD_Clear(LCD_COLOR_BLACK); |
codebreaker7 | 0:919da762f527 | 25 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
codebreaker7 | 0:919da762f527 | 26 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
codebreaker7 | 0:919da762f527 | 27 | BSP_LCD_SetFont(&Font16); |
codebreaker7 | 0:919da762f527 | 28 | |
codebreaker7 | 0:919da762f527 | 29 | DMA2D_Config(); |
codebreaker7 | 0:919da762f527 | 30 | |
codebreaker7 | 0:919da762f527 | 31 | HAL_DMA2D_Start(&hdma2d, (uint32_t)&ARGB4444_150x150, (uint32_t)&ramBuffer, 150, 150); |
codebreaker7 | 0:919da762f527 | 32 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 0:919da762f527 | 33 | |
codebreaker7 | 0:919da762f527 | 34 | hdma2d.Init.Mode = DMA2D_M2M_PFC; |
codebreaker7 | 0:919da762f527 | 35 | hdma2d.Init.ColorMode = DMA2D_ARGB8888; |
codebreaker7 | 0:919da762f527 | 36 | hdma2d.Init.OutputOffset = 480 - 150; |
codebreaker7 | 0:919da762f527 | 37 | |
codebreaker7 | 0:919da762f527 | 38 | hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
codebreaker7 | 0:919da762f527 | 39 | hdma2d.LayerCfg[1].InputAlpha = 0xff; |
codebreaker7 | 0:919da762f527 | 40 | hdma2d.LayerCfg[1].InputColorMode = CM_ARGB4444; |
codebreaker7 | 0:919da762f527 | 41 | hdma2d.LayerCfg[1].InputOffset = 0; |
codebreaker7 | 0:919da762f527 | 42 | |
codebreaker7 | 0:919da762f527 | 43 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 0:919da762f527 | 44 | HAL_DMA2D_ConfigLayer(&hdma2d, 1); |
codebreaker7 | 0:919da762f527 | 45 | HAL_DMA2D_Start(&hdma2d, (uint32_t)&ramBuffer, LCD_FB_START_ADDRESS + offset, 150, 150); |
codebreaker7 | 0:919da762f527 | 46 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 0:919da762f527 | 47 | |
codebreaker7 | 0:919da762f527 | 48 | for(;;){ |
codebreaker7 | 0:919da762f527 | 49 | // fill the previous position of image |
codebreaker7 | 0:919da762f527 | 50 | hdma2d.Init.Mode = DMA2D_R2M; |
codebreaker7 | 0:919da762f527 | 51 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 2:b4b0e5e08b0a | 52 | HAL_DMA2D_Start(&hdma2d, 0x00ff0000, LCD_MEM_ADDR, 480, 272); |
codebreaker7 | 0:919da762f527 | 53 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 2:b4b0e5e08b0a | 54 | |
codebreaker7 | 2:b4b0e5e08b0a | 55 | // draw red square in position 10,10 |
codebreaker7 | 2:b4b0e5e08b0a | 56 | hdma2d.Init.Mode = DMA2D_R2M; |
codebreaker7 | 2:b4b0e5e08b0a | 57 | hdma2d.Init.OutputOffset = 480 - 50; |
codebreaker7 | 2:b4b0e5e08b0a | 58 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 2:b4b0e5e08b0a | 59 | HAL_DMA2D_Start(&hdma2d, 0xffff0000, LCD_MEM_ADDR + (10 * 480 + 10) * 4, 50, 50); |
codebreaker7 | 2:b4b0e5e08b0a | 60 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 2:b4b0e5e08b0a | 61 | |
codebreaker7 | 0:919da762f527 | 62 | // and move to the next |
codebreaker7 | 0:919da762f527 | 63 | xpos_offset += 4; |
codebreaker7 | 0:919da762f527 | 64 | if (xpos_offset == 300) |
codebreaker7 | 0:919da762f527 | 65 | xpos_offset = 0; |
codebreaker7 | 0:919da762f527 | 66 | hdma2d.Init.Mode = DMA2D_M2M_PFC; |
codebreaker7 | 0:919da762f527 | 67 | hdma2d.Init.ColorMode = DMA2D_ARGB8888; |
codebreaker7 | 0:919da762f527 | 68 | hdma2d.Init.OutputOffset = 480 - 150; |
codebreaker7 | 0:919da762f527 | 69 | hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
codebreaker7 | 0:919da762f527 | 70 | hdma2d.LayerCfg[1].InputAlpha = 0xff; |
codebreaker7 | 0:919da762f527 | 71 | hdma2d.LayerCfg[1].InputColorMode = CM_ARGB4444; |
codebreaker7 | 0:919da762f527 | 72 | hdma2d.LayerCfg[1].InputOffset = 0; |
codebreaker7 | 0:919da762f527 | 73 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 0:919da762f527 | 74 | HAL_DMA2D_ConfigLayer(&hdma2d, 1); |
codebreaker7 | 0:919da762f527 | 75 | //HAL_DMA2D_Start(&hdma2d, (uint32_t)&ramBuffer, LCD_FB_START_ADDRESS + offset + xpos_offset, 150, 150); |
codebreaker7 | 0:919da762f527 | 76 | HAL_DMA2D_Start(&hdma2d, (uint32_t)&ramBuffer, LCD_MEM_ADDR + offset + xpos_offset, 150, 150); |
codebreaker7 | 0:919da762f527 | 77 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 0:919da762f527 | 78 | hdma2d.Init.OutputOffset = 0; |
codebreaker7 | 0:919da762f527 | 79 | hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
codebreaker7 | 0:919da762f527 | 80 | hdma2d.LayerCfg[1].InputAlpha = 0xff; |
codebreaker7 | 0:919da762f527 | 81 | hdma2d.LayerCfg[1].InputColorMode = CM_ARGB8888; |
codebreaker7 | 0:919da762f527 | 82 | hdma2d.LayerCfg[1].InputOffset = 0; |
codebreaker7 | 0:919da762f527 | 83 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 0:919da762f527 | 84 | HAL_DMA2D_ConfigLayer(&hdma2d, 1); |
codebreaker7 | 0:919da762f527 | 85 | HAL_DMA2D_Start(&hdma2d, LCD_MEM_ADDR, LCD_FB_START_ADDRESS, 480, 272); |
codebreaker7 | 0:919da762f527 | 86 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 0:919da762f527 | 87 | HAL_Delay(50); |
codebreaker7 | 0:919da762f527 | 88 | } |
codebreaker7 | 0:919da762f527 | 89 | } |
codebreaker7 | 0:919da762f527 | 90 | |
codebreaker7 | 0:919da762f527 | 91 | void DMA2D_Config(void) { |
codebreaker7 | 0:919da762f527 | 92 | hdma2d.Init.Mode = DMA2D_M2M; |
codebreaker7 | 0:919da762f527 | 93 | hdma2d.Init.OutputOffset = 0; |
codebreaker7 | 0:919da762f527 | 94 | hdma2d.Init.ColorMode = DMA2D_ARGB4444; |
codebreaker7 | 0:919da762f527 | 95 | |
codebreaker7 | 0:919da762f527 | 96 | hdma2d.Instance = DMA2D; |
codebreaker7 | 0:919da762f527 | 97 | |
codebreaker7 | 0:919da762f527 | 98 | hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
codebreaker7 | 0:919da762f527 | 99 | hdma2d.LayerCfg[1].InputAlpha = 0xff; |
codebreaker7 | 0:919da762f527 | 100 | hdma2d.LayerCfg[1].InputOffset = 0; |
codebreaker7 | 0:919da762f527 | 101 | hdma2d.LayerCfg[1].InputColorMode = CM_ARGB4444; |
codebreaker7 | 0:919da762f527 | 102 | |
codebreaker7 | 0:919da762f527 | 103 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 0:919da762f527 | 104 | HAL_DMA2D_ConfigLayer(&hdma2d, 1); |
codebreaker7 | 0:919da762f527 | 105 | } |