diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2018-11-05 13:01:55 +0100 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-04-06 18:15:41 +0200 |
commit | 180cef835bf40d0081895773aaa637ac926bb0ac (patch) | |
tree | 48c380d76c0ea40931cb5e863b40fc5dfa1ecba4 /firmware/target/hosted/xduoo/lcd-xduoo.c | |
parent | ced3a20aacf26642ccc3ffd136f64247c67e5769 (diff) | |
download | rockbox-180cef835bf40d0081895773aaa637ac926bb0ac.tar.gz rockbox-180cef835bf40d0081895773aaa637ac926bb0ac.zip |
xDuoo X3II and X20 port
Provided by Roman Stolyarov
Integration, Refactoring, and Upstreaming by Solomon Peachy
X3II confirmed working by forum tester, X20 is nearly identical.
This includes bootloader, main firmware, and the flash image patcher.
Eventual Todo:
* Further refactor AGPTek Rocker & xduoo hiby bootloaders
* Further refactor AGPTek Rocker & xduoo hosted platform code
Change-Id: I34a674051d368efcc75d1d18c725971fe46c3eee
Diffstat (limited to 'firmware/target/hosted/xduoo/lcd-xduoo.c')
-rw-r--r-- | firmware/target/hosted/xduoo/lcd-xduoo.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/firmware/target/hosted/xduoo/lcd-xduoo.c b/firmware/target/hosted/xduoo/lcd-xduoo.c new file mode 100644 index 0000000000..4b3148da03 --- /dev/null +++ b/firmware/target/hosted/xduoo/lcd-xduoo.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2017 Marcin Bukat | ||
10 | * Copyright (C) 2016 Amaury Pouly | ||
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 <linux/fb.h> | ||
26 | #include <sys/mman.h> | ||
27 | #include <sys/ioctl.h> | ||
28 | #include <fcntl.h> | ||
29 | #include "lcd.h" | ||
30 | #include "lcd-target.h" | ||
31 | #include "backlight-target.h" | ||
32 | #include "sysfs.h" | ||
33 | #include "panic.h" | ||
34 | |||
35 | static int fd = -1; | ||
36 | static struct fb_var_screeninfo vinfo; | ||
37 | fb_data *framebuffer = 0; /* global variable, see lcd-target.h */ | ||
38 | |||
39 | void lcd_init_device(void) | ||
40 | { | ||
41 | const char * const fb_dev = "/dev/fb0"; | ||
42 | fd = open(fb_dev, O_RDWR); | ||
43 | if(fd < 0) | ||
44 | { | ||
45 | panicf("Cannot open framebuffer: %s\n", fb_dev); | ||
46 | } | ||
47 | |||
48 | /* get fixed and variable information */ | ||
49 | struct fb_fix_screeninfo finfo; | ||
50 | if(ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) | ||
51 | { | ||
52 | panicf("Cannot read framebuffer fixed information"); | ||
53 | } | ||
54 | |||
55 | if(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) | ||
56 | { | ||
57 | panicf("Cannot read framebuffer variable information"); | ||
58 | } | ||
59 | |||
60 | #if 0 | ||
61 | /* check resolution and framebuffer size */ | ||
62 | if(vinfo.xres != LCD_WIDTH || vinfo.yres != LCD_HEIGHT || vinfo.bits_per_pixel != LCD_DEPTH) | ||
63 | { | ||
64 | panicf("Unexpected framebuffer resolution: %dx%dx%d\n", vinfo.xres, | ||
65 | vinfo.yres, vinfo.bits_per_pixel); | ||
66 | } | ||
67 | #endif | ||
68 | /* Note: we use a framebuffer size of width*height*bbp. We cannot trust the | ||
69 | * values returned by the driver for line_length */ | ||
70 | |||
71 | /* map framebuffer */ | ||
72 | framebuffer = mmap(0, FRAMEBUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | ||
73 | if((void *)framebuffer == MAP_FAILED) | ||
74 | { | ||
75 | panicf("Cannot map framebuffer"); | ||
76 | } | ||
77 | |||
78 | #ifdef HAVE_LCD_ENABLE | ||
79 | lcd_set_active(true); | ||
80 | #endif | ||
81 | } | ||
82 | |||
83 | #ifdef HAVE_LCD_SHUTDOWN | ||
84 | void lcd_shutdown(void) | ||
85 | { | ||
86 | munmap(framebuffer, FRAMEBUFFER_SIZE); | ||
87 | close(fd); | ||
88 | } | ||
89 | #endif | ||
90 | |||
91 | void lcd_enable(bool on) | ||
92 | { | ||
93 | const char * const sysfs_fb_blank = "/sys/class/graphics/fb0/blank"; | ||
94 | |||
95 | if (lcd_active() != on) | ||
96 | { | ||
97 | sysfs_set_int(sysfs_fb_blank, on ? 0 : 1); | ||
98 | lcd_set_active(on); | ||
99 | |||
100 | if (on) | ||
101 | { | ||
102 | send_event(LCD_EVENT_ACTIVATION, NULL); | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | |||
107 | static void redraw(void) | ||
108 | { | ||
109 | ioctl(fd, FBIOPAN_DISPLAY, &vinfo); | ||
110 | } | ||
111 | |||
112 | extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src, | ||
113 | int width, int height); | ||
114 | |||
115 | void lcd_update(void) | ||
116 | { | ||
117 | /* Copy the Rockbox framebuffer to the second framebuffer */ | ||
118 | lcd_copy_buffer_rect(LCD_FRAMEBUF_ADDR(0, 0), FBADDR(0,0), | ||
119 | LCD_WIDTH*LCD_HEIGHT, 1); | ||
120 | redraw(); | ||
121 | } | ||
122 | |||
123 | void lcd_update_rect(int x, int y, int width, int height) | ||
124 | { | ||
125 | fb_data *dst = LCD_FRAMEBUF_ADDR(x, y); | ||
126 | fb_data * src = FBADDR(x,y); | ||
127 | |||
128 | /* Copy part of the Rockbox framebuffer to the second framebuffer */ | ||
129 | if (width < LCD_WIDTH) | ||
130 | { | ||
131 | /* Not full width - do line-by-line */ | ||
132 | lcd_copy_buffer_rect(dst, src, width, height); | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | /* Full width - copy as one line */ | ||
137 | lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1); | ||
138 | } | ||
139 | redraw(); | ||
140 | } | ||