Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
imahjoub committed Aug 12, 2024
1 parent f04132b commit b747161
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 58 deletions.
28 changes: 14 additions & 14 deletions Src/App/OS/OS_Task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions Src/Cdd/CddI2c/CddI2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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++)
{
Expand All @@ -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 */ }

Expand Down
6 changes: 3 additions & 3 deletions Src/Cdd/CddI2c/CddI2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
50 changes: 12 additions & 38 deletions Src/Cdd/CddSerLCD/CddSerLCD_I2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -139,24 +114,23 @@ 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] : ' ');

/* 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
}

0 comments on commit b747161

Please sign in to comment.