summaryrefslogtreecommitdiffstats
path: root/apps/osmocomBB/osmocomBB/include/fb
diff options
context:
space:
mode:
Diffstat (limited to 'apps/osmocomBB/osmocomBB/include/fb')
-rw-r--r--apps/osmocomBB/osmocomBB/include/fb/fb_bw8.h51
-rw-r--r--apps/osmocomBB/osmocomBB/include/fb/fb_rgb332.h47
-rw-r--r--apps/osmocomBB/osmocomBB/include/fb/font.h82
-rw-r--r--apps/osmocomBB/osmocomBB/include/fb/framebuffer.h128
4 files changed, 308 insertions, 0 deletions
diff --git a/apps/osmocomBB/osmocomBB/include/fb/fb_bw8.h b/apps/osmocomBB/osmocomBB/include/fb/fb_bw8.h
new file mode 100644
index 0000000000..c77fa71f19
--- /dev/null
+++ b/apps/osmocomBB/osmocomBB/include/fb/fb_bw8.h
@@ -0,0 +1,51 @@
+#ifndef FB_BW8_H
+#define FB_BW8_H
+
+/* 8bit monochrome framebuffer, organized with 8 stacked pixels
+ per byte, backed by local memory. fb_bw8.c lists functions that
+ are common to simmilar organized displays. */
+
+/*
+ Sketch of Memory Layout
+ Left Upper Corner of Display
+
+ col0 col2
+ col1
+ +-------------
+ 1st row: | A0 B0 C0
+ 2nd row: | A1 B1 C1
+ ...
+ 7th row: | A6 B6 C6
+ 8th row: | A7 B7 C7
+ 9th row: | Q0 R0 S0
+ 10th row: | Q1 R1 S1 ...
+ ...
+
+ Backing store (and internal display memory?) looks like...
+
+ uint8_t mem[] = { A, B, C, .... Q, R, S, ... }
+
+ We work on a in-memory copy of the framebuffer and only
+ update the physical display on demand. The damage window
+ has two corners, left upper inclusive x1,y1 and right
+ lower x2,y2 exclusive. So dirty pixels are defined to
+ be x1 <= x_pixel < x2 and y1 <= y_pixel < y2.
+*/
+
+/* data specific to a bw8-type framebuffer as described above */
+
+struct fb_bw8 {
+ uint8_t *mem; /* set to backingstore memory */
+ uint16_t damage_x1,damage_y1; /* current damage window, ul */
+ uint16_t damage_x2,damage_y2; /* current damage window, lr */
+};
+
+extern struct fb_bw8 *fb_bw8; /* symbol defined by the specific LCD driver */
+
+extern void fb_bw8_clear();
+extern void fb_bw8_boxto(uint16_t x,uint16_t y); /* draw a box from cursor to x,y */
+extern void fb_bw8_lineto(uint16_t x,uint16_t y); /* draw a line from cursor to x,y */
+
+extern int fb_bw8_putstr(char *str,int maxwidth);
+
+#endif
diff --git a/apps/osmocomBB/osmocomBB/include/fb/fb_rgb332.h b/apps/osmocomBB/osmocomBB/include/fb/fb_rgb332.h
new file mode 100644
index 0000000000..4df44e4ec1
--- /dev/null
+++ b/apps/osmocomBB/osmocomBB/include/fb/fb_rgb332.h
@@ -0,0 +1,47 @@
+#ifndef FB_RGB332_H
+#define FB_RGB332_H
+
+/* RGB framebuffer with 1 byte per pixel, bits mapped as RRRGGGBB */
+
+struct fb_rgb332 {
+ uint8_t *mem; /* set to backingstore memory */
+ uint16_t damage_x1,damage_y1; /* current damage window, ul (incl) */
+ uint16_t damage_x2,damage_y2; /* current damage window, lr (excl) */
+};
+
+extern void fb_rgb332_clear();
+
+/* draw a box from cursor to x,y */
+extern void fb_rgb332_boxto(uint16_t x,uint16_t y);
+/* draw a line from cursor to x,y */
+extern void fb_rgb332_lineto(uint16_t x,uint16_t y);
+
+/* put string str onto framebuffer with line (bottom
+ left pixel of, e.g. "m") starting at cursor.
+ Maximum width consumed is maxwidth, actual width
+ needed is returned */
+extern int fb_rgb332_putstr(char *str,int maxwidth);
+
+extern struct fb_rgb332 *fb_rgb332;
+
+/* this convenience function can be used if you choose to
+ * back a RGB565 display with a RGB332 framebuffer to conserve
+ * ARM memory. It converts a rgb332 value to rgb565 as indicated
+ * in the comments. */
+
+static inline uint16_t
+rgb332_to_565(uint8_t rgb332){
+
+ uint8_t red = (rgb332 & 0xe0) >> 5 ; // rrr. .... -> .... .rrr
+ uint8_t green = ((rgb332 & 0x1c) >> 2); // ...g gg.. -> .... .ggg
+ uint8_t blue = rgb332 & 0x03; // .... ..bb -> .... ..bb
+
+ red = (red << 2) | (red >> 1); /* .....210 -> ...21021 */
+ green = (green << 3) | (green); /* .....210 -> ..210210 */
+ blue = (blue << 3) | (blue << 1) | (blue >> 1); /* ......10 -> ...10101 */
+
+ /* rrrrrggg gggbbbbb */
+ return (red << 11) | (green << 5) | blue;
+}
+
+#endif
diff --git a/apps/osmocomBB/osmocomBB/include/fb/font.h b/apps/osmocomBB/osmocomBB/include/fb/font.h
new file mode 100644
index 0000000000..9dee8ffb34
--- /dev/null
+++ b/apps/osmocomBB/osmocomBB/include/fb/font.h
@@ -0,0 +1,82 @@
+#ifndef _FB_FONT_H
+#define _FB_FONT_H
+
+#include <stdint.h>
+#include <unistd.h>
+
+/*
+ Example:
+ Font Helvetica 14
+
+
+ Character W ('X' and '.' is the character font data)
+
+ X.....X......&...
+ X.....X......X...
+ X....X.X.....X...
+ .X...X.X....X....
+ .X...X.X....X....
+ .X...X.X....X....
+ ..X.X....X.X.....
+ ..X.X....X.X.....
+ ..X.X....X.X.....
+ ...X......X......
+ @%..X......X...$..
+ <---dwidth---->
+
+ @ is the cursor position (origin) for this character
+ $ is the cursor position (origin) for the next character
+ % is the character boundingbox origin,
+ & is the character boundingbox top right corner
+
+ */
+
+/* data for char c is found by getting the index into the
+ chardata array from the charoffs array.
+
+ if charoffs[c] == FB_FONT_NOCHAR, then this glyph does
+ not exist! Better use the convenience function fb_font_get_char below! */
+
+#define FB_FONT_NOCHAR 0xffff
+
+struct fb_font {
+ int8_t height; /* total height of font */
+ int8_t ascent; /* topmost pixel is "ascend" above
+ current cursor position y */
+ uint8_t firstchar,lastchar; /* range of characters in font (iso8859-1) */
+ uint8_t const *chardata;
+ uint16_t const *charoffs; /* byte offsets relative to chardata */
+ uint8_t const *widths; /* widths for characters */
+};
+
+struct fb_char {
+ int8_t width;
+ int8_t bbox_w,bbox_h,bbox_x,bbox_y;
+ uint8_t data[0];
+};
+
+/* there are currently 6 fonts available, Helvetica 8, 14, 24 point
+ in bold and regular shapes. The following enum has to match the
+ order of the array fb_fonts in framebuffer.c!
+*/
+
+enum fb_font_id {
+// FB_FONT_4X6,
+// FB_FONT_5X8,
+ FB_FONT_HELVR08,
+// FB_FONT_HELVR14
+// FB_FONT_HELVR24,
+// FB_FONT_HELVB08,
+ FB_FONT_HELVB14,
+// FB_FONT_HELVB24,
+ FB_FONT_C64,
+ FB_FONT_SYMBOLS,
+};
+
+extern const struct fb_font *fb_fonts[]; // note: has to match fb_font_id enum!
+
+extern const struct fb_char *
+fb_font_get_char(const struct fb_font *fnt,unsigned char c);
+
+#endif
+
diff --git a/apps/osmocomBB/osmocomBB/include/fb/framebuffer.h b/apps/osmocomBB/osmocomBB/include/fb/framebuffer.h
new file mode 100644
index 0000000000..e765b36da5
--- /dev/null
+++ b/apps/osmocomBB/osmocomBB/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
+