Use of double buffer on the DISCO_F746NG board
Dependencies: BSP_DISCO_F746NG
main.cpp@4:571a6b9cefbf, 21 months ago (annotated)
- Committer:
- codebreaker7
- Date:
- Thu Sep 29 10:22:48 2022 +0000
- Revision:
- 4:571a6b9cefbf
- Parent:
- 3:9f66aabe7b3b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:9933f7db9a9b | 1 | #include "mbed.h" |
Jerome Coutant
3:9f66aabe7b3b
|
2
|
#include "stm32746g_discovery_lcd.h"
|
|
Jerome Coutant
3:9f66aabe7b3b
|
3
|
#include "stm32746g_discovery_ts.h"
|
|
codebreaker7 | 4:571a6b9cefbf | 4 | #include "Monster1.h" |
codebreaker7 | 4:571a6b9cefbf | 5 | #include "upbutton.h" |
codebreaker7 | 4:571a6b9cefbf | 6 | #include "downbutton.h" |
codebreaker7 | 4:571a6b9cefbf | 7 | |
codebreaker7 | 4:571a6b9cefbf | 8 | #define LCD_FB1_START_ADDRESS (LCD_FB_START_ADDRESS + (480 * 272) * 4) |
codebreaker7 | 4:571a6b9cefbf | 9 | #define LCD_MEM_ADDR (LCD_FB1_START_ADDRESS + 4 * 480 * 272) |
codebreaker7 | 4:571a6b9cefbf | 10 | |
codebreaker7 | 4:571a6b9cefbf | 11 | TIM_HandleTypeDef htim3; |
codebreaker7 | 4:571a6b9cefbf | 12 | DMA2D_HandleTypeDef hdma2d; |
codebreaker7 | 4:571a6b9cefbf | 13 | |
codebreaker7 | 4:571a6b9cefbf | 14 | uint32_t ramBuffer[ (192 * 32 * 2) / 4]; |
codebreaker7 | 4:571a6b9cefbf | 15 | |
codebreaker7 | 4:571a6b9cefbf | 16 | int y_offset = 0; |
codebreaker7 | 4:571a6b9cefbf | 17 | int old_x_offset = 0, old_y_offset = 0; |
codebreaker7 | 4:571a6b9cefbf | 18 | |
codebreaker7 | 4:571a6b9cefbf | 19 | extern "C" void Init_TimerSensor(void) { |
codebreaker7 | 4:571a6b9cefbf | 20 | uint32_t prescalerValue = 0; |
codebreaker7 | 4:571a6b9cefbf | 21 | |
codebreaker7 | 4:571a6b9cefbf | 22 | __HAL_RCC_TIM3_CLK_ENABLE(); |
codebreaker7 | 4:571a6b9cefbf | 23 | |
codebreaker7 | 4:571a6b9cefbf | 24 | prescalerValue = (uint32_t)(SystemCoreClock / 2 / 10000)-1; |
codebreaker7 | 4:571a6b9cefbf | 25 | htim3.Instance = TIM3; |
codebreaker7 | 4:571a6b9cefbf | 26 | htim3.Init.Prescaler = prescalerValue; |
codebreaker7 | 4:571a6b9cefbf | 27 | htim3.Init.Period = 100 - 1; |
codebreaker7 | 4:571a6b9cefbf | 28 | htim3.Init.ClockDivision = 0; |
codebreaker7 | 4:571a6b9cefbf | 29 | htim3.Init.RepetitionCounter = 0; |
codebreaker7 | 4:571a6b9cefbf | 30 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
codebreaker7 | 4:571a6b9cefbf | 31 | HAL_TIM_Base_Init(&htim3); |
codebreaker7 | 4:571a6b9cefbf | 32 | |
codebreaker7 | 4:571a6b9cefbf | 33 | HAL_NVIC_SetPriority(TIM3_IRQn, 3, 0); |
codebreaker7 | 4:571a6b9cefbf | 34 | |
codebreaker7 | 4:571a6b9cefbf | 35 | HAL_NVIC_EnableIRQ(TIM3_IRQn); |
codebreaker7 | 4:571a6b9cefbf | 36 | |
codebreaker7 | 4:571a6b9cefbf | 37 | HAL_TIM_Base_Start_IT(&htim3); |
codebreaker7 | 4:571a6b9cefbf | 38 | } |
codebreaker7 | 4:571a6b9cefbf | 39 | |
codebreaker7 | 4:571a6b9cefbf | 40 | extern "C" void TIM3_IRQHandler(void) { |
codebreaker7 | 4:571a6b9cefbf | 41 | HAL_TIM_IRQHandler(&htim3); |
codebreaker7 | 4:571a6b9cefbf | 42 | } |
codebreaker7 | 4:571a6b9cefbf | 43 | |
codebreaker7 | 4:571a6b9cefbf | 44 | extern "C" void EXTI15_10_IRQHandler(void) { |
codebreaker7 | 4:571a6b9cefbf | 45 | HAL_GPIO_EXTI_IRQHandler(TS_INT_PIN); |
codebreaker7 | 4:571a6b9cefbf | 46 | } |
codebreaker7 | 4:571a6b9cefbf | 47 | |
codebreaker7 | 4:571a6b9cefbf | 48 | void DMA2D_Config(void); |
codebreaker7 | 4:571a6b9cefbf | 49 | void FillRectWithColor(uint32_t color, uint32_t dst_addr, int x, int y, int width, int height); |
codebreaker7 | 4:571a6b9cefbf | 50 | void MoveTileToMemory(uint32_t source_addr, uint32_t dest_addr, int width, int height); |
bcostm | 0:9933f7db9a9b | 51 | |
bcostm | 0:9933f7db9a9b | 52 | int main() |
bcostm | 0:9933f7db9a9b | 53 | { |
codebreaker7 | 4:571a6b9cefbf | 54 | HAL_Init(); |
codebreaker7 | 4:571a6b9cefbf | 55 | |
bcostm | 0:9933f7db9a9b | 56 | TS_StateTypeDef TS_State; |
bcostm | 0:9933f7db9a9b | 57 | uint16_t x, y; |
bcostm | 0:9933f7db9a9b | 58 | uint8_t text[30]; |
bcostm | 0:9933f7db9a9b | 59 | uint8_t status; |
bcostm | 0:9933f7db9a9b | 60 | uint8_t idx; |
bcostm | 0:9933f7db9a9b | 61 | uint8_t cleared = 0; |
bcostm | 0:9933f7db9a9b | 62 | uint8_t prev_nb_touches = 0; |
bcostm | 0:9933f7db9a9b | 63 | |
Jerome Coutant
3:9f66aabe7b3b
|
64
|
BSP_LCD_Init();
|
|
codebreaker7 | 4:571a6b9cefbf | 65 | BSP_LCD_LayerDefaultInit(0, LCD_FB1_START_ADDRESS); // init background layer address |
codebreaker7 | 4:571a6b9cefbf | 66 | |
Jerome Coutant
3:9f66aabe7b3b
|
67
|
BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
68
|
BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
|
|
codebreaker7 | 4:571a6b9cefbf | 69 | BSP_LCD_SetColorKeying(1, 0xffffffff); |
bcostm | 0:9933f7db9a9b | 70 | |
Jerome Coutant
3:9f66aabe7b3b
|
71
|
BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
72
|
HAL_Delay(1000);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
73
|
|
|
Jerome Coutant
3:9f66aabe7b3b
|
74
|
status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
|
|
bcostm | 0:9933f7db9a9b | 75 | if (status != TS_OK) { |
Jerome Coutant
3:9f66aabe7b3b
|
76
|
BSP_LCD_Clear(LCD_COLOR_RED);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
77
|
BSP_LCD_SetBackColor(LCD_COLOR_RED);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
78
|
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
79
|
BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
|
|
bcostm | 0:9933f7db9a9b | 80 | } else { |
codebreaker7 | 4:571a6b9cefbf | 81 | //BSP_LCD_Clear(LCD_COLOR_GREEN); |
Jerome Coutant
3:9f66aabe7b3b
|
82
|
BSP_LCD_SetBackColor(LCD_COLOR_GREEN);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
83
|
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
|
|
codebreaker7 | 4:571a6b9cefbf | 84 | //BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); |
codebreaker7 | 4:571a6b9cefbf | 85 | } |
codebreaker7 | 4:571a6b9cefbf | 86 | |
codebreaker7 | 4:571a6b9cefbf | 87 | if (BSP_TS_ITConfig() != TS_OK) { |
codebreaker7 | 4:571a6b9cefbf | 88 | BSP_LCD_Clear(LCD_COLOR_RED); |
codebreaker7 | 4:571a6b9cefbf | 89 | BSP_LCD_SetBackColor(LCD_COLOR_RED); |
codebreaker7 | 4:571a6b9cefbf | 90 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
codebreaker7 | 4:571a6b9cefbf | 91 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INTERRUPT FAIL", CENTER_MODE); |
bcostm | 0:9933f7db9a9b | 92 | } |
bcostm | 0:9933f7db9a9b | 93 | |
Jerome Coutant
3:9f66aabe7b3b
|
94
|
HAL_Delay(1000);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
95
|
BSP_LCD_SetFont(&Font12);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
96
|
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
|
|
Jerome Coutant
3:9f66aabe7b3b
|
97
|
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
|
|
codebreaker7 | 4:571a6b9cefbf | 98 | |
codebreaker7 | 4:571a6b9cefbf | 99 | //Init_TimerSensor(); |
codebreaker7 | 4:571a6b9cefbf | 100 | |
codebreaker7 | 4:571a6b9cefbf | 101 | // load image into memory |
codebreaker7 | 4:571a6b9cefbf | 102 | DMA2D_Config(); |
codebreaker7 | 4:571a6b9cefbf | 103 | HAL_DMA2D_Start(&hdma2d, (uint32_t)&pic_Dude_Monster_Walk_6_bmp, (uint32_t)&ramBuffer, 192, 32); |
codebreaker7 | 4:571a6b9cefbf | 104 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 4:571a6b9cefbf | 105 | |
codebreaker7 | 4:571a6b9cefbf | 106 | HAL_DMA2D_Start(&hdma2d, (uint32_t)&down_button_image_array, LCD_MEM_ADDR, 64, 64); |
codebreaker7 | 4:571a6b9cefbf | 107 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 4:571a6b9cefbf | 108 | HAL_DMA2D_Start(&hdma2d, (uint32_t)&up_button_image_array, LCD_MEM_ADDR + 64*64*2, 64, 64); |
codebreaker7 | 4:571a6b9cefbf | 109 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 4:571a6b9cefbf | 110 | |
codebreaker7 | 4:571a6b9cefbf | 111 | FillRectWithColor(0xff00ff00, LCD_FB_START_ADDRESS, 0, 0, 480, 272); |
codebreaker7 | 4:571a6b9cefbf | 112 | HAL_DMA2D_Start(&hdma2d, 0xff00ff00, LCD_FB1_START_ADDRESS, 480, 272); |
codebreaker7 | 4:571a6b9cefbf | 113 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 4:571a6b9cefbf | 114 | |
codebreaker7 | 4:571a6b9cefbf | 115 | |
codebreaker7 | 4:571a6b9cefbf | 116 | hdma2d.Init.Mode = DMA2D_M2M_PFC; |
codebreaker7 | 4:571a6b9cefbf | 117 | hdma2d.Init.ColorMode = DMA2D_ARGB8888; |
codebreaker7 | 4:571a6b9cefbf | 118 | hdma2d.Init.OutputOffset = 480 - 64; |
codebreaker7 | 4:571a6b9cefbf | 119 | hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
codebreaker7 | 4:571a6b9cefbf | 120 | hdma2d.LayerCfg[1].InputAlpha = 0xff; |
codebreaker7 | 4:571a6b9cefbf | 121 | hdma2d.LayerCfg[1].InputColorMode = CM_RGB565; |
codebreaker7 | 4:571a6b9cefbf | 122 | hdma2d.LayerCfg[1].InputOffset = 0; |
codebreaker7 | 4:571a6b9cefbf | 123 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 4:571a6b9cefbf | 124 | HAL_DMA2D_ConfigLayer(&hdma2d, 1); |
codebreaker7 | 4:571a6b9cefbf | 125 | HAL_DMA2D_Start(&hdma2d, LCD_MEM_ADDR, LCD_FB_START_ADDRESS + 240 * 4 + 480 * 200 * 4, 64, 64); |
codebreaker7 | 4:571a6b9cefbf | 126 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 4:571a6b9cefbf | 127 | HAL_DMA2D_Start(&hdma2d, LCD_MEM_ADDR + 64*64*2, LCD_FB_START_ADDRESS + 240 * 4 + 480 * 136 * 4, 64, 64); |
codebreaker7 | 4:571a6b9cefbf | 128 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 4:571a6b9cefbf | 129 | |
codebreaker7 | 4:571a6b9cefbf | 130 | int counter = 0; |
codebreaker7 | 4:571a6b9cefbf | 131 | int xpos_offset = 0; |
codebreaker7 | 4:571a6b9cefbf | 132 | int dir = 0; |
bcostm | 0:9933f7db9a9b | 133 | |
bcostm | 0:9933f7db9a9b | 134 | while(1) { |
codebreaker7 | 4:571a6b9cefbf | 135 | HAL_Delay(50); |
codebreaker7 | 4:571a6b9cefbf | 136 | // fill all area |
codebreaker7 | 4:571a6b9cefbf | 137 | FillRectWithColor(0xff00ff00, LCD_FB_START_ADDRESS, 0, 0, 480, 100); |
codebreaker7 | 4:571a6b9cefbf | 138 | |
codebreaker7 | 4:571a6b9cefbf | 139 | hdma2d.Init.Mode = DMA2D_M2M_PFC; |
codebreaker7 | 4:571a6b9cefbf | 140 | hdma2d.Init.ColorMode = DMA2D_ARGB8888; |
codebreaker7 | 4:571a6b9cefbf | 141 | hdma2d.Init.OutputOffset = 480 - 32; |
codebreaker7 | 4:571a6b9cefbf | 142 | hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
codebreaker7 | 4:571a6b9cefbf | 143 | hdma2d.LayerCfg[1].InputAlpha = 0xff; |
codebreaker7 | 4:571a6b9cefbf | 144 | hdma2d.LayerCfg[1].InputColorMode = CM_RGB565; |
codebreaker7 | 4:571a6b9cefbf | 145 | hdma2d.LayerCfg[1].InputOffset = 192 - 32; |
codebreaker7 | 4:571a6b9cefbf | 146 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 4:571a6b9cefbf | 147 | HAL_DMA2D_ConfigLayer(&hdma2d, 1); |
codebreaker7 | 4:571a6b9cefbf | 148 | //HAL_DMA2D_Start(&hdma2d, (uint32_t)&ramBuffer, LCD_FB_START_ADDRESS + offset + xpos_offset, 150, 150); |
codebreaker7 | 4:571a6b9cefbf | 149 | HAL_DMA2D_Start(&hdma2d, ((uint32_t)&ramBuffer) + counter * 64, LCD_FB_START_ADDRESS + xpos_offset * 4 + y_offset * 480 * 4, 32, 32); |
codebreaker7 | 4:571a6b9cefbf | 150 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 4:571a6b9cefbf | 151 | if (dir == 0) { |
codebreaker7 | 4:571a6b9cefbf | 152 | old_x_offset = xpos_offset; |
codebreaker7 | 4:571a6b9cefbf | 153 | xpos_offset++; |
codebreaker7 | 4:571a6b9cefbf | 154 | if (xpos_offset == 480-32) dir = 1; |
codebreaker7 | 4:571a6b9cefbf | 155 | } |
codebreaker7 | 4:571a6b9cefbf | 156 | else { |
codebreaker7 | 4:571a6b9cefbf | 157 | old_x_offset = xpos_offset; |
codebreaker7 | 4:571a6b9cefbf | 158 | xpos_offset--; |
codebreaker7 | 4:571a6b9cefbf | 159 | if (xpos_offset == 0) dir = 0; |
codebreaker7 | 4:571a6b9cefbf | 160 | } |
codebreaker7 | 4:571a6b9cefbf | 161 | counter++; |
codebreaker7 | 4:571a6b9cefbf | 162 | if (counter == 6) |
codebreaker7 | 4:571a6b9cefbf | 163 | counter = 0; |
codebreaker7 | 4:571a6b9cefbf | 164 | |
codebreaker7 | 4:571a6b9cefbf | 165 | /*BSP_TS_GetState(&TS_State); |
bcostm | 0:9933f7db9a9b | 166 | if (TS_State.touchDetected) { |
bcostm | 0:9933f7db9a9b | 167 | // Clear lines corresponding to old touches coordinates |
bcostm | 0:9933f7db9a9b | 168 | if (TS_State.touchDetected < prev_nb_touches) { |
bcostm | 0:9933f7db9a9b | 169 | for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) { |
Jerome Coutant
3:9f66aabe7b3b
|
170
|
BSP_LCD_ClearStringLine(idx);
|
|
bcostm | 0:9933f7db9a9b | 171 | } |
bcostm | 0:9933f7db9a9b | 172 | } |
bcostm | 0:9933f7db9a9b | 173 | prev_nb_touches = TS_State.touchDetected; |
bcostm | 0:9933f7db9a9b | 174 | |
bcostm | 0:9933f7db9a9b | 175 | cleared = 0; |
bcostm | 0:9933f7db9a9b | 176 | |
bcostm | 0:9933f7db9a9b | 177 | sprintf((char*)text, "Touches: %d", TS_State.touchDetected); |
Jerome Coutant
3:9f66aabe7b3b
|
178
|
BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
|
|
bcostm | 0:9933f7db9a9b | 179 | |
bcostm | 0:9933f7db9a9b | 180 | for (idx = 0; idx < TS_State.touchDetected; idx++) { |
bcostm | 0:9933f7db9a9b | 181 | x = TS_State.touchX[idx]; |
bcostm | 0:9933f7db9a9b | 182 | y = TS_State.touchY[idx]; |
bcostm | 0:9933f7db9a9b | 183 | sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); |
Jerome Coutant
3:9f66aabe7b3b
|
184
|
BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE);
|
|
bcostm | 0:9933f7db9a9b | 185 | } |
bcostm | 0:9933f7db9a9b | 186 | |
Jerome Coutant
3:9f66aabe7b3b
|
187
|
BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE);
|
|
bcostm | 0:9933f7db9a9b | 188 | } else { |
bcostm | 0:9933f7db9a9b | 189 | if (!cleared) { |
Jerome Coutant
3:9f66aabe7b3b
|
190
|
BSP_LCD_Clear(LCD_COLOR_BLUE);
|
|
bcostm | 0:9933f7db9a9b | 191 | sprintf((char*)text, "Touches: 0"); |
Jerome Coutant
3:9f66aabe7b3b
|
192
|
BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
|
|
bcostm | 0:9933f7db9a9b | 193 | cleared = 1; |
bcostm | 0:9933f7db9a9b | 194 | } |
codebreaker7 | 4:571a6b9cefbf | 195 | }*/ |
codebreaker7 | 4:571a6b9cefbf | 196 | } |
codebreaker7 | 4:571a6b9cefbf | 197 | } |
codebreaker7 | 4:571a6b9cefbf | 198 | |
codebreaker7 | 4:571a6b9cefbf | 199 | extern "C" void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { |
codebreaker7 | 4:571a6b9cefbf | 200 | TS_StateTypeDef ts; |
codebreaker7 | 4:571a6b9cefbf | 201 | BSP_TS_GetState(&ts); |
codebreaker7 | 4:571a6b9cefbf | 202 | if (ts.touchDetected) { |
codebreaker7 | 4:571a6b9cefbf | 203 | int x = ts.touchX[0]; |
codebreaker7 | 4:571a6b9cefbf | 204 | int y = ts.touchY[0]; |
codebreaker7 | 4:571a6b9cefbf | 205 | if (x > 240 && y > 136 && x < 304 && y < 200 && y_offset > 0) { |
codebreaker7 | 4:571a6b9cefbf | 206 | y_offset -= 2; |
codebreaker7 | 4:571a6b9cefbf | 207 | } |
codebreaker7 | 4:571a6b9cefbf | 208 | else if (x > 240 && y > 200 && x < 304 && y < 264 && y_offset < 72) { |
codebreaker7 | 4:571a6b9cefbf | 209 | y_offset += 2; |
bcostm | 0:9933f7db9a9b | 210 | } |
bcostm | 0:9933f7db9a9b | 211 | } |
bcostm | 0:9933f7db9a9b | 212 | } |
codebreaker7 | 4:571a6b9cefbf | 213 | |
codebreaker7 | 4:571a6b9cefbf | 214 | extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
codebreaker7 | 4:571a6b9cefbf | 215 | TS_StateTypeDef ts; |
codebreaker7 | 4:571a6b9cefbf | 216 | BSP_TS_GetState(&ts); |
codebreaker7 | 4:571a6b9cefbf | 217 | if (ts.touchDetected) { |
codebreaker7 | 4:571a6b9cefbf | 218 | int x = ts.touchX[0]; |
codebreaker7 | 4:571a6b9cefbf | 219 | int y = ts.touchY[0]; |
codebreaker7 | 4:571a6b9cefbf | 220 | if (x > 240 && y > 136 && x < 304 && y < 200 && y_offset > 0) { |
codebreaker7 | 4:571a6b9cefbf | 221 | old_y_offset = y_offset; |
codebreaker7 | 4:571a6b9cefbf | 222 | y_offset -= 2; |
codebreaker7 | 4:571a6b9cefbf | 223 | } |
codebreaker7 | 4:571a6b9cefbf | 224 | else if (x > 240 && y > 200 && x < 304 && y < 264 && y_offset < 72) { |
codebreaker7 | 4:571a6b9cefbf | 225 | old_y_offset = y_offset; |
codebreaker7 | 4:571a6b9cefbf | 226 | y_offset += 2; |
codebreaker7 | 4:571a6b9cefbf | 227 | } |
codebreaker7 | 4:571a6b9cefbf | 228 | } |
codebreaker7 | 4:571a6b9cefbf | 229 | } |
codebreaker7 | 4:571a6b9cefbf | 230 | |
codebreaker7 | 4:571a6b9cefbf | 231 | void DMA2D_Config(void) { |
codebreaker7 | 4:571a6b9cefbf | 232 | hdma2d.Instance = DMA2D; |
codebreaker7 | 4:571a6b9cefbf | 233 | hdma2d.Init.Mode = DMA2D_M2M; |
codebreaker7 | 4:571a6b9cefbf | 234 | hdma2d.Init.OutputOffset = 0; |
codebreaker7 | 4:571a6b9cefbf | 235 | hdma2d.Init.ColorMode = DMA2D_RGB565; |
codebreaker7 | 4:571a6b9cefbf | 236 | |
codebreaker7 | 4:571a6b9cefbf | 237 | hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
codebreaker7 | 4:571a6b9cefbf | 238 | hdma2d.LayerCfg[1].InputAlpha = 0xff; |
codebreaker7 | 4:571a6b9cefbf | 239 | hdma2d.LayerCfg[1].InputOffset = 0; |
codebreaker7 | 4:571a6b9cefbf | 240 | hdma2d.LayerCfg[1].InputColorMode = CM_RGB565; |
codebreaker7 | 4:571a6b9cefbf | 241 | |
codebreaker7 | 4:571a6b9cefbf | 242 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 4:571a6b9cefbf | 243 | HAL_DMA2D_ConfigLayer(&hdma2d, 1); |
codebreaker7 | 4:571a6b9cefbf | 244 | } |
codebreaker7 | 4:571a6b9cefbf | 245 | |
codebreaker7 | 4:571a6b9cefbf | 246 | void FillRectWithColor(uint32_t color, uint32_t dst_addr, int x, int y, int width, int height) { |
codebreaker7 | 4:571a6b9cefbf | 247 | hdma2d.Init.Mode = DMA2D_R2M; |
codebreaker7 | 4:571a6b9cefbf | 248 | hdma2d.Init.ColorMode = DMA2D_ARGB8888; |
codebreaker7 | 4:571a6b9cefbf | 249 | hdma2d.Init.OutputOffset = 480 - width; |
codebreaker7 | 4:571a6b9cefbf | 250 | HAL_DMA2D_Init(&hdma2d); |
codebreaker7 | 4:571a6b9cefbf | 251 | HAL_DMA2D_Start(&hdma2d, color, dst_addr + x * 4 + y * 480 * 4, width, height); |
codebreaker7 | 4:571a6b9cefbf | 252 | while(HAL_DMA2D_PollForTransfer(&hdma2d, 1000) != HAL_OK); |
codebreaker7 | 4:571a6b9cefbf | 253 | } |
codebreaker7 | 4:571a6b9cefbf | 254 | |
codebreaker7 | 4:571a6b9cefbf | 255 | void MoveTileToMemory(uint32_t source_addr, uint32_t dest_addr, int width, int height) { |
codebreaker7 | 4:571a6b9cefbf | 256 | // apply necessary changes |
codebreaker7 | 4:571a6b9cefbf | 257 | //HAL_DMA2D_Start(&hdma2d, (uint32_t)&ramBuffer, LCD_FB_START_ADDRESS, 32, 32); |
codebreaker7 | 4:571a6b9cefbf | 258 | } |
codebreaker7 | 4:571a6b9cefbf | 259 |