Merge pull request #120 from gbouille/SSD1306_improvment

A little improvment on SSD refresh
This commit is contained in:
Stephen White 2019-01-02 11:54:47 +11:00 committed by GitHub
commit dba374593e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 479 additions and 455 deletions

View file

@ -118,6 +118,17 @@ void SSD1306::SendData(u8 data)
RPI_I2CWrite(BSCMaster, address, buffer, sizeof(buffer));
}
//We can send up to 16 bytes to the i2c bus
void SSD1306::SendDataLong(void* data, u8 length)
{
char buffer[15];
buffer[0] = SSD1306_DATA_REG;
memcpy(&buffer[1], data, length);
RPI_I2CWrite(BSCMaster, address, buffer, ++length);
}
void SSD1306::Home()
{
SetDataPointer(0, 0);
@ -193,10 +204,22 @@ void SSD1306::RefreshPage(u32 page)
if (new_start >= 0)
{
SetDataPointer(page, new_start-start);
for (i = new_start; i <= new_end; i++)
new_end++;
while (new_start < new_end)
{
SendData(frame[i]);
oldFrame[i] = frame[i];
i = (new_end-new_start < 15) ? new_end-new_start : 15;
if (i == 1)
{
SendData(frame[new_start]);
oldFrame[new_start] = frame[new_start];
}
else // Use the ability to send up to 16 byte in a row
// (1 for command and 15 for data)
{
SendDataLong(&frame[new_start],i);
memcpy(&oldFrame[new_start], &frame[new_start],i);
}
new_start += i;
}
}
}
@ -204,7 +227,7 @@ void SSD1306::RefreshPage(u32 page)
void SSD1306::ClearScreen()
{
memset(frame, 0, sizeof_frame);
memset(oldFrame, 0xff, sizeof_frame); // to force update
//memset(oldFrame, 0xff, sizeof_frame); // to force update
RefreshScreen();
}

View file

@ -98,6 +98,7 @@ public:
protected:
void SendCommand(u8 command);
void SendData(u8 data);
void SendDataLong(void* data, u8 length);
void Home();
void SetDataPointer(u8 row, u8 col);