From 58bd75f00f71da139b484f0bc2715fd1e279e6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Grennerat?= Date: Sun, 14 Sep 2025 01:39:24 +0200 Subject: [PATCH] Working screen coordinates calibration template --- Core/Inc/LCD_driver.h | 4 +-- Core/Src/LCD_driver.c | 53 ++++++++++++++++-------------------- Core/Src/main.c | 5 ++-- Core/Src/stm32f1xx_hal_msp.c | 2 +- ow-dash-cube.ioc | 4 +-- 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/Core/Inc/LCD_driver.h b/Core/Inc/LCD_driver.h index 2e146ef..5ba5df0 100644 --- a/Core/Inc/LCD_driver.h +++ b/Core/Inc/LCD_driver.h @@ -28,8 +28,8 @@ #define SPI1_BASEDR_ADR SPI1_BASE //adresse du reg SPI3 DR pour acces 8 bits (defs std permet accès 16bits seulement) -#define LCD_SCREEN_HEIGHT 320 -#define LCD_SCREEN_WIDTH 480 +#define LCD_SCREEN_HEIGHT 470 // ST7365 is 480 (aligned at the origin) +#define LCD_SCREEN_WIDTH 282 // ST7365 is 320 (centered, offset = 19) //CHIP SELECT PIN AND PORT, STANDARD GPIO #define LCD_CS_PIN (1<<8) diff --git a/Core/Src/LCD_driver.c b/Core/Src/LCD_driver.c index af1a2be..3248c5e 100644 --- a/Core/Src/LCD_driver.c +++ b/Core/Src/LCD_driver.c @@ -72,7 +72,6 @@ void LCD_Write_Command(uint8_t Command) { ; while ((SPI1->SR & SPI_SR_TXE) == 0); SPI1->DR = Command;// Cast sur pointeur, pour ecriture 8 bits. Sinon l'acces 16 bits provoque un tfert 16 bits - while ((SPI1->SR & SPI_SR_BSY) != 0); } /* Send Data (char) to LCD via SPI bus */ void LCD_Write_Data(uint8_t Data) { @@ -81,7 +80,6 @@ void LCD_Write_Data(uint8_t Data) { ; while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available. SPI1->DR = Data; - while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy } void LCD_Write_Data16(uint16_t data) { while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy @@ -90,8 +88,7 @@ void LCD_Write_Data16(uint16_t data) { while ((SPI1->SR & SPI_SR_TXE) == 0);// Wait for TX buffer empty SPI1->DR = (data >> 8) & 0xFF;// Send MSB while ((SPI1->SR & SPI_SR_TXE) == 0);// Wait for TX buffer empty - SPI1->DR = data & 0xFF; // Send LSB - while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy + SPI1->DR = data & 0xFF;// Send LSB } /* Set the frame to draw into and sends a write into frame command */ @@ -164,9 +161,12 @@ void LCD_Init(void) { LCD_Write_Data(0x55); HAL_Delay(150); -// Disable color inversion (INVOFF) +// Enable color inversion (INVON) LCD_Write_Command(0x21); +// Disable partial mode + LCD_Write_Command(0x13); + // Exit sleep LCD_Write_Command(0x11); HAL_Delay(150); @@ -175,30 +175,27 @@ void LCD_Init(void) { LCD_Write_Command(0x29); HAL_Delay(400); - // Fill white - //LCD_Fill_Screen(0xFFFF); +// Fill white + LCD_Fill_Screen(WHITE); +// End the end with black +// LCD_Draw_Rectangle(0, LCD_SCREEN_WIDTH, LCD_SCREEN_WIDTH, +// LCD_SCREEN_HEIGHT - LCD_SCREEN_WIDTH, BLACK); +// Draw colors columns + LCD_Set_Address(20, 20, LCD_SCREEN_WIDTH - 60, LCD_SCREEN_WIDTH - 60); + uint32_t size = (LCD_SCREEN_WIDTH - 40) * 20; + LCD_Draw_Colour_Burst(BLACK, size); + LCD_Draw_Colour_Burst(WHITE, size); + LCD_Draw_Colour_Burst(BLUE, size); + LCD_Draw_Colour_Burst(GREEN, size); + LCD_Draw_Colour_Burst(RED, size); - //LCD_Set_Address(0, 0, 100, 100); - //LCD_Draw_Colour_Burst(0xFFFF, 6000); - - // End the filling with black - //LCD_Draw_Rectangle(0, 320, 320, 480 - 320 - 1, 0xFFFF); - - - // Draw colors columns - LCD_Set_Address(10, 100, 300, 300); - - - LCD_Draw_Colour_Burst(0xFFFF, 6000); // White - LCD_Draw_Colour_Burst(0x0000, 6000); // Black - - LCD_Draw_Colour_Burst(0b0000000000011111, 6000);// Blue - LCD_Draw_Colour_Burst(BLUE, 6000); - LCD_Draw_Colour_Burst(0b0000011111100000, 6000);// Green - LCD_Draw_Colour_Burst(GREEN, 6000); - LCD_Draw_Colour_Burst(0b1111100000000000, 6000);// Red - LCD_Draw_Colour_Burst(RED, 6000); +// Draw rectangles in the angles + LCD_Draw_Rectangle(1, 1, 20, 20, RED); + LCD_Draw_Rectangle(LCD_SCREEN_WIDTH - 21, 1, 20, 20, GREEN); + LCD_Draw_Rectangle(LCD_SCREEN_WIDTH - 21, LCD_SCREEN_HEIGHT - 21, 20, 20, + MAGENTA); + LCD_Draw_Rectangle(1, LCD_SCREEN_HEIGHT - 21, 20, 20, BLUE); // STARTING ROTATION //LCD_Set_Rotation(SCREEN_HORIZONTAL_1); @@ -213,10 +210,8 @@ void LCD_Draw_Colour_Burst(uint16_t color, uint32_t size) { for (uint32_t j = 0; j < size; j++) { while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available. SPI1->DR = (color >> 8) & 0xFF; - while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available. SPI1->DR = color & 0xFF; - while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy } } diff --git a/Core/Src/main.c b/Core/Src/main.c index 5ff3a77..3437465 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -101,8 +101,9 @@ int main(void) /* USER CODE BEGIN WHILE */ while (1) { + HAL_Delay(500); LCD_Init(); - HAL_Delay(300); + /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ @@ -171,7 +172,7 @@ static void MX_SPI1_Init(void) hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi1.Init.TIMode = SPI_TIMODE_DISABLE; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; diff --git a/Core/Src/stm32f1xx_hal_msp.c b/Core/Src/stm32f1xx_hal_msp.c index 101ab99..d7925bc 100644 --- a/Core/Src/stm32f1xx_hal_msp.c +++ b/Core/Src/stm32f1xx_hal_msp.c @@ -74,7 +74,7 @@ void HAL_MspInit(void) /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled */ - //__HAL_AFIO_REMAP_SWJ_NOJTAG(); + __HAL_AFIO_REMAP_SWJ_NOJTAG(); /* USER CODE BEGIN MspInit 1 */ diff --git a/ow-dash-cube.ioc b/ow-dash-cube.ioc index 671b82a..992ef5f 100644 --- a/ow-dash-cube.ioc +++ b/ow-dash-cube.ioc @@ -250,8 +250,8 @@ RCC.SYSCLKFreq_VALUE=64000000 RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK RCC.TimSysFreq_Value=64000000 RCC.USBFreq_Value=64000000 -SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 -SPI1.CalculateBaudRate=4.0 MBits/s +SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4 +SPI1.CalculateBaudRate=16.0 MBits/s SPI1.DataSize=SPI_DATASIZE_8BIT SPI1.Direction=SPI_DIRECTION_2LINES SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,VirtualNSS,BaudRatePrescaler,DataSize