Skip to content

Commit

Permalink
fix: crash with HAL/LL driver for MDA2D and LTDC
Browse files Browse the repository at this point in the history
  • Loading branch information
gagarinlg committed Sep 22, 2023
1 parent f61ea54 commit 9982bc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 97 deletions.
62 changes: 17 additions & 45 deletions radio/src/targets/nv14/lcd_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();

Expand Down
55 changes: 3 additions & 52 deletions radio/src/targets/nv14/lcd_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 9982bc6

Please sign in to comment.