From c28827a71f363437856c9cdda66d11f927aab542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Grennerat?= Date: Sun, 14 Sep 2025 00:48:13 +0200 Subject: [PATCH] Working displaying of colors --- .cproject | 176 ++++++++++++++++++++++++++++++++ .settings/language.settings.xml | 4 +- Core/Inc/main.h | 1 - Core/Src/LCD_driver.c | 95 +++++++++-------- Core/Src/main.c | 47 ++++----- Core/Src/stm32f1xx_hal_msp.c | 4 +- ow-dash-cube.ioc | 13 ++- 7 files changed, 262 insertions(+), 78 deletions(-) create mode 100644 .cproject diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..8a69f36 --- /dev/null +++ b/.cproject @@ -0,0 +1,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index d840b96..4ae7347 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -1,6 +1,6 @@ - + @@ -11,7 +11,7 @@ - + diff --git a/Core/Inc/main.h b/Core/Inc/main.h index d43cf29..687f2cf 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -31,7 +31,6 @@ extern "C" { /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include "LCD_driver.h" /* USER CODE END Includes */ diff --git a/Core/Src/LCD_driver.c b/Core/Src/LCD_driver.c index 6803798..af1a2be 100644 --- a/Core/Src/LCD_driver.c +++ b/Core/Src/LCD_driver.c @@ -65,47 +65,44 @@ volatile uint16_t LCD_WIDTH = LCD_SCREEN_WIDTH; // SPI3->CR1 |= SPI_CR1_SPE; // //} - /* Send command (char) to LCD via SPI bus */ void LCD_Write_Command(uint8_t Command) { + while ((SPI1->SR & SPI_SR_BSY) != 0); CMD ; -//CS_ON; - while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available. + 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); //Attendre fin envoi trame (cf RM P1289) -//CS_OFF; + while ((SPI1->SR & SPI_SR_BSY) != 0); } /* Send Data (char) to LCD via SPI bus */ void LCD_Write_Data(uint8_t Data) { + while ((SPI1->SR & SPI_SR_BSY) != 0);//Attendre fin envoi trame DATA ; -//CS_ON; while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available. SPI1->DR = Data; -//while ((SPI1->SR & SPI_SR_BSY) != 0); //Attendre fin envoi trame (cf RM P1289) -//CS_OFF; + while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy } -/* Send Data (char) to LCD via SPI bus */ -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 DATA ; -//CS_ON; - while ((SPI1->SR & SPI_SR_TXE) == 0);// Waiting for TX register to be available. - SPI1->DR = Data; -//while ((SPI1->SR & SPI_SR_BSY) != 0); //Attendre fin envoi trame (cf RM P1289) -//CS_OFF; + 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 } /* Set the frame to draw into and sends a write into frame command */ void LCD_Set_Address(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2) { LCD_Write_Command(0x2A); - LCD_Write_Data(X1); - LCD_Write_Data(X2); + LCD_Write_Data16(X1); + LCD_Write_Data16(X2); LCD_Write_Command(0x2B); - LCD_Write_Data(Y1); - LCD_Write_Data(Y2); + LCD_Write_Data16(Y1); + LCD_Write_Data16(Y2); LCD_Write_Command(0x2C); } @@ -152,12 +149,10 @@ void LCD_HardwareReset() { void LCD_Init(void) { - //LCD_SPI_Init(); - LCD_HardwareReset(); - // enable spi1 - SPI1->CR1 |= SPI_CR1_SPE; // NSS (CS) pin is automatically pulled low +// enable spi1 + SPI1->CR1 |= SPI_CR1_SPE;// NSS (CS) pin is automatically pulled low HAL_Delay(300); // Software reset @@ -169,6 +164,9 @@ void LCD_Init(void) { LCD_Write_Data(0x55); HAL_Delay(150); +// Disable color inversion (INVOFF) + LCD_Write_Command(0x21); + // Exit sleep LCD_Write_Command(0x11); HAL_Delay(150); @@ -177,9 +175,30 @@ void LCD_Init(void) { LCD_Write_Command(0x29); HAL_Delay(400); - LCD_Fill_Screen(WHITE); + // Fill white + //LCD_Fill_Screen(0xFFFF); - //LCD_Draw_Rectangle(0, 0, 10, 10, RED); + + //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); // STARTING ROTATION //LCD_Set_Rotation(SCREEN_HORIZONTAL_1); @@ -187,28 +206,24 @@ void LCD_Init(void) { //INTERNAL FUNCTION OF LIBRARY /*Sends block colour information to LCD*/ -void LCD_Draw_Colour_Burst(uint16_t Colour, uint32_t Size) { - short bufColour; -// On envoie la même couleur sur Size pixels - bufColour = Colour >> 8;// pour le tfert dans DR en 1 seul write mais - bufColour |= Colour << 8;// en mode 8 bits, il faut inverser les octets MSB/LSB +void LCD_Draw_Colour_Burst(uint16_t color, uint32_t size) { + while ((SPI1->SR & SPI_SR_BSY) != 0);// Wait until SPI is not busy DATA ; - //CS_ON; - 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 ((SPI3->SR & SPI_SR_TXE) == 0);//Si FIFO full (TX buffer Empty=0), on attend - SPI1->DR = Colour; //bufColour; + 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 } - //while ((SPI3->SR & SPI_SR_BSY) != 0);//Attendre fin envoi trame - //CS_OFF; } //FILL THE ENTIRE SCREEN WITH SELECTED COLOUR (either #define-d ones or custom 16bit) /*Sets address (entire screen) and Sends Height*Width ammount of colour information to LCD*/ -void LCD_Fill_Screen(uint16_t Colour) { - LCD_Set_Address(0, 0, LCD_WIDTH, LCD_HEIGHT); - LCD_Draw_Colour_Burst(Colour, LCD_WIDTH * LCD_HEIGHT); +void LCD_Fill_Screen(uint16_t color) { + LCD_Draw_Rectangle(0, 0, LCD_WIDTH, LCD_HEIGHT, color); } //DRAW PIXEL AT XY POSITION WITH SELECTED COLOUR @@ -551,7 +566,6 @@ void LCD_Draw_Text( // while ((SPI3->SR & SPI_SR_BSY) != 0);//Attendre fin envoi trame // CS_OFF; //} - /*Draws a full screen picture from flash. Image converted from RGB .jpeg/other to C array using online converter*/ //USING CONVERTER: http://www.digole.com/tools/PicturetoC_Hex_converter.php //65K colour (2Bytes / Pixel) @@ -592,4 +606,3 @@ void LCD_Draw_Text( // while ((SPI3->SR & SPI_SR_BSY) != 0);//Attendre fin envoi trame // CS_OFF; //} - diff --git a/Core/Src/main.c b/Core/Src/main.c index 8134a03..5ff3a77 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -1,29 +1,27 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include "LCD_driver.h" -#include "5x5_font.h" -#include "LogoIUT.h" + /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -97,16 +95,14 @@ int main(void) MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ - LCD_Init(); - /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ - while (1) { - - HAL_Delay(1000); + while (1) + { LCD_Init(); + HAL_Delay(300); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ @@ -171,7 +167,7 @@ static void MX_SPI1_Init(void) hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES; - hspi1.Init.DataSize = SPI_DATASIZE_16BIT; + hspi1.Init.DataSize = SPI_DATASIZE_8BIT; hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT; @@ -322,7 +318,8 @@ void Error_Handler(void) /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); - while (1) { + while (1) + { } /* USER CODE END Error_Handler_Debug */ } diff --git a/Core/Src/stm32f1xx_hal_msp.c b/Core/Src/stm32f1xx_hal_msp.c index c583f40..101ab99 100644 --- a/Core/Src/stm32f1xx_hal_msp.c +++ b/Core/Src/stm32f1xx_hal_msp.c @@ -72,9 +72,9 @@ void HAL_MspInit(void) /* System interrupt init*/ - /** DISABLE: JTAG-DP Disabled and SW-DP Disabled + /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled */ - //__HAL_AFIO_REMAP_SWJ_DISABLE(); + //__HAL_AFIO_REMAP_SWJ_NOJTAG(); /* USER CODE BEGIN MspInit 1 */ diff --git a/ow-dash-cube.ioc b/ow-dash-cube.ioc index 6707fc2..671b82a 100644 --- a/ow-dash-cube.ioc +++ b/ow-dash-cube.ioc @@ -1,6 +1,6 @@ #MicroXplorer Configuration settings - do not modify CAD.formats=[] -CAD.pinconfig=Dual +CAD.pinconfig=Project naming CAD.provider= File.Version=6 GPIO.groupedBy=Group By Peripherals @@ -43,15 +43,14 @@ Mcu.Pin30=PB5 Mcu.Pin31=PB6 Mcu.Pin32=PB7 Mcu.Pin33=PB9 -Mcu.Pin34=VP_SYS_VS_ND -Mcu.Pin35=VP_SYS_VS_Systick +Mcu.Pin34=VP_SYS_VS_Systick Mcu.Pin4=PD1-OSC_OUT Mcu.Pin5=PA0-WKUP Mcu.Pin6=PA1 Mcu.Pin7=PA2 Mcu.Pin8=PA3 Mcu.Pin9=PA4 -Mcu.PinsNb=36 +Mcu.PinsNb=35 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F103CBTx @@ -89,8 +88,10 @@ PA12.GPIO_Label=A12 PA12.Locked=true PA12.Signal=GPIO_Input PA13.Locked=true +PA13.Mode=Serial_Wire PA13.Signal=SYS_JTMS-SWDIO PA14.Locked=true +PA14.Mode=Serial_Wire PA14.Signal=SYS_JTCK-SWCLK PA2.GPIOParameters=GPIO_Label PA2.GPIO_Label=DTE @@ -251,7 +252,7 @@ RCC.TimSysFreq_Value=64000000 RCC.USBFreq_Value=64000000 SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 SPI1.CalculateBaudRate=4.0 MBits/s -SPI1.DataSize=SPI_DATASIZE_16BIT +SPI1.DataSize=SPI_DATASIZE_8BIT SPI1.Direction=SPI_DIRECTION_2LINES SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,VirtualNSS,BaudRatePrescaler,DataSize SPI1.Mode=SPI_MODE_MASTER @@ -259,8 +260,6 @@ SPI1.VirtualNSS=VM_NSSHARD SPI1.VirtualType=VM_MASTER USART1.IPParameters=VirtualMode USART1.VirtualMode=VM_ASYNC -VP_SYS_VS_ND.Mode=No_Debug -VP_SYS_VS_ND.Signal=SYS_VS_ND VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick board=custom