Working screen coordinates calibration template

This commit is contained in:
Clément Grennerat 2025-09-14 01:39:24 +02:00
parent c28827a71f
commit 58bd75f00f
5 changed files with 32 additions and 36 deletions

View File

@ -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 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_HEIGHT 470 // ST7365 is 480 (aligned at the origin)
#define LCD_SCREEN_WIDTH 480 #define LCD_SCREEN_WIDTH 282 // ST7365 is 320 (centered, offset = 19)
//CHIP SELECT PIN AND PORT, STANDARD GPIO //CHIP SELECT PIN AND PORT, STANDARD GPIO
#define LCD_CS_PIN (1<<8) #define LCD_CS_PIN (1<<8)

View File

@ -72,7 +72,6 @@ void LCD_Write_Command(uint8_t Command) {
; ;
while ((SPI1->SR & SPI_SR_TXE) == 0); 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 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 */ /* Send Data (char) to LCD via SPI bus */
void LCD_Write_Data(uint8_t Data) { 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. while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available.
SPI1->DR = Data; SPI1->DR = Data;
while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy
} }
void LCD_Write_Data16(uint16_t data) { void LCD_Write_Data16(uint16_t data) {
while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy 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 while ((SPI1->SR & SPI_SR_TXE) == 0);// Wait for TX buffer empty
SPI1->DR = (data >> 8) & 0xFF;// Send MSB SPI1->DR = (data >> 8) & 0xFF;// Send MSB
while ((SPI1->SR & SPI_SR_TXE) == 0);// Wait for TX buffer empty while ((SPI1->SR & SPI_SR_TXE) == 0);// Wait for TX buffer empty
SPI1->DR = data & 0xFF; // Send LSB SPI1->DR = data & 0xFF;// Send LSB
while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy
} }
/* Set the frame to draw into and sends a write into frame command */ /* 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); LCD_Write_Data(0x55);
HAL_Delay(150); HAL_Delay(150);
// Disable color inversion (INVOFF) // Enable color inversion (INVON)
LCD_Write_Command(0x21); LCD_Write_Command(0x21);
// Disable partial mode
LCD_Write_Command(0x13);
// Exit sleep // Exit sleep
LCD_Write_Command(0x11); LCD_Write_Command(0x11);
HAL_Delay(150); HAL_Delay(150);
@ -175,30 +175,27 @@ void LCD_Init(void) {
LCD_Write_Command(0x29); LCD_Write_Command(0x29);
HAL_Delay(400); HAL_Delay(400);
// Fill white // Fill white
//LCD_Fill_Screen(0xFFFF); 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); // Draw rectangles in the angles
//LCD_Draw_Colour_Burst(0xFFFF, 6000); LCD_Draw_Rectangle(1, 1, 20, 20, RED);
LCD_Draw_Rectangle(LCD_SCREEN_WIDTH - 21, 1, 20, 20, GREEN);
// End the filling with black LCD_Draw_Rectangle(LCD_SCREEN_WIDTH - 21, LCD_SCREEN_HEIGHT - 21, 20, 20,
//LCD_Draw_Rectangle(0, 320, 320, 480 - 320 - 1, 0xFFFF); MAGENTA);
LCD_Draw_Rectangle(1, LCD_SCREEN_HEIGHT - 21, 20, 20, BLUE);
// 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);
// STARTING ROTATION // STARTING ROTATION
//LCD_Set_Rotation(SCREEN_HORIZONTAL_1); //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++) { for (uint32_t j = 0; j < size; j++) {
while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available. while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available.
SPI1->DR = (color >> 8) & 0xFF; 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. while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available.
SPI1->DR = color & 0xFF; SPI1->DR = color & 0xFF;
while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy
} }
} }

View File

@ -101,8 +101,9 @@ int main(void)
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
while (1) while (1)
{ {
HAL_Delay(500);
LCD_Init(); LCD_Init();
HAL_Delay(300);
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
@ -171,7 +172,7 @@ static void MX_SPI1_Init(void)
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT; 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.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE; hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

View File

@ -74,7 +74,7 @@ void HAL_MspInit(void)
/** NOJTAG: JTAG-DP Disabled and SW-DP Enabled /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
*/ */
//__HAL_AFIO_REMAP_SWJ_NOJTAG(); __HAL_AFIO_REMAP_SWJ_NOJTAG();
/* USER CODE BEGIN MspInit 1 */ /* USER CODE BEGIN MspInit 1 */

View File

@ -250,8 +250,8 @@ RCC.SYSCLKFreq_VALUE=64000000
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.TimSysFreq_Value=64000000 RCC.TimSysFreq_Value=64000000
RCC.USBFreq_Value=64000000 RCC.USBFreq_Value=64000000
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
SPI1.CalculateBaudRate=4.0 MBits/s SPI1.CalculateBaudRate=16.0 MBits/s
SPI1.DataSize=SPI_DATASIZE_8BIT SPI1.DataSize=SPI_DATASIZE_8BIT
SPI1.Direction=SPI_DIRECTION_2LINES SPI1.Direction=SPI_DIRECTION_2LINES
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,VirtualNSS,BaudRatePrescaler,DataSize SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,VirtualNSS,BaudRatePrescaler,DataSize