78 #define LCD_MIRROR_Y 1 80 #define XSIZE_PHYS 800 81 #define YSIZE_PHYS 480 84 #define NUM_VSCREENS 1 86 #define BK_COLOR GUI_DARKBLUE 89 #define GUI_NUM_LAYERS 2 91 #define COLOR_CONVERSION_0 GUICC_M565 92 #define DISPLAY_DRIVER_0 GUIDRV_LIN_16 95 #if (GUI_NUM_LAYERS > 1) 96 #define COLOR_CONVERSION_1 GUICC_M1555I 97 #define DISPLAY_DRIVER_1 GUIDRV_LIN_16 102 #error Physical X size of display is not defined! 105 #error Physical Y size of display is not defined! 108 #define NUM_VSCREENS 1 110 #if (NUM_VSCREENS <= 0) 111 #error At least one screeen needs to be defined! 114 #if (NUM_VSCREENS > 1) && (NUM_BUFFERS > 1) 115 #error Virtual screens and multiple buffers are not allowed! 120 #define LCD_LAYER0_FRAME_BUFFER ((int)0xC0400000) 121 #define LCD_LAYER1_FRAME_BUFFER ((int)0xC0800000) 140 #if GUI_NUM_LAYERS > 1 152 static U32 GetPixelformat(
U32 LayerIndex);
153 static U32 GetBufferSize(
U32 LayerIndex);
155 static void DMA2D_CopyBufferWithAlpha(
U32 LayerIndex,
void * pSrc,
void * pDst,
U32 xSize,
U32 ySize,
U32 OffLineSrc,
U32 OffLineDst);
156 static void DMA2D_CopyBuffer (
U32 LayerIndex,
void * pSrc,
void * pDst,
U32 xSize,
U32 ySize,
U32 OffLineSrc,
U32 OffLineDst);
157 static void DMA2D_FillBuffer(
U32 LayerIndex,
void * pDst,
U32 xSize,
U32 ySize,
U32 OffLine,
U32 ColorIndex);
159 static void LCD_LL_Init(
void);
160 static void LCD_LL_Reset(
void);
161 static void LCD_LL_CopyBuffer(
int LayerIndex,
int IndexSrc,
int IndexDst);
162 static void LCD_LL_CopyRect(
int LayerIndex,
int x0,
int y0,
int x1,
int y1,
int xSize,
int ySize);
163 static void LCD_LL_FillRect(
int LayerIndex,
int x0,
int y0,
int x1,
int y1,
U32 PixelIndex);
164 static void LCD_LL_DrawBitmap8bpp(
int LayerIndex,
int x,
int y,
U8 const * p,
int xSize,
int ySize,
int BytesPerLine);
180 HAL_DSI_ShortWrite(&
hdsi_eval, 0, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]);
184 HAL_DSI_LongWrite(&
hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams);
194 static void LCD_LL_Reset(
void)
204 gpio_init_structure.
Speed = GPIO_SPEED_HIGH;
226 static void LCD_LL_Init(
void)
232 uint32_t LcdClock = 27429;
233 uint32_t Clockratio = 0;
236 uint32_t laneByteClk_kHz = 0;
252 __HAL_RCC_LTDC_CLK_ENABLE();
255 __HAL_RCC_LTDC_FORCE_RESET();
256 __HAL_RCC_LTDC_RELEASE_RESET();
266 __HAL_RCC_DSI_CLK_ENABLE();
269 __HAL_RCC_DSI_FORCE_RESET();
270 __HAL_RCC_DSI_RELEASE_RESET();
281 dsiPllInit.PLLNDIV = 100;
282 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
283 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
284 laneByteClk_kHz = 62500;
287 hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
290 hdsi_eval.Init.TXEscapeCkdiv = laneByteClk_kHz/15620;
292 HAL_DSI_Init(&(
hdsi_eval), &(dsiPllInit));
293 Clockratio = laneByteClk_kHz/LcdClock;
357 hltdc_eval.Init.AccumulatedHBP = (HSA + HBP - 1);
358 hltdc_eval.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
359 hltdc_eval.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
381 hltdc_eval.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
401 static void LCD_LL_LayerInit(
U32 LayerIndex,
U32 address)
403 LTDC_LayerCfgTypeDef Layercfg;
406 Layercfg.WindowX0 = 0;
408 Layercfg.WindowY0 = 0;
410 Layercfg.PixelFormat = GetPixelformat(LayerIndex);
411 Layercfg.FBStartAdress = address;
412 Layercfg.Alpha = 255;
414 Layercfg.Backcolor.Blue = 0;
415 Layercfg.Backcolor.Green = 0;
416 Layercfg.Backcolor.Red = 0;
417 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
418 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
422 HAL_LTDC_ConfigLayer(&
hltdc_eval, &Layercfg, LayerIndex);
432 static U32 GetPixelformat(
U32 LayerIndex)
436 return LTDC_PIXEL_FORMAT_RGB565;
440 return LTDC_PIXEL_FORMAT_ARGB1555;
449 static void DMA2D_CopyBuffer(
U32 LayerIndex,
void * pSrc,
void * pDst,
U32 xSize,
U32 ySize,
U32 OffLineSrc,
U32 OffLineDst)
453 PixelFormat = GetPixelformat(LayerIndex);
454 DMA2D->CR = 0x00000000UL | (1 << 9);
459 DMA2D->FGOR = OffLineSrc;
460 DMA2D->OOR = OffLineDst;
463 DMA2D->FGPFCCR = PixelFormat;
480 static void DMA2D_CopyBufferWithAlpha(
U32 LayerIndex,
void * pSrc,
void * pDst,
U32 xSize,
U32 ySize,
U32 OffLineSrc,
U32 OffLineDst)
482 uint32_t PixelFormat;
484 PixelFormat = GetPixelformat(LayerIndex);
485 DMA2D->CR = 0x00000000UL | (1 << 9) | (0x2 << 16);
491 DMA2D->FGOR = OffLineSrc;
492 DMA2D->OOR = OffLineDst;
493 DMA2D->BGOR = OffLineDst;
496 DMA2D->FGPFCCR = LTDC_PIXEL_FORMAT_ARGB8888;
497 DMA2D->BGPFCCR = PixelFormat;
498 DMA2D->OPFCCR = PixelFormat;
521 static void DMA2D_FillBuffer(
U32 LayerIndex,
void * pDst,
U32 xSize,
U32 ySize,
U32 OffLine,
U32 ColorIndex)
526 PixelFormat = GetPixelformat(LayerIndex);
529 DMA2D->CR = 0x00030000UL | (1 << 9);
530 DMA2D->OCOLR = ColorIndex;
536 DMA2D->OOR = OffLine;
539 DMA2D->OPFCCR = PixelFormat;
558 static U32 GetBufferSize(
U32 LayerIndex)
560 return (layer_prop[LayerIndex].xSize * layer_prop[LayerIndex].ySize * layer_prop[LayerIndex].BytesPerPixel);
570 static void LCD_LL_CopyBuffer(
int LayerIndex,
int IndexSrc,
int IndexDst) {
571 U32 BufferSize, AddrSrc, AddrDst;
573 BufferSize = GetBufferSize(LayerIndex);
574 AddrSrc = layer_prop[LayerIndex].
address + BufferSize * IndexSrc;
575 AddrDst = layer_prop[LayerIndex].
address + BufferSize * IndexDst;
576 DMA2D_CopyBuffer(LayerIndex, (
void *)AddrSrc, (
void *)AddrDst, layer_prop[LayerIndex].xSize, layer_prop[LayerIndex].ySize, 0, 0);
591 static void LCD_LL_CopyRect(
int LayerIndex,
int x0,
int y0,
int x1,
int y1,
int xSize,
int ySize)
593 U32 AddrSrc, AddrDst;
595 AddrSrc = layer_prop[LayerIndex].
address + (y0 * layer_prop[LayerIndex].
xSize + x0) * layer_prop[LayerIndex].BytesPerPixel;
596 AddrDst = layer_prop[LayerIndex].
address + (y1 * layer_prop[LayerIndex].
xSize + x1) * layer_prop[LayerIndex].BytesPerPixel;
597 DMA2D_CopyBuffer(LayerIndex, (
void *)AddrSrc, (
void *)AddrDst, xSize, ySize, layer_prop[LayerIndex].xSize - xSize, layer_prop[LayerIndex].xSize - xSize);
610 static void LCD_LL_FillRect(
int LayerIndex,
int x0,
int y0,
int x1,
int y1,
U32 PixelIndex)
612 U32 BufferSize, AddrDst;
625 BufferSize = GetBufferSize(LayerIndex);
626 AddrDst = layer_prop[LayerIndex].
address + BufferSize * layer_prop[LayerIndex].
buffer_index + (y0 * layer_prop[LayerIndex].
xSize + x0) * layer_prop[LayerIndex].BytesPerPixel;
627 DMA2D_FillBuffer(LayerIndex, (
void *)AddrDst, xSize, ySize, layer_prop[LayerIndex].xSize - xSize, PixelIndex);
642 static void DMA2D_DrawBitmapL8(
void * pSrc,
void * pDst,
U32 OffSrc,
U32 OffDst,
U32 PixelFormatDst,
U32 xSize,
U32 ySize)
645 DMA2D->CR = 0x00010000UL | (1 << 9);
652 DMA2D->FGOR = OffSrc;
656 DMA2D->FGPFCCR = LTDC_PIXEL_FORMAT_L8;
657 DMA2D->OPFCCR = PixelFormatDst;
660 DMA2D->NLR = (
U32)(xSize << 16) | ySize;
685 U32 BufferSize, AddrDst;
686 int OffLineSrc, OffLineDst;
688 BufferSize = GetBufferSize(LayerIndex);
689 AddrDst = layer_prop[LayerIndex].
address + BufferSize * layer_prop[LayerIndex].
buffer_index + (y * layer_prop[LayerIndex].
xSize + x) * layer_prop[LayerIndex].BytesPerPixel;
690 OffLineSrc = (BytesPerLine / 2) - xSize;
691 OffLineDst = layer_prop[LayerIndex].
xSize - xSize;
692 DMA2D_CopyBuffer(LayerIndex, (
void *)p, (
void *)AddrDst, xSize, ySize, OffLineSrc, OffLineDst);
697 U32 BufferSize, AddrDst;
698 int OffLineSrc, OffLineDst;
700 BufferSize = GetBufferSize(LayerIndex);
701 AddrDst = layer_prop[LayerIndex].
address + BufferSize * layer_prop[LayerIndex].
buffer_index + (y * layer_prop[LayerIndex].
xSize + x) * layer_prop[LayerIndex].BytesPerPixel;
702 OffLineSrc = (BytesPerLine / 4) - xSize;
703 OffLineDst = layer_prop[LayerIndex].
xSize - xSize;
704 DMA2D_CopyBufferWithAlpha(LayerIndex, (
void *)p, (
void *)AddrDst, xSize, ySize, OffLineSrc, OffLineDst);
718 static void LCD_LL_DrawBitmap8bpp(
int LayerIndex,
int x,
int y,
U8 const * p,
int xSize,
int ySize,
int BytesPerLine)
720 U32 BufferSize, AddrDst;
721 int OffLineSrc, OffLineDst;
724 BufferSize = GetBufferSize(LayerIndex);
725 AddrDst = layer_prop[LayerIndex].
address + BufferSize * layer_prop[LayerIndex].
buffer_index + (y * layer_prop[LayerIndex].
xSize + x) * layer_prop[LayerIndex].BytesPerPixel;
726 OffLineSrc = BytesPerLine - xSize;
727 OffLineDst = layer_prop[LayerIndex].
xSize - xSize;
728 PixelFormat = GetPixelformat(LayerIndex);
729 DMA2D_DrawBitmapL8((
void *)p, (
void *)AddrDst, OffLineSrc, OffLineDst, PixelFormat, xSize, ySize);
745 if (layer_prop[layer].pending_buffer >= 0)
748 Addr = layer_prop[layer].
address + \
753 __HAL_LTDC_RELOAD_CONFIG(hltdc_eval);
763 HAL_LTDC_ProgramLineEvent(hltdc_eval, 0);
779 #if (NUM_BUFFERS > 1) 797 #if (GUI_NUM_LAYERS > 1) 816 #if (GUI_NUM_LAYERS > 1) 867 LCD_LL_LayerInit(LayerIndex, layer_prop[LayerIndex].address);
872 HAL_LTDC_SetAddress(&
hltdc_eval, addr, LayerIndex);
890 __HAL_LTDC_LAYER_ENABLE(&
hltdc_eval, LayerIndex);
894 __HAL_LTDC_LAYER_DISABLE(&
hltdc_eval, LayerIndex);
911 HAL_LTDC_SetWindowPosition(&
hltdc_eval, xPos, yPos, LayerIndex);
921 HAL_LTDC_EnableColorKeying(&
hltdc_eval, LayerIndex);
925 HAL_LTDC_DisableColorKeying(&
hltdc_eval, LayerIndex);
935 HAL_LTDC_ConfigColorKeying(&
hltdc_eval, Color, LayerIndex);
GUI_DRAWMODE GUI_GetDrawMode(void)
DSI_HandleTypeDef hdsi_eval
uint32_t PeriphClockSelection
LCD_API_COLOR_CONV * pColorConvAPI
#define COLOR_CONVERSION_1
int LCD_GetSwapXYEx(int LayerIndex)
#define LCD_DEVFUNC_DRAWBMP_32BPP
#define LCD_LAYER1_FRAME_BUFFER
void HAL_Delay(__IO uint32_t Delay)
This function provides accurate delay (in milliseconds) based on variable incremented.
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
GUI_DEVICE * GUI_DEVICE_CreateAndLink(const GUI_DEVICE_API *pDeviceAPI, const LCD_API_COLOR_CONV *pColorConvAPI, U16 Flags, int LayerIndex)
void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
DCS or Generic short/long write command.
#define OTM8009A_800X480_WIDTH
void GUI_MULTIBUF_ConfigEx(int LayerIndex, int NumBuffers)
void GUI_MULTIBUF_ConfirmEx(int LayerIndex, int BufferIndex)
int LCD_SetSizeEx(int LayerIndex, int xSize, int ySize)
LTDC_HandleTypeDef hltdc_eval
#define OTM8009A_800X480_HFP
int LCD_SetVSizeEx(int LayerIndex, int xSize, int ySize)
#define LCD_DEVFUNC_DRAWBMP_16BPP
#define LCD_X_INITCONTROLLER
#define __HAL_RCC_DMA2D_FORCE_RESET()
void LCD_LL_DrawBitmap16bpp(int LayerIndex, int x, int y, U16 const *p, int xSize, int ySize, int BytesPerLine)
Draw 16bpp bitmap file.
#define OTM8009A_800X480_HEIGHT
#define __DSB()
Data Synchronization Barrier.
void LCD_X_Config(void)
Called during the initialization process in order to set up the display driver configuration.
#define LCD_DEVFUNC_FILLRECT
#define __HAL_RCC_GPIOJ_CLK_ENABLE()
#define OTM8009A_800X480_HSYNC
OTM8009A_800X480 Timing parameters for Landscape orientation mode Same values as for Portrait mode in...
RCC extended clocks structure definition.
__IO int32_t pending_buffer
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
void GUI_GetLayerPosEx(unsigned Index, int *pxPos, int *pyPos)
#define __HAL_RCC_DMA2D_CLK_ENABLE()
#define OTM8009A_800X480_VSYNC
#define __HAL_RCC_DMA2D_RELEASE_RESET()
#define LCD_X_SETCHROMAMODE
LCD_LayerPropTypedef layer_prop[GUI_NUM_LAYERS]
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
void HAL_LTDC_LineEvenCallback(LTDC_HandleTypeDef *hltdc_eval)
Line Event callback.
#define LCD_DEVFUNC_COPYRECT
GPIO Init structure definition.
void LCD_LL_DrawBitmap32bpp(int LayerIndex, int x, int y, U8 const *p, int xSize, int ySize, int BytesPerLine)
#define OTM8009A_ORIENTATION_LANDSCAPE
int LCD_SetDevFunc(int LayerIndex, int IdFunc, void(*pDriverFunc)(void))
DSI_PLLInitTypeDef dsiPllInit
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
#define LCD_DEVFUNC_DRAWBMP_8BPP
#define LCD_DEVFUNC_COPYBUFFER
int LCD_SetVRAMAddrEx(int LayerIndex, void *pVRAM)
int LCD_GetBitsPerPixelEx(int LayerIndex)
#define COLOR_CONVERSION_0
#define LCD_LAYER0_FRAME_BUFFER
#define OTM8009A_800X480_HBP
DSI_VidCfgTypeDef hdsivideo_handle
#define OTM8009A_800X480_VBP
void LCD_FillRect(int x0, int y0, int x1, int y1)
uint8_t OTM8009A_Init(uint32_t ColorCoding, uint32_t orientation)
Initializes the LCD KoD display part by communication in DSI mode in Video Mode with IC Display Drive...
#define GPIO_MODE_OUTPUT_PP
int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void *pData)
This function is called by the display driver for several purposes. To support the according task the...
#define OTM8009A_800X480_VFP
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct
RCC_PLLSAIInitTypeDef PLLSAI