-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from kienvo/fb
Add dynamic framebuffer
- Loading branch information
Showing
4 changed files
with
179 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "fb.h" | ||
#include <memory.h> | ||
|
||
volatile static fb_t *current, *head, *tail; | ||
|
||
static void fb_add(fb_t *new, fb_t *prev, fb_t *next) | ||
{ | ||
next->prev = new; | ||
new->next = next; | ||
new->prev = prev; | ||
prev->next = new; | ||
} | ||
|
||
fb_t *fblist_insert(fb_t *at, fb_t *new) | ||
{ | ||
fb_add(new, at, at->next); | ||
return new; | ||
} | ||
|
||
fb_t *fblist_append(fb_t *new) | ||
{ | ||
fblist_insert(new, tail); | ||
tail = new; | ||
return new; | ||
} | ||
|
||
fb_t *fblist_gonext() | ||
{ | ||
current = current->next; | ||
current->scroll = 0; | ||
return current; | ||
} | ||
|
||
fb_t *fblist_goprev() | ||
{ | ||
current = current->prev; | ||
current->scroll = 0; | ||
return current; | ||
} | ||
|
||
fb_t *fblist_gohead() | ||
{ | ||
current = head; | ||
current->scroll = 0; | ||
return current; | ||
} | ||
|
||
fb_t *fblist_currentfb() | ||
{ | ||
return current; | ||
} | ||
|
||
static void list_del(fb_t *prev, fb_t *next) | ||
{ | ||
prev->next = next; | ||
next->prev = prev; | ||
} | ||
|
||
fb_t *fblist_drop(fb_t *fb) | ||
{ | ||
list_del(fb->prev, fb->next); | ||
return fb->next; | ||
} | ||
|
||
fb_t *fb_new(uint16_t width) | ||
{ | ||
fb_t *fb = malloc(sizeof(fb_t)); | ||
memset(fb, 0, sizeof(fb_t)); | ||
|
||
fb->width = width; | ||
fb->buf = malloc(width * sizeof(uint16_t)); | ||
memset(fb->buf, 0, width * sizeof(uint16_t)); | ||
|
||
fb->modes = FIXED; | ||
|
||
fb->next = fb; | ||
fb->prev = fb; | ||
|
||
return fb; | ||
} | ||
|
||
void fblist_init(uint16_t first_fb_width) | ||
{ | ||
current = fb_new(first_fb_width); | ||
head = current; | ||
tail = current; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#ifndef __FB_H__ | ||
#define __FB_H__ | ||
|
||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
enum ANIMATION_MODES { | ||
LEFT = 0, | ||
RIGHT, | ||
UP, | ||
DOWN, | ||
FIXED, | ||
SNOWFLAKE, | ||
PICTURE, | ||
ANIMATION, | ||
LASER, | ||
}; | ||
|
||
typedef struct fb_st { | ||
uint16_t *buf; | ||
uint16_t width; | ||
uint8_t modes; | ||
int is_flash; | ||
int is_marquee; | ||
// TODO: feat: Brightness for each fb | ||
int brightness; | ||
// TODO: feat: Timeout for each fb to switch to next fb | ||
uint32_t timeout; // zero mean no timeout | ||
uint16_t scroll; | ||
|
||
struct fb_st *next; | ||
struct fb_st *prev; | ||
} fb_t; | ||
|
||
fb_t *fb_new(uint16_t width); | ||
static inline void fb_free(fb_t *fb) | ||
{ | ||
free((fb)->buf); | ||
free((fb)); | ||
} | ||
|
||
fb_t *fblist_insert(fb_t *at, fb_t *new); | ||
fb_t *fblist_append(fb_t *new); | ||
fb_t *fblist_drop(fb_t *fb); | ||
|
||
fb_t *fblist_gonext(); | ||
fb_t *fblist_goprev() ; | ||
fb_t *fblist_gohead(); | ||
fb_t *fblist_currentfb(); | ||
|
||
void fblist_init(uint16_t first_fb_width); | ||
|
||
#endif /* __FB_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters