summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/ypr0/lcd-ypr0.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/ypr0/lcd-ypr0.c')
-rw-r--r--firmware/target/hosted/ypr0/lcd-ypr0.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/firmware/target/hosted/ypr0/lcd-ypr0.c b/firmware/target/hosted/ypr0/lcd-ypr0.c
new file mode 100644
index 0000000000..f0565ae2d4
--- /dev/null
+++ b/firmware/target/hosted/ypr0/lcd-ypr0.c
@@ -0,0 +1,147 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: lcd-bitmap.c 29248 2011-02-08 20:05:25Z thomasjfox $
9 *
10 * Copyright (C) 2011 Lorenzo Miori, Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <unistd.h>
24#include <stdio.h>
25#include "string.h"
26#include <linux/fb.h>
27#include <sys/mman.h>
28#include <sys/ioctl.h>
29
30#include "file.h"
31#include "debug.h"
32#include "system.h"
33#include "screendump.h"
34#include "lcd.h"
35
36/* eqivalent to fb + y*width + x */
37#define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
38
39static int dev_fd = 0;
40static fb_data *dev_fb = 0;
41
42void lcd_update(void)
43{
44 /* update the entire display */
45 memcpy(dev_fb, lcd_framebuffer, sizeof(lcd_framebuffer));
46}
47
48/* Copy Rockbox frame buffer to the mmapped lcd device */
49void lcd_update_rect(int x, int y, int width, int height)
50{
51 /* nothing to draw? */
52 if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) ||
53 (y >= LCD_HEIGHT) || (x + width <= 0) || (y + height <= 0))
54 return;
55
56 /* do the necessary clipping */
57 if (x < 0)
58 { /* clip left */
59 width += x;
60 x = 0;
61 }
62 if (y < 0)
63 { /* clip top */
64 height += y;
65 y = 0;
66 }
67 if (x + width > LCD_WIDTH)
68 width = LCD_WIDTH - x; /* clip right */
69 if (y + height > LCD_HEIGHT)
70 height = LCD_HEIGHT - y; /* clip bottom */
71
72 fb_data* src = LCDADDR(x, y);
73 fb_data* dst = dev_fb + y*LCD_WIDTH + x;
74
75 if (LCD_WIDTH == width)
76 { /* optimized full-width update */
77 memcpy(dst, src, width * height * sizeof(fb_data));
78 }
79 else
80 { /* row by row */
81 do
82 {
83 memcpy(dst, src, width * sizeof(fb_data));
84 src += LCD_WIDTH;
85 dst += LCD_WIDTH;
86 } while(--height > 0);
87 }
88}
89
90void lcd_shutdown(void)
91{
92 printf("FB closed.");
93 munmap(dev_fb, sizeof(lcd_framebuffer));
94 close(dev_fd);
95}
96
97void lcd_init_device(void)
98{
99 size_t screensize;
100 struct fb_var_screeninfo vinfo;
101 struct fb_fix_screeninfo finfo;
102
103 /* Open the framebuffer device */
104 dev_fd = open("/dev/fb0", O_RDWR);
105 if (dev_fd == -1) {
106 perror("Error: cannot open framebuffer device");
107 exit(1);
108 }
109 printf("The framebuffer device was opened successfully.\n");
110
111 /* Get the fixed properties */
112 if (ioctl(dev_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
113 perror("Error reading fixed information");
114 exit(2);
115 }
116
117 /* Now we get the settable settings, and we set 16 bit bpp */
118 if (ioctl(dev_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
119 perror("Error reading variable information");
120 exit(3);
121 }
122
123 vinfo.bits_per_pixel = 16;
124
125 if (ioctl(dev_fd, FBIOPUT_VSCREENINFO, &vinfo)) {
126 perror("fbset(ioctl)");
127 exit(4);
128 }
129
130 printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
131
132 /* Figure out the size of the screen in bytes */
133 screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
134 if (screensize != sizeof(lcd_framebuffer))
135 {
136 exit(4);
137 perror("Display and framebuffer mismatch!\n");
138 }
139
140 /* Map the device to memory */
141 dev_fb = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
142 if ((int)dev_fb == -1) {
143 perror("Error: failed to map framebuffer device to memory");
144 exit(4);
145 }
146 printf("The framebuffer device was mapped to memory successfully.\n");
147}