diff options
| -rw-r--r-- | main/InovaLedDisplay.cpp | 34 | ||||
| -rw-r--r-- | main/InovaLedDisplay.h | 6 | ||||
| -rw-r--r-- | main/main.cpp | 16 |
3 files changed, 43 insertions, 13 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; + } } } } diff --git a/main/InovaLedDisplay.h b/main/InovaLedDisplay.h index b394708..a1d9ad9 100644 --- a/main/InovaLedDisplay.h +++ b/main/InovaLedDisplay.h @@ -16,16 +16,18 @@ class InovaLedDisplay : public virtual Adafruit_GFX { void drawPixel(int16_t x, int16_t y, uint16_t c); - void updateDisplay(void); + void swapBuffer(void); void runDisplay(void); void stopDisplay(void); private: - uint16_t displayBuffer[NUM_ROW][NUM_COL / 8]; // each column is two bits, so 8 can fit in 16-bit integer + uint16_t displayBuffer[2][NUM_ROW][NUM_COL / 8]; // each column is two bits, so 8 can fit in 16-bit integer spi_device_handle_t spi; bool run = true; + bool shouldSwapBuffer = false; + uint8_t backBufferIndex = 0; gpio_num_t latch, oe, addr0, addr1, addr2; }; diff --git a/main/main.cpp b/main/main.cpp index 1d64d95..7555410 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -10,9 +10,10 @@ #define CHAR_HEIGHT 8 #define CHAR_WIDTH 8 -#define RED 1 -#define GREEN 2 -#define ORANGE 3 +#define BLACK 0x0000 +#define RED 0xF800 +#define GREEN 0x07E0 +#define ORANGE 0xFFE0 #define PIN_NUM_MISO 12 #define PIN_NUM_MOSI 13 @@ -55,19 +56,19 @@ extern "C" void runDisplayTask(void* taskParams) { extern "C" void app_main(void) { InovaLedDisplay display = InovaLedDisplay(PIN_NUM_MISO, PIN_NUM_MOSI, PIN_NUM_CLK, PIN_NUM_CS, PIN_NUM_R_LATCH, PIN_NUM_R_CLK, PIN_NUM_R_ADDR_0, PIN_NUM_R_ADDR_1, PIN_NUM_R_ADDR_2); - + display.fillScreen(0); display.setCursor(0, 0); - display.setTextColor(2); + display.setTextColor(RED); display.setTextWrap(false); display.print("Adafruit GFX 0123456789"); TaskHandle_t taskHandle; xTaskCreate(runDisplayTask, "updateDisplay", STACK_SIZE, &display, tskIDLE_PRIORITY, &taskHandle); - + //runDisplayTask(&display); - + //while(true) { // vTaskDelay(100 / portTICK_PERIOD_MS); //} @@ -80,6 +81,7 @@ extern "C" void app_main(void) display.fillScreen(0); display.setCursor(j, 0); display.print(hello); + display.swapBuffer(); if(--j == min_x) { j = display.width(); |
