From 9c912ffb85fd17ddc5c82b317e9795734f5e9a49 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Wed, 3 Oct 2018 07:16:54 +0000 Subject: [PATCH] Add sample framebuffer shifting code --- drivers/framebuffer.c | 29 +++++++++++++++++++++++++++++ drivers/framebuffer.h | 10 ++++++---- pingpong.c | 17 ++++++++++++++++- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/drivers/framebuffer.c b/drivers/framebuffer.c index 82ecab4..3859211 100644 --- a/drivers/framebuffer.c +++ b/drivers/framebuffer.c @@ -2,3 +2,32 @@ #include "framebuffer.h" FRAMEBUFFER; + +#if FB_DEPTH==1 + +void fb_fill(uint8_t c) { + memset(framebuffer, c, sizeof(framebuffer[0][0]) * FB_HEIGHT * FB_WIDTH_BYTES); +} + +void fb_shift(uint16_t newcol) { + int x, y; + uint8_t transfer = 0, tmp = 0; + for (y = 0; y < FB_HEIGHT; y++) { + for (x = FB_WIDTH_BYTES - 1; x >= 0; x--) { + tmp = transfer; + transfer = (framebuffer[y][x] & 1); + framebuffer[y][x] = (framebuffer[y][x] >> 1) | (tmp << 7); + } + transfer = 0; + FB_SET(FB_WIDTH - 1, y, newcol & 1); + newcol = newcol >> 1; + } +} + +#elif FB_DEPTH==8 + +void fb_fill(uint8_t c) { + memset(framebuffer, c, sizeof(framebuffer[0][0]) * FB_HEIGHT * FB_WIDTH); +} + +#endif diff --git a/drivers/framebuffer.h b/drivers/framebuffer.h index e1f05b9..d6e24d6 100644 --- a/drivers/framebuffer.h +++ b/drivers/framebuffer.h @@ -1,4 +1,5 @@ #include +#include #define CEILDIV(x, y) (((x)+((y)-1))/(y)) @@ -7,20 +8,21 @@ #define FB_WIDTH_BYTES CEILDIV(FB_WIDTH, 8) #define FRAMEBUFFER uint8_t framebuffer[FB_HEIGHT][FB_WIDTH_BYTES]; #define FB_SET(w,h,c) if (c) { \ - framebuffer[h][w>>3] |= (1 << (w & 7)); \ + framebuffer[h][(w)>>3] |= (1 << ((w) & 7)); \ } else { \ - framebuffer[h][w>>3] &= ~(1 << (w & 7)); \ + framebuffer[h][(w)>>3] &= ~(1 << ((w) & 7)); \ } -#define FB_CLEAR() memset(framebuffer, 0, sizeof(framebuffer[0][0]) * FB_HEIGHT * FB_WIDTH_BYTES); #elif FB_DEPTH==8 #define FRAMEBUFFER uint8_t framebuffer][FB_HEIGHT][FB_WIDTH]; #define FB_SET(w,h,c) framebuffer[h][w] = c -#define FB_CLEAR() memset(framebuffer, 0, sizeof(framebuffer[0][0]) * FB_HEIGHT * FB_WIDTH); #endif #ifndef DONT_DECLARE_FRAMEBUFFER extern FRAMEBUFFER #endif + +void fb_fill(uint8_t c); +void fb_shift(); diff --git a/pingpong.c b/pingpong.c index c3ab4a6..f03ba1c 100644 --- a/pingpong.c +++ b/pingpong.c @@ -1,9 +1,11 @@ #include #include "drivers/framebuffer.h" -int main(void) { +void ani_recorder(unsigned int count) { int8_t px, py, mx, my; + fb_fill(0); + px = 0; py = 0; mx = 1; @@ -24,9 +26,11 @@ int main(void) { if (py >= FB_HEIGHT - 1) { my = -1; + count --; } FB_SET(px,py,0); + if (!count) return; px += mx; py += my; FB_SET(px,py,1); @@ -34,3 +38,14 @@ int main(void) { _delay_ms(50); } } + +int main() { + uint16_t i = 0; + while(1) { + ani_recorder(4); + for (i = 0; i < 256; i++) { + _delay_ms(50); + fb_shift(i); + } + } +}