avr-firmwares/drivers/framebuffer.c

63 lines
1.3 KiB
C
Raw Permalink Normal View History

#define DONT_DECLARE_FRAMEBUFFER 1
#include "framebuffer.h"
FRAMEBUFFER;
2018-10-03 09:16:54 +02:00
#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
2018-10-03 22:20:35 +02:00
void fb_hline(uint8_t y, uint8_t x1, uint8_t x2, uint8_t c) {
uint8_t i;
for (i = x1; i <= x2; i++) {
FB_SET(i, y, c);
}
}
void fb_vline(uint8_t x, uint8_t y1, uint8_t y2, uint8_t c) {
uint8_t i;
for (i = y1; i <= y2; i++) {
FB_SET(x, i, c);
}
}
void fb_box(uint8_t ax, uint8_t ay, uint8_t bx, uint8_t by, uint8_t c) {
fb_hline(ay, ax, bx, c);
fb_hline(by, ax, bx, c);
fb_vline(ax, ay, by, c);
fb_vline(bx, ay, by, c);
}
void fb_area(uint8_t ax, uint8_t ay, uint8_t bx, uint8_t by, uint8_t c) {
uint8_t i;
for (i = ay; i <= by; i++) {
fb_hline(i, ax, bx, c);
}
}