From 1af8b782566c0f74f2a3b784fd455e45599c6871 Mon Sep 17 00:00:00 2001 From: Malte Langermann <54738901+gagarinlg@users.noreply.github.com> Date: Mon, 23 Oct 2023 10:58:02 +0200 Subject: [PATCH] refactor: DMA2D and LTDC conversion to HAL/LL (#3036) Co-authored-by: Peter Feerick --- radio/src/gui/colorlcd/lcd.cpp | 10 +- radio/src/gui/colorlcd/lcd.h | 3 +- .../arm/stm32/bootloader/CMakeLists.txt | 1 + radio/src/targets/common/arm/stm32/dma2d.cpp | 156 ++++++ radio/src/targets/common/arm/stm32/dma2d.h | 39 ++ .../common/arm/stm32/f4/CMakeLists.txt | 15 +- .../targets/common/arm/stm32/stm32_hal_ll.h | 1 + .../common/arm/stm32/stm32f4xx_hal_conf.h | 6 +- radio/src/targets/horus/CMakeLists.txt | 2 +- radio/src/targets/horus/board.cpp | 3 + radio/src/targets/horus/board.h | 12 +- radio/src/targets/horus/hal.h | 10 +- radio/src/targets/horus/lcd_driver.cpp | 388 ++++----------- radio/src/targets/nv14/CMakeLists.txt | 1 + radio/src/targets/nv14/board.cpp | 1 + radio/src/targets/nv14/board.h | 15 +- radio/src/targets/nv14/hal.h | 19 +- radio/src/targets/nv14/lcd_driver.cpp | 457 +++++------------- radio/src/targets/nv14/lcd_driver.h | 79 +-- radio/src/targets/simu/simulcd.cpp | 4 - .../thirdparty/libopenui/src/bitmapbuffer.cpp | 6 +- .../libopenui/src/libopenui_defines.h | 2 +- .../thirdparty/libopenui/src/mainwindow.cpp | 1 + radio/src/usb_joystick.cpp | 2 + 24 files changed, 488 insertions(+), 745 deletions(-) create mode 100644 radio/src/targets/common/arm/stm32/dma2d.cpp create mode 100644 radio/src/targets/common/arm/stm32/dma2d.h diff --git a/radio/src/gui/colorlcd/lcd.cpp b/radio/src/gui/colorlcd/lcd.cpp index ef656cf4b..3e70e34d6 100644 --- a/radio/src/gui/colorlcd/lcd.cpp +++ b/radio/src/gui/colorlcd/lcd.cpp @@ -19,7 +19,10 @@ * GNU General Public License for more details. */ +#include "board.h" #include "lcd.h" +#include "dma2d.h" +#include "bitmapbuffer.h" #include 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); diff --git a/radio/src/gui/colorlcd/lcd.h b/radio/src/gui/colorlcd/lcd.h index 016cc3381..46c234581 100644 --- a/radio/src/gui/colorlcd/lcd.h +++ b/radio/src/gui/colorlcd/lcd.h @@ -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(); diff --git a/radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt b/radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt index 4e3ef1831..33741fc9e 100644 --- a/radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt +++ b/radio/src/targets/common/arm/stm32/bootloader/CMakeLists.txt @@ -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 diff --git a/radio/src/targets/common/arm/stm32/dma2d.cpp b/radio/src/targets/common/arm/stm32/dma2d.cpp new file mode 100644 index 000000000..fc75a1d3f --- /dev/null +++ b/radio/src/targets/common/arm/stm32/dma2d.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); +} diff --git a/radio/src/targets/common/arm/stm32/dma2d.h b/radio/src/targets/common/arm/stm32/dma2d.h new file mode 100644 index 000000000..2802eaa19 --- /dev/null +++ b/radio/src/targets/common/arm/stm32/dma2d.h @@ -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); diff --git a/radio/src/targets/common/arm/stm32/f4/CMakeLists.txt b/radio/src/targets/common/arm/stm32/f4/CMakeLists.txt index 3c6842346..1d7ed31be 100644 --- a/radio/src/targets/common/arm/stm32/f4/CMakeLists.txt +++ b/radio/src/targets/common/arm/stm32/f4/CMakeLists.txt @@ -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} diff --git a/radio/src/targets/common/arm/stm32/stm32_hal_ll.h b/radio/src/targets/common/arm/stm32/stm32_hal_ll.h index 526318d29..467998ecc 100644 --- a/radio/src/targets/common/arm/stm32/stm32_hal_ll.h +++ b/radio/src/targets/common/arm/stm32/stm32_hal_ll.h @@ -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" diff --git a/radio/src/targets/common/arm/stm32/stm32f4xx_hal_conf.h b/radio/src/targets/common/arm/stm32/stm32f4xx_hal_conf.h index 9d25a1eb1..8d5f1e8ca 100644 --- a/radio/src/targets/common/arm/stm32/stm32f4xx_hal_conf.h +++ b/radio/src/targets/common/arm/stm32/stm32f4xx_hal_conf.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 diff --git a/radio/src/targets/horus/CMakeLists.txt b/radio/src/targets/horus/CMakeLists.txt index 7162e1589..4a38d59c8 100644 --- a/radio/src/targets/horus/CMakeLists.txt +++ b/radio/src/targets/horus/CMakeLists.txt @@ -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 ) diff --git a/radio/src/targets/horus/board.cpp b/radio/src/targets/horus/board.cpp index 6cccb4e8e..23a22836a 100644 --- a/radio/src/targets/horus/board.cpp +++ b/radio/src/targets/horus/board.cpp @@ -196,6 +196,9 @@ void boardInit() #endif ledBlue(); +#if !defined(LCD_VERTICAL_INVERT) + lcdSetInitalFrameBuffer(lcdFront->getData()); +#endif } #endif diff --git a/radio/src/targets/horus/board.h b/radio/src/targets/horus/board.h index c1cb19955..d56344281 100644 --- a/radio/src/targets/horus/board.h +++ b/radio/src/targets/horus/board.h @@ -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 */ diff --git a/radio/src/targets/horus/hal.h b/radio/src/targets/horus/hal.h index 470171b9b..232a19c12 100644 --- a/radio/src/targets/horus/hal.h +++ b/radio/src/targets/horus/hal.h @@ -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_ diff --git a/radio/src/targets/horus/lcd_driver.cpp b/radio/src/targets/horus/lcd_driver.cpp index e807e50f1..0d9949a06 100644 --- a/radio/src/targets/horus/lcd_driver.cpp +++ b/radio/src/targets/horus/lcd_driver.cpp @@ -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 -#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; } diff --git a/radio/src/targets/nv14/CMakeLists.txt b/radio/src/targets/nv14/CMakeLists.txt index 577a20905..4a3e55214 100644 --- a/radio/src/targets/nv14/CMakeLists.txt +++ b/radio/src/targets/nv14/CMakeLists.txt @@ -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 diff --git a/radio/src/targets/nv14/board.cpp b/radio/src/targets/nv14/board.cpp index 1db3e02bb..67522258f 100644 --- a/radio/src/targets/nv14/board.cpp +++ b/radio/src/targets/nv14/board.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( diff --git a/radio/src/targets/nv14/board.h b/radio/src/targets/nv14/board.h index b35e196e6..28aefedf1 100644 --- a/radio/src/targets/nv14/board.h +++ b/radio/src/targets/nv14/board.h @@ -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(); diff --git a/radio/src/targets/nv14/hal.h b/radio/src/targets/nv14/hal.h index 663370c6c..7d93d7dda 100644 --- a/radio/src/targets/nv14/hal.h +++ b/radio/src/targets/nv14/hal.h @@ -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_ diff --git a/radio/src/targets/nv14/lcd_driver.cpp b/radio/src/targets/nv14/lcd_driver.cpp index 986918c21..b61c52bb2 100644 --- a/radio/src/targets/nv14/lcd_driver.cpp +++ b/radio/src/targets/nv14/lcd_driver.cpp @@ -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; } diff --git a/radio/src/targets/nv14/lcd_driver.h b/radio/src/targets/nv14/lcd_driver.h index 27519c686..4d0e45bee 100644 --- a/radio/src/targets/nv14/lcd_driver.h +++ b/radio/src/targets/nv14/lcd_driver.h @@ -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 diff --git a/radio/src/targets/simu/simulcd.cpp b/radio/src/targets/simu/simulcd.cpp index 0fc69390c..172154498 100644 --- a/radio/src/targets/simu/simulcd.cpp +++ b/radio/src/targets/simu/simulcd.cpp @@ -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) { diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index cdc6dc4cb..fbf9133ca 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -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(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) diff --git a/radio/src/thirdparty/libopenui/src/libopenui_defines.h b/radio/src/thirdparty/libopenui/src/libopenui_defines.h index a3ce4c621..1354e576a 100644 --- a/radio/src/thirdparty/libopenui/src/libopenui_defines.h +++ b/radio/src/thirdparty/libopenui/src/libopenui_defines.h @@ -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" diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.cpp b/radio/src/thirdparty/libopenui/src/mainwindow.cpp index da340e140..14b6ab11e 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.cpp +++ b/radio/src/thirdparty/libopenui/src/mainwindow.cpp @@ -20,6 +20,7 @@ #include "keyboard_base.h" #include "lvgl/lvgl.h" +#include "board.h" MainWindow * MainWindow::_instance = nullptr; diff --git a/radio/src/usb_joystick.cpp b/radio/src/usb_joystick.cpp index fc7178111..dc2f502e1 100644 --- a/radio/src/usb_joystick.cpp +++ b/radio/src/usb_joystick.cpp @@ -19,6 +19,8 @@ * GNU General Public License for more details. */ +#include + #include "opentx.h" #include "usb_joystick.h"