summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Vogel <vogelchr@vogel.cx>2010-10-11 20:51:55 +0200
committerHarald Welte <laforge@gnumonks.org>2012-02-03 23:59:35 +0100
commitec097f532e5fd77cc627f8d18a0455bbeb694962 (patch)
treeef950cdaac018b9f1c3837f88803e8353d50a021
parent45d88fa052995da4fb77deb72ddf1597cfdb058c (diff)
Calypso FB: Main framebuffer header file.
-rw-r--r--src/target/firmware/fb/framebuffer.c28
-rw-r--r--src/target/firmware/include/fb/framebuffer.h128
2 files changed, 156 insertions, 0 deletions
diff --git a/src/target/firmware/fb/framebuffer.c b/src/target/firmware/fb/framebuffer.c
new file mode 100644
index 00000000..ab547694
--- /dev/null
+++ b/src/target/firmware/fb/framebuffer.c
@@ -0,0 +1,28 @@
+/* Framebuffer - Utility Functions */
+
+/* (C) 2010 by Christian Vogel <vogelchr@vogel.cx>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <fb/framebuffer.h>
+
+/* currently everything's inline in framebuffer .h */
+
+
+
diff --git a/src/target/firmware/include/fb/framebuffer.h b/src/target/firmware/include/fb/framebuffer.h
new file mode 100644
index 00000000..e765b36d
--- /dev/null
+++ b/src/target/firmware/include/fb/framebuffer.h
@@ -0,0 +1,128 @@
+#ifndef _FB_FRAMEBUFFER_H
+#define _FB_FRAMEBUFFER_H
+
+#include <fb/font.h>
+#include <stdint.h>
+
+/* color is encoded as <special><red><green><blue> */
+/* if a color is "special", then the RGB components most likely
+ don't make sense. Use "special" colours when you have to
+ mask out bits with transparency or you have to encode
+ colours in a fixed color palette... */
+
+#define FB_COLOR_WHITE 0x00ffffffU
+#define FB_COLOR_BLACK 0x00000000U
+#define FB_COLOR_TRANSP 0x01ffffffU
+
+#define FB_COLOR_RGB(r,g,b) ((((r) & 0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))
+#define FB_COLOR_RED FB_COLOR_RGB(0xff,0x00,0x00)
+#define FB_COLOR_GREEN FB_COLOR_RGB(0x00,0xff,0x00)
+#define FB_COLOR_BLUE FB_COLOR_RGB(0x00,0x00,0xff)
+
+/* encode */
+
+/* decode */
+#define FB_COLOR_IS_SPECIAL(v) (!!((v) & 0xff000000U))
+#define FB_COLOR_TO_R(v) (((v)>>16) & 0xff)
+#define FB_COLOR_TO_G(v) (((v)>> 8) & 0xff)
+#define FB_COLOR_TO_B(v) ( (v) & 0xff)
+
+struct framebuffer {
+ char name[8]; // keep it short!
+ void (*init)(); // (re)initialize
+ void (*clear)(); // clear display
+ void (*boxto)(uint16_t x,uint16_t y); // draw box to xy
+ void (*lineto)(uint16_t x,uint16_t y); // draw line to xy
+ int (*putstr)(char *c,int maxwidth); // put text in current font to fb
+ void (*flush)(); // flush changes
+
+ uint16_t width,height; // width/height of fb
+ uint16_t cursor_x,cursor_y; // current cursor
+ uint32_t fg_color,bg_color; // current fg/bg color
+ enum fb_font_id font; // current font
+};
+
+/* there is a single framebuffer, the specific driver defines
+ the "framebuffer" symbol */
+extern struct framebuffer *framebuffer;
+
+static inline void
+fb_init(){
+ framebuffer->init();
+}
+
+static inline void
+fb_clear(){
+ framebuffer->clear();
+}
+
+static inline void
+fb_boxto(uint16_t x,uint16_t y){
+ framebuffer->boxto(x,y);
+}
+
+static inline void
+fb_lineto(uint16_t x,uint16_t y){
+ framebuffer->lineto(x,y);
+}
+
+static inline int
+fb_putstr(char *str,int maxwidth){
+ return framebuffer->putstr(str,maxwidth);
+}
+
+static inline void
+fb_flush(){
+ framebuffer->flush();
+}
+
+static inline void
+fb_gotoxy(uint16_t x,uint16_t y){
+ framebuffer->cursor_x = x;
+ framebuffer->cursor_y = y;
+}
+
+static inline void
+fb_setfg(uint32_t color){
+ framebuffer->fg_color = color;
+}
+
+static inline void
+fb_setbg(uint32_t color){
+ framebuffer->bg_color = color;
+}
+
+static inline void
+fb_setfont(enum fb_font_id fid){
+ framebuffer->font = fid;
+}
+
+/* utility function: limit coordinates to area of framebuffer */
+static inline void
+fb_limit_fb_range(uint16_t *x,uint16_t *y){
+ if(*x >= framebuffer->width)
+ *x = framebuffer->width - 1;
+ if(*y >= framebuffer->height)
+ *y = framebuffer->height - 1;
+}
+
+/* utility function: limit box coordinates to area of framebuffer
+ and make sure that x1y1 is left upper edge, x2y2 is right lower */
+static inline void
+fb_sanitize_box(uint16_t *x1,uint16_t *y1,uint16_t *x2,uint16_t *y2){
+ fb_limit_fb_range(x1,y1);
+ fb_limit_fb_range(x2,y2);
+ if(*x1 > *x2){
+ uint16_t tmp = *x1;
+ *x1 = *x2;
+ *x2 = tmp;
+ }
+ if(*y1 > *y2){
+ uint16_t tmp = *y1;
+ *y1 = *y2;
+ *y2 = tmp;
+ }
+}
+
+#endif
+