Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions radio/src/boards/jumper-h750/lcd_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#include "stm32_hal.h"
#include "stm32_gpio_driver.h"
#include "edgetx_types.h"
#include "dma2d.h"
#include "hal.h"
#include "delays_driver.h"
#include "debug.h"
#include "lcd.h"
#include "lcd_driver.h"
Expand All @@ -35,14 +33,15 @@
#include "stm32_gpio.h"
#include "hal/gpio.h"

uint8_t TouchControllerType = 0; // 0: other; 1: CST836U
static volatile uint16_t lcd_phys_w = LCD_H;
static volatile uint16_t lcd_phys_h = LCD_W;

static LTDC_HandleTypeDef hltdc;
static void* initialFrameBuffer = nullptr;

#if defined(BOOT)
static volatile uint8_t _frame_addr_reloaded = 0;
#endif

static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
const rect_t &copy_area)
Expand All @@ -54,25 +53,27 @@ static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
// faster than cleaning by address
SCB_CleanDCache();

// LTDC_Layer1->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
#if defined(BOOT)
_frame_addr_reloaded = 0;
#endif

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
#if defined(BOOT)
// wait for reload to finish - required for bootloader
while(_frame_addr_reloaded == 0);
#endif
}

lcdSpiInitFucPtr lcdInitFunction;
lcdSpiInitFucPtr lcdOffFunction;
lcdSpiInitFucPtr lcdOnFunction;
uint32_t lcdPixelClock;

volatile uint8_t LCD_ReadBuffer[24] = { 0, 0 };

static void LCD_Delay(void) {
volatile unsigned int i;

Expand Down Expand Up @@ -1884,7 +1885,6 @@ void LCD_Init_LTDC() {

// Trigger on last line
HAL_LTDC_ProgramLineEvent(&hltdc, lcd_phys_h);
__HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI);
}

void LCD_LayerInit() {
Expand Down Expand Up @@ -2009,5 +2009,10 @@ extern "C" void LTDC_IRQHandler(void)
{
__HAL_LTDC_CLEAR_FLAG(&hltdc, LTDC_FLAG_LI);
__HAL_LTDC_DISABLE_IT(&hltdc, LTDC_IT_LI);

#if defined(BOOT)
_frame_addr_reloaded = 1;
}
#else
lvglFlushed();
#endif
}
6 changes: 1 addition & 5 deletions radio/src/boards/jumper-h750/lcd_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* GNU General Public License for more details.
*/

#ifndef __LCD_DRIVER_H__
#define __LCD_DRIVER_H__
#pragma once

#define HBP ( 24 ) // TODO use names from FlySky
#define VBP ( 10 )
Expand Down Expand Up @@ -66,12 +65,9 @@ extern lcdSpiInitFucPtr lcdOnFunction;

#define LCD_READ_DATA_PIN() LL_GPIO_IsInputPinSet(LCD_SPI_GPIO, LCD_SPI_MOSI_GPIO_PIN)


#define HORIZONTAL_SYNC_WIDTH ( 4 )
#define HORIZONTAL_BACK_PORCH ( 24 )
#define HORIZONTAL_FRONT_PORCH ( 140 - HORIZONTAL_BACK_PORCH )
#define VERTICAL_SYNC_HEIGHT ( 2 )
#define VERTICAL_BACK_PORCH ( 10 )
#define VERTICAL_FRONT_PORCH ( 22 - VERTICAL_BACK_PORCH )

#endif
55 changes: 24 additions & 31 deletions radio/src/boards/rm-h750/lcd_driver_480.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#include "stm32_hal_ll.h"
#include "stm32_hal.h"
#include "edgetx_types.h"
#include "dma2d.h"
#include "hal.h"
#include "delays_driver.h"
#include "debug.h"
#include "lcd.h"
#include "lcd_driver_480.h"
Expand All @@ -34,14 +32,12 @@
#include "stm32_gpio.h"
#include "stm32_qspi.h"

uint8_t TouchControllerType = 0; // 0: other; 1: CST836U
static volatile uint16_t lcd_phys_w = LCD_PHYS_W;
static volatile uint16_t lcd_phys_h = LCD_PHYS_H;

static LTDC_HandleTypeDef hltdc;
static void* initialFrameBuffer = nullptr;

#if defined(BOOT)
static volatile uint8_t _frame_addr_reloaded = 0;
#endif

static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
const rect_t &copy_area)
Expand All @@ -53,25 +49,22 @@ static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
// faster than cleaning by address
SCB_CleanDCache();

#if defined(BOOT)
_frame_addr_reloaded = 0;
#endif

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
#if defined(BOOT)
// wait for reload to finish - required for bootloader
while(_frame_addr_reloaded == 0);
#endif
}

lcdSpiInitFucPtr lcdInitFunction;
lcdSpiInitFucPtr lcdOffFunction;
lcdSpiInitFucPtr lcdOnFunction;
uint32_t lcdPixelClock;

volatile uint8_t LCD_ReadBuffer[24] = { 0, 0 };

static void LCD_Delay(void) {
volatile unsigned int i;

Expand Down Expand Up @@ -424,13 +417,13 @@ void LCD_Init_LTDC() {
/* Configure accumulated vertical back porch */
hltdc.Init.AccumulatedVBP = VSH+VBP-1;
/* Configure accumulated active width */
hltdc.Init.AccumulatedActiveW = lcd_phys_w + HBP+HSW-1;
hltdc.Init.AccumulatedActiveW = LCD_PHYS_W + HBP+HSW-1;
/* Configure accumulated active height */
hltdc.Init.AccumulatedActiveH = lcd_phys_h + VBP+VSH-1;
hltdc.Init.AccumulatedActiveH = LCD_PHYS_H + VBP+VSH-1;
/* Configure total width */
hltdc.Init.TotalWidth = lcd_phys_w + HBP + HFP + HSW -1;
hltdc.Init.TotalWidth = LCD_PHYS_W + HBP + HFP + HSW -1;
/* Configure total height */
hltdc.Init.TotalHeigh = lcd_phys_h + VBP + VFP+VSH-1;
hltdc.Init.TotalHeigh = LCD_PHYS_H + VBP + VFP+VSH-1;

HAL_LTDC_Init(&hltdc);

Expand All @@ -439,18 +432,17 @@ void LCD_Init_LTDC() {
NVIC_EnableIRQ(LTDC_IRQn);

// Trigger on last line
HAL_LTDC_ProgramLineEvent(&hltdc, lcd_phys_h);
__HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI);
HAL_LTDC_ProgramLineEvent(&hltdc, LCD_PHYS_H);
}

void LCD_LayerInit() {
auto& layer = hltdc.LayerCfg[0];

/* Windowing configuration */
layer.WindowX0 = 0;
layer.WindowX1 = lcd_phys_w;
layer.WindowX1 = LCD_PHYS_W;
layer.WindowY0 = 0;
layer.WindowY1 = lcd_phys_h;
layer.WindowY1 = LCD_PHYS_H;

/* Pixel Format configuration*/
layer.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
Expand All @@ -468,8 +460,8 @@ void LCD_LayerInit() {
layer.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
layer.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;

layer.ImageWidth = lcd_phys_w;
layer.ImageHeight = 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 */
layer.FBStartAdress = (intptr_t)initialFrameBuffer;
Expand Down Expand Up @@ -508,12 +500,9 @@ void lcdInit(void)
/* Send LCD initialization commands */
TRACE("LCD INIT (default): ST7365");
boardLcdType = "ST7365 (Default)";
lcdInitFunction = LCD_ST7365_Init;
lcdOffFunction = LCD_ST7365_Off;
lcdOnFunction = LCD_ST7365_On;

__HAL_RCC_LTDC_CLK_ENABLE();
lcdInitFunction();
LCD_ST7365_Init();

LCD_Init_LTDC();
LCD_LayerInit();
Expand All @@ -533,6 +522,10 @@ extern "C" void LTDC_IRQHandler(void)
{
__HAL_LTDC_CLEAR_FLAG(&hltdc, LTDC_FLAG_LI);
__HAL_LTDC_DISABLE_IT(&hltdc, LTDC_IT_LI);

#if defined(BOOT)
_frame_addr_reloaded = 1;
#else
lvglFlushed();
#endif
}

14 changes: 1 addition & 13 deletions radio/src/boards/rm-h750/lcd_driver_480.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
* GNU General Public License for more details.
*/

#ifndef __LCD_DRIVER_H__
#define __LCD_DRIVER_H__

#include "bsp_io.h"
#pragma once

#define HBP ( 20 )
#define VBP ( 10 )
Expand All @@ -35,9 +32,6 @@

#define LCD_DELAY() LCD_Delay()

typedef void (*lcdSpiInitFucPtr)(void);
typedef unsigned int LcdReadIDFucPtr( void );

#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 )

Expand All @@ -57,9 +51,3 @@ typedef unsigned int LcdReadIDFucPtr( void );
#define LCD_MOSI_AS_OUTPUT() SET_IO_OUTPUT( LCD_SPI_MOSI_GPIO, LCD_SPI_MOSI_GPIO_PIN )

#define LCD_READ_DATA_PIN() LL_GPIO_IsInputPinSet(LCD_SPI_MOSI_GPIO, LCD_SPI_MOSI_GPIO_PIN)

#endif




Loading