refactor: DMA2D and LTDC conversion to HAL/LL (#3036)
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
co-authored by
Peter Feerick
parent
d0ae5bd85c
commit
1af8b78256
@@ -19,7 +19,10 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "lcd.h"
|
||||
#include "dma2d.h"
|
||||
#include "bitmapbuffer.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
pixel_t LCD_FIRST_FRAME_BUFFER[DISPLAY_BUFFER_SIZE] __SDRAM;
|
||||
@@ -129,7 +132,7 @@ static void flushLcd(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_
|
||||
src, LCD_W, LCD_H, refr_area.x1, refr_area.y1,
|
||||
area_w, area_h);
|
||||
}
|
||||
|
||||
DMAWait(); // wait for the last DMACopyBitmap to be completed before sending completion message
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
#endif
|
||||
} else {
|
||||
@@ -246,6 +249,11 @@ static void _draw_buf_flush(lv_disp_t* disp)
|
||||
}
|
||||
}
|
||||
|
||||
void lcdClear()
|
||||
{
|
||||
lcd->clear();
|
||||
}
|
||||
|
||||
void lcdRefresh()
|
||||
{
|
||||
_draw_buf_flush(disp);
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#ifndef _LCD_H_
|
||||
#define _LCD_H_
|
||||
|
||||
#include "bitmapbuffer.h"
|
||||
#include "opentx_types.h"
|
||||
|
||||
#include "colors.h"
|
||||
@@ -51,7 +50,7 @@ void lcdInitDisplayDriver();
|
||||
// Patch the draw context to allow for direct drawing
|
||||
void lcdInitDirectDrawing();
|
||||
|
||||
inline void lcdClear() { lcd->clear(); }
|
||||
void lcdClear();
|
||||
|
||||
void lcdRefresh();
|
||||
void lcdFlushed();
|
||||
|
||||
@@ -76,6 +76,7 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
|
||||
../../../../../fonts/lvgl/lv_font_roboto_bl_16.c
|
||||
../../../../../thirdparty/libopenui/src/bitmapbuffer.cpp
|
||||
../../../../../thirdparty/libopenui/thirdparty/lz4/lz4.c
|
||||
../../../../../targets/common/arm/stm32/dma2d.cpp
|
||||
../../../../../targets/common/arm/stm32/diskio_sdio.cpp
|
||||
../../../../../targets/common/arm/stm32/rtc_driver.cpp
|
||||
../../../../../targets/common/arm/stm32/diskio_spi_flash.cpp
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include "definitions.h"
|
||||
#include "libopenui_defines.h"
|
||||
#include "dma2d.h"
|
||||
|
||||
void DMACopyBitmap(uint16_t *dest, uint16_t destw, uint16_t desth, uint16_t x,
|
||||
uint16_t y, const uint16_t *src, uint16_t srcw,
|
||||
uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w,
|
||||
uint16_t h)
|
||||
{
|
||||
DMAWait();
|
||||
|
||||
LL_DMA2D_DeInit(DMA2D);
|
||||
|
||||
LL_DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
LL_DMA2D_StructInit(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_InitStruct.Mode = LL_DMA2D_MODE_M2M;
|
||||
DMA2D_InitStruct.ColorMode = LL_DMA2D_OUTPUT_MODE_RGB565;
|
||||
DMA2D_InitStruct.OutputMemoryAddress = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.LineOffset = destw - w;
|
||||
DMA2D_InitStruct.NbrOfLines = h;
|
||||
DMA2D_InitStruct.NbrOfPixelsPerLines = w;
|
||||
LL_DMA2D_Init(DMA2D, &DMA2D_InitStruct);
|
||||
|
||||
LL_DMA2D_FGND_SetMemAddr(DMA2D, CONVERT_PTR_UINT(src + srcy*srcw + srcx));
|
||||
LL_DMA2D_FGND_SetLineOffset(DMA2D, srcw - w);
|
||||
LL_DMA2D_FGND_SetColorMode(DMA2D, LL_DMA2D_INPUT_MODE_RGB565);
|
||||
LL_DMA2D_FGND_SetAlphaMode(DMA2D, LL_DMA2D_ALPHA_MODE_NO_MODIF);
|
||||
LL_DMA2D_FGND_SetAlpha(DMA2D, 0);
|
||||
|
||||
/* Start Transfer */
|
||||
LL_DMA2D_Start(DMA2D);
|
||||
}
|
||||
|
||||
void DMACopyAlphaBitmap(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
uint16_t x, uint16_t y, const uint16_t *src,
|
||||
uint16_t srcw, uint16_t srch, uint16_t srcx,
|
||||
uint16_t srcy, uint16_t w, uint16_t h)
|
||||
{
|
||||
DMAWait();
|
||||
LL_DMA2D_DeInit(DMA2D);
|
||||
|
||||
LL_DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
LL_DMA2D_StructInit(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_InitStruct.Mode = LL_DMA2D_MODE_M2M_BLEND;
|
||||
DMA2D_InitStruct.ColorMode = LL_DMA2D_OUTPUT_MODE_RGB565;
|
||||
DMA2D_InitStruct.OutputMemoryAddress = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.LineOffset = destw - w;
|
||||
DMA2D_InitStruct.NbrOfLines = h;
|
||||
DMA2D_InitStruct.NbrOfPixelsPerLines = w;
|
||||
LL_DMA2D_Init(DMA2D, &DMA2D_InitStruct);
|
||||
|
||||
LL_DMA2D_FGND_SetMemAddr(DMA2D, CONVERT_PTR_UINT(src + srcy*srcw + srcx));
|
||||
LL_DMA2D_FGND_SetLineOffset(DMA2D, srcw - w);
|
||||
LL_DMA2D_FGND_SetColorMode(DMA2D, LL_DMA2D_INPUT_MODE_ARGB4444);
|
||||
LL_DMA2D_FGND_SetAlphaMode(DMA2D, LL_DMA2D_ALPHA_MODE_NO_MODIF);
|
||||
LL_DMA2D_FGND_SetAlpha(DMA2D, 0);
|
||||
|
||||
LL_DMA2D_BGND_SetMemAddr(DMA2D, CONVERT_PTR_UINT(dest + y*destw + x));
|
||||
LL_DMA2D_BGND_SetLineOffset(DMA2D, destw - w);
|
||||
LL_DMA2D_BGND_SetColorMode(DMA2D, LL_DMA2D_OUTPUT_MODE_RGB565);
|
||||
LL_DMA2D_BGND_SetAlphaMode(DMA2D, LL_DMA2D_ALPHA_MODE_NO_MODIF);
|
||||
LL_DMA2D_BGND_SetAlpha(DMA2D, 0);
|
||||
|
||||
/* Start Transfer */
|
||||
LL_DMA2D_Start(DMA2D);
|
||||
}
|
||||
|
||||
// same as DMACopyAlphaBitmap(), but with an 8 bit mask for each pixel (used by fonts)
|
||||
void DMACopyAlphaMask(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
uint16_t x, uint16_t y, const uint8_t *src, uint16_t srcw,
|
||||
uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w,
|
||||
uint16_t h, uint16_t bg_color)
|
||||
{
|
||||
DMAWait();
|
||||
LL_DMA2D_DeInit(DMA2D);
|
||||
|
||||
LL_DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
LL_DMA2D_StructInit(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_InitStruct.Mode = LL_DMA2D_MODE_M2M_BLEND;
|
||||
DMA2D_InitStruct.ColorMode = LL_DMA2D_OUTPUT_MODE_RGB565;
|
||||
DMA2D_InitStruct.OutputMemoryAddress = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.LineOffset = destw - w;
|
||||
DMA2D_InitStruct.NbrOfLines = h;
|
||||
DMA2D_InitStruct.NbrOfPixelsPerLines = w;
|
||||
LL_DMA2D_Init(DMA2D, &DMA2D_InitStruct);
|
||||
|
||||
LL_DMA2D_FGND_SetMemAddr(DMA2D, CONVERT_PTR_UINT(src + srcy*srcw + srcx));
|
||||
LL_DMA2D_FGND_SetLineOffset(DMA2D, srcw - w);
|
||||
LL_DMA2D_FGND_SetColorMode(DMA2D, LL_DMA2D_INPUT_MODE_A8);
|
||||
LL_DMA2D_FGND_SetAlphaMode(DMA2D, LL_DMA2D_ALPHA_MODE_NO_MODIF);
|
||||
LL_DMA2D_FGND_SetAlpha(DMA2D, 0);
|
||||
LL_DMA2D_FGND_SetRedColor(DMA2D, GET_RED(bg_color)); // 8 bit red
|
||||
LL_DMA2D_FGND_SetGreenColor(DMA2D, GET_GREEN(bg_color)); // 8 bit green
|
||||
LL_DMA2D_FGND_SetBlueColor(DMA2D, GET_BLUE(bg_color)); // 8 bit blue
|
||||
|
||||
LL_DMA2D_BGND_SetMemAddr(DMA2D, CONVERT_PTR_UINT(dest + y*destw + x));
|
||||
LL_DMA2D_BGND_SetLineOffset(DMA2D, destw - w);
|
||||
LL_DMA2D_BGND_SetColorMode(DMA2D, LL_DMA2D_OUTPUT_MODE_RGB565);
|
||||
LL_DMA2D_BGND_SetAlphaMode(DMA2D, LL_DMA2D_ALPHA_MODE_NO_MODIF);
|
||||
LL_DMA2D_BGND_SetAlpha(DMA2D, 0);
|
||||
|
||||
/* Start Transfer */
|
||||
LL_DMA2D_Start(DMA2D);
|
||||
DMAWait();
|
||||
}
|
||||
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format)
|
||||
{
|
||||
DMAWait();
|
||||
LL_DMA2D_DeInit(DMA2D);
|
||||
|
||||
LL_DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
LL_DMA2D_StructInit(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_InitStruct.Mode = LL_DMA2D_MODE_M2M_PFC;
|
||||
DMA2D_InitStruct.ColorMode = format;
|
||||
DMA2D_InitStruct.OutputMemoryAddress = CONVERT_PTR_UINT(dest);
|
||||
DMA2D_InitStruct.NbrOfLines = h;
|
||||
DMA2D_InitStruct.NbrOfPixelsPerLines = w;
|
||||
LL_DMA2D_Init(DMA2D, &DMA2D_InitStruct);
|
||||
|
||||
LL_DMA2D_FGND_SetMemAddr(DMA2D, CONVERT_PTR_UINT(src));
|
||||
LL_DMA2D_FGND_SetLineOffset(DMA2D, 0);
|
||||
LL_DMA2D_FGND_SetColorMode(DMA2D, LL_DMA2D_INPUT_MODE_ARGB8888);
|
||||
LL_DMA2D_FGND_SetAlphaMode(DMA2D, LL_DMA2D_ALPHA_MODE_REPLACE);
|
||||
LL_DMA2D_FGND_SetAlpha(DMA2D, 0);
|
||||
|
||||
/* Start Transfer */
|
||||
LL_DMA2D_Start(DMA2D);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "opentx_types.h"
|
||||
|
||||
#if !defined(SIMU)
|
||||
static inline void DMAWait()
|
||||
{
|
||||
while(DMA2D->CR & DMA2D_CR_START);
|
||||
}
|
||||
#else
|
||||
static inline void DMAWait() {}
|
||||
#endif
|
||||
|
||||
void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
|
||||
void DMACopyBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
|
||||
void DMACopyAlphaBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
|
||||
void DMACopyAlphaMask(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint8_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h, uint16_t bg_color);
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format);
|
||||
@@ -6,6 +6,14 @@ if(NOT NATIVE_BUILD)
|
||||
# STM32 HAL/LL library
|
||||
set(STM32CUBE_DIR ${THIRDPARTY_DIR}/STM32F4xx_HAL_Driver)
|
||||
include_directories(${STM32CUBE_DIR}/Inc)
|
||||
|
||||
if(CPU_TYPE_FULL STREQUAL STM32F429xI)
|
||||
set(STM32_COLORLCD_DRIVERS
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_dma2d.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_ltdc.c
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
add_library(stm32cube_ll OBJECT EXCLUDE_FROM_ALL
|
||||
# LL drivers
|
||||
@@ -23,11 +31,16 @@ if(NOT NATIVE_BUILD)
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_pwr.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_pwr_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_rcc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_rcc_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_rtc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_i2c.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_i2c_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_sd.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_dma.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_cortex.c
|
||||
|
||||
${STM32_COLORLCD_DRIVERS}
|
||||
|
||||
)
|
||||
|
||||
target_compile_options(stm32cube_ll PRIVATE -DUSE_FULL_LL_DRIVER)
|
||||
@@ -62,9 +75,7 @@ if(CPU_TYPE_FULL STREQUAL STM32F429xI)
|
||||
set(STM32_STDPERIPH_SRC ${STM32_STDPERIPH_SRC}
|
||||
targets/${TARGET_DIR}/startup_stm32f42_43xxx.s
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_fmc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_ltdc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_dma.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_dma2d.c
|
||||
)
|
||||
elseif (CPU_TYPE_FULL STREQUAL STM32F413xG)
|
||||
set(STM32_STDPERIPH_SRC ${STM32_STDPERIPH_SRC}
|
||||
|
||||
@@ -30,6 +30,7 @@ extern "C" {
|
||||
#define USE_FULL_LL_DRIVER
|
||||
#if defined(STM32F4)
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma2d.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h"
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
// #define HAL_SMBUS_MODULE_ENABLED
|
||||
// #define HAL_I2S_MODULE_ENABLED
|
||||
// #define HAL_IWDG_MODULE_ENABLED
|
||||
// #define HAL_LTDC_MODULE_ENABLED
|
||||
#if defined(COLORLCD)
|
||||
#define HAL_LTDC_MODULE_ENABLED
|
||||
#endif
|
||||
// #define HAL_DSI_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
// #define HAL_QSPI_MODULE_ENABLED
|
||||
@@ -78,7 +80,7 @@
|
||||
// #define HAL_IRDA_MODULE_ENABLED
|
||||
// #define HAL_SMARTCARD_MODULE_ENABLED
|
||||
// #define HAL_WWDG_MODULE_ENABLED
|
||||
// #define HAL_CORTEX_MODULE_ENABLED
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
// #define HAL_PCD_MODULE_ENABLED
|
||||
// #define HAL_HCD_MODULE_ENABLED
|
||||
// #define HAL_FMPI2C_MODULE_ENABLED
|
||||
|
||||
@@ -265,6 +265,7 @@ set(FIRMWARE_SRC
|
||||
targets/common/arm/stm32/heartbeat_driver.cpp
|
||||
targets/common/arm/stm32/ads79xx.cpp
|
||||
targets/common/arm/stm32/diskio_sdio.cpp
|
||||
targets/common/arm/stm32/dma2d.cpp
|
||||
targets/common/arm/stm32/spi_flash.cpp
|
||||
targets/common/arm/stm32/diskio_spi_flash.cpp
|
||||
drivers/frftl.cpp
|
||||
@@ -297,5 +298,4 @@ set(STM32LIB_SRC
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmc.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_ltdc.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_tim.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma2d.c
|
||||
)
|
||||
|
||||
@@ -196,6 +196,9 @@ void boardInit()
|
||||
#endif
|
||||
|
||||
ledBlue();
|
||||
#if !defined(LCD_VERTICAL_INVERT)
|
||||
lcdSetInitalFrameBuffer(lcdFront->getData());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -210,20 +210,12 @@ void ledBlue();
|
||||
#endif
|
||||
|
||||
// LCD driver
|
||||
#define LCD_W 480
|
||||
#define LCD_H 272
|
||||
#define LCD_PHYS_H LCD_H
|
||||
#define LCD_PHYS_W LCD_W
|
||||
#define LCD_DEPTH 16
|
||||
|
||||
void lcdSetInitalFrameBuffer(void* fbAddress);
|
||||
|
||||
void lcdInit();
|
||||
void lcdCopy(void * dest, void * src);
|
||||
|
||||
void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
|
||||
void DMACopyBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
|
||||
void DMACopyAlphaBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
|
||||
void DMACopyAlphaMask(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint8_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h, uint16_t bg_color);
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format);
|
||||
|
||||
#define lcdOff() backlightEnable(0) /* just disable the backlight */
|
||||
|
||||
|
||||
@@ -571,10 +571,10 @@
|
||||
#define LCD_RCC_APB2Periph RCC_APB2Periph_LTDC
|
||||
#if defined(PCBX12S)
|
||||
#define LCD_GPIO_NRST GPIOF
|
||||
#define LCD_GPIO_PIN_NRST GPIO_Pin_10 // PF.10
|
||||
#define LCD_GPIO_PIN_NRST LL_GPIO_PIN_10 // PF.10
|
||||
#elif defined(PCBX10)
|
||||
#define LCD_GPIO_NRST GPIOI
|
||||
#define LCD_GPIO_PIN_NRST GPIO_Pin_10 // PI.10
|
||||
#define LCD_GPIO_PIN_NRST LL_GPIO_PIN_10 // PI.10
|
||||
#endif
|
||||
#if defined(PCBX10) && !defined(RADIO_T18)
|
||||
#define LCD_VERTICAL_INVERT
|
||||
@@ -1052,4 +1052,10 @@
|
||||
#define BT_EN_GPIO_PIN LL_GPIO_PIN_10 // PG.10
|
||||
#endif
|
||||
|
||||
#define LCD_W 480
|
||||
#define LCD_H 272
|
||||
#define LCD_PHYS_H LCD_H
|
||||
#define LCD_PHYS_W LCD_W
|
||||
#define LCD_DEPTH 16
|
||||
|
||||
#endif // _HAL_H_
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "opentx_types.h"
|
||||
#include "dma2d.h"
|
||||
#include "hal.h"
|
||||
#include "delays_driver.h"
|
||||
|
||||
#include "lcd.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#include "stm32f4xx_dma2d.h"
|
||||
#include "stm32f4xx_ltdc.h"
|
||||
|
||||
#if defined(RADIO_T18)
|
||||
#define HBP 43
|
||||
#define VBP 12
|
||||
@@ -46,7 +49,11 @@
|
||||
#define VFP 2
|
||||
#endif
|
||||
|
||||
static LTDC_HandleTypeDef hltdc;
|
||||
static void* initialFrameBuffer = nullptr;
|
||||
|
||||
#if defined(LCD_VERTICAL_INVERT)
|
||||
typedef uint16_t pixel_t;
|
||||
static pixel_t _LCD_BUF_1[DISPLAY_BUFFER_SIZE] __SDRAM;
|
||||
static pixel_t _LCD_BUF_2[DISPLAY_BUFFER_SIZE] __SDRAM;
|
||||
|
||||
@@ -177,17 +184,18 @@ static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
|
||||
|
||||
inline void LCD_NRST_LOW()
|
||||
{
|
||||
LCD_GPIO_NRST->BSRRH = LCD_GPIO_PIN_NRST;
|
||||
LL_GPIO_ResetOutputPin(LCD_GPIO_NRST, LCD_GPIO_PIN_NRST);
|
||||
}
|
||||
|
||||
inline void LCD_NRST_HIGH()
|
||||
{
|
||||
LCD_GPIO_NRST->BSRRL = LCD_GPIO_PIN_NRST;
|
||||
LL_GPIO_SetOutputPin(LCD_GPIO_NRST, LCD_GPIO_PIN_NRST);
|
||||
}
|
||||
|
||||
static void LCD_AF_GPIOConfig()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
LL_GPIO_InitTypeDef GPIO_InitStructure;
|
||||
LL_GPIO_StructInit(&GPIO_InitStructure);
|
||||
|
||||
/* GPIOs Configuration */
|
||||
/*
|
||||
@@ -207,66 +215,41 @@ static void LCD_AF_GPIOConfig()
|
||||
| LCD_CS <-> PI.10 |LCD_SCK<->PI.11
|
||||
-----------------------------------------------------
|
||||
*/
|
||||
|
||||
// GPIOI configuration
|
||||
GPIO_PinAFConfig(GPIOI, GPIO_PinSource12, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOI, GPIO_PinSource13, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOI, GPIO_PinSource14, GPIO_AF_LTDC);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
|
||||
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType =GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(GPIOI, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource7, GPIO_AF_LTDC);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_Init(GPIOK, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = LL_GPIO_PIN_12 | LL_GPIO_PIN_13 | LL_GPIO_PIN_14;
|
||||
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStructure.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStructure.Pull = LL_GPIO_PULL_NO;
|
||||
GPIO_InitStructure.Alternate = LL_GPIO_AF_14; // AF LTDC
|
||||
LL_GPIO_Init(GPIOI, &GPIO_InitStructure);
|
||||
|
||||
// GPIOJ configuration
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource2, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource3, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource4, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource5, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource6, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource9, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource10, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource11, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource15, GPIO_AF_LTDC);
|
||||
GPIO_InitStructure.Pin = LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5 | LL_GPIO_PIN_6
|
||||
| LL_GPIO_PIN_9 | LL_GPIO_PIN_10 | LL_GPIO_PIN_11 | LL_GPIO_PIN_15;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | \
|
||||
GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_15;
|
||||
|
||||
GPIO_Init(GPIOJ, &GPIO_InitStructure);
|
||||
LL_GPIO_Init(GPIOJ, &GPIO_InitStructure);
|
||||
|
||||
// GPIOK configuration
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource0, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource1, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource2, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource3, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource4, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource5, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource6, GPIO_AF_LTDC);
|
||||
GPIO_InitStructure.Pin = LL_GPIO_PIN_0 | LL_GPIO_PIN_1 | LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4
|
||||
| LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_7;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 ;
|
||||
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(GPIOK, &GPIO_InitStructure);
|
||||
LL_GPIO_Init(GPIOK, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
static void LCD_NRSTConfig(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = LCD_GPIO_PIN_NRST;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(LCD_GPIO_NRST, &GPIO_InitStructure);
|
||||
LL_GPIO_InitTypeDef GPIO_InitStructure;
|
||||
LL_GPIO_StructInit(&GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.Pin = LCD_GPIO_PIN_NRST;
|
||||
GPIO_InitStructure.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStructure.Pull = LL_GPIO_PULL_NO;
|
||||
|
||||
LL_GPIO_Init(LCD_GPIO_NRST, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
static void lcdReset(void)
|
||||
@@ -287,7 +270,7 @@ static void lcdReset(void)
|
||||
|
||||
void LCD_Init_LTDC()
|
||||
{
|
||||
LTDC_InitTypeDef LTDC_InitStruct;
|
||||
hltdc.Instance = LTDC;
|
||||
|
||||
/* Configure PLLSAI prescalers for LCD */
|
||||
/* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 MHz */
|
||||
@@ -297,66 +280,60 @@ void LCD_Init_LTDC()
|
||||
/* alternatively LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 MHz */
|
||||
//second pam is for audio
|
||||
//third pam is for LCD
|
||||
RCC_PLLSAIConfig(192, 6, 3);
|
||||
RCC_PeriphCLKInitTypeDef clkConfig;
|
||||
clkConfig.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
|
||||
clkConfig.PLLSAI.PLLSAIN = 192;
|
||||
clkConfig.PLLSAI.PLLSAIR = 3;
|
||||
clkConfig.PLLSAIDivQ = 6;
|
||||
#if defined(RADIO_TX16S)
|
||||
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8);
|
||||
clkConfig.PLLSAIDivR = RCC_PLLSAIDIVR_8;
|
||||
#else
|
||||
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div4);
|
||||
clkConfig.PLLSAIDivR = RCC_PLLSAIDIVR_4;
|
||||
#endif
|
||||
/* Enable PLLSAI Clock */
|
||||
RCC_PLLSAICmd(ENABLE);
|
||||
|
||||
/* Wait for PLLSAI activation */
|
||||
while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET)
|
||||
{
|
||||
}
|
||||
HAL_RCCEx_PeriphCLKConfig(&clkConfig);
|
||||
|
||||
/* LTDC Configuration *********************************************************/
|
||||
/* Polarity configuration */
|
||||
/* Initialize the horizontal synchronization polarity as active low */
|
||||
LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;
|
||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
||||
/* Initialize the vertical synchronization polarity as active low */
|
||||
LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;
|
||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
||||
/* Initialize the data enable polarity as active low */
|
||||
LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;
|
||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
||||
/* Initialize the pixel clock polarity as input pixel clock */
|
||||
LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC;
|
||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
||||
|
||||
/* Configure R,G,B component values for LCD background color */
|
||||
LTDC_InitStruct.LTDC_BackgroundRedValue = 0;
|
||||
LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;
|
||||
LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;
|
||||
hltdc.Init.Backcolor.Red = 0;
|
||||
hltdc.Init.Backcolor.Green = 0;
|
||||
hltdc.Init.Backcolor.Blue = 0;
|
||||
|
||||
/* Configure horizontal synchronization width */
|
||||
LTDC_InitStruct.LTDC_HorizontalSync = HSW;
|
||||
hltdc.Init.HorizontalSync = HSW;
|
||||
/* Configure vertical synchronization height */
|
||||
LTDC_InitStruct.LTDC_VerticalSync = VSW;
|
||||
hltdc.Init.VerticalSync = VSW;
|
||||
/* Configure accumulated horizontal back porch */
|
||||
LTDC_InitStruct.LTDC_AccumulatedHBP = HBP;
|
||||
hltdc.Init.AccumulatedHBP = HBP;
|
||||
/* Configure accumulated vertical back porch */
|
||||
LTDC_InitStruct.LTDC_AccumulatedVBP = VBP;
|
||||
hltdc.Init.AccumulatedVBP = VBP;
|
||||
/* Configure accumulated active width */
|
||||
LTDC_InitStruct.LTDC_AccumulatedActiveW = LCD_PHYS_W + HBP;
|
||||
hltdc.Init.AccumulatedActiveW = LCD_PHYS_W + HBP;
|
||||
/* Configure accumulated active height */
|
||||
LTDC_InitStruct.LTDC_AccumulatedActiveH = LCD_PHYS_H + VBP;
|
||||
hltdc.Init.AccumulatedActiveH = LCD_PHYS_H + VBP;
|
||||
/* Configure total width */
|
||||
LTDC_InitStruct.LTDC_TotalWidth = LCD_PHYS_W + HBP + HFP;
|
||||
hltdc.Init.TotalWidth = LCD_PHYS_W + HBP + HFP;
|
||||
/* Configure total height */
|
||||
LTDC_InitStruct.LTDC_TotalHeigh = LCD_PHYS_H + VBP + VFP;
|
||||
hltdc.Init.TotalHeigh = LCD_PHYS_H + VBP + VFP;
|
||||
|
||||
LTDC_Init(<DC_InitStruct);
|
||||
HAL_LTDC_Init(&hltdc);
|
||||
|
||||
// Configure IRQ (line)
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = LTDC_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LTDC_IRQ_PRIO;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init( &NVIC_InitStructure );
|
||||
NVIC_SetPriority(LTDC_IRQn, LTDC_IRQ_PRIO);
|
||||
NVIC_EnableIRQ(LTDC_IRQn);
|
||||
|
||||
// Trigger on last line
|
||||
LTDC_LIPConfig(LCD_PHYS_H);
|
||||
LTDC_ITConfig(LTDC_IER_LIE, ENABLE);
|
||||
HAL_LTDC_ProgramLineEvent(&hltdc, LCD_PHYS_H);
|
||||
__HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI);
|
||||
|
||||
#if 0
|
||||
DMA2D_ITConfig(DMA2D_CR_TCIE, ENABLE);
|
||||
@@ -372,66 +349,49 @@ void LCD_Init_LTDC()
|
||||
|
||||
void LCD_LayerInit()
|
||||
{
|
||||
LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct;
|
||||
auto& layer = hltdc.LayerCfg[0];
|
||||
|
||||
/* Windowing configuration */
|
||||
/* In this case all the active display area is used to display a picture then :
|
||||
Horizontal start = horizontal synchronization + Horizontal back porch = 30
|
||||
Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1
|
||||
Vertical start = vertical synchronization + vertical back porch = 4
|
||||
Vertical stop = Vertical start + window height -1 = 4 + 320 -1 */
|
||||
LTDC_Layer_InitStruct.LTDC_HorizontalStart = HBP + 1;
|
||||
LTDC_Layer_InitStruct.LTDC_HorizontalStop = (LCD_PHYS_W + HBP);
|
||||
LTDC_Layer_InitStruct.LTDC_VerticalStart = VBP + 1;;
|
||||
LTDC_Layer_InitStruct.LTDC_VerticalStop = (LCD_PHYS_H + VBP);
|
||||
/* In this case all the active display area is used to display a picture */
|
||||
layer.WindowX0 = 0;
|
||||
layer.WindowX1 = LCD_PHYS_W;
|
||||
layer.WindowY0 = 0;
|
||||
layer.WindowY1 = LCD_PHYS_H;
|
||||
|
||||
/* Pixel Format configuration*/
|
||||
LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
|
||||
layer.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
||||
|
||||
/* Alpha constant (255 totally opaque) */
|
||||
LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255;
|
||||
layer.Alpha = 255;
|
||||
|
||||
/* Default Color configuration (configure A,R,G,B component values) */
|
||||
LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0;
|
||||
LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0;
|
||||
LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0;
|
||||
LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0;
|
||||
layer.Backcolor.Blue = 0;
|
||||
layer.Backcolor.Green = 0;
|
||||
layer.Backcolor.Red = 0;
|
||||
layer.Alpha0 = 0;
|
||||
|
||||
/* Configure blending factors */
|
||||
LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA;
|
||||
LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA;
|
||||
layer.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
|
||||
layer.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
|
||||
|
||||
/* the length of one line of pixels in bytes + 3 then :
|
||||
Line Lenth = Active high width x number of bytes per pixel + 3
|
||||
Active high width = LCD_W
|
||||
number of bytes per pixel = 2 (pixel_format : RGB565)
|
||||
*/
|
||||
LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((LCD_PHYS_W * 2) + 3);
|
||||
/* the pitch is the increment from the start of one line of pixels to the
|
||||
start of the next line in bytes, then :
|
||||
Pitch = Active high width x number of bytes per pixel */
|
||||
LTDC_Layer_InitStruct.LTDC_CFBPitch = (LCD_PHYS_W * 2);
|
||||
|
||||
/* Configure the number of lines */
|
||||
LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_PHYS_H;
|
||||
layer.ImageWidth = LCD_PHYS_W;
|
||||
layer.ImageHeight = LCD_PHYS_H;
|
||||
|
||||
/* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */
|
||||
#if defined(LCD_VERTICAL_INVERT)
|
||||
uint32_t layer_address = (uint32_t)_LCD_BUF_1;
|
||||
intptr_t layer_address = (intptr_t)_LCD_BUF_1;
|
||||
#else
|
||||
uint32_t layer_address = (uint32_t)lcdFront->getData();
|
||||
intptr_t layer_address = (intptr_t)initialFrameBuffer;
|
||||
#endif
|
||||
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = layer_address;
|
||||
layer.FBStartAdress = layer_address;
|
||||
|
||||
/* Initialize LTDC layer 1 */
|
||||
LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct);
|
||||
HAL_LTDC_ConfigLayer(&hltdc, &hltdc.LayerCfg[0], 0);
|
||||
}
|
||||
|
||||
/* LTDC configuration reload */
|
||||
LTDC_ReloadConfig(LTDC_IMReload);
|
||||
|
||||
// Enable layer and reload
|
||||
LTDC_LayerCmd(LTDC_Layer1, ENABLE);
|
||||
LTDC_ReloadConfig(LTDC_IMReload);
|
||||
extern "C"
|
||||
void lcdSetInitalFrameBuffer(void* fbAddress)
|
||||
{
|
||||
initialFrameBuffer = fbAddress;
|
||||
}
|
||||
|
||||
void LCD_Init(void)
|
||||
@@ -450,6 +410,7 @@ void LCD_Init(void)
|
||||
LCD_Init_LTDC();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void lcdInit()
|
||||
{
|
||||
#if defined(LCD_VERTICAL_INVERT)
|
||||
@@ -463,175 +424,16 @@ void lcdInit()
|
||||
LCD_LayerInit();
|
||||
|
||||
// Enable LCD display
|
||||
LTDC_Cmd(ENABLE);
|
||||
__HAL_LTDC_ENABLE(&hltdc);
|
||||
|
||||
lcdSetFlushCb(startLcdRefresh);
|
||||
}
|
||||
|
||||
void DMAWait()
|
||||
{
|
||||
while(DMA2D->CR & DMA2D_CR_START);
|
||||
}
|
||||
|
||||
void DMACopyBitmap(uint16_t *dest, uint16_t destw, uint16_t desth, uint16_t x,
|
||||
uint16_t y, const uint16_t *src, uint16_t srcw,
|
||||
uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w,
|
||||
uint16_t h)
|
||||
{
|
||||
DMAWait();
|
||||
DMA2D_DeInit();
|
||||
|
||||
DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M;
|
||||
DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565;
|
||||
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputRed = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputOffset = destw - w;
|
||||
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
|
||||
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
|
||||
DMA2D_Init(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
|
||||
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src + srcy*srcw + srcx);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGO = srcw - w;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_RGB565;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
|
||||
|
||||
/* Start Transfer */
|
||||
DMA2D_StartTransfer();
|
||||
}
|
||||
|
||||
void DMACopyAlphaBitmap(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
uint16_t x, uint16_t y, const uint16_t *src,
|
||||
uint16_t srcw, uint16_t srch, uint16_t srcx,
|
||||
uint16_t srcy, uint16_t w, uint16_t h)
|
||||
{
|
||||
DMAWait();
|
||||
DMA2D_DeInit();
|
||||
|
||||
DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_BLEND;
|
||||
DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565;
|
||||
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputRed = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputOffset = destw - w;
|
||||
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
|
||||
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
|
||||
DMA2D_Init(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
|
||||
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src + srcy*srcw + srcx);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGO = srcw - w;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_ARGB4444;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
|
||||
|
||||
DMA2D_BG_InitTypeDef DMA2D_BG_InitStruct;
|
||||
DMA2D_BG_StructInit(&DMA2D_BG_InitStruct);
|
||||
DMA2D_BG_InitStruct.DMA2D_BGMA = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_BG_InitStruct.DMA2D_BGO = destw - w;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGCM = CM_RGB565;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_BGConfig(&DMA2D_BG_InitStruct);
|
||||
|
||||
/* Start Transfer */
|
||||
DMA2D_StartTransfer();
|
||||
}
|
||||
|
||||
// same as DMACopyAlphaBitmap(), but with an 8 bit mask for each pixel (used by fonts)
|
||||
void DMACopyAlphaMask(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
uint16_t x, uint16_t y, const uint8_t *src, uint16_t srcw,
|
||||
uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w,
|
||||
uint16_t h, uint16_t bg_color)
|
||||
{
|
||||
DMAWait();
|
||||
DMA2D_DeInit();
|
||||
|
||||
DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_BLEND;
|
||||
DMA2D_InitStruct.DMA2D_CMode = CM_RGB565;
|
||||
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputRed = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputOffset = destw - w;
|
||||
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
|
||||
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
|
||||
DMA2D_Init(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
|
||||
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src + srcy*srcw + srcx);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGO = srcw - w;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_A8; // 8 bit inputs every time
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGC_RED = GET_RED(bg_color); // 8 bit red
|
||||
DMA2D_FG_InitStruct.DMA2D_FGC_GREEN = GET_GREEN(bg_color); // 8 bit green
|
||||
DMA2D_FG_InitStruct.DMA2D_FGC_BLUE = GET_BLUE(bg_color); // 8 bit blue
|
||||
|
||||
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
|
||||
|
||||
DMA2D_BG_InitTypeDef DMA2D_BG_InitStruct;
|
||||
DMA2D_BG_StructInit(&DMA2D_BG_InitStruct);
|
||||
DMA2D_BG_InitStruct.DMA2D_BGMA = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_BG_InitStruct.DMA2D_BGO = destw - w;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGCM = CM_RGB565;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_BGConfig(&DMA2D_BG_InitStruct);
|
||||
|
||||
/* Start Transfer */
|
||||
DMA2D_StartTransfer();
|
||||
}
|
||||
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format)
|
||||
{
|
||||
DMA2D_DeInit();
|
||||
|
||||
DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_PFC;
|
||||
DMA2D_InitStruct.DMA2D_CMode = format;
|
||||
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest);
|
||||
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputRed = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputOffset = 0;
|
||||
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
|
||||
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
|
||||
DMA2D_Init(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
|
||||
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGO = 0;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_ARGB8888;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = REPLACE_ALPHA_VALUE;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
|
||||
|
||||
/* Start Transfer */
|
||||
DMA2D_StartTransfer();
|
||||
}
|
||||
|
||||
extern "C" void LTDC_IRQHandler(void)
|
||||
{
|
||||
// clear interrupt flag
|
||||
LTDC->ICR = LTDC_ICR_CLIF;
|
||||
__HAL_LTDC_CLEAR_FLAG(&hltdc, LTDC_FLAG_LI);
|
||||
_frame_addr_reloaded = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,7 @@ set(FIRMWARE_TARGET_SRC
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
targets/common/arm/stm32/diskio_sdio.cpp
|
||||
targets/common/arm/stm32/dma2d.cpp
|
||||
targets/common/arm/stm32/spi_flash.cpp
|
||||
targets/common/arm/stm32/diskio_spi_flash.cpp
|
||||
drivers/frftl.cpp
|
||||
|
||||
@@ -277,6 +277,7 @@ void boardInit()
|
||||
rtcInit(); // RTC must be initialized before rambackupRestore() is called
|
||||
#endif
|
||||
|
||||
lcdSetInitalFrameBuffer(lcdFront->getData());
|
||||
|
||||
#if defined(DEBUG)
|
||||
DBGMCU_APB1PeriphConfig(
|
||||
|
||||
@@ -172,23 +172,10 @@ uint32_t pwrPressedDuration();;
|
||||
const etx_serial_port_t* auxSerialGetPort(int port_nr);
|
||||
|
||||
// LCD driver
|
||||
#define LCD_W 320
|
||||
#define LCD_H 480
|
||||
|
||||
#define LCD_PHYS_W 320
|
||||
#define LCD_PHYS_H 480
|
||||
|
||||
#define LCD_DEPTH 16
|
||||
#define LCD_CONTRAST_DEFAULT 20
|
||||
|
||||
void lcdSetInitalFrameBuffer(void* fbAddress);
|
||||
void lcdInit();
|
||||
void lcdCopy(void * dest, void * src);
|
||||
|
||||
void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
|
||||
void DMACopyBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
|
||||
void DMACopyAlphaBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
|
||||
void DMACopyAlphaMask(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint8_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h, uint16_t bg_color);
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format);
|
||||
|
||||
void lcdOff();
|
||||
void lcdOn();
|
||||
|
||||
@@ -271,12 +271,12 @@
|
||||
#define LCD_RCC_APB1Periph 0
|
||||
#define LCD_RCC_APB2Periph RCC_APB2Periph_LTDC
|
||||
#define LCD_NRST_GPIO GPIOG
|
||||
#define LCD_NRST_GPIO_PIN GPIO_Pin_9 // PG.09
|
||||
#define LCD_NRST_GPIO_PIN LL_GPIO_PIN_9 // PG.09
|
||||
#define LCD_SPI_GPIO GPIOE
|
||||
#define LCD_SPI_CS_GPIO_PIN GPIO_Pin_4 // PE.04
|
||||
#define LCD_SPI_SCK_GPIO_PIN GPIO_Pin_2 // PE.02
|
||||
#define LCD_SPI_MISO_GPIO_PIN GPIO_Pin_5 // PE.05
|
||||
#define LCD_SPI_MOSI_GPIO_PIN GPIO_Pin_6 // PE.06
|
||||
#define LCD_SPI_CS_GPIO_PIN LL_GPIO_PIN_4 // PE.04
|
||||
#define LCD_SPI_SCK_GPIO_PIN LL_GPIO_PIN_2 // PE.02
|
||||
#define LCD_SPI_MISO_GPIO_PIN LL_GPIO_PIN_5 // PE.05
|
||||
#define LCD_SPI_MOSI_GPIO_PIN LL_GPIO_PIN_6 // PE.06
|
||||
#define LTDC_IRQ_PRIO 4
|
||||
#define DMA_SCREEN_IRQ_PRIO 6
|
||||
|
||||
@@ -575,4 +575,13 @@
|
||||
#define MIXER_SCHEDULER_TIMER_IRQn TIM8_BRK_TIM12_IRQn
|
||||
#define MIXER_SCHEDULER_TIMER_IRQHandler TIM8_BRK_TIM12_IRQHandler
|
||||
|
||||
#define LCD_W 320
|
||||
#define LCD_H 480
|
||||
|
||||
#define LCD_PHYS_W 320
|
||||
#define LCD_PHYS_H 480
|
||||
|
||||
#define LCD_DEPTH 16
|
||||
#define LCD_CONTRAST_DEFAULT 20
|
||||
|
||||
#endif // _HAL_H_
|
||||
|
||||
@@ -19,13 +19,18 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "opentx_types.h"
|
||||
#include "dma2d.h"
|
||||
#include "hal.h"
|
||||
#include "delays_driver.h"
|
||||
#include "debug.h"
|
||||
#include "lcd.h"
|
||||
#include "lcd_driver.h"
|
||||
|
||||
// StdPeriph
|
||||
#include "stm32f4xx_ltdc.h"
|
||||
#include "stm32f4xx_dma2d.h"
|
||||
static LTDC_HandleTypeDef hltdc;
|
||||
static void* initialFrameBuffer = nullptr;
|
||||
|
||||
static volatile uint8_t _frame_addr_reloaded = 0;
|
||||
|
||||
@@ -35,11 +40,12 @@ static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
|
||||
(void)disp_drv;
|
||||
(void)copy_area;
|
||||
|
||||
LTDC_Layer1->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
|
||||
LTDC_Layer1->CFBAR = (uint32_t)buffer;
|
||||
|
||||
// reload shadow registers on vertical blank
|
||||
_frame_addr_reloaded = 0;
|
||||
LTDC->SRCR = LTDC_SRCR_VBR;
|
||||
__HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI);
|
||||
|
||||
// wait for reload
|
||||
// TODO: replace through some smarter mechanism without busy wait
|
||||
@@ -77,34 +83,9 @@ enum ENUM_IO_MODE
|
||||
IO_MODE_ANALOG
|
||||
};
|
||||
|
||||
|
||||
void GPIO_SetDirection( GPIO_TypeDef *GPIOx, unsigned char Pin, unsigned char IsInput )
|
||||
{
|
||||
unsigned int Mask;
|
||||
unsigned int Position;
|
||||
unsigned int Register;
|
||||
|
||||
|
||||
Position = Pin << 1;
|
||||
Mask = ~( 0x03UL << Position );
|
||||
|
||||
//EnterCritical();
|
||||
Register = GPIOx->OSPEEDR & Mask;
|
||||
Register |= IO_SPEED_HIGH << Position;
|
||||
GPIOx->OSPEEDR = Register;
|
||||
//ExitCritical();
|
||||
|
||||
//EnterCritical();
|
||||
Register = GPIOx->MODER & Mask;
|
||||
if( !IsInput )
|
||||
{
|
||||
Register |= IO_MODE_OUTPUT << Position;
|
||||
}
|
||||
|
||||
GPIOx->MODER = Register;
|
||||
//ExitCritical();
|
||||
}
|
||||
static void LCD_AF_GPIOConfig(void) {
|
||||
LL_GPIO_InitTypeDef GPIO_InitStructure;
|
||||
LL_GPIO_StructInit(&GPIO_InitStructure);
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
LCD_CLK <-> PG.07 | LCD_HSYNC <-> PI.12 | LCD_R3 <-> PJ.02 | LCD_G5 <-> PK.00
|
||||
@@ -119,69 +100,50 @@ static void LCD_AF_GPIOConfig(void) {
|
||||
*/
|
||||
|
||||
// GPIOG configuration
|
||||
GPIO_PinAFConfig(GPIOG, GPIO_PinSource7, GPIO_AF_LTDC);
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = LL_GPIO_PIN_7;
|
||||
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStructure.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStructure.Pull = LL_GPIO_PULL_NO;
|
||||
GPIO_InitStructure.Alternate = LL_GPIO_AF_14; // AF LTDC
|
||||
LL_GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||
|
||||
// GPIOI configuration
|
||||
GPIO_PinAFConfig(GPIOI, GPIO_PinSource12, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOI, GPIO_PinSource13, GPIO_AF_LTDC);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13;
|
||||
GPIO_Init(GPIOI, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = LL_GPIO_PIN_12 | LL_GPIO_PIN_13;
|
||||
LL_GPIO_Init(GPIOI, &GPIO_InitStructure);
|
||||
|
||||
// GPIOJ configuration
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource2, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource3, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource4, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource5, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource6, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource9, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource10, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource11, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource15, GPIO_AF_LTDC);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_15;
|
||||
GPIO_Init(GPIOJ, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_9 | LL_GPIO_PIN_10 | LL_GPIO_PIN_11 | LL_GPIO_PIN_15;
|
||||
LL_GPIO_Init(GPIOJ, &GPIO_InitStructure);
|
||||
|
||||
// GPIOK configuration
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource0, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource1, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource2, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource3, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource4, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource5, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource6, GPIO_AF_LTDC);
|
||||
GPIO_PinAFConfig(GPIOK, GPIO_PinSource7, GPIO_AF_LTDC);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
|
||||
GPIO_Init(GPIOK, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = LL_GPIO_PIN_0 | LL_GPIO_PIN_1 | LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_7;
|
||||
LL_GPIO_Init(GPIOK, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
static void lcdSpiConfig(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
LL_GPIO_InitTypeDef GPIO_InitStructure;
|
||||
LL_GPIO_StructInit(&GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_GPIO_PIN | LCD_SPI_MOSI_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(LCD_SPI_GPIO, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = LCD_SPI_SCK_GPIO_PIN | LCD_SPI_MOSI_GPIO_PIN;
|
||||
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStructure.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStructure.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(LCD_SPI_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = LCD_SPI_CS_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(LCD_SPI_GPIO, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = LCD_SPI_CS_GPIO_PIN;
|
||||
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStructure.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStructure.Pull = LL_GPIO_PULL_UP;
|
||||
LL_GPIO_Init(LCD_SPI_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = LCD_NRST_GPIO_PIN;
|
||||
GPIO_Init(LCD_NRST_GPIO, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = LCD_NRST_GPIO_PIN;
|
||||
LL_GPIO_Init(LCD_NRST_GPIO, &GPIO_InitStructure);
|
||||
|
||||
/* Set the chip select pin aways low */
|
||||
CLR_LCD_CS();
|
||||
LCD_CS_LOW();
|
||||
}
|
||||
|
||||
void lcdDelay() {
|
||||
@@ -192,25 +154,25 @@ unsigned char LCD_ReadByteOnFallingEdge(void) {
|
||||
unsigned int i;
|
||||
unsigned char ReceiveData = 0;
|
||||
|
||||
SET_LCD_DATA();
|
||||
SET_LCD_DATA_INPUT();
|
||||
LCD_MOSI_HIGH();
|
||||
LCD_MOSI_AS_INPUT();
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
LCD_DELAY();
|
||||
SET_LCD_CLK();
|
||||
LCD_SCK_HIGH();
|
||||
LCD_DELAY();
|
||||
LCD_DELAY();
|
||||
ReceiveData <<= 1;
|
||||
|
||||
CLR_LCD_CLK();
|
||||
LCD_SCK_LOW();
|
||||
LCD_DELAY();
|
||||
LCD_DELAY();
|
||||
if (READ_LCD_DATA_PIN()) {
|
||||
if (LCD_READ_DATA_PIN()) {
|
||||
ReceiveData |= 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
SET_LCD_DATA_OUTPUT();
|
||||
LCD_MOSI_AS_OUTPUT();
|
||||
|
||||
return (ReceiveData);
|
||||
}
|
||||
@@ -251,22 +213,22 @@ unsigned char LCD_ReadByte(void) {
|
||||
unsigned int i;
|
||||
unsigned char ReceiveData = 0;
|
||||
|
||||
SET_LCD_DATA();
|
||||
SET_LCD_DATA_INPUT();
|
||||
LCD_MOSI_HIGH();
|
||||
LCD_MOSI_AS_INPUT();
|
||||
for (i = 0; i < 8; i++) {
|
||||
CLR_LCD_CLK();
|
||||
LCD_SCK_LOW();
|
||||
LCD_DELAY();
|
||||
LCD_DELAY();
|
||||
ReceiveData <<= 1;
|
||||
SET_LCD_CLK();
|
||||
LCD_SCK_HIGH();
|
||||
LCD_DELAY();
|
||||
LCD_DELAY();
|
||||
if (READ_LCD_DATA_PIN()) {
|
||||
if (LCD_READ_DATA_PIN()) {
|
||||
ReceiveData |= 0x01;
|
||||
}
|
||||
}
|
||||
CLR_LCD_CLK();
|
||||
SET_LCD_DATA_OUTPUT();
|
||||
LCD_SCK_LOW();
|
||||
LCD_MOSI_AS_OUTPUT();
|
||||
return (ReceiveData);
|
||||
}
|
||||
|
||||
@@ -1113,12 +1075,11 @@ unsigned int LCD_ST7796S_ReadID(void) {
|
||||
|
||||
lcdWriteCommand( 0XD3 );
|
||||
|
||||
SET_LCD_CLK_OUTPUT();
|
||||
SET_LCD_DATA_INPUT();
|
||||
CLR_LCD_CLK();
|
||||
LCD_MOSI_AS_INPUT();
|
||||
LCD_SCK_LOW();
|
||||
LCD_DELAY();
|
||||
LCD_DELAY();
|
||||
SET_LCD_CLK();
|
||||
LCD_SCK_HIGH();
|
||||
LCD_DELAY();
|
||||
LCD_DELAY();
|
||||
|
||||
@@ -1141,7 +1102,7 @@ static void lcdReset() {
|
||||
}
|
||||
|
||||
void LCD_Init_LTDC() {
|
||||
LTDC_InitTypeDef LTDC_InitStruct;
|
||||
hltdc.Instance = LTDC;
|
||||
|
||||
/* Configure PLLSAI prescalers for LCD */
|
||||
/* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
|
||||
@@ -1149,61 +1110,56 @@ void LCD_Init_LTDC() {
|
||||
/* PLLLCDCLK = PLLSAI_VCO Output/PLL_LTDC = PLLSAI_VCO/4 = YY Mhz */
|
||||
/* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = YY/4 = lcdPixelClock Mhz */
|
||||
uint32_t clock = (lcdPixelClock*16) / 1000000; // clock*16 in MHz
|
||||
RCC_PLLSAIConfig(clock, 6, 4);
|
||||
RCC_LTDCCLKDivConfig (RCC_PLLSAIDivR_Div4);
|
||||
|
||||
/* Enable PLLSAI Clock */
|
||||
RCC_PLLSAICmd(ENABLE);
|
||||
|
||||
/* Wait for PLLSAI activation */
|
||||
while (RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET);
|
||||
RCC_PeriphCLKInitTypeDef clkConfig;
|
||||
clkConfig.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
|
||||
clkConfig.PLLSAI.PLLSAIN = clock;
|
||||
clkConfig.PLLSAI.PLLSAIR = 4;
|
||||
clkConfig.PLLSAIDivQ = 6;
|
||||
clkConfig.PLLSAIDivR = RCC_PLLSAIDIVR_4;
|
||||
HAL_RCCEx_PeriphCLKConfig(&clkConfig);
|
||||
|
||||
/* LTDC Configuration *********************************************************/
|
||||
/* Polarity configuration */
|
||||
/* Initialize the horizontal synchronization polarity as active low */
|
||||
LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;
|
||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
||||
/* Initialize the vertical synchronization polarity as active low */
|
||||
LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;
|
||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
||||
/* Initialize the data enable polarity as active low */
|
||||
LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;
|
||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
||||
/* Initialize the pixel clock polarity as input pixel clock */
|
||||
LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC;
|
||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
||||
|
||||
/* Configure R,G,B component values for LCD background color */
|
||||
LTDC_InitStruct.LTDC_BackgroundRedValue = 0;
|
||||
LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;
|
||||
LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;
|
||||
hltdc.Init.Backcolor.Red = 0;
|
||||
hltdc.Init.Backcolor.Green = 0;
|
||||
hltdc.Init.Backcolor.Blue = 0;
|
||||
|
||||
/* Configure horizontal synchronization width */
|
||||
LTDC_InitStruct.LTDC_HorizontalSync = HSW;
|
||||
hltdc.Init.HorizontalSync = HSW;
|
||||
/* Configure vertical synchronization height */
|
||||
LTDC_InitStruct.LTDC_VerticalSync = VSH;
|
||||
hltdc.Init.VerticalSync = VSH;
|
||||
/* Configure accumulated horizontal back porch */
|
||||
LTDC_InitStruct.LTDC_AccumulatedHBP = HBP;
|
||||
hltdc.Init.AccumulatedHBP = HBP;
|
||||
/* Configure accumulated vertical back porch */
|
||||
LTDC_InitStruct.LTDC_AccumulatedVBP = VBP;
|
||||
hltdc.Init.AccumulatedVBP = VBP;
|
||||
/* Configure accumulated active width */
|
||||
LTDC_InitStruct.LTDC_AccumulatedActiveW = LCD_PHYS_W + HBP;
|
||||
hltdc.Init.AccumulatedActiveW = LCD_PHYS_W + HBP;
|
||||
/* Configure accumulated active height */
|
||||
LTDC_InitStruct.LTDC_AccumulatedActiveH = LCD_PHYS_H + VBP;
|
||||
hltdc.Init.AccumulatedActiveH = LCD_PHYS_H + VBP;
|
||||
/* Configure total width */
|
||||
LTDC_InitStruct.LTDC_TotalWidth = LCD_PHYS_W + HBP + HFP;
|
||||
hltdc.Init.TotalWidth = LCD_PHYS_W + HBP + HFP;
|
||||
/* Configure total height */
|
||||
LTDC_InitStruct.LTDC_TotalHeigh = LCD_PHYS_H + VBP + VFP;
|
||||
hltdc.Init.TotalHeigh = LCD_PHYS_H + VBP + VFP;
|
||||
|
||||
LTDC_Init(<DC_InitStruct);
|
||||
HAL_LTDC_Init(&hltdc);
|
||||
|
||||
// Configure IRQ (line)
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = LTDC_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LTDC_IRQ_PRIO;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
NVIC_SetPriority(LTDC_IRQn, LTDC_IRQ_PRIO);
|
||||
NVIC_EnableIRQ(LTDC_IRQn);
|
||||
|
||||
// Trigger on last line
|
||||
LTDC_LIPConfig(LCD_PHYS_H);
|
||||
LTDC_ITConfig(LTDC_IER_LIE, ENABLE);
|
||||
HAL_LTDC_ProgramLineEvent(&hltdc, LCD_PHYS_H);
|
||||
__HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI);
|
||||
|
||||
#if 0
|
||||
DMA2D_ITConfig(DMA2D_CR_TCIE, ENABLE);
|
||||
@@ -1217,75 +1173,57 @@ void LCD_Init_LTDC() {
|
||||
}
|
||||
|
||||
void LCD_LayerInit() {
|
||||
LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct;
|
||||
auto& layer = hltdc.LayerCfg[0];
|
||||
|
||||
/* Windowing configuration */
|
||||
/* In this case all the active display area is used to display a picture then :
|
||||
Horizontal start = horizontal synchronization + Horizontal back porch = 30
|
||||
Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1
|
||||
Vertical start = vertical synchronization + vertical back porch = 4
|
||||
Vertical stop = Vertical start + window height -1 = 4 + 320 -1 */
|
||||
LTDC_Layer_InitStruct.LTDC_HorizontalStart = HBP + 1;
|
||||
LTDC_Layer_InitStruct.LTDC_HorizontalStop = (LCD_PHYS_W + HBP);
|
||||
LTDC_Layer_InitStruct.LTDC_VerticalStart = VBP + 1;
|
||||
LTDC_Layer_InitStruct.LTDC_VerticalStop = (LCD_PHYS_H + VBP);
|
||||
layer.WindowX0 = 0;
|
||||
layer.WindowX1 = LCD_PHYS_W;
|
||||
layer.WindowY0 = 0;
|
||||
layer.WindowY1 = LCD_PHYS_H;
|
||||
|
||||
/* Pixel Format configuration*/
|
||||
LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
|
||||
layer.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
||||
|
||||
/* Alpha constant (255 totally opaque) */
|
||||
LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255;
|
||||
layer.Alpha = 255;
|
||||
|
||||
/* Default Color configuration (configure A,R,G,B component values) */
|
||||
LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0;
|
||||
LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0;
|
||||
LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0;
|
||||
LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0;
|
||||
layer.Backcolor.Blue = 0;
|
||||
layer.Backcolor.Green = 0;
|
||||
layer.Backcolor.Red = 0;
|
||||
layer.Alpha0 = 0;
|
||||
|
||||
/* Configure blending factors */
|
||||
LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA;
|
||||
LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA;
|
||||
layer.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
|
||||
layer.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
|
||||
|
||||
/* the length of one line of pixels in bytes + 3 then :
|
||||
Line Lenth = Active high width x number of bytes per pixel + 3
|
||||
Active high width = LCD_W
|
||||
number of bytes per pixel = 2 (pixel_format : RGB565)
|
||||
*/
|
||||
LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((LCD_PHYS_W * 2) + 3);
|
||||
/* the pitch is the increment from the start of one line of pixels to the
|
||||
start of the next line in bytes, then :
|
||||
Pitch = Active high width x number of bytes per pixel */
|
||||
LTDC_Layer_InitStruct.LTDC_CFBPitch = (LCD_PHYS_W * 2);
|
||||
|
||||
/* Configure the number of lines */
|
||||
LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_PHYS_H;
|
||||
layer.ImageWidth = LCD_PHYS_W;
|
||||
layer.ImageHeight = LCD_PHYS_H;
|
||||
|
||||
/* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */
|
||||
uint32_t layer_address = (uint32_t)lcdFront->getData();
|
||||
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = layer_address;
|
||||
layer.FBStartAdress = (intptr_t)initialFrameBuffer;
|
||||
|
||||
/* Initialize LTDC layer 1 */
|
||||
LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct);
|
||||
|
||||
/* LTDC configuration reload */
|
||||
LTDC_ReloadConfig(LTDC_IMReload);
|
||||
|
||||
LTDC_LayerCmd(LTDC_Layer1, ENABLE);
|
||||
LTDC_LayerAlpha(LTDC_Layer1, 255);
|
||||
|
||||
LTDC_ReloadConfig(LTDC_IMReload);
|
||||
HAL_LTDC_ConfigLayer(&hltdc, &hltdc.LayerCfg[0], 0);
|
||||
|
||||
/* dithering activation */
|
||||
LTDC_DitherCmd(ENABLE);
|
||||
HAL_LTDC_EnableDither(&hltdc);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void lcdSetInitalFrameBuffer(void* fbAddress)
|
||||
{
|
||||
initialFrameBuffer = fbAddress;
|
||||
}
|
||||
|
||||
const char* boardLcdType = "";
|
||||
|
||||
extern "C"
|
||||
void lcdInit(void)
|
||||
{
|
||||
/* Configure the LCD SPI+RESET pins */
|
||||
lcdSpiConfig();
|
||||
|
||||
// TODO: init lVGL
|
||||
|
||||
/* Reset the LCD --------------------------------------------------------*/
|
||||
lcdReset();
|
||||
|
||||
@@ -1337,176 +1275,17 @@ void lcdInit(void)
|
||||
|
||||
LCD_Init_LTDC();
|
||||
LCD_LayerInit();
|
||||
LTDC_Cmd(ENABLE);
|
||||
LTDC_ReloadConfig(LTDC_IMReload);
|
||||
|
||||
// Enable LCD display
|
||||
__HAL_LTDC_ENABLE(&hltdc);
|
||||
|
||||
lcdSetFlushCb(startLcdRefresh);
|
||||
}
|
||||
|
||||
void DMAWait()
|
||||
{
|
||||
while(DMA2D->CR & DMA2D_CR_START);
|
||||
}
|
||||
|
||||
void DMACopyBitmap(uint16_t *dest, uint16_t destw, uint16_t desth, uint16_t x,
|
||||
uint16_t y, const uint16_t *src, uint16_t srcw,
|
||||
uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w,
|
||||
uint16_t h)
|
||||
{
|
||||
DMAWait();
|
||||
DMA2D_DeInit();
|
||||
|
||||
DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M;
|
||||
DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565;
|
||||
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputRed = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputOffset = destw - w;
|
||||
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
|
||||
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
|
||||
DMA2D_Init(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
|
||||
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src + srcy*srcw + srcx);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGO = srcw - w;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_RGB565;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
|
||||
|
||||
/* Start Transfer */
|
||||
DMA2D_StartTransfer();
|
||||
}
|
||||
|
||||
void DMACopyAlphaBitmap(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
uint16_t x, uint16_t y, const uint16_t *src,
|
||||
uint16_t srcw, uint16_t srch, uint16_t srcx,
|
||||
uint16_t srcy, uint16_t w, uint16_t h)
|
||||
{
|
||||
DMAWait();
|
||||
DMA2D_DeInit();
|
||||
|
||||
DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_BLEND;
|
||||
DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565;
|
||||
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputRed = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputOffset = destw - w;
|
||||
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
|
||||
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
|
||||
DMA2D_Init(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
|
||||
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src + srcy*srcw + srcx);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGO = srcw - w;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_ARGB4444;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
|
||||
|
||||
DMA2D_BG_InitTypeDef DMA2D_BG_InitStruct;
|
||||
DMA2D_BG_StructInit(&DMA2D_BG_InitStruct);
|
||||
DMA2D_BG_InitStruct.DMA2D_BGMA = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_BG_InitStruct.DMA2D_BGO = destw - w;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGCM = CM_RGB565;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_BGConfig(&DMA2D_BG_InitStruct);
|
||||
|
||||
/* Start Transfer */
|
||||
DMA2D_StartTransfer();
|
||||
}
|
||||
|
||||
// same as DMACopyAlphaBitmap(), but with an 8 bit mask for each pixel (used by fonts)
|
||||
void DMACopyAlphaMask(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
uint16_t x, uint16_t y, const uint8_t *src, uint16_t srcw,
|
||||
uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w,
|
||||
uint16_t h, uint16_t bg_color)
|
||||
{
|
||||
DMAWait();
|
||||
DMA2D_DeInit();
|
||||
|
||||
DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_BLEND;
|
||||
DMA2D_InitStruct.DMA2D_CMode = CM_RGB565;
|
||||
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputRed = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputOffset = destw - w;
|
||||
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
|
||||
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
|
||||
DMA2D_Init(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
|
||||
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src + srcy*srcw + srcx);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGO = srcw - w;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_A8; // 8 bit inputs every time
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGC_RED = GET_RED(bg_color); // 8 bit red
|
||||
DMA2D_FG_InitStruct.DMA2D_FGC_GREEN = GET_GREEN(bg_color); // 8 bit green
|
||||
DMA2D_FG_InitStruct.DMA2D_FGC_BLUE = GET_BLUE(bg_color); // 8 bit blue
|
||||
|
||||
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
|
||||
|
||||
DMA2D_BG_InitTypeDef DMA2D_BG_InitStruct;
|
||||
DMA2D_BG_StructInit(&DMA2D_BG_InitStruct);
|
||||
DMA2D_BG_InitStruct.DMA2D_BGMA = CONVERT_PTR_UINT(dest + y*destw + x);
|
||||
DMA2D_BG_InitStruct.DMA2D_BGO = destw - w;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGCM = CM_RGB565;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
|
||||
DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_BGConfig(&DMA2D_BG_InitStruct);
|
||||
|
||||
/* Start Transfer */
|
||||
DMA2D_StartTransfer();
|
||||
}
|
||||
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format)
|
||||
{
|
||||
DMAWait();
|
||||
DMA2D_DeInit();
|
||||
|
||||
DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_PFC;
|
||||
DMA2D_InitStruct.DMA2D_CMode = format;
|
||||
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest);
|
||||
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputRed = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
|
||||
DMA2D_InitStruct.DMA2D_OutputOffset = 0;
|
||||
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
|
||||
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
|
||||
DMA2D_Init(&DMA2D_InitStruct);
|
||||
|
||||
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
|
||||
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src);
|
||||
DMA2D_FG_InitStruct.DMA2D_FGO = 0;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_ARGB8888;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = REPLACE_ALPHA_VALUE;
|
||||
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
|
||||
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
|
||||
|
||||
/* Start Transfer */
|
||||
DMA2D_StartTransfer();
|
||||
}
|
||||
|
||||
extern "C" void LTDC_IRQHandler(void)
|
||||
{
|
||||
// clear interrupt flag
|
||||
LTDC->ICR = LTDC_ICR_CLIF;
|
||||
__HAL_LTDC_CLEAR_FLAG(&hltdc, LTDC_FLAG_LI);
|
||||
__HAL_LTDC_DISABLE_IT(&hltdc, LTDC_IT_LI);
|
||||
_frame_addr_reloaded = 1;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#ifndef __LCD_DRIVER_H__
|
||||
#define __LCD_DRIVER_H__
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define HBP ( 24 ) // TODO use names from FlySky
|
||||
#define VBP ( 10 )
|
||||
|
||||
@@ -34,44 +32,6 @@
|
||||
#define VFP ( 22 - VBP )
|
||||
|
||||
|
||||
#define PORT_LCD_CS ( GPIOE )
|
||||
#define LCD_CS_PIN ( GPIO_Pin_4 )
|
||||
#define PIN_LCD_CS ( 4 )
|
||||
|
||||
#define PORT_LCD_CLK ( GPIOE )
|
||||
#define LCD_CLK_PIN ( GPIO_Pin_2 )
|
||||
#define PIN_LCD_CLK ( 2 )
|
||||
|
||||
#define PORT_LCD_MOSI ( GPIOE )
|
||||
#define LCD_MOSI_PIN ( GPIO_Pin_6 )
|
||||
#define PIN_LCD_MOSI ( 6 )
|
||||
|
||||
#define PORT_LCD_MISO ( GPIOE )
|
||||
#define LCD_MISO_PIN ( GPIO_Pin_5 )
|
||||
#define PIN_LCD_MISO ( 5 )
|
||||
|
||||
#define PORT_LCD_DE ( GPIOK )
|
||||
#define LCD_DE_PIN ( GPIO_Pin_7 )
|
||||
#define PIN_LCD_DE ( 7 )
|
||||
|
||||
#define PORT_LCD_RESET ( GPIOG )
|
||||
#define LCD_RESET_PIN ( GPIO_Pin_9 )
|
||||
#define PIN_LCD_RESET ( 9 )
|
||||
|
||||
#define PORT_LCD_HSYNC ( GPIOI )
|
||||
#define LCD_HSYNC_PIN ( GPIO_Pin_12 )
|
||||
#define PIN_LCD_HSYNC ( 12 )
|
||||
|
||||
#define PORT_LCD_VSYNC ( GPIOI )
|
||||
#define LCD_VSYNC_PIN ( GPIO_Pin_13 )
|
||||
#define PIN_LCD_VSYNC ( 13 )
|
||||
|
||||
#define PORT_LCD_DOTCLK ( GPIOG )
|
||||
#define LCD_DOTCLK_PIN ( GPIO_Pin_7 )
|
||||
#define PIN_LCD_DOTCLK ( 7 )
|
||||
|
||||
#define SUPPORTED_LCD_CNT ( 5 )
|
||||
|
||||
#define LCD_ST7796S_ID ( 0x7796 )
|
||||
#define LCD_ILI9481_ID ( 0x9481 )
|
||||
#define LCD_ILI9486_ID ( 0x9486 )
|
||||
@@ -83,42 +43,29 @@
|
||||
typedef void (*lcdSpiInitFucPtr)(void);
|
||||
typedef unsigned int LcdReadIDFucPtr( void );
|
||||
|
||||
extern void GPIO_SetDirection( GPIO_TypeDef *GPIOx, unsigned char Pin, unsigned char IsInput );
|
||||
|
||||
extern lcdSpiInitFucPtr lcdInitFunction;
|
||||
extern lcdSpiInitFucPtr lcdOffFunction;
|
||||
extern lcdSpiInitFucPtr lcdOnFunction;
|
||||
|
||||
#define SET_IO_INPUT( PORT, PIN ) GPIO_SetDirection( PORT, PIN, 1 )
|
||||
#define SET_IO_OUTPUT( PORT, PIN ) GPIO_SetDirection( PORT, PIN, 0 )
|
||||
#define SET_IO_INPUT( PORT, PIN ) LL_GPIO_SetPinMode( PORT, PIN, LL_GPIO_MODE_INPUT )
|
||||
#define SET_IO_OUTPUT( PORT, PIN ) LL_GPIO_SetPinMode( PORT, PIN, LL_GPIO_MODE_OUTPUT )
|
||||
|
||||
#define LCD_NRST_HIGH() GPIO_WriteBit(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN, Bit_SET)
|
||||
#define LCD_NRST_LOW() GPIO_WriteBit(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN, Bit_RESET)
|
||||
#define LCD_NRST_HIGH() LL_GPIO_SetOutputPin(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN)
|
||||
#define LCD_NRST_LOW() LL_GPIO_ResetOutputPin(LCD_NRST_GPIO, LCD_NRST_GPIO_PIN)
|
||||
|
||||
#define LCD_CS_HIGH() GPIO_WriteBit(LCD_SPI_GPIO, LCD_SPI_CS_GPIO_PIN, Bit_SET)
|
||||
#define LCD_CS_LOW() GPIO_WriteBit(LCD_SPI_GPIO, LCD_SPI_CS_GPIO_PIN, Bit_RESET)
|
||||
#define LCD_CS_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_CS_GPIO_PIN)
|
||||
#define LCD_CS_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_CS_GPIO_PIN)
|
||||
|
||||
#define LCD_SCK_HIGH() GPIO_WriteBit(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN, Bit_SET)
|
||||
#define LCD_SCK_LOW() GPIO_WriteBit(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN, Bit_RESET)
|
||||
#define LCD_SCK_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN)
|
||||
#define LCD_SCK_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_SCK_GPIO_PIN)
|
||||
|
||||
#define LCD_MOSI_HIGH() GPIO_WriteBit(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN, Bit_SET)
|
||||
#define LCD_MOSI_LOW() GPIO_WriteBit(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN, Bit_RESET)
|
||||
#define LCD_MOSI_HIGH() LL_GPIO_SetOutputPin(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN)
|
||||
#define LCD_MOSI_LOW() LL_GPIO_ResetOutputPin(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN)
|
||||
|
||||
#define SET_LCD_CS() GPIO_WriteBit(PORT_LCD_CS, LCD_CS_PIN, Bit_SET)
|
||||
#define CLR_LCD_CS() GPIO_WriteBit(PORT_LCD_CS, LCD_CS_PIN, Bit_RESET)
|
||||
#define SET_LCD_CS_OUTPUT() SET_IO_OUTPUT( PORT_LCD_CS, PIN_LCD_CS )
|
||||
|
||||
#define SET_LCD_CLK() GPIO_WriteBit( PORT_LCD_CLK, LCD_CLK_PIN, Bit_SET )
|
||||
#define CLR_LCD_CLK() GPIO_WriteBit( PORT_LCD_CLK, LCD_CLK_PIN, Bit_RESET )
|
||||
#define SET_LCD_CLK_OUTPUT() SET_IO_OUTPUT( PORT_LCD_CLK, PIN_LCD_CLK )
|
||||
|
||||
#define SET_LCD_DATA() GPIO_WriteBit( PORT_LCD_MOSI, LCD_MOSI_PIN, Bit_SET )
|
||||
#define CLR_LCD_DATA() GPIO_WriteBit( PORT_LCD_MOSI, LCD_MOSI_PIN, Bit_RESET )
|
||||
#define SET_LCD_DATA_INPUT() SET_IO_INPUT( PORT_LCD_MOSI, PIN_LCD_MOSI )
|
||||
#define SET_LCD_DATA_OUTPUT() SET_IO_OUTPUT( PORT_LCD_MOSI, PIN_LCD_MOSI )
|
||||
|
||||
#define READ_LCD_DATA_PIN() GPIO_ReadInputDataBit(PORT_LCD_MOSI, LCD_MOSI_PIN)
|
||||
#define LCD_MOSI_AS_INPUT() SET_IO_INPUT( LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN )
|
||||
#define LCD_MOSI_AS_OUTPUT() SET_IO_OUTPUT( LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN )
|
||||
|
||||
#define LCD_READ_DATA_PIN() LL_GPIO_IsInputPinSet(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN)
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
@@ -211,10 +211,6 @@ void lcdInit()
|
||||
lcdSetFlushCb(simuRefreshLcd);
|
||||
}
|
||||
|
||||
void DMAWait()
|
||||
{
|
||||
}
|
||||
|
||||
void DMAFillRect(uint16_t *dest, uint16_t destw, uint16_t desth, uint16_t x,
|
||||
uint16_t y, uint16_t w, uint16_t h, uint16_t color)
|
||||
{
|
||||
|
||||
+3
-3
@@ -24,11 +24,10 @@
|
||||
#include "opentx_helpers.h"
|
||||
#include "libopenui_file.h"
|
||||
#include "font.h"
|
||||
#include "dma2d.h"
|
||||
|
||||
#include "lvgl/src/draw/sw/lv_draw_sw.h"
|
||||
|
||||
void DMAWait();
|
||||
|
||||
RLEBitmap::RLEBitmap(uint8_t format, const uint8_t* rle_data) :
|
||||
BitmapBufferBase<uint16_t>(format, 0, 0, nullptr)
|
||||
{
|
||||
@@ -106,6 +105,7 @@ BitmapBuffer::BitmapBuffer(uint8_t format, uint16_t width, uint16_t height,
|
||||
|
||||
BitmapBuffer::~BitmapBuffer()
|
||||
{
|
||||
DMAWait();
|
||||
if (dataAllocated) {
|
||||
#if !defined(BOOT)
|
||||
lv_obj_del(canvas);
|
||||
@@ -216,6 +216,7 @@ void BitmapBuffer::drawBitmapAbs(coord_t x, coord_t y, const T *bmp,
|
||||
DMACopyBitmap(data, _width, _height, x, y, bmp->getData(), bmpw, bmph,
|
||||
srcx, srcy, srcw, srch);
|
||||
}
|
||||
DMAWait();
|
||||
} else {
|
||||
|
||||
int scaledw = srcw * scale;
|
||||
@@ -670,7 +671,6 @@ void BitmapBuffer::drawFilledTriangle(coord_t x0, coord_t y0, coord_t x1,
|
||||
if (y1 > y2) { SWAP(y2, y1); SWAP(x2, x1); }
|
||||
if (y0 > y1) { SWAP(y0, y1); SWAP(x0, x1); }
|
||||
|
||||
DMAWait();
|
||||
if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
|
||||
a = b = x0;
|
||||
if (x1 < a)
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "debug.h"
|
||||
#include "board.h"
|
||||
#include "hal.h"
|
||||
#include "colors.h"
|
||||
#include "keys.h"
|
||||
#include "opentx_types.h"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "keyboard_base.h"
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
#include "board.h"
|
||||
|
||||
MainWindow * MainWindow::_instance = nullptr;
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "opentx.h"
|
||||
#include "usb_joystick.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user