Add sample framebuffer shifting code

This commit is contained in:
Nero 2018-10-03 07:16:54 +00:00
parent 1aa9341549
commit 9c912ffb85
3 changed files with 51 additions and 5 deletions

View File

@ -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

View File

@ -1,4 +1,5 @@
#include <stdint.h>
#include <string.h>
#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();

View File

@ -1,9 +1,11 @@
#include <util/delay.h>
#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);
}
}
}