Code commenté du projet LED

Dependencies:   BSP_DISCO_F746NG

Committer:
treina
Date:
Thu Jun 16 09:58:06 2022 +0000
Revision:
6:72febbe3ea91
Parent:
5:071136c3eefa
azd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JohnnyK 3:4f5dc253eb7b 1 /**
JohnnyK 3:4f5dc253eb7b 2 * @file tft.c
JohnnyK 3:4f5dc253eb7b 3 *
JohnnyK 3:4f5dc253eb7b 4 */
JohnnyK 5:071136c3eefa 5
JohnnyK 3:4f5dc253eb7b 6 /*********************
JohnnyK 3:4f5dc253eb7b 7 * INCLUDES
JohnnyK 3:4f5dc253eb7b 8 *********************/
JohnnyK 3:4f5dc253eb7b 9 #include "lv_conf.h"
JohnnyK 3:4f5dc253eb7b 10 #include "lvgl/lvgl.h"
JohnnyK 3:4f5dc253eb7b 11 #include <string.h>
JohnnyK 3:4f5dc253eb7b 12 #include <stdlib.h>
JohnnyK 5:071136c3eefa 13
JohnnyK 3:4f5dc253eb7b 14 #include "tft.h"
JohnnyK 3:4f5dc253eb7b 15 #include "stm32f7xx.h"
JohnnyK 3:4f5dc253eb7b 16 #include "stm32746g_discovery.h"
JohnnyK 3:4f5dc253eb7b 17 #include "stm32746g_discovery_sdram.h"
JohnnyK 3:4f5dc253eb7b 18 #include "stm32746g_discovery_ts.h"
JohnnyK 3:4f5dc253eb7b 19 #include "../Components/rk043fn48h/rk043fn48h.h"
JohnnyK 5:071136c3eefa 20
JohnnyK 3:4f5dc253eb7b 21 /*********************
JohnnyK 3:4f5dc253eb7b 22 * DEFINES
JohnnyK 3:4f5dc253eb7b 23 *********************/
JohnnyK 5:071136c3eefa 24
JohnnyK 3:4f5dc253eb7b 25 #if LV_COLOR_DEPTH != 16 && LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32
JohnnyK 3:4f5dc253eb7b 26 #error LV_COLOR_DEPTH must be 16, 24, or 32
JohnnyK 3:4f5dc253eb7b 27 #endif
JohnnyK 3:4f5dc253eb7b 28
JohnnyK 5:071136c3eefa 29 #define LV_USE_GPU 0
JohnnyK 5:071136c3eefa 30
JohnnyK 3:4f5dc253eb7b 31 /**
JohnnyK 3:4f5dc253eb7b 32 * @brief LCD status structure definition
JohnnyK 3:4f5dc253eb7b 33 */
JohnnyK 3:4f5dc253eb7b 34 #define LCD_OK ((uint8_t)0x00)
JohnnyK 3:4f5dc253eb7b 35 #define LCD_ERROR ((uint8_t)0x01)
JohnnyK 3:4f5dc253eb7b 36 #define LCD_TIMEOUT ((uint8_t)0x02)
JohnnyK 5:071136c3eefa 37
JohnnyK 3:4f5dc253eb7b 38 /**
JohnnyK 3:4f5dc253eb7b 39 * @brief LCD special pins
JohnnyK 3:4f5dc253eb7b 40 */
JohnnyK 3:4f5dc253eb7b 41 /* Display enable pin */
JohnnyK 3:4f5dc253eb7b 42 #define LCD_DISP_PIN GPIO_PIN_12
JohnnyK 3:4f5dc253eb7b 43 #define LCD_DISP_GPIO_PORT GPIOI
JohnnyK 3:4f5dc253eb7b 44 #define LCD_DISP_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
JohnnyK 3:4f5dc253eb7b 45 #define LCD_DISP_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
JohnnyK 5:071136c3eefa 46
JohnnyK 3:4f5dc253eb7b 47 /* Backlight control pin */
JohnnyK 3:4f5dc253eb7b 48 #define LCD_BL_CTRL_PIN GPIO_PIN_3
JohnnyK 3:4f5dc253eb7b 49 #define LCD_BL_CTRL_GPIO_PORT GPIOK
JohnnyK 3:4f5dc253eb7b 50 #define LCD_BL_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
JohnnyK 3:4f5dc253eb7b 51 #define LCD_BL_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
JohnnyK 5:071136c3eefa 52
JohnnyK 3:4f5dc253eb7b 53 #define CPY_BUF_DMA_STREAM DMA2_Stream0
JohnnyK 3:4f5dc253eb7b 54 #define CPY_BUF_DMA_CHANNEL DMA_CHANNEL_0
JohnnyK 3:4f5dc253eb7b 55 #define CPY_BUF_DMA_STREAM_IRQ DMA2_Stream0_IRQn
JohnnyK 3:4f5dc253eb7b 56 #define CPY_BUF_DMA_STREAM_IRQHANDLER DMA2_Stream0_IRQHandler
JohnnyK 5:071136c3eefa 57
JohnnyK 3:4f5dc253eb7b 58 /**********************
JohnnyK 3:4f5dc253eb7b 59 * TYPEDEFS
JohnnyK 3:4f5dc253eb7b 60 **********************/
JohnnyK 5:071136c3eefa 61
JohnnyK 3:4f5dc253eb7b 62 /**********************
JohnnyK 3:4f5dc253eb7b 63 * STATIC PROTOTYPES
JohnnyK 3:4f5dc253eb7b 64 **********************/
JohnnyK 5:071136c3eefa 65
JohnnyK 3:4f5dc253eb7b 66 /*These 3 functions are needed by LittlevGL*/
JohnnyK 3:4f5dc253eb7b 67 static void ex_disp_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t * color_p);
JohnnyK 3:4f5dc253eb7b 68 #if LV_USE_GPU
JohnnyK 3:4f5dc253eb7b 69 static void gpu_mem_blend(lv_disp_drv_t *disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
JohnnyK 3:4f5dc253eb7b 70 static void gpu_mem_fill(lv_disp_drv_t *disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width, const lv_area_t * fill_area, lv_color_t color);
JohnnyK 3:4f5dc253eb7b 71 #endif
JohnnyK 5:071136c3eefa 72
JohnnyK 3:4f5dc253eb7b 73 static uint8_t LCD_Init(void);
JohnnyK 3:4f5dc253eb7b 74 static void LCD_LayerRgb565Init(uint32_t FB_Address);
JohnnyK 3:4f5dc253eb7b 75 static void LCD_DisplayOn(void);
JohnnyK 5:071136c3eefa 76
JohnnyK 3:4f5dc253eb7b 77 static void DMA_Config(void);
JohnnyK 3:4f5dc253eb7b 78 static void DMA_TransferComplete(DMA_HandleTypeDef *han);
JohnnyK 3:4f5dc253eb7b 79 static void DMA_TransferError(DMA_HandleTypeDef *han);
JohnnyK 5:071136c3eefa 80
JohnnyK 3:4f5dc253eb7b 81 #if LV_USE_GPU
JohnnyK 3:4f5dc253eb7b 82 static void DMA2D_Config(void);
JohnnyK 3:4f5dc253eb7b 83 #endif
JohnnyK 5:071136c3eefa 84
JohnnyK 3:4f5dc253eb7b 85 /**********************
JohnnyK 3:4f5dc253eb7b 86 * STATIC VARIABLES
JohnnyK 3:4f5dc253eb7b 87 **********************/
JohnnyK 3:4f5dc253eb7b 88 #if LV_USE_GPU
JohnnyK 3:4f5dc253eb7b 89 static DMA2D_HandleTypeDef Dma2dHandle;
JohnnyK 3:4f5dc253eb7b 90 #endif
JohnnyK 3:4f5dc253eb7b 91 static LTDC_HandleTypeDef hLtdcHandler;
JohnnyK 5:071136c3eefa 92
JohnnyK 3:4f5dc253eb7b 93 #if LV_COLOR_DEPTH == 16
JohnnyK 3:4f5dc253eb7b 94 typedef uint16_t uintpixel_t;
JohnnyK 3:4f5dc253eb7b 95 #elif LV_COLOR_DEPTH == 24 || LV_COLOR_DEPTH == 32
JohnnyK 3:4f5dc253eb7b 96 typedef uint32_t uintpixel_t;
JohnnyK 3:4f5dc253eb7b 97 #endif
JohnnyK 5:071136c3eefa 98
JohnnyK 3:4f5dc253eb7b 99 /* You can try to change buffer to internal ram by uncommenting line below and commenting
JohnnyK 3:4f5dc253eb7b 100 * SDRAM one. */
JohnnyK 3:4f5dc253eb7b 101 //static uintpixel_t my_fb[TFT_HOR_RES * TFT_VER_RES];
JohnnyK 5:071136c3eefa 102
JohnnyK 3:4f5dc253eb7b 103 static __IO uintpixel_t * my_fb = (__IO uintpixel_t*) (SDRAM_DEVICE_ADDR);
JohnnyK 5:071136c3eefa 104
JohnnyK 3:4f5dc253eb7b 105 static DMA_HandleTypeDef DmaHandle;
JohnnyK 3:4f5dc253eb7b 106 static int32_t x1_flush;
JohnnyK 3:4f5dc253eb7b 107 static int32_t y1_flush;
JohnnyK 3:4f5dc253eb7b 108 static int32_t x2_flush;
JohnnyK 3:4f5dc253eb7b 109 static int32_t y2_fill;
JohnnyK 3:4f5dc253eb7b 110 static int32_t y_fill_act;
JohnnyK 3:4f5dc253eb7b 111 static const lv_color_t * buf_to_flush;
JohnnyK 5:071136c3eefa 112 static lv_disp_drv_t disp_drv;
JohnnyK 5:071136c3eefa 113
JohnnyK 3:4f5dc253eb7b 114 static lv_disp_t *our_disp = NULL;
JohnnyK 3:4f5dc253eb7b 115 /**********************
JohnnyK 3:4f5dc253eb7b 116 * MACROS
JohnnyK 3:4f5dc253eb7b 117 **********************/
JohnnyK 5:071136c3eefa 118
JohnnyK 3:4f5dc253eb7b 119 /**
JohnnyK 3:4f5dc253eb7b 120 * Initialize your display here
JohnnyK 3:4f5dc253eb7b 121 */
JohnnyK 5:071136c3eefa 122
JohnnyK 3:4f5dc253eb7b 123 void tft_init(void)
JohnnyK 3:4f5dc253eb7b 124 {
JohnnyK 5:071136c3eefa 125 /* There is only one display on STM32 */
JohnnyK 5:071136c3eefa 126 if(our_disp != NULL)
JohnnyK 5:071136c3eefa 127 abort();
JohnnyK 3:4f5dc253eb7b 128 /* LCD Initialization */
JohnnyK 3:4f5dc253eb7b 129 LCD_Init();
JohnnyK 5:071136c3eefa 130
JohnnyK 3:4f5dc253eb7b 131 /* LCD Initialization */
JohnnyK 3:4f5dc253eb7b 132 LCD_LayerRgb565Init((uint32_t)my_fb);
JohnnyK 5:071136c3eefa 133
JohnnyK 3:4f5dc253eb7b 134 /* Enable the LCD */
JohnnyK 3:4f5dc253eb7b 135 LCD_DisplayOn();
JohnnyK 5:071136c3eefa 136
JohnnyK 3:4f5dc253eb7b 137 DMA_Config();
JohnnyK 5:071136c3eefa 138
JohnnyK 3:4f5dc253eb7b 139 #if LV_USE_GPU != 0
JohnnyK 3:4f5dc253eb7b 140 DMA2D_Config();
JohnnyK 3:4f5dc253eb7b 141 #endif
JohnnyK 3:4f5dc253eb7b 142 /*-----------------------------
JohnnyK 5:071136c3eefa 143 * Create a buffer for drawing
JohnnyK 5:071136c3eefa 144 *----------------------------*/
JohnnyK 5:071136c3eefa 145
JohnnyK 3:4f5dc253eb7b 146 /* LittlevGL requires a buffer where it draws the objects. The buffer's has to be greater than 1 display row*/
JohnnyK 5:071136c3eefa 147
JohnnyK 5:071136c3eefa 148 static lv_disp_draw_buf_t buf;
JohnnyK 5:071136c3eefa 149 static lv_color_t buf1_1[TFT_HOR_RES * 68];
JohnnyK 5:071136c3eefa 150 static lv_color_t buf1_2[TFT_HOR_RES * 68];
JohnnyK 5:071136c3eefa 151 lv_disp_draw_buf_init(&buf, buf1_1, buf1_2, TFT_HOR_RES * 68); /*Initialize the display buffer*/
JohnnyK 5:071136c3eefa 152
JohnnyK 5:071136c3eefa 153
JohnnyK 5:071136c3eefa 154 /*-----------------------------------
JohnnyK 5:071136c3eefa 155 * Register the display in LittlevGL
JohnnyK 5:071136c3eefa 156 *----------------------------------*/
JohnnyK 5:071136c3eefa 157
JohnnyK 5:071136c3eefa 158 /*Descriptor of a display driver*/
JohnnyK 5:071136c3eefa 159 lv_disp_drv_init(&disp_drv); /*Basic initialization*/
JohnnyK 5:071136c3eefa 160
JohnnyK 5:071136c3eefa 161 /*Set up the functions to access to your display*/
JohnnyK 5:071136c3eefa 162
JohnnyK 5:071136c3eefa 163 /*Set the resolution of the display*/
JohnnyK 5:071136c3eefa 164 disp_drv.hor_res = TFT_HOR_RES;
JohnnyK 5:071136c3eefa 165 disp_drv.ver_res = TFT_VER_RES;
JohnnyK 5:071136c3eefa 166
JohnnyK 5:071136c3eefa 167 /*Used to copy the buffer's content to the display*/
JohnnyK 5:071136c3eefa 168 disp_drv.flush_cb = ex_disp_flush;
JohnnyK 5:071136c3eefa 169
JohnnyK 5:071136c3eefa 170 /*Set a display buffer*/
JohnnyK 5:071136c3eefa 171 disp_drv.draw_buf = &buf;
JohnnyK 5:071136c3eefa 172
JohnnyK 5:071136c3eefa 173
JohnnyK 5:071136c3eefa 174 /*Finally register the driver*/
JohnnyK 5:071136c3eefa 175 our_disp = lv_disp_drv_register(&disp_drv);
JohnnyK 3:4f5dc253eb7b 176 }
JohnnyK 5:071136c3eefa 177
JohnnyK 3:4f5dc253eb7b 178 /**********************
JohnnyK 3:4f5dc253eb7b 179 * STATIC FUNCTIONS
JohnnyK 3:4f5dc253eb7b 180 **********************/
JohnnyK 5:071136c3eefa 181
JohnnyK 3:4f5dc253eb7b 182 /* Flush the content of the internal buffer the specific area on the display
JohnnyK 3:4f5dc253eb7b 183 * You can use DMA or any hardware acceleration to do this operation in the background but
JohnnyK 3:4f5dc253eb7b 184 * 'lv_flush_ready()' has to be called when finished
JohnnyK 3:4f5dc253eb7b 185 * This function is required only when LV_VDB_SIZE != 0 in lv_conf.h*/
JohnnyK 3:4f5dc253eb7b 186 static void ex_disp_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t * color_p)
JohnnyK 3:4f5dc253eb7b 187 {
JohnnyK 5:071136c3eefa 188 int32_t x1 = area->x1;
JohnnyK 5:071136c3eefa 189 int32_t x2 = area->x2;
JohnnyK 5:071136c3eefa 190 int32_t y1 = area->y1;
JohnnyK 5:071136c3eefa 191 int32_t y2 = area->y2;
JohnnyK 3:4f5dc253eb7b 192 /*Return if the area is out the screen*/
JohnnyK 5:071136c3eefa 193
JohnnyK 3:4f5dc253eb7b 194 if(x2 < 0) return;
JohnnyK 3:4f5dc253eb7b 195 if(y2 < 0) return;
JohnnyK 3:4f5dc253eb7b 196 if(x1 > TFT_HOR_RES - 1) return;
JohnnyK 3:4f5dc253eb7b 197 if(y1 > TFT_VER_RES - 1) return;
JohnnyK 5:071136c3eefa 198
JohnnyK 3:4f5dc253eb7b 199 /*Truncate the area to the screen*/
JohnnyK 3:4f5dc253eb7b 200 int32_t act_x1 = x1 < 0 ? 0 : x1;
JohnnyK 3:4f5dc253eb7b 201 int32_t act_y1 = y1 < 0 ? 0 : y1;
JohnnyK 3:4f5dc253eb7b 202 int32_t act_x2 = x2 > TFT_HOR_RES - 1 ? TFT_HOR_RES - 1 : x2;
JohnnyK 3:4f5dc253eb7b 203 int32_t act_y2 = y2 > TFT_VER_RES - 1 ? TFT_VER_RES - 1 : y2;
JohnnyK 5:071136c3eefa 204
JohnnyK 3:4f5dc253eb7b 205 x1_flush = act_x1;
JohnnyK 3:4f5dc253eb7b 206 y1_flush = act_y1;
JohnnyK 3:4f5dc253eb7b 207 x2_flush = act_x2;
JohnnyK 3:4f5dc253eb7b 208 y2_fill = act_y2;
JohnnyK 3:4f5dc253eb7b 209 y_fill_act = act_y1;
JohnnyK 3:4f5dc253eb7b 210 buf_to_flush = color_p;
JohnnyK 5:071136c3eefa 211
JohnnyK 5:071136c3eefa 212 SCB_CleanInvalidateDCache();
JohnnyK 5:071136c3eefa 213 SCB_InvalidateICache();
JohnnyK 3:4f5dc253eb7b 214 /*##-7- Start the DMA transfer using the interrupt mode #*/
JohnnyK 3:4f5dc253eb7b 215 /* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */
JohnnyK 3:4f5dc253eb7b 216 /* Enable All the DMA interrupts */
JohnnyK 3:4f5dc253eb7b 217 HAL_StatusTypeDef err;
JohnnyK 3:4f5dc253eb7b 218 uint32_t length = (x2_flush - x1_flush + 1);
JohnnyK 3:4f5dc253eb7b 219 #if LV_COLOR_DEPTH == 24 || LV_COLOR_DEPTH == 32
JohnnyK 3:4f5dc253eb7b 220 length *= 2; /* STM32 DMA uses 16-bit chunks so multiply by 2 for 32-bit color */
JohnnyK 3:4f5dc253eb7b 221 #endif
JohnnyK 3:4f5dc253eb7b 222 err = HAL_DMA_Start_IT(&DmaHandle,(uint32_t)buf_to_flush, (uint32_t)&my_fb[y_fill_act * TFT_HOR_RES + x1_flush],
JohnnyK 3:4f5dc253eb7b 223 length);
JohnnyK 3:4f5dc253eb7b 224 if(err != HAL_OK)
JohnnyK 3:4f5dc253eb7b 225 {
JohnnyK 5:071136c3eefa 226 while(1); /*Halt on error*/
JohnnyK 3:4f5dc253eb7b 227 }
JohnnyK 3:4f5dc253eb7b 228 }
JohnnyK 5:071136c3eefa 229
JohnnyK 5:071136c3eefa 230
JohnnyK 3:4f5dc253eb7b 231 /**
JohnnyK 3:4f5dc253eb7b 232 * @brief Configure LCD pins, and peripheral clocks.
JohnnyK 3:4f5dc253eb7b 233 */
JohnnyK 3:4f5dc253eb7b 234 static void LCD_MspInit(void)
JohnnyK 3:4f5dc253eb7b 235 {
JohnnyK 3:4f5dc253eb7b 236 GPIO_InitTypeDef gpio_init_structure;
JohnnyK 5:071136c3eefa 237
JohnnyK 3:4f5dc253eb7b 238 /* Enable the LTDC and DMA2D clocks */
JohnnyK 3:4f5dc253eb7b 239 __HAL_RCC_LTDC_CLK_ENABLE();
JohnnyK 3:4f5dc253eb7b 240 #if LV_USE_GPU != 0
JohnnyK 3:4f5dc253eb7b 241 __HAL_RCC_DMA2D_CLK_ENABLE();
JohnnyK 3:4f5dc253eb7b 242 #endif
JohnnyK 3:4f5dc253eb7b 243 /* Enable GPIOs clock */
JohnnyK 3:4f5dc253eb7b 244 __HAL_RCC_GPIOE_CLK_ENABLE();
JohnnyK 3:4f5dc253eb7b 245 __HAL_RCC_GPIOG_CLK_ENABLE();
JohnnyK 3:4f5dc253eb7b 246 __HAL_RCC_GPIOI_CLK_ENABLE();
JohnnyK 3:4f5dc253eb7b 247 __HAL_RCC_GPIOJ_CLK_ENABLE();
JohnnyK 3:4f5dc253eb7b 248 __HAL_RCC_GPIOK_CLK_ENABLE();
JohnnyK 3:4f5dc253eb7b 249 LCD_DISP_GPIO_CLK_ENABLE();
JohnnyK 3:4f5dc253eb7b 250 LCD_BL_CTRL_GPIO_CLK_ENABLE();
JohnnyK 5:071136c3eefa 251
JohnnyK 3:4f5dc253eb7b 252 /*** LTDC Pins configuration ***/
JohnnyK 3:4f5dc253eb7b 253 /* GPIOE configuration */
JohnnyK 3:4f5dc253eb7b 254 gpio_init_structure.Pin = GPIO_PIN_4;
JohnnyK 3:4f5dc253eb7b 255 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
JohnnyK 3:4f5dc253eb7b 256 gpio_init_structure.Pull = GPIO_NOPULL;
JohnnyK 3:4f5dc253eb7b 257 gpio_init_structure.Speed = GPIO_SPEED_FAST;
JohnnyK 3:4f5dc253eb7b 258 gpio_init_structure.Alternate = GPIO_AF14_LTDC;
JohnnyK 3:4f5dc253eb7b 259 HAL_GPIO_Init(GPIOE, &gpio_init_structure);
JohnnyK 5:071136c3eefa 260
JohnnyK 3:4f5dc253eb7b 261 /* GPIOG configuration */
JohnnyK 3:4f5dc253eb7b 262 gpio_init_structure.Pin = GPIO_PIN_12;
JohnnyK 3:4f5dc253eb7b 263 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
JohnnyK 3:4f5dc253eb7b 264 gpio_init_structure.Alternate = GPIO_AF9_LTDC;
JohnnyK 3:4f5dc253eb7b 265 HAL_GPIO_Init(GPIOG, &gpio_init_structure);
JohnnyK 5:071136c3eefa 266
JohnnyK 3:4f5dc253eb7b 267 /* GPIOI LTDC alternate configuration */
JohnnyK 3:4f5dc253eb7b 268 gpio_init_structure.Pin = GPIO_PIN_9 | GPIO_PIN_10 | \
JohnnyK 3:4f5dc253eb7b 269 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
JohnnyK 3:4f5dc253eb7b 270 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
JohnnyK 3:4f5dc253eb7b 271 gpio_init_structure.Alternate = GPIO_AF14_LTDC;
JohnnyK 3:4f5dc253eb7b 272 HAL_GPIO_Init(GPIOI, &gpio_init_structure);
JohnnyK 5:071136c3eefa 273
JohnnyK 3:4f5dc253eb7b 274 /* GPIOJ configuration */
JohnnyK 3:4f5dc253eb7b 275 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | \
JohnnyK 3:4f5dc253eb7b 276 GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | \
JohnnyK 3:4f5dc253eb7b 277 GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \
JohnnyK 3:4f5dc253eb7b 278 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
JohnnyK 3:4f5dc253eb7b 279 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
JohnnyK 3:4f5dc253eb7b 280 gpio_init_structure.Alternate = GPIO_AF14_LTDC;
JohnnyK 3:4f5dc253eb7b 281 HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
JohnnyK 5:071136c3eefa 282
JohnnyK 3:4f5dc253eb7b 283 /* GPIOK configuration */
JohnnyK 3:4f5dc253eb7b 284 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_4 | \
JohnnyK 3:4f5dc253eb7b 285 GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
JohnnyK 3:4f5dc253eb7b 286 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
JohnnyK 3:4f5dc253eb7b 287 gpio_init_structure.Alternate = GPIO_AF14_LTDC;
JohnnyK 3:4f5dc253eb7b 288 HAL_GPIO_Init(GPIOK, &gpio_init_structure);
JohnnyK 5:071136c3eefa 289
JohnnyK 3:4f5dc253eb7b 290 /* LCD_DISP GPIO configuration */
JohnnyK 3:4f5dc253eb7b 291 gpio_init_structure.Pin = LCD_DISP_PIN; /* LCD_DISP pin has to be manually controlled */
JohnnyK 3:4f5dc253eb7b 292 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
JohnnyK 3:4f5dc253eb7b 293 HAL_GPIO_Init(LCD_DISP_GPIO_PORT, &gpio_init_structure);
JohnnyK 5:071136c3eefa 294
JohnnyK 3:4f5dc253eb7b 295 /* LCD_BL_CTRL GPIO configuration */
JohnnyK 3:4f5dc253eb7b 296 gpio_init_structure.Pin = LCD_BL_CTRL_PIN; /* LCD_BL_CTRL pin has to be manually controlled */
JohnnyK 3:4f5dc253eb7b 297 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
JohnnyK 3:4f5dc253eb7b 298 HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &gpio_init_structure);
JohnnyK 3:4f5dc253eb7b 299 }
JohnnyK 5:071136c3eefa 300
JohnnyK 3:4f5dc253eb7b 301 /**
JohnnyK 3:4f5dc253eb7b 302 * @brief Configure LTDC PLL.
JohnnyK 3:4f5dc253eb7b 303 */
JohnnyK 3:4f5dc253eb7b 304 static void LCD_ClockConfig(void)
JohnnyK 3:4f5dc253eb7b 305 {
JohnnyK 3:4f5dc253eb7b 306 static RCC_PeriphCLKInitTypeDef periph_clk_init_struct;
JohnnyK 5:071136c3eefa 307
JohnnyK 3:4f5dc253eb7b 308 /* RK043FN48H LCD clock configuration */
JohnnyK 3:4f5dc253eb7b 309 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
JohnnyK 3:4f5dc253eb7b 310 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
JohnnyK 3:4f5dc253eb7b 311 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/5 = 38.4 Mhz */
JohnnyK 3:4f5dc253eb7b 312 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_4 = 38.4/4 = 9.6Mhz */
JohnnyK 3:4f5dc253eb7b 313 periph_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
JohnnyK 3:4f5dc253eb7b 314 periph_clk_init_struct.PLLSAI.PLLSAIN = 192;
JohnnyK 3:4f5dc253eb7b 315 periph_clk_init_struct.PLLSAI.PLLSAIR = RK043FN48H_FREQUENCY_DIVIDER;
JohnnyK 3:4f5dc253eb7b 316 periph_clk_init_struct.PLLSAIDivR = RCC_PLLSAIDIVR_4;
JohnnyK 3:4f5dc253eb7b 317 HAL_RCCEx_PeriphCLKConfig(&periph_clk_init_struct);
JohnnyK 3:4f5dc253eb7b 318 }
JohnnyK 5:071136c3eefa 319
JohnnyK 3:4f5dc253eb7b 320 /**
JohnnyK 3:4f5dc253eb7b 321 * @brief Initializes the LCD.
JohnnyK 3:4f5dc253eb7b 322 * @retval LCD state
JohnnyK 3:4f5dc253eb7b 323 */
JohnnyK 3:4f5dc253eb7b 324 static uint8_t LCD_Init(void)
JohnnyK 3:4f5dc253eb7b 325 {
JohnnyK 3:4f5dc253eb7b 326 /* Select the used LCD */
JohnnyK 5:071136c3eefa 327
JohnnyK 3:4f5dc253eb7b 328 /* The RK043FN48H LCD 480x272 is selected */
JohnnyK 3:4f5dc253eb7b 329 /* Timing Configuration */
JohnnyK 3:4f5dc253eb7b 330 hLtdcHandler.Init.HorizontalSync = (RK043FN48H_HSYNC - 1);
JohnnyK 3:4f5dc253eb7b 331 hLtdcHandler.Init.VerticalSync = (RK043FN48H_VSYNC - 1);
JohnnyK 3:4f5dc253eb7b 332 hLtdcHandler.Init.AccumulatedHBP = (RK043FN48H_HSYNC + RK043FN48H_HBP - 1);
JohnnyK 3:4f5dc253eb7b 333 hLtdcHandler.Init.AccumulatedVBP = (RK043FN48H_VSYNC + RK043FN48H_VBP - 1);
JohnnyK 3:4f5dc253eb7b 334 hLtdcHandler.Init.AccumulatedActiveH = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP - 1);
JohnnyK 3:4f5dc253eb7b 335 hLtdcHandler.Init.AccumulatedActiveW = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP - 1);
JohnnyK 3:4f5dc253eb7b 336 hLtdcHandler.Init.TotalHeigh = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP + RK043FN48H_VFP - 1);
JohnnyK 3:4f5dc253eb7b 337 hLtdcHandler.Init.TotalWidth = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP + RK043FN48H_HFP - 1);
JohnnyK 5:071136c3eefa 338
JohnnyK 3:4f5dc253eb7b 339 /* LCD clock configuration */
JohnnyK 3:4f5dc253eb7b 340 LCD_ClockConfig();
JohnnyK 5:071136c3eefa 341
JohnnyK 3:4f5dc253eb7b 342 /* Initialize the LCD pixel width and pixel height */
JohnnyK 3:4f5dc253eb7b 343 hLtdcHandler.LayerCfg->ImageWidth = RK043FN48H_WIDTH;
JohnnyK 3:4f5dc253eb7b 344 hLtdcHandler.LayerCfg->ImageHeight = RK043FN48H_HEIGHT;
JohnnyK 5:071136c3eefa 345
JohnnyK 3:4f5dc253eb7b 346 /* Background value */
JohnnyK 3:4f5dc253eb7b 347 hLtdcHandler.Init.Backcolor.Blue = 0;
JohnnyK 3:4f5dc253eb7b 348 hLtdcHandler.Init.Backcolor.Green = 0;
JohnnyK 3:4f5dc253eb7b 349 hLtdcHandler.Init.Backcolor.Red = 0;
JohnnyK 5:071136c3eefa 350
JohnnyK 3:4f5dc253eb7b 351 /* Polarity */
JohnnyK 3:4f5dc253eb7b 352 hLtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL;
JohnnyK 3:4f5dc253eb7b 353 hLtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL;
JohnnyK 3:4f5dc253eb7b 354 hLtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL;
JohnnyK 3:4f5dc253eb7b 355 hLtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
JohnnyK 3:4f5dc253eb7b 356 hLtdcHandler.Instance = LTDC;
JohnnyK 5:071136c3eefa 357
JohnnyK 3:4f5dc253eb7b 358 if(HAL_LTDC_GetState(&hLtdcHandler) == HAL_LTDC_STATE_RESET)
JohnnyK 3:4f5dc253eb7b 359 {
JohnnyK 3:4f5dc253eb7b 360 /* Initialize the LCD Msp: this __weak function can be rewritten by the application */
JohnnyK 3:4f5dc253eb7b 361 LCD_MspInit();
JohnnyK 3:4f5dc253eb7b 362 }
JohnnyK 3:4f5dc253eb7b 363 HAL_LTDC_Init(&hLtdcHandler);
JohnnyK 5:071136c3eefa 364
JohnnyK 3:4f5dc253eb7b 365 /* Assert display enable LCD_DISP pin */
JohnnyK 3:4f5dc253eb7b 366 HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_SET);
JohnnyK 5:071136c3eefa 367
JohnnyK 3:4f5dc253eb7b 368 /* Assert backlight LCD_BL_CTRL pin */
JohnnyK 3:4f5dc253eb7b 369 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET);
JohnnyK 5:071136c3eefa 370
JohnnyK 3:4f5dc253eb7b 371 BSP_SDRAM_Init();
JohnnyK 5:071136c3eefa 372
JohnnyK 3:4f5dc253eb7b 373 uint32_t i;
JohnnyK 3:4f5dc253eb7b 374 for(i = 0; i < (TFT_HOR_RES * TFT_VER_RES) ; i++)
JohnnyK 3:4f5dc253eb7b 375 {
JohnnyK 3:4f5dc253eb7b 376 my_fb[i] = 0;
JohnnyK 3:4f5dc253eb7b 377 }
JohnnyK 5:071136c3eefa 378
JohnnyK 3:4f5dc253eb7b 379 return LCD_OK;
JohnnyK 3:4f5dc253eb7b 380 }
JohnnyK 5:071136c3eefa 381
JohnnyK 3:4f5dc253eb7b 382 static void LCD_LayerRgb565Init(uint32_t FB_Address)
JohnnyK 3:4f5dc253eb7b 383 {
JohnnyK 3:4f5dc253eb7b 384 LTDC_LayerCfgTypeDef layer_cfg;
JohnnyK 5:071136c3eefa 385
JohnnyK 3:4f5dc253eb7b 386 /* Layer Init */
JohnnyK 3:4f5dc253eb7b 387 layer_cfg.WindowX0 = 0;
JohnnyK 3:4f5dc253eb7b 388 layer_cfg.WindowX1 = TFT_HOR_RES;
JohnnyK 3:4f5dc253eb7b 389 layer_cfg.WindowY0 = 0;
JohnnyK 3:4f5dc253eb7b 390 layer_cfg.WindowY1 = TFT_VER_RES;
JohnnyK 5:071136c3eefa 391
JohnnyK 3:4f5dc253eb7b 392 #if LV_COLOR_DEPTH == 16
JohnnyK 3:4f5dc253eb7b 393 layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
JohnnyK 3:4f5dc253eb7b 394 #elif LV_COLOR_DEPTH == 24 || LV_COLOR_DEPTH == 32
JohnnyK 3:4f5dc253eb7b 395 layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
JohnnyK 3:4f5dc253eb7b 396 #else
JohnnyK 3:4f5dc253eb7b 397 #error Unsupported color depth (see tft.c)
JohnnyK 3:4f5dc253eb7b 398 #endif
JohnnyK 3:4f5dc253eb7b 399 layer_cfg.FBStartAdress = FB_Address;
JohnnyK 3:4f5dc253eb7b 400 layer_cfg.Alpha = 255;
JohnnyK 3:4f5dc253eb7b 401 layer_cfg.Alpha0 = 0;
JohnnyK 3:4f5dc253eb7b 402 layer_cfg.Backcolor.Blue = 0;
JohnnyK 3:4f5dc253eb7b 403 layer_cfg.Backcolor.Green = 0;
JohnnyK 3:4f5dc253eb7b 404 layer_cfg.Backcolor.Red = 0;
JohnnyK 3:4f5dc253eb7b 405 layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
JohnnyK 3:4f5dc253eb7b 406 layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
JohnnyK 3:4f5dc253eb7b 407 layer_cfg.ImageWidth = TFT_HOR_RES;
JohnnyK 3:4f5dc253eb7b 408 layer_cfg.ImageHeight = TFT_VER_RES;
JohnnyK 5:071136c3eefa 409
JohnnyK 3:4f5dc253eb7b 410 HAL_LTDC_ConfigLayer(&hLtdcHandler, &layer_cfg, 0);
JohnnyK 3:4f5dc253eb7b 411 }
JohnnyK 5:071136c3eefa 412
JohnnyK 3:4f5dc253eb7b 413 static void LCD_DisplayOn(void)
JohnnyK 3:4f5dc253eb7b 414 {
JohnnyK 3:4f5dc253eb7b 415 /* Display On */
JohnnyK 3:4f5dc253eb7b 416 __HAL_LTDC_ENABLE(&hLtdcHandler);
JohnnyK 3:4f5dc253eb7b 417 HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_SET); /* Assert LCD_DISP pin */
JohnnyK 3:4f5dc253eb7b 418 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET); /* Assert LCD_BL_CTRL pin */
JohnnyK 3:4f5dc253eb7b 419 }
JohnnyK 5:071136c3eefa 420
JohnnyK 3:4f5dc253eb7b 421 static void DMA_Config(void)
JohnnyK 3:4f5dc253eb7b 422 {
JohnnyK 3:4f5dc253eb7b 423 /*## -1- Enable DMA2 clock #################################################*/
JohnnyK 3:4f5dc253eb7b 424 __HAL_RCC_DMA2_CLK_ENABLE();
JohnnyK 5:071136c3eefa 425
JohnnyK 3:4f5dc253eb7b 426 /*##-2- Select the DMA functional Parameters ###############################*/
JohnnyK 3:4f5dc253eb7b 427 DmaHandle.Init.Channel = CPY_BUF_DMA_CHANNEL; /* DMA_CHANNEL_0 */
JohnnyK 3:4f5dc253eb7b 428 DmaHandle.Init.Direction = DMA_MEMORY_TO_MEMORY; /* M2M transfer mode */
JohnnyK 3:4f5dc253eb7b 429 DmaHandle.Init.PeriphInc = DMA_PINC_ENABLE; /* Peripheral increment mode Enable */
JohnnyK 3:4f5dc253eb7b 430 DmaHandle.Init.MemInc = DMA_MINC_ENABLE; /* Memory increment mode Enable */
JohnnyK 3:4f5dc253eb7b 431 DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; /* Peripheral data alignment : 16bit */
JohnnyK 3:4f5dc253eb7b 432 DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; /* memory data alignment : 16bit */
JohnnyK 3:4f5dc253eb7b 433 DmaHandle.Init.Mode = DMA_NORMAL; /* Normal DMA mode */
JohnnyK 3:4f5dc253eb7b 434 DmaHandle.Init.Priority = DMA_PRIORITY_HIGH; /* priority level : high */
JohnnyK 3:4f5dc253eb7b 435 DmaHandle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; /* FIFO mode enabled */
JohnnyK 3:4f5dc253eb7b 436 DmaHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_1QUARTERFULL; /* FIFO threshold: 1/4 full */
JohnnyK 3:4f5dc253eb7b 437 DmaHandle.Init.MemBurst = DMA_MBURST_SINGLE; /* Memory burst */
JohnnyK 3:4f5dc253eb7b 438 DmaHandle.Init.PeriphBurst = DMA_PBURST_SINGLE; /* Peripheral burst */
JohnnyK 5:071136c3eefa 439
JohnnyK 3:4f5dc253eb7b 440 /*##-3- Select the DMA instance to be used for the transfer : DMA2_Stream0 #*/
JohnnyK 3:4f5dc253eb7b 441 DmaHandle.Instance = CPY_BUF_DMA_STREAM;
JohnnyK 5:071136c3eefa 442
JohnnyK 3:4f5dc253eb7b 443 /*##-4- Initialize the DMA stream ##########################################*/
JohnnyK 3:4f5dc253eb7b 444 if(HAL_DMA_Init(&DmaHandle) != HAL_OK)
JohnnyK 3:4f5dc253eb7b 445 {
JohnnyK 3:4f5dc253eb7b 446 while(1)
JohnnyK 3:4f5dc253eb7b 447 {
JohnnyK 3:4f5dc253eb7b 448 }
JohnnyK 3:4f5dc253eb7b 449 }
JohnnyK 5:071136c3eefa 450
JohnnyK 3:4f5dc253eb7b 451 /*##-5- Select Callbacks functions called after Transfer complete and Transfer error */
JohnnyK 3:4f5dc253eb7b 452 HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_CPLT_CB_ID, DMA_TransferComplete);
JohnnyK 3:4f5dc253eb7b 453 HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_ERROR_CB_ID, DMA_TransferError);
JohnnyK 5:071136c3eefa 454
JohnnyK 3:4f5dc253eb7b 455 /*##-6- Configure NVIC for DMA transfer complete/error interrupts ##########*/
JohnnyK 3:4f5dc253eb7b 456 HAL_NVIC_SetPriority(CPY_BUF_DMA_STREAM_IRQ, 0, 0);
JohnnyK 3:4f5dc253eb7b 457 HAL_NVIC_EnableIRQ(CPY_BUF_DMA_STREAM_IRQ);
JohnnyK 3:4f5dc253eb7b 458 }
JohnnyK 5:071136c3eefa 459
JohnnyK 3:4f5dc253eb7b 460 /**
JohnnyK 3:4f5dc253eb7b 461 * @brief DMA conversion complete callback
JohnnyK 3:4f5dc253eb7b 462 * @note This function is executed when the transfer complete interrupt
JohnnyK 3:4f5dc253eb7b 463 * is generated
JohnnyK 3:4f5dc253eb7b 464 * @retval None
JohnnyK 3:4f5dc253eb7b 465 */
JohnnyK 3:4f5dc253eb7b 466 static void DMA_TransferComplete(DMA_HandleTypeDef *han)
JohnnyK 3:4f5dc253eb7b 467 {
JohnnyK 3:4f5dc253eb7b 468 y_fill_act ++;
JohnnyK 5:071136c3eefa 469
JohnnyK 3:4f5dc253eb7b 470 if(y_fill_act > y2_fill) {
JohnnyK 5:071136c3eefa 471 SCB_CleanInvalidateDCache();
JohnnyK 5:071136c3eefa 472 SCB_InvalidateICache();
JohnnyK 5:071136c3eefa 473 lv_disp_flush_ready(&disp_drv);
JohnnyK 3:4f5dc253eb7b 474 } else {
JohnnyK 5:071136c3eefa 475 uint32_t length = (x2_flush - x1_flush + 1);
JohnnyK 3:4f5dc253eb7b 476 buf_to_flush += x2_flush - x1_flush + 1;
JohnnyK 3:4f5dc253eb7b 477 /*##-7- Start the DMA transfer using the interrupt mode ####################*/
JohnnyK 3:4f5dc253eb7b 478 /* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */
JohnnyK 3:4f5dc253eb7b 479 /* Enable All the DMA interrupts */
JohnnyK 3:4f5dc253eb7b 480 #if LV_COLOR_DEPTH == 24 || LV_COLOR_DEPTH == 32
JohnnyK 3:4f5dc253eb7b 481 length *= 2; /* STM32 DMA uses 16-bit chunks so multiply by 2 for 32-bit color */
JohnnyK 3:4f5dc253eb7b 482 #endif
JohnnyK 3:4f5dc253eb7b 483 if(HAL_DMA_Start_IT(han,(uint32_t)buf_to_flush, (uint32_t)&my_fb[y_fill_act * TFT_HOR_RES + x1_flush],
JohnnyK 3:4f5dc253eb7b 484 length) != HAL_OK)
JohnnyK 3:4f5dc253eb7b 485 {
JohnnyK 5:071136c3eefa 486 while(1); /*Halt on error*/
JohnnyK 3:4f5dc253eb7b 487 }
JohnnyK 3:4f5dc253eb7b 488 }
JohnnyK 3:4f5dc253eb7b 489 }
JohnnyK 5:071136c3eefa 490
JohnnyK 3:4f5dc253eb7b 491 /**
JohnnyK 3:4f5dc253eb7b 492 * @brief DMA conversion error callback
JohnnyK 3:4f5dc253eb7b 493 * @note This function is executed when the transfer error interrupt
JohnnyK 3:4f5dc253eb7b 494 * is generated during DMA transfer
JohnnyK 3:4f5dc253eb7b 495 * @retval None
JohnnyK 3:4f5dc253eb7b 496 */
JohnnyK 3:4f5dc253eb7b 497 static void DMA_TransferError(DMA_HandleTypeDef *han)
JohnnyK 3:4f5dc253eb7b 498 {
JohnnyK 5:071136c3eefa 499
JohnnyK 3:4f5dc253eb7b 500 }
JohnnyK 5:071136c3eefa 501
JohnnyK 3:4f5dc253eb7b 502 /**
JohnnyK 3:4f5dc253eb7b 503 * @brief This function handles DMA Stream interrupt request.
JohnnyK 3:4f5dc253eb7b 504 * @param None
JohnnyK 3:4f5dc253eb7b 505 * @retval None
JohnnyK 3:4f5dc253eb7b 506 */
JohnnyK 3:4f5dc253eb7b 507 void CPY_BUF_DMA_STREAM_IRQHANDLER(void)
JohnnyK 3:4f5dc253eb7b 508 {
JohnnyK 3:4f5dc253eb7b 509 /* Check the interrupt and clear flag */
JohnnyK 3:4f5dc253eb7b 510 HAL_DMA_IRQHandler(&DmaHandle);
JohnnyK 3:4f5dc253eb7b 511 }
JohnnyK 5:071136c3eefa 512
JohnnyK 5:071136c3eefa 513
JohnnyK 3:4f5dc253eb7b 514 #if LV_USE_GPU != 0
JohnnyK 5:071136c3eefa 515
JohnnyK 3:4f5dc253eb7b 516 static void Error_Handler(void)
JohnnyK 3:4f5dc253eb7b 517 {
JohnnyK 3:4f5dc253eb7b 518 while(1)
JohnnyK 3:4f5dc253eb7b 519 {
JohnnyK 3:4f5dc253eb7b 520 }
JohnnyK 3:4f5dc253eb7b 521 }
JohnnyK 3:4f5dc253eb7b 522 /**
JohnnyK 3:4f5dc253eb7b 523 * @brief DMA2D Transfer completed callback
JohnnyK 3:4f5dc253eb7b 524 * @param hdma2d: DMA2D handle.
JohnnyK 3:4f5dc253eb7b 525 * @note This example shows a simple way to report end of DMA2D transfer, and
JohnnyK 3:4f5dc253eb7b 526 * you can add your own implementation.
JohnnyK 3:4f5dc253eb7b 527 * @retval None
JohnnyK 3:4f5dc253eb7b 528 */
JohnnyK 3:4f5dc253eb7b 529 static void DMA2D_TransferComplete(DMA2D_HandleTypeDef *hdma2d)
JohnnyK 3:4f5dc253eb7b 530 {
JohnnyK 5:071136c3eefa 531
JohnnyK 3:4f5dc253eb7b 532 }
JohnnyK 5:071136c3eefa 533
JohnnyK 3:4f5dc253eb7b 534 /**
JohnnyK 3:4f5dc253eb7b 535 * @brief DMA2D error callbacks
JohnnyK 3:4f5dc253eb7b 536 * @param hdma2d: DMA2D handle
JohnnyK 3:4f5dc253eb7b 537 * @note This example shows a simple way to report DMA2D transfer error, and you can
JohnnyK 3:4f5dc253eb7b 538 * add your own implementation.
JohnnyK 3:4f5dc253eb7b 539 * @retval None
JohnnyK 3:4f5dc253eb7b 540 */
JohnnyK 3:4f5dc253eb7b 541 static void DMA2D_TransferError(DMA2D_HandleTypeDef *hdma2d)
JohnnyK 3:4f5dc253eb7b 542 {
JohnnyK 5:071136c3eefa 543
JohnnyK 3:4f5dc253eb7b 544 }
JohnnyK 5:071136c3eefa 545
JohnnyK 3:4f5dc253eb7b 546 /**
JohnnyK 3:4f5dc253eb7b 547 * @brief DMA2D configuration.
JohnnyK 3:4f5dc253eb7b 548 * @note This function Configure the DMA2D peripheral :
JohnnyK 3:4f5dc253eb7b 549 * 1) Configure the Transfer mode as memory to memory with blending.
JohnnyK 3:4f5dc253eb7b 550 * 2) Configure the output color mode as RGB565 pixel format.
JohnnyK 3:4f5dc253eb7b 551 * 3) Configure the foreground
JohnnyK 3:4f5dc253eb7b 552 * - first image loaded from FLASH memory
JohnnyK 3:4f5dc253eb7b 553 * - constant alpha value (decreased to see the background)
JohnnyK 3:4f5dc253eb7b 554 * - color mode as RGB565 pixel format
JohnnyK 3:4f5dc253eb7b 555 * 4) Configure the background
JohnnyK 3:4f5dc253eb7b 556 * - second image loaded from FLASH memory
JohnnyK 3:4f5dc253eb7b 557 * - color mode as RGB565 pixel format
JohnnyK 3:4f5dc253eb7b 558 * @retval None
JohnnyK 3:4f5dc253eb7b 559 */
JohnnyK 3:4f5dc253eb7b 560 static void DMA2D_Config(void)
JohnnyK 3:4f5dc253eb7b 561 {
JohnnyK 3:4f5dc253eb7b 562 /* Configure the DMA2D Mode, Color Mode and output offset */
JohnnyK 3:4f5dc253eb7b 563 Dma2dHandle.Init.Mode = DMA2D_M2M_BLEND;
JohnnyK 3:4f5dc253eb7b 564 #if LV_COLOR_DEPTH == 16
JohnnyK 3:4f5dc253eb7b 565 Dma2dHandle.Init.ColorMode = DMA2D_RGB565;
JohnnyK 3:4f5dc253eb7b 566 #elif LV_COLOR_DEPTH == 24 || LV_COLOR_DEPTH == 32
JohnnyK 3:4f5dc253eb7b 567 Dma2dHandle.Init.ColorMode = DMA2D_ARGB8888;
JohnnyK 3:4f5dc253eb7b 568 #endif
JohnnyK 3:4f5dc253eb7b 569 Dma2dHandle.Init.OutputOffset = 0x0;
JohnnyK 5:071136c3eefa 570
JohnnyK 3:4f5dc253eb7b 571 /* DMA2D Callbacks Configuration */
JohnnyK 3:4f5dc253eb7b 572 Dma2dHandle.XferCpltCallback = DMA2D_TransferComplete;
JohnnyK 3:4f5dc253eb7b 573 Dma2dHandle.XferErrorCallback = DMA2D_TransferError;
JohnnyK 5:071136c3eefa 574
JohnnyK 3:4f5dc253eb7b 575 /* Foreground Configuration */
JohnnyK 3:4f5dc253eb7b 576 Dma2dHandle.LayerCfg[1].AlphaMode = DMA2D_REPLACE_ALPHA;
JohnnyK 3:4f5dc253eb7b 577 Dma2dHandle.LayerCfg[1].InputAlpha = 0xFF;
JohnnyK 3:4f5dc253eb7b 578 #if LV_COLOR_DEPTH == 16
JohnnyK 3:4f5dc253eb7b 579 Dma2dHandle.LayerCfg[1].InputColorMode = DMA2D_INPUT_RGB565;
JohnnyK 3:4f5dc253eb7b 580 #elif LV_COLOR_DEPTH == 24 || LV_COLOR_DEPTH == 32
JohnnyK 3:4f5dc253eb7b 581 Dma2dHandle.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
JohnnyK 3:4f5dc253eb7b 582 #endif
JohnnyK 5:071136c3eefa 583
JohnnyK 3:4f5dc253eb7b 584 Dma2dHandle.LayerCfg[1].InputOffset = 0x0;
JohnnyK 5:071136c3eefa 585
JohnnyK 3:4f5dc253eb7b 586 /* Background Configuration */
JohnnyK 3:4f5dc253eb7b 587 Dma2dHandle.LayerCfg[0].AlphaMode = DMA2D_REPLACE_ALPHA;
JohnnyK 3:4f5dc253eb7b 588 Dma2dHandle.LayerCfg[0].InputAlpha = 0xFF;
JohnnyK 3:4f5dc253eb7b 589 #if LV_COLOR_DEPTH == 16
JohnnyK 3:4f5dc253eb7b 590 Dma2dHandle.LayerCfg[0].InputColorMode = DMA2D_INPUT_RGB565;
JohnnyK 3:4f5dc253eb7b 591 #elif LV_COLOR_DEPTH == 24 || LV_COLOR_DEPTH == 32
JohnnyK 3:4f5dc253eb7b 592 Dma2dHandle.LayerCfg[0].InputColorMode = DMA2D_INPUT_ARGB8888;
JohnnyK 3:4f5dc253eb7b 593 #endif
JohnnyK 3:4f5dc253eb7b 594 Dma2dHandle.LayerCfg[0].InputOffset = 0x0;
JohnnyK 5:071136c3eefa 595
JohnnyK 3:4f5dc253eb7b 596 Dma2dHandle.Instance = DMA2D;
JohnnyK 5:071136c3eefa 597
JohnnyK 3:4f5dc253eb7b 598 /* DMA2D Initialization */
JohnnyK 3:4f5dc253eb7b 599 if(HAL_DMA2D_Init(&Dma2dHandle) != HAL_OK)
JohnnyK 3:4f5dc253eb7b 600 {
JohnnyK 3:4f5dc253eb7b 601 /* Initialization Error */
JohnnyK 3:4f5dc253eb7b 602 Error_Handler();
JohnnyK 3:4f5dc253eb7b 603 }
JohnnyK 5:071136c3eefa 604
JohnnyK 3:4f5dc253eb7b 605 HAL_DMA2D_ConfigLayer(&Dma2dHandle, 0);
JohnnyK 3:4f5dc253eb7b 606 HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1);
JohnnyK 3:4f5dc253eb7b 607 }
JohnnyK 5:071136c3eefa 608 #endif