mirror of
https://github.com/Team-Resurgent/DynamicDisplay.git
synced 2026-08-15 11:18:39 -07:00
130 lines
2.9 KiB
C++
130 lines
2.9 KiB
C++
#include "pico/stdlib.h"
|
|
#include "pico/multicore.h"
|
|
#include "pico/mutex.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <queue>
|
|
|
|
#include "fonts.h"
|
|
#include "deviceLegacy.h"
|
|
#include "deviceRTC.h"
|
|
#include "deviceEEPROM.h"
|
|
#include "deviceTouch.h"
|
|
#include "pixelDisplayDriver.h"
|
|
#include "pixelDisplayGC9A01A.h"
|
|
#include "pixelDisplayILI9341.h"
|
|
#include "pixelDisplaySH1106.h"
|
|
#include "pixelDisplaySH1122.h"
|
|
#include "pixelDisplayST7789.h"
|
|
#include "pixelDisplaySSD1306.h"
|
|
#include "pixelDisplaySSD1309.h"
|
|
#include "textDisplayDriver.h"
|
|
#include "textDisplayUS2066.h"
|
|
#include "color.h"
|
|
|
|
static deviceLegacy* device = NULL;
|
|
static volatile bool refresh = false;
|
|
static mutex_t mutex;
|
|
|
|
|
|
static volatile uint8_t displayDelayTimer=0;
|
|
struct repeating_timer timer;
|
|
bool timers_tick(struct repeating_timer *t)
|
|
{
|
|
if(displayDelayTimer) displayDelayTimer--;
|
|
return true;
|
|
}
|
|
|
|
void print_screen()
|
|
{
|
|
printf("\e[1;1H");
|
|
for(int r=0;r<device->getRows();r++)
|
|
{
|
|
for(int c=0;c<device->getCols();c++)
|
|
{
|
|
printf("%c",device->getDisplayChar(r,c));
|
|
}
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
|
|
void render_loop()
|
|
{
|
|
const uint16_t width = 128;
|
|
const uint16_t height = 64;
|
|
const uint16_t xShift = 0;
|
|
const uint16_t yShift = 0;
|
|
const uint16_t bitsPerPixel = 1;
|
|
|
|
spi_inst_t* spi = spi1;
|
|
const uint32_t baudRate = 100 * 1000;
|
|
const uint8_t txPin = 11;
|
|
const uint8_t sckPin = 10;
|
|
const uint8_t csnPin = 9;
|
|
const uint8_t rstPin = 12;
|
|
const uint8_t dcPin = 8;
|
|
const uint8_t backlightPin = 20;
|
|
|
|
pixelDisplaySSD1309* display = new pixelDisplaySSD1309(width, height, xShift, yShift, bitsPerPixel);
|
|
display->initSpi(spi, baudRate, txPin, sckPin, csnPin, rstPin, dcPin, backlightPin);
|
|
display->fill(0x000000);
|
|
display->drawDisplay();
|
|
|
|
while (true)
|
|
{
|
|
if (refresh == true)
|
|
{
|
|
refresh = false;
|
|
display->fill(0x000000);
|
|
mutex_enter_blocking(&mutex);
|
|
print_screen();
|
|
for (int y = 0; y < device->getRows(); y++)
|
|
{
|
|
for (int x = 0; x < device->getCols(); x++)
|
|
{
|
|
display->drawChar(0xffffff, fonts::Font_6x8(), (x * 6) + 2, y << 3, device->getDisplayChar(y, x));
|
|
}
|
|
}
|
|
mutex_exit(&mutex);
|
|
display->drawDisplay();
|
|
}
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
stdio_init_all();
|
|
|
|
mutex_init(&mutex);
|
|
|
|
spi_inst_t* spi = spi0;
|
|
const uint32_t baudRate = 100 * 1000;
|
|
const uint8_t rxPin = 0;
|
|
const uint8_t csnPin = 1;
|
|
const uint8_t sckPin = 2;
|
|
|
|
device = new deviceLegacy(4, 20);
|
|
device->initSpi(spi, baudRate, rxPin, sckPin, csnPin);
|
|
add_repeating_timer_ms(-10, timers_tick, NULL, &timer);//Countdown variable will be decremented by 1 every 10ms if it is > 0
|
|
multicore_launch_core1(render_loop);
|
|
|
|
while (true)
|
|
{
|
|
if (device->listenMaster())
|
|
{
|
|
//Enabling the countdown timer to 10 ticks (10ms * 50 = 500ms)
|
|
displayDelayTimer = 10;//10ms * 10 = 1000ms
|
|
while(displayDelayTimer)
|
|
{
|
|
device->listenMaster();
|
|
}
|
|
mutex_enter_blocking(&mutex);
|
|
device->RefreshDisplayBuffer();
|
|
mutex_exit(&mutex);
|
|
refresh = true;
|
|
}
|
|
}
|
|
}
|