Code commenté du projet LED

Dependencies:   BSP_DISCO_F746NG

Committer:
JohnnyK
Date:
Sat Apr 24 19:08:28 2021 +0000
Revision:
3:4f5dc253eb7b
Child:
5:071136c3eefa
Rework to LVGL 7.10.1 and MbedOS 6.10

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