From 26db6bf03d6d591d978151e9925d7d15fbe56907 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 8 Mar 2024 14:07:09 +0100 Subject: [PATCH 1/2] a funny light show --- canvas.c | 4 ++- canvas.h | 1 + displayTest.c | 83 +++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 78 insertions(+), 10 deletions(-) diff --git a/canvas.c b/canvas.c index 8df3b0a..72f0740 100644 --- a/canvas.c +++ b/canvas.c @@ -28,4 +28,6 @@ void canvasShow() { displayDriverTransferCanvas(); } - +void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color) { + *((canvas.canvas) + (row * canvas.width + column)) = (color + 0x80); +} diff --git a/canvas.h b/canvas.h index 7c7ec65..bf324ed 100644 --- a/canvas.h +++ b/canvas.h @@ -17,6 +17,7 @@ typedef struct { void canvasInit(); canvas_t *canvasGet(); void canvasShow(); +void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color); diff --git a/displayTest.c b/displayTest.c index 38b242a..502a486 100644 --- a/displayTest.c +++ b/displayTest.c @@ -4,19 +4,84 @@ static canvas_t *canvas; -static uint8_t lastPixel = 0xff; -static uint8_t currentPixel = 0; + +#define MAX_COLOR 0x0d void displayTestExec(void *args) { - if (lastPixel != 0xff) { - *((canvas->canvas)+lastPixel) = 0x80; + static uint8_t last = 0xff; + static uint8_t current = 0; + static uint8_t color = 0x01; + static uint8_t state = 1; + + switch (state) { + case 0: + for (uint16_t i = 0; i < canvas->height; i++) { + canvasSetPixel(last, i, 0); + } + last = 0xff; + state = 1; + case 1: + if (last != 0xff) { + *((canvas->canvas)+last) = 0x80; + } + + last = current; + *((canvas->canvas)+current) = (color + 0x80); + current++; + if (current >= canvas->size) { + current = 0; + state = 2; + } + break; + case 2: + *((canvas->canvas)+last) = 0x80; + last = 0xff; + state = 3; + case 3: + if (last != 0xff) { + for (uint16_t i = 0; i < canvas->width; i++) { + canvasSetPixel(i, last, 0); + } + } + + last = current; + for (uint16_t i = 0; i < canvas->width; i++) { + canvasSetPixel(i, current, color); + } + current++; + if (current >= canvas->height) { + current = 0; + state = 4; + } + break; + case 4: + for (uint16_t i = 0; i < canvas->width; i++) { + canvasSetPixel(i, last, 0); + } + last = 0xff; + state = 5; + case 5: + if (last != 0xff) { + for (uint16_t i = 0; i < canvas->height; i++) { + canvasSetPixel(last, i, 0); + } + } + + last = current; + for (uint16_t i = 0; i < canvas->height; i++) { + canvasSetPixel(current, i, color); + } + current++; + if (current >= canvas->width) { + current = 0; + state = 0; + } + break; } - lastPixel = currentPixel; - *((canvas->canvas)+currentPixel) = 0x81; - currentPixel++; - if (currentPixel >= canvas->size) { - currentPixel = 0; + color++; + if (color > MAX_COLOR) { + color = 1; } canvasShow(); From 167617ad2cf3fe448544786f6e6a3b308e2b46fb Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 8 Mar 2024 14:13:21 +0100 Subject: [PATCH 2/2] faster spi --- displayDriver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/displayDriver.c b/displayDriver.c index b9be624..d0d9df2 100644 --- a/displayDriver.c +++ b/displayDriver.c @@ -34,7 +34,7 @@ void displayDriverInit() { UCB0CTL0 = UCMST; // SPI timing config UCB0CTL1 = UCSSEL_3; - UCB0BR0 = 8; + UCB0BR0 = 4; // 2 would be too fast and ends up with errors UCB0BR1 = 0; // BIT5: UCB0CLK