Trying to fix timing issues

This commit is contained in:
Clément Grennerat 2025-09-14 17:14:33 +02:00
parent 6132478e3d
commit d6bf59644a

View File

@ -34,26 +34,26 @@ volatile uint16_t LCD_WIDTH = LCD_SCREEN_WIDTH;
// Set all 16 data pins (DB0-DB15) based on a 16-bit value // Set all 16 data pins (DB0-DB15) based on a 16-bit value
//void SetDataPins(uint16_t value) { void SetDataPins(uint16_t value) {
// GPIOA->BSRR = (value & (1 << 0) ? DB0_Pin : (DB0_Pin << 16)) | // DB0 (GPIOA) GPIOA->BSRR = (value & (1 << 0) ? DB0_Pin : (DB0_Pin << 16)) | // DB0 (GPIOA)
// (value & (1 << 14) ? DB14_Pin : (DB14_Pin << 16)); // DB14 (GPIOA) (value & (1 << 14) ? DB14_Pin : (DB14_Pin << 16)); // DB14 (GPIOA)
// GPIOB->BSRR = (value & (1 << 1) ? DB1_Pin : (DB1_Pin << 16)) | // DB1 (GPIOB) GPIOB->BSRR = (value & (1 << 1) ? DB1_Pin : (DB1_Pin << 16)) | // DB1 (GPIOB)
// (value & (1 << 3) ? DB3_Pin : (DB3_Pin << 16)) | // DB3 (GPIOB) (value & (1 << 3) ? DB3_Pin : (DB3_Pin << 16)) | // DB3 (GPIOB)
// (value & (1 << 5) ? DB5_Pin : (DB5_Pin << 16)) | // DB5 (GPIOB) (value & (1 << 5) ? DB5_Pin : (DB5_Pin << 16)) | // DB5 (GPIOB)
// (value & (1 << 7) ? DB7_Pin : (DB7_Pin << 16)) | // DB7 (GPIOB) (value & (1 << 7) ? DB7_Pin : (DB7_Pin << 16)) | // DB7 (GPIOB)
// (value & (1 << 9) ? DB9_Pin : (DB9_Pin << 16)) | // DB9 (GPIOB) (value & (1 << 9) ? DB9_Pin : (DB9_Pin << 16)) | // DB9 (GPIOB)
// (value & (1 << 11) ? DB11_Pin : (DB11_Pin << 16)) | // DB11 (GPIOB) (value & (1 << 11) ? DB11_Pin : (DB11_Pin << 16)) | // DB11 (GPIOB)
// (value & (1 << 12) ? DB12_Pin : (DB12_Pin << 16)) | // DB12 (GPIOB) (value & (1 << 12) ? DB12_Pin : (DB12_Pin << 16)) | // DB12 (GPIOB)
// (value & (1 << 13) ? DB13_Pin : (DB13_Pin << 16)) | // DB13 (GPIOB) (value & (1 << 13) ? DB13_Pin : (DB13_Pin << 16)) | // DB13 (GPIOB)
// (value & (1 << 15) ? DB15_Pin : (DB15_Pin << 16)); // DB15 (GPIOB) (value & (1 << 15) ? DB15_Pin : (DB15_Pin << 16)); // DB15 (GPIOB)
//
// GPIOD->BSRR = (value & (1 << 2) ? DB2_Pin : (DB2_Pin << 16)) | // DB2 (GPIOD) GPIOD->BSRR = (value & (1 << 2) ? DB2_Pin : (DB2_Pin << 16)) | // DB2 (GPIOD)
// (value & (1 << 4) ? DB4_Pin : (DB4_Pin << 16)); // DB4 (GPIOD) (value & (1 << 4) ? DB4_Pin : (DB4_Pin << 16)); // DB4 (GPIOD)
//
// GPIOC->BSRR = (value & (1 << 6) ? DB6_Pin : (DB6_Pin << 16)) | // DB6 (GPIOC) GPIOC->BSRR = (value & (1 << 6) ? DB6_Pin : (DB6_Pin << 16)) | // DB6 (GPIOC)
// (value & (1 << 8) ? DB8_Pin : (DB8_Pin << 16)) | // DB8 (GPIOC) (value & (1 << 8) ? DB8_Pin : (DB8_Pin << 16)) | // DB8 (GPIOC)
// (value & (1 << 10) ? DB10_Pin : (DB10_Pin << 16)); // DB10 (GPIOC) (value & (1 << 10) ? DB10_Pin : (DB10_Pin << 16)); // DB10 (GPIOC)
//} }
//void SetDataPins(uint16_t value) { //void SetDataPins(uint16_t value) {
// // Reset all data pins to 0 first (using BRR) // // Reset all data pins to 0 first (using BRR)
// GPIOA->BRR = DB0_Pin | DB14_Pin; // Reset DB0, DB14 (GPIOA) // GPIOA->BRR = DB0_Pin | DB14_Pin; // Reset DB0, DB14 (GPIOA)
@ -80,40 +80,40 @@ volatile uint16_t LCD_WIDTH = LCD_SCREEN_WIDTH;
// if (value & (1 << 14)) GPIOA->BSRR = DB14_Pin; // DB14 (GPIOA) // if (value & (1 << 14)) GPIOA->BSRR = DB14_Pin; // DB14 (GPIOA)
// if (value & (1 << 15)) GPIOB->BSRR = DB15_Pin; // DB15 (GPIOB) // if (value & (1 << 15)) GPIOB->BSRR = DB15_Pin; // DB15 (GPIOB)
//} //}
typedef struct { //typedef struct {
GPIO_TypeDef* port; // GPIO_TypeDef* port;
uint16_t pin; // uint16_t pin;
} DataPin; //} DataPin;
//
// Map each data bit (DB0-DB15) to its GPIO port and pin //// Map each data bit (DB0-DB15) to its GPIO port and pin
const DataPin dataPins[16] = { //const DataPin dataPins[16] = {
{DB0_GPIO_Port, DB0_Pin}, // DB0 // {DB0_GPIO_Port, DB0_Pin}, // DB0
{DB1_GPIO_Port, DB1_Pin}, // DB1 // {DB1_GPIO_Port, DB1_Pin}, // DB1
{DB2_GPIO_Port, DB2_Pin}, // DB2 // {DB2_GPIO_Port, DB2_Pin}, // DB2
{DB3_GPIO_Port, DB3_Pin}, // DB3 // {DB3_GPIO_Port, DB3_Pin}, // DB3
{DB4_GPIO_Port, DB4_Pin}, // DB4 // {DB4_GPIO_Port, DB4_Pin}, // DB4
{DB5_GPIO_Port, DB5_Pin}, // DB5 // {DB5_GPIO_Port, DB5_Pin}, // DB5
{DB6_GPIO_Port, DB6_Pin}, // DB6 // {DB6_GPIO_Port, DB6_Pin}, // DB6
{DB7_GPIO_Port, DB7_Pin}, // DB7 // {DB7_GPIO_Port, DB7_Pin}, // DB7
{DB8_GPIO_Port, DB8_Pin}, // DB8 // {DB8_GPIO_Port, DB8_Pin}, // DB8
{DB9_GPIO_Port, DB9_Pin}, // DB9 // {DB9_GPIO_Port, DB9_Pin}, // DB9
{DB10_GPIO_Port, DB10_Pin}, // DB10 // {DB10_GPIO_Port, DB10_Pin}, // DB10
{DB11_GPIO_Port, DB11_Pin}, // DB11 // {DB11_GPIO_Port, DB11_Pin}, // DB11
{DB12_GPIO_Port, DB12_Pin}, // DB12 // {DB12_GPIO_Port, DB12_Pin}, // DB12
{DB13_GPIO_Port, DB13_Pin}, // DB13 // {DB13_GPIO_Port, DB13_Pin}, // DB13
{DB14_GPIO_Port, DB14_Pin}, // DB14 // {DB14_GPIO_Port, DB14_Pin}, // DB14
{DB15_GPIO_Port, DB15_Pin} // DB15 // {DB15_GPIO_Port, DB15_Pin} // DB15
}; //};
//
void SetDataPins(uint16_t value) { //void SetDataPins(uint16_t value) {
for (int i = 0; i < 16; i++) { // for (int i = 0; i < 16; i++) {
// Check if the i-th bit in 'value' is set // // Check if the i-th bit in 'value' is set
GPIO_PinState state = (value & (1 << i)) ? GPIO_PIN_SET : GPIO_PIN_RESET; // GPIO_PinState state = (value & (1 << i)) ? GPIO_PIN_SET : GPIO_PIN_RESET;
//
// Write the state to the corresponding GPIO pin // // Write the state to the corresponding GPIO pin
HAL_GPIO_WritePin(dataPins[i].port, dataPins[i].pin, state); // HAL_GPIO_WritePin(dataPins[i].port, dataPins[i].pin, state);
} // }
} //}
//void ScreenWriteCmd(uint16_t command) { //void ScreenWriteCmd(uint16_t command) {
// MCU_RS_LOW(); // MCU_RS_LOW();
@ -253,8 +253,8 @@ void LCD_Init(void) {
LCD_HardwareReset(); LCD_HardwareReset();
// Software reset // Software reset
ScreenWriteCmd(0x01); // 1 //ScreenWriteCmd(0x01); // 1
HAL_Delay(150); //HAL_Delay(150);
// Color mode: 16bit/pixels // Color mode: 16bit/pixels
ScreenWriteCmd(0x3A); ScreenWriteCmd(0x3A);