12 #define FBDEV_PATH "/dev/fb0"
17 static struct fb_var_screeninfo vinfo
;
18 static struct fb_fix_screeninfo finfo
;
22 return vinfo
.xres_virtual
* vinfo
.yres_virtual
* BPP
;
27 fd
= open(FBDEV_PATH
, O_RDWR
);
29 xerror("can't open " FBDEV_PATH
);
30 if (ioctl(fd
, FBIOGET_VSCREENINFO
, &vinfo
) == -1)
31 xerror("ioctl failed");
32 if (ioctl(fd
, FBIOGET_FSCREENINFO
, &finfo
) == -1)
33 xerror("ioctl failed");
34 fb
= mmap(NULL
, fb_len(), PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
36 xerror("can't map the framebuffer");
39 void fb_put(int r
, int c
, u16_t val
)
41 long loc
= (c
+ vinfo
.xoffset
) * BPP
+
42 (r
+ vinfo
.yoffset
) * finfo
.line_length
;
43 memcpy(fb
+ loc
, &val
, BPP
);
52 static u16_t
color_bits(struct fb_bitfield
*bf
, unsigned char v
)
54 unsigned char moved
= v
>> (8 - bf
->length
);
55 return moved
<< bf
->offset
;
58 u16_t
fb_color(u8_t r
, u8_t g
, u8_t b
)
60 return color_bits(&vinfo
.red
, r
) |
61 color_bits(&vinfo
.green
, g
) |
62 color_bits(&vinfo
.blue
, b
);
67 return vinfo
.yres_virtual
;
72 return vinfo
.xres_virtual
;
75 void fb_box(int sr
, int sc
, int er
, int ec
, u16_t val
)
78 for (r
= sr
; r
< er
; r
++)
79 for (c
= sc
; c
< ec
; c
++)
83 static char *rowaddr(int r
)
85 return fb
+ (r
+ vinfo
.yoffset
) * finfo
.line_length
;
88 void fb_scroll(int sr
, int nr
, int n
, u16_t val
)
91 for (r
= sr
; r
< sr
+ nr
; r
++)
92 memcpy(rowaddr(r
+ n
), rowaddr(r
), finfo
.line_length
);
94 fb_box(sr
, 0, n
, sr
+ n
, val
);
96 fb_box(sr
+ nr
+ n
, 0, sr
+ nr
, fb_cols(), val
);