mirror of
https://github.com/OneOfEleven/uv-k5-firmware-custom.git
synced 2025-04-28 22:31:25 +03:00
st7565.c: Move wait and data write to a single function.
This makes the code much easier to follow and understand.
This commit is contained in:
parent
f494b8565b
commit
b087ed5502
@ -32,6 +32,13 @@ uint8_t g_frame_buffer[7][128];
|
|||||||
uint8_t contrast = 31; // 0 ~ 63
|
uint8_t contrast = 31; // 0 ~ 63
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline void ST7565_LowLevelWrite(uint8_t Value)
|
||||||
|
{
|
||||||
|
/* Wait for space in the fifo */
|
||||||
|
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
||||||
|
SPI0->WDR = Value;
|
||||||
|
}
|
||||||
|
|
||||||
void ST7565_DrawLine(const unsigned int Column, const unsigned int Line, const unsigned int Size, const uint8_t *pBitmap)
|
void ST7565_DrawLine(const unsigned int Column, const unsigned int Line, const unsigned int Size, const uint8_t *pBitmap)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -46,16 +53,14 @@ void ST7565_DrawLine(const unsigned int Column, const unsigned int Line, const u
|
|||||||
{
|
{
|
||||||
for (i = 0; i < Size; i++)
|
for (i = 0; i < Size; i++)
|
||||||
{
|
{
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
ST7565_LowLevelWrite(pBitmap[i]);
|
||||||
SPI0->WDR = pBitmap[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; i < Size; i++)
|
for (i = 0; i < Size; i++)
|
||||||
{
|
{
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
ST7565_LowLevelWrite(0);
|
||||||
SPI0->WDR = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +88,7 @@ void ST7565_BlitFullScreen(void)
|
|||||||
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
|
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
|
||||||
for (Column = 0; Column < ARRAY_SIZE(g_frame_buffer[0]); Column++)
|
for (Column = 0; Column < ARRAY_SIZE(g_frame_buffer[0]); Column++)
|
||||||
{
|
{
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
ST7565_LowLevelWrite(g_frame_buffer[Line][Column]);
|
||||||
SPI0->WDR = g_frame_buffer[Line][Column];
|
|
||||||
}
|
}
|
||||||
SPI_WaitForUndocumentedTxFifoStatusBit();
|
SPI_WaitForUndocumentedTxFifoStatusBit();
|
||||||
}
|
}
|
||||||
@ -114,8 +118,7 @@ void ST7565_BlitStatusLine(void)
|
|||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(g_status_line); i++)
|
for (i = 0; i < ARRAY_SIZE(g_status_line); i++)
|
||||||
{
|
{
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
ST7565_LowLevelWrite(g_status_line[i]);
|
||||||
SPI0->WDR = g_status_line[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SPI_WaitForUndocumentedTxFifoStatusBit();
|
SPI_WaitForUndocumentedTxFifoStatusBit();
|
||||||
@ -140,8 +143,7 @@ void ST7565_FillScreen(const uint8_t Value)
|
|||||||
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
|
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
|
||||||
for (j = 0; j < 132; j++)
|
for (j = 0; j < 132; j++)
|
||||||
{
|
{
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
ST7565_LowLevelWrite(Value);
|
||||||
SPI0->WDR = Value;
|
|
||||||
}
|
}
|
||||||
SPI_WaitForUndocumentedTxFifoStatusBit();
|
SPI_WaitForUndocumentedTxFifoStatusBit();
|
||||||
}
|
}
|
||||||
@ -226,20 +228,16 @@ void ST7565_HardwareReset(void)
|
|||||||
void ST7565_SelectColumnAndLine(const uint8_t Column, const uint8_t Line)
|
void ST7565_SelectColumnAndLine(const uint8_t Column, const uint8_t Line)
|
||||||
{
|
{
|
||||||
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
|
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
ST7565_LowLevelWrite(Line + 176);
|
||||||
SPI0->WDR = Line + 176;
|
ST7565_LowLevelWrite(((Column >> 4) & 0x0F) | 0x10);
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
ST7565_LowLevelWrite((Column >> 0) & 0x0F);
|
||||||
SPI0->WDR = ((Column >> 4) & 0x0F) | 0x10;
|
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
|
||||||
SPI0->WDR = ((Column >> 0) & 0x0F);
|
|
||||||
SPI_WaitForUndocumentedTxFifoStatusBit();
|
SPI_WaitForUndocumentedTxFifoStatusBit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ST7565_WriteByte(const uint8_t Value)
|
void ST7565_WriteByte(const uint8_t Value)
|
||||||
{
|
{
|
||||||
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
|
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
|
||||||
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {}
|
ST7565_LowLevelWrite(Value);
|
||||||
SPI0->WDR = Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_CONTRAST
|
#ifdef ENABLE_CONTRAST
|
||||||
|
Loading…
x
Reference in New Issue
Block a user