Skip to content

Commit

Permalink
flipped buffer, performance up
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed May 4, 2021
1 parent 4c4e7f3 commit 87d1570
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/modm/driver/display/max7219_matrix_horizontal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Max7219MatrixHorizontal<SPI, CS, COLUMNS, ROWS>::update()
// a group of eight pixels horizontal
for (uint8_t col = 0; col < COLUMNS; ++col)
{
buf[--idx] = this->buffer[row * 8 + ledCol][col];
buf[--idx] = this->buffer[col][row * 8 + ledCol];
}
}

Expand Down
38 changes: 11 additions & 27 deletions src/modm/driver/display/sh1106.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,33 @@ class Sh1106 : public Ssd1306<I2cMaster, Height>
public:
Sh1106(uint8_t address = 0x3C) : Ssd1306<I2cMaster, Height>(address) {}

modm::ResumableResult<bool>
writeDisplay() override
protected:
// TODO Generalize in Ssd1306 so no more override is required
inline modm::ResumableResult<void>
startWriteDisplay() override
{
RF_BEGIN();

this->TransactionSuccess = true;
currentPage = 0;

this->commandBuffer[0] = ssd1306::AdressingCommands::HigherColumnStartAddress;
this->commandBuffer[1] = 0x02;

while (currentPage < Height / 8)
{
do {
this->commandBuffer[2] = 0xB0 | currentPage;
this->TransactionSuccess &= RF_CALL(this->writeCommands(3));

// TODO Rearrange MonochromeGraphicDisplay::buffer so we do not have to convert
// HACK Transform buffer - very unperformant transitional solution
for (size_t i = 0; i < 128; i++)
pageBuffer[i] = this->buffer[i][currentPage];

RF_CALL(startWriteDisplay());
RF_WAIT_UNTIL(
this->transaction.configureDisplayWrite((uint8_t*)&this->buffer[currentPage], 128));
RF_WAIT_UNTIL(this->startTransaction());
RF_WAIT_WHILE(this->isTransactionRunning());
// this->TransactionSuccess &= RF_CALL(this->wasTransactionSuccessful());

currentPage++;
}
this->TransactionSuccess &= this->wasTransactionSuccessful();
} while (++currentPage < Height / 8);

RF_END_RETURN(this->TransactionSuccess);
}

protected:
// TODO Generalize in Ssd1306 so no more override is required
inline modm::ResumableResult<void>
startWriteDisplay() override
{
RF_BEGIN();

RF_WAIT_UNTIL(this->transaction.configureDisplayWrite(pageBuffer, 128) and this->startTransaction());

RF_END();
}

inline modm::ResumableResult<void>
initializeMemoryMode() override
{
Expand All @@ -83,7 +68,6 @@ class Sh1106 : public Ssd1306<I2cMaster, Height>
}

private:
uint8_t pageBuffer[128];
size_t currentPage;
};
} // namespace modm
Expand Down
5 changes: 1 addition & 4 deletions src/modm/driver/display/ssd1306_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ modm::Ssd1306<I2cMaster, Height>::initializeMemoryMode()
{
RF_BEGIN();
commandBuffer[0] = AdressingCommands::MemoryMode;
// TODO Switch to MemoryMode::HORIZONTAL once MonochromeGraphicDisplay::buffer is rearranged
// due to modm::Sh1106 compatability. See sh1106.hpp
// commandBuffer[3] = MemoryMode::HORIZONTAL;
commandBuffer[1] = MemoryMode::VERTICAL;
commandBuffer[1] = MemoryMode::HORIZONTAL;
TransactionSuccess &= RF_CALL(writeCommands(2));

// Default on Power-up - can be omitted
Expand Down
2 changes: 1 addition & 1 deletion src/modm/ui/display/monochrome_graphic_display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MonochromeGraphicDisplay : public GraphicDisplay
clear() final;

protected:
uint8_t buffer[BufferWidth][BufferHeight];
uint8_t buffer[BufferHeight][BufferWidth];
};
} // namespace modm

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ template<int16_t Width, int16_t Height>
void
MonochromeGraphicDisplayHorizontal<Width, Height>::setPixel(int16_t x, int16_t y)
{
if ((x < Width) and (y < Height)) { this->buffer[y][x / 8] |= (1 << (x % 8)); }
if ((x < Width) and (y < Height)) { this->buffer[x / 8][y] |= (1 << (x % 8)); }
}

template<int16_t Width, int16_t Height>
void
MonochromeGraphicDisplayHorizontal<Width, Height>::clearPixel(int16_t x, int16_t y)
{
if ((x < Width) and (y < Height)) { this->buffer[y][x / 8] &= ~(1 << (x % 8)); }
if ((x < Width) and (y < Height)) { this->buffer[x / 8][y] &= ~(1 << (x % 8)); }
}

template<int16_t Width, int16_t Height>
bool
MonochromeGraphicDisplayHorizontal<Width, Height>::getPixel(int16_t x, int16_t y) const
{
if ((x < Width) and (y < Height))
return (this->buffer[y][x / 8] & (1 << (x % 8)));
return (this->buffer[x / 8][y] & (1 << (x % 8)));
else
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modm/ui/display/monochrome_graphic_display_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ template<int16_t Width, int16_t Height, std::size_t BufferWidth, std::size_t Buf
void
modm::MonochromeGraphicDisplay<Width, Height, BufferWidth, BufferHeight>::clear()
{
std::fill(&buffer[0][0], &buffer[BufferWidth][BufferHeight], 0);
this->cursor = glcd::Point(0, 0);
std::fill(&buffer[0][0], &buffer[0][0] + sizeof(buffer), 0);
this->cursor = {0, 0};
}
18 changes: 9 additions & 9 deletions src/modm/ui/display/monochrome_graphic_display_vertical_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ modm::MonochromeGraphicDisplayVertical<Width, Height>::drawHorizontalLine(glcd::
const uint8_t byte = 1 << (start.y % 8);
for (int_fast16_t x = start.x; x < static_cast<int16_t>(start.x + length); ++x)
{
if (x < Width) { this->buffer[x][y] |= byte; }
if (x < Width) { this->buffer[y][x] |= byte; }
}
// } else
// {
// const uint8_t byte = ~(1 << (start.y % 8));
// for (int_fast16_t x = start.x; x < static_cast<int16_t>(start.x + length);
// ++x)
// {
// if (x < Width and y < Height) { this->buffer[x][y] &= byte; }
// if (x >= 0 and x < Width and y >= 0 and y < Height) { this->buffer[y][x] &= byte; }
// }
// }
}
Expand All @@ -62,7 +62,7 @@ modm::MonochromeGraphicDisplayVertical<Width, Height>::drawVerticalLine(glcd::Po
{
if (y < Height / 8)
{
this->buffer[start.x][y] |= byte;
this->buffer[y][start.x] |= byte;
byte = 0xFF;
}
y++;
Expand All @@ -71,7 +71,7 @@ modm::MonochromeGraphicDisplayVertical<Width, Height>::drawVerticalLine(glcd::Po
if (y < Height / 8)
{
byte &= 0xFF >> (8 - end_y % 8);
this->buffer[start.x][y] |= byte;
this->buffer[y][start.x] |= byte;
}
}
}
Expand All @@ -95,7 +95,7 @@ modm::MonochromeGraphicDisplayVertical<Width, Height>::drawImageRaw(
uint16_t x = start.x + i;
uint16_t y = k + row;

if (x < Width and y < Height) { this->buffer[x][y] = data[i + k * width]; }
if (x < Width and y < Height / 8) {this->buffer[y][x] = data[i + k * width]; }
}
}
return;
Expand All @@ -109,22 +109,22 @@ template<int16_t Width, int16_t Height>
void
modm::MonochromeGraphicDisplayVertical<Width, Height>::setPixel(int16_t x, int16_t y)
{
if (x < Width and y < Height) { this->buffer[x][y / 8] |= (1 << y % 8); }
if (x >= 0 and x < Width and y >= 0 and y < Height) { this->buffer[y / 8][x] |= (1 << y % 8); }
}

template<int16_t Width, int16_t Height>
void
modm::MonochromeGraphicDisplayVertical<Width, Height>::clearPixel(int16_t x, int16_t y)
{
if (x < Width and y < Height) { this->buffer[x][y / 8] &= ~(1 << y % 8); }
if (x >= 0 and x < Width and y >= 0 and y < Height) { this->buffer[y / 8][x] &= ~(1 << y % 8); }
}

template<int16_t Width, int16_t Height>
bool
modm::MonochromeGraphicDisplayVertical<Width, Height>::getPixel(int16_t x, int16_t y) const
{
if (x < Width and y < Height)
return (this->buffer[x][y / 8] & (1 << y % 8));
if (x >= 0 and x < Width and y >= 0 and y < Height)
return (this->buffer[y / 8][x] & (1 << y % 8));
else
return false;
}

0 comments on commit 87d1570

Please sign in to comment.