From 9982bc69b53df03e10830da26adb4dec0d218825 Mon Sep 17 00:00:00 2001 From: gagarinlg Date: Fri, 22 Sep 2023 21:31:22 +0200 Subject: [PATCH] fix: crash with HAL/LL driver for MDA2D and LTDC --- radio/src/targets/nv14/lcd_driver.cpp | 62 ++++++++------------------- radio/src/targets/nv14/lcd_driver.h | 55 ++---------------------- 2 files changed, 20 insertions(+), 97 deletions(-) diff --git a/radio/src/targets/nv14/lcd_driver.cpp b/radio/src/targets/nv14/lcd_driver.cpp index 6417b99c97c..e3c03eeeb5b 100644 --- a/radio/src/targets/nv14/lcd_driver.cpp +++ b/radio/src/targets/nv14/lcd_driver.cpp @@ -84,33 +84,6 @@ 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); @@ -171,7 +144,7 @@ static void lcdSpiConfig(void) { LL_GPIO_Init(LCD_NRST_GPIO, &GPIO_InitStructure); /* Set the chip select pin aways low */ - CLR_LCD_CS(); + LCD_CS_LOW(); } void lcdDelay() { @@ -182,25 +155,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); } @@ -241,22 +214,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); } @@ -1103,12 +1076,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(); diff --git a/radio/src/targets/nv14/lcd_driver.h b/radio/src/targets/nv14/lcd_driver.h index 2656167a490..f943bafc51d 100644 --- a/radio/src/targets/nv14/lcd_driver.h +++ b/radio/src/targets/nv14/lcd_driver.h @@ -34,42 +34,6 @@ #define VFP ( 22 - VBP ) -#define PORT_LCD_CS ( GPIOE ) -#define LCD_CS_PIN ( LL_GPIO_PIN_4 ) -#define PIN_LCD_CS ( 4 ) - -#define PORT_LCD_CLK ( GPIOE ) -#define LCD_CLK_PIN ( LL_GPIO_PIN_2 ) -#define PIN_LCD_CLK ( 2 ) - -#define PORT_LCD_MOSI ( GPIOE ) -#define LCD_MOSI_PIN ( LL_GPIO_PIN_6 ) -#define PIN_LCD_MOSI ( 6 ) - -#define PORT_LCD_MISO ( GPIOE ) -#define LCD_MISO_PIN ( LL_GPIO_PIN_5 ) -#define PIN_LCD_MISO ( 5 ) - -#define PORT_LCD_DE ( GPIOK ) -#define LCD_DE_PIN ( LL_GPIO_PIN_7 ) -#define PIN_LCD_DE ( 7 ) - -#define PORT_LCD_RESET ( GPIOG ) -#define LCD_RESET_PIN ( LL_GPIO_PIN_9 ) -#define PIN_LCD_RESET ( 9 ) - -#define PORT_LCD_HSYNC ( GPIOI ) -#define LCD_HSYNC_PIN ( LL_GPIO_PIN_12 ) -#define PIN_LCD_HSYNC ( 12 ) - -#define PORT_LCD_VSYNC ( GPIOI ) -#define LCD_VSYNC_PIN ( LL_GPIO_PIN_13 ) -#define PIN_LCD_VSYNC ( 13 ) - -#define PORT_LCD_DOTCLK ( GPIOG ) -#define LCD_DOTCLK_PIN ( LL_GPIO_PIN_7 ) -#define PIN_LCD_DOTCLK ( 7 ) - #define LCD_ST7796S_ID ( 0x7796 ) #define LCD_ILI9481_ID ( 0x9481 ) #define LCD_ILI9486_ID ( 0x9486 ) @@ -81,8 +45,6 @@ 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; @@ -102,21 +64,10 @@ extern lcdSpiInitFucPtr lcdOnFunction; #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() LL_GPIO_SetOutputPin(PORT_LCD_CS, LCD_CS_PIN) -#define CLR_LCD_CS() LL_GPIO_ResetOutputPin(PORT_LCD_CS, LCD_CS_PIN) -#define SET_LCD_CS_OUTPUT() SET_IO_OUTPUT( PORT_LCD_CS, PIN_LCD_CS ) - -#define SET_LCD_CLK() LL_GPIO_SetOutputPin(PORT_LCD_CLK, LCD_CLK_PIN ) -#define CLR_LCD_CLK() LL_GPIO_ResetOutputPin( PORT_LCD_CLK, LCD_CLK_PIN ) -#define SET_LCD_CLK_OUTPUT() SET_IO_OUTPUT( PORT_LCD_CLK, PIN_LCD_CLK ) - -#define SET_LCD_DATA() LL_GPIO_SetOutputPin( PORT_LCD_MOSI, LCD_MOSI_PIN ) -#define CLR_LCD_DATA() LL_GPIO_ResetOutputPin( PORT_LCD_MOSI, LCD_MOSI_PIN ) -#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() ((LL_GPIO_ReadInputPort(PORT_LCD_MOSI) & LCD_MOSI_PIN) != 0) +#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