diff --git a/Src/App/OS/OS_Task.c b/Src/App/OS/OS_Task.c index 3c71d63..d927ff1 100644 --- a/Src/App/OS/OS_Task.c +++ b/Src/App/OS/OS_Task.c @@ -124,20 +124,20 @@ void Task03_Func(void) { #if defined(OS_TASK_USE_SERLCD_I2C) - //char HelloString[] = { "hello" }; - //char WorldString[] = { "World" }; - // - //CddSerLCD_I2c_SendCommand(CDD_SERLCD_CLEAR_DISPLAY); - ///* Delay to ensure the clear command is processed */ - //CddSerLcd_I2c_msDelays(5U); - //CddSerLCD_I2c_PrintString(HelloString, sizeof(HelloString)/sizeof(HelloString[0])); - //CddSerLcd_I2c_msDelays(2000U); - // - //CddSerLCD_I2c_SendCommand(CDD_SERLCD_CLEAR_DISPLAY); - ///* Delay to ensure the clear command is processed */ - //CddSerLcd_I2c_msDelays(5U); - //CddSerLCD_I2c_PrintString(WorldString, sizeof(WorldString) / sizeof(WorldString[0])); - //CddSerLcd_I2c_msDelays(2000U); + char HelloString[] = { "hello" }; + char WorldString[] = { "World" }; + + CddSerLCD_I2c_SendCommand(CDD_SERLCD_CLEAR_DISPLAY); + /* Delay to ensure the clear command is processed */ + CddSerLcd_I2c_msDelays(5U); + CddSerLCD_I2c_PrintString(HelloString, sizeof(HelloString)/sizeof(HelloString[0])); + CddSerLcd_I2c_msDelays(2000U); + + CddSerLCD_I2c_SendCommand(CDD_SERLCD_CLEAR_DISPLAY); + /* Delay to ensure the clear command is processed */ + CddSerLcd_I2c_msDelays(5U); + CddSerLCD_I2c_PrintString(WorldString, sizeof(WorldString) / sizeof(WorldString[0])); + CddSerLcd_I2c_msDelays(2000U); #endif } diff --git a/Src/Cdd/CddI2c/CddI2c.c b/Src/Cdd/CddI2c/CddI2c.c index 8e60823..d551e18 100644 --- a/Src/Cdd/CddI2c/CddI2c.c +++ b/Src/Cdd/CddI2c/CddI2c.c @@ -71,7 +71,7 @@ void CddI2c_Init(void) I2C1_CR1 |= (uint32_t)(1UL << 0U); } -void CddI2c_StartTransmission(uint8_t DeviceAddress, size_t DataSize, uint8_t WriteReadMode) +void CddI2c_StartTransmission(const uint8_t DeviceAddress, const size_t DataSize, const uint8_t WriteReadMode) { uint32_t CddI2cTempReg = I2C1_CR2; @@ -88,7 +88,7 @@ void CddI2c_StartTransmission(uint8_t DeviceAddress, size_t DataSize, uint8_t Wr } -void CddI2c_TransferMultipleByte(uint8_t* Data, size_t DataSize) +void CddI2c_TransferMultipleByte(const uint8_t* Data, const size_t DataSize) { for (uint8_t i = 0U; i < DataSize; i++) { @@ -102,7 +102,7 @@ void CddI2c_TransferMultipleByte(uint8_t* Data, size_t DataSize) while (!(I2C1_ISR & (1UL << 6U))); } -void CddI2c_TransferSingleByte(uint8_t Data) +void CddI2c_TransferSingleByte(const uint8_t Data) { while (!(I2C1_ISR & (1UL << 1U))) { /* Wait until TX buffer is empty */ } diff --git a/Src/Cdd/CddI2c/CddI2c.h b/Src/Cdd/CddI2c/CddI2c.h index aed37bd..1cb9571 100644 --- a/Src/Cdd/CddI2c/CddI2c.h +++ b/Src/Cdd/CddI2c/CddI2c.h @@ -5,9 +5,9 @@ #include "stdint.h" void CddI2c_Init(void); - void CddI2c_StartTransmission(uint8_t DeviceAddress, size_t DataSize, uint8_t WriteReadMode); - void CddI2c_TransferMultipleByte(uint8_t* Data, size_t DataSize); - void CddI2c_TransferSingleByte(uint8_t Data); + void CddI2c_StartTransmission(const uint8_t DeviceAddress, const size_t DataSize, const uint8_t WriteReadMode); + void CddI2c_TransferMultipleByte(const uint8_t* Data, const size_t DataSize); + void CddI2c_TransferSingleByte(const uint8_t Data); void CddI2c_Stop(void); #endif /* Cdd_I2C_2024_03_06_H */ diff --git a/Src/Cdd/CddSerLCD/CddSerLCD_I2c.c b/Src/Cdd/CddSerLCD/CddSerLCD_I2c.c index c427e32..5378646 100644 --- a/Src/Cdd/CddSerLCD/CddSerLCD_I2c.c +++ b/Src/Cdd/CddSerLCD/CddSerLCD_I2c.c @@ -19,7 +19,7 @@ void CddSerLCD_I2c_PrintString(char* StringToPrint, uint8_t StringSize) while (*StringToPrint) { - CddI2c_TransferSingleByte((uint8_t)(*StringToPrint)); + CddI2c_TransferMultipleByte((uint8_t)(*StringToPrint), StringSize); ++StringToPrint; } @@ -29,14 +29,15 @@ void CddSerLCD_I2c_PrintString(char* StringToPrint, uint8_t StringSize) void CddSerLCD_I2c_SendCommand(uint8_t Command) { + /* LCD command buffer */ + const uint8_t LCDCmdBuffer[2U] = { CDD_SERLCD_SETTING_MODE, Command}; + const size_t LCDCmdBufferSize = (size_t)((sizeof(LCDCmdBuffer) / sizeof(LCDCmdBuffer[0]))); + /* Start, set slave address to write */ CddI2c_StartTransmission(CDD_SERLCD_ADDRESS, 2U, CDD_SERLCD_MODE_WRITE); /* Command mode */ - CddI2c_TransferSingleByte(CDD_SERLCD_SETTING_MODE); - - /* Send the command */ - CddI2c_TransferSingleByte(Command); + CddI2c_TransferMultipleByte(LCDCmdBuffer, LCDCmdBufferSize); /* Stop condition */ CddI2c_Stop(); @@ -92,44 +93,18 @@ static void CddSerLcd_I2c_SelectLine(const size_t LineIndexToUse) void CddSerLCD_I2c_Init(void) { -#if 0 - CddI2c_StartTransmission(CDD_SERLCD_ADDRESS, 1U, CDD_SERLCD_MODE_WRITE); - CddI2c_TransferSingleByte(CDD_SERLCD_SETTING_MODE); - CddI2c_Stop(); - - CddI2c_StartTransmission(CDD_SERLCD_ADDRESS, 1U, CDD_SERLCD_MODE_WRITE); - CddI2c_TransferSingleByte(CDD_SERLCD_CLEAR_DISPLAY); - CddI2c_Stop(); -#endif - - - uint8_t data[] = { 'H', 'i' }; - CddI2c_StartTransmission(CDD_SERLCD_ADDRESS, (sizeof(data) / sizeof(data[0])), CDD_SERLCD_MODE_WRITE); - CddI2c_TransferMultipleByte(data, (sizeof(data) / sizeof(data[0]))); - CddI2c_Stop(); - - CddI2c_StartTransmission(CDD_SERLCD_ADDRESS, 1U, CDD_SERLCD_MODE_WRITE); - CddI2c_TransferSingleByte('!'); - CddI2c_Stop(); - - - /* Clear display */ - //CddSerLcd_I2c_ClearLCD(); + CddSerLcd_I2c_ClearLCD(); /* Set blue backlight */ - //CddSerLcd_I2c_SetBlueBacklight(); + CddSerLcd_I2c_SetBlueBacklight(); /* Set blue backlight */ - //CddSerLcd_I2c_SetLCDSize(); - - - + CddSerLcd_I2c_SetLCDSize(); } void CddSerLCD_I2c_WriteLine(const char* StringToPrint, const size_t StringSize, const size_t LineIndex) { -#if 0 // Limit to the maximum width of the display width. const size_t LineIndexToUse = ((LineIndex > (size_t) 3U) ? (size_t) 3U : LineIndex); @@ -139,11 +114,11 @@ void CddSerLCD_I2c_WriteLine(const char* StringToPrint, const size_t StringSize, CddSerLcd_I2c_SelectLine(LineIndexToUse); /* Start, set slave address to write */ - CddI2c_StartTransmission(CDD_SERLCD_ADDRESS, CDD_SERLCD_MODE_WRITE); + CddI2c_StartTransmission(CDD_SERLCD_ADDRESS, 20U, CDD_SERLCD_MODE_WRITE); for(size_t idx = (size_t) 0U; idx < (size_t) 20U; ++idx) { - /* Chip select enable */ + /* Delay to ensure the command is processed */ CddSerLcd_I2c_msDelays(4U); const char CharToWrite = ((idx < SizeToWrite) ? StringToPrint[idx] : ' '); @@ -151,12 +126,11 @@ void CddSerLCD_I2c_WriteLine(const char* StringToPrint, const size_t StringSize, /* Send next character. */ CddI2c_TransferSingleByte(CharToWrite); - /* Chip select disable */ + /* Delay to ensure the command is processed */ CddSerLcd_I2c_msDelays(4U); } /* Stop condition */ CddI2c_Stop(); -#endif }