aboutsummaryrefslogtreecommitdiff
path: root/main/InovaLedDisplay.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/InovaLedDisplay.cpp')
-rw-r--r--main/InovaLedDisplay.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/main/InovaLedDisplay.cpp b/main/InovaLedDisplay.cpp
index f579043..0d8d7e8 100644
--- a/main/InovaLedDisplay.cpp
+++ b/main/InovaLedDisplay.cpp
@@ -48,12 +48,32 @@ InovaLedDisplay::InovaLedDisplay(uint8_t r0, uint8_t g0, uint8_t clk, uint8_t cs
void InovaLedDisplay::drawPixel(int16_t x, int16_t y, uint16_t color) {
- displayBuffer[y][x / 8] = displayBuffer[y][x / 8] & ~(0b0000000000000011 << (14 - (2 * (x % 8)))); // clear this column (note the bitwise inversion)
- displayBuffer[y][x / 8] = displayBuffer[y][x / 8] | (color << (14 - (2 * (x % 8)))); // write color to column
+
+ if(x < 0 || x >= _width || y < 0 || y >= _height) return;
+
+ // Adafruit GFX color is 16-bit 5-6-5 rgb
+ // We store only 2-bit rg, so we assume any amount of red or green wants that color
+ uint8_t r, g;
+ r = color >> 11; // RRRRRggggggbbbbb
+ g = (color >> 5) & 0x3F; // rrrrrGGGGGGbbbbb
+
+ color = 0;
+ if(g > 0) color += 1;
+ if(r > 0) color += 2;
+
+ uint8_t i = backBufferIndex;
+ displayBuffer[i][y][x / 8] = displayBuffer[i][y][x / 8] & ~(0b0000000000000011 << (14 - (2 * (x % 8)))); // clear this column (note the bitwise inversion)
+ displayBuffer[i][y][x / 8] = displayBuffer[i][y][x / 8] | (color << (14 - (2 * (x % 8)))); // write color to column
}
-void InovaLedDisplay::updateDisplay(void) {}
+void InovaLedDisplay::swapBuffer(void) {
+ shouldSwapBuffer = true;
+
+ while(shouldSwapBuffer) {
+ vTaskDelay(1 / portTICK_PERIOD_MS);
+ }
+}
void InovaLedDisplay::runDisplay(void) {
@@ -73,7 +93,7 @@ void InovaLedDisplay::runDisplay(void) {
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length = 16;
- data = SPI_SWAP_DATA_TX(displayBuffer[current_row][i], 16);
+ data = SPI_SWAP_DATA_TX(displayBuffer[1 - backBufferIndex][current_row][i], 16);
t.tx_buffer = &data;
t.flags = SPI_TRANS_MODE_DIO; // output on two data lines. Even bits go to GREEN, odd to RED
ret = spi_device_polling_transmit(spi, &t);
@@ -92,6 +112,12 @@ void InovaLedDisplay::runDisplay(void) {
if(++current_row == NUM_ROW) {
current_row = 0;
+
+ if(shouldSwapBuffer) {
+ backBufferIndex++;
+ backBufferIndex = backBufferIndex % 2;
+ shouldSwapBuffer = false;
+ }
}
}
}