Working displaying of colors

This commit is contained in:
Clément Grennerat
2025-09-14 00:48:13 +02:00
parent 81c4eb79c4
commit c28827a71f
7 changed files with 262 additions and 78 deletions
-1
View File
@@ -31,7 +31,6 @@ extern "C" {
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "LCD_driver.h"
/* USER CODE END Includes */
+54 -41
View File
@@ -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;
//}
+22 -25
View File
@@ -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 */
}
+2 -2
View File
@@ -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 */