| 1 | /* $Id$ |
|---|
| 2 | * $URL$ |
|---|
| 3 | * |
|---|
| 4 | * LUIse lcd4linux driver |
|---|
| 5 | * |
|---|
| 6 | * Copyright (C) 2005 Theo Schneider <theo@schneider-berlin.net> |
|---|
| 7 | * Copyright (C) 2005 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net> |
|---|
| 8 | * |
|---|
| 9 | * This file is part of LCD4Linux. |
|---|
| 10 | * |
|---|
| 11 | * LCD4Linux is free software; you can redistribute it and/or modify |
|---|
| 12 | * it under the terms of the GNU General Public License as published by |
|---|
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
|---|
| 14 | * any later version. |
|---|
| 15 | * |
|---|
| 16 | * LCD4Linux is distributed in the hope that it will be useful, |
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | * GNU General Public License for more details. |
|---|
| 20 | * |
|---|
| 21 | * You should have received a copy of the GNU General Public License |
|---|
| 22 | * along with this program; if not, write to the Free Software |
|---|
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 24 | * |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | /* |
|---|
| 28 | * |
|---|
| 29 | * exported fuctions: |
|---|
| 30 | * |
|---|
| 31 | * struct DRIVER drv_LUIse |
|---|
| 32 | * |
|---|
| 33 | */ |
|---|
| 34 | |
|---|
| 35 | #include "config.h" |
|---|
| 36 | |
|---|
| 37 | #include <stdlib.h> |
|---|
| 38 | #include <stdio.h> |
|---|
| 39 | #include <string.h> |
|---|
| 40 | #include <errno.h> |
|---|
| 41 | |
|---|
| 42 | #include <usb.h> |
|---|
| 43 | #include <luise.h> |
|---|
| 44 | |
|---|
| 45 | #include "debug.h" |
|---|
| 46 | #include "cfg.h" |
|---|
| 47 | #include "qprintf.h" |
|---|
| 48 | #include "udelay.h" |
|---|
| 49 | #include "plugin.h" |
|---|
| 50 | #include "drv.h" |
|---|
| 51 | #include "drv_generic_graphic.h" |
|---|
| 52 | |
|---|
| 53 | static char Name[] = "LUIse"; |
|---|
| 54 | |
|---|
| 55 | /* default Wert */ |
|---|
| 56 | static int devNum = 0; |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | /****************************************/ |
|---|
| 61 | /*** hardware dependant functions ***/ |
|---|
| 62 | /****************************************/ |
|---|
| 63 | static void drv_LUIse_clear(void) |
|---|
| 64 | { |
|---|
| 65 | unsigned char buf[9600]; |
|---|
| 66 | int x; |
|---|
| 67 | |
|---|
| 68 | // clear text |
|---|
| 69 | LUI_Text(devNum, 0, 0, 320, 240, 0, 0, 1, 1, ""); |
|---|
| 70 | |
|---|
| 71 | // clear picture |
|---|
| 72 | for (x = 0; x < 9600; x++) |
|---|
| 73 | buf[x] = 0x00; |
|---|
| 74 | LUI_Bitmap(devNum, 0, 0, 0, 0, 0, DCOLS, DROWS, DCOLS, DROWS, buf); |
|---|
| 75 | LUI_Bitmap(devNum, 1, 0, 0, 0, 0, DCOLS, DROWS, DCOLS, DROWS, buf); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | static void drv_LUIse_blit(const int row, const int col, const int height, const int width) |
|---|
| 80 | { |
|---|
| 81 | int r, c; |
|---|
| 82 | |
|---|
| 83 | for (r = row; r < row + height; r++) { |
|---|
| 84 | for (c = col; c < col + width; c++) { |
|---|
| 85 | if (drv_generic_graphic_black(r, c)) { |
|---|
| 86 | LUI_SetPixel(devNum, 0, c, r, 1); |
|---|
| 87 | } else { |
|---|
| 88 | LUI_SetPixel(devNum, 0, c, r, 0); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | static int drv_LUIse_contrast(int contrast) |
|---|
| 95 | { |
|---|
| 96 | /* adjust limits according to the display */ |
|---|
| 97 | if (contrast < 0) |
|---|
| 98 | contrast = 0; |
|---|
| 99 | if (contrast > 255) |
|---|
| 100 | contrast = 255; |
|---|
| 101 | |
|---|
| 102 | LUI_SetContrast(devNum, contrast); |
|---|
| 103 | |
|---|
| 104 | return contrast; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | static int drv_LUIse_backlight(int backlight) |
|---|
| 108 | { |
|---|
| 109 | if (backlight < 0) |
|---|
| 110 | backlight = 0; |
|---|
| 111 | if (backlight > 1) |
|---|
| 112 | backlight = 1; |
|---|
| 113 | |
|---|
| 114 | LUI_CCFL(devNum, backlight); |
|---|
| 115 | |
|---|
| 116 | return backlight; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | /* start graphic display */ |
|---|
| 121 | static int drv_LUIse_start(const char *section) |
|---|
| 122 | { |
|---|
| 123 | char *s; |
|---|
| 124 | int gfxmode, gfxinvert, ScreenRotation, IOrefresh; |
|---|
| 125 | int contrast, backlight; |
|---|
| 126 | |
|---|
| 127 | /* read devNum from config */ |
|---|
| 128 | s = cfg_get(section, "DeviceNum", 0); |
|---|
| 129 | if (s == NULL || *s == '\0') { |
|---|
| 130 | error("%s: no '%s.DeviceNum' entry from %s", Name, section, cfg_source()); |
|---|
| 131 | return -1; |
|---|
| 132 | } |
|---|
| 133 | if (sscanf(s, "%d", &devNum) < 0 || devNum > 4) { |
|---|
| 134 | error("%s: bad DeviceNum '%s' from %s", Name, s, cfg_source()); |
|---|
| 135 | return -1; |
|---|
| 136 | } |
|---|
| 137 | info("%s: using DeviceNum '%d'", Name, devNum); |
|---|
| 138 | |
|---|
| 139 | /* open communication with the display */ |
|---|
| 140 | if (LUI_OpenDevice(devNum) > 0) { |
|---|
| 141 | error("unable to open DeviceNum: %d", devNum); |
|---|
| 142 | return -1; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | /* |
|---|
| 146 | * 0 : gfxmode 0 = or, 1 = and, 2 = xor |
|---|
| 147 | * 0 : gfxinvert 0 = normal, 1 = invert |
|---|
| 148 | * 0 : ScreenRotation 0 =, 1 =, 2 =, 3 =, |
|---|
| 149 | * 2 : IOrefresh 0 = 25ms...255=256*25ms |
|---|
| 150 | */ |
|---|
| 151 | |
|---|
| 152 | s = cfg_get(section, "Mode", "0.0.0.2"); |
|---|
| 153 | if (s == NULL || *s == '\0') { |
|---|
| 154 | error("%s: no '%s.Mode' entry from %s", Name, section, cfg_source()); |
|---|
| 155 | return -1; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | if (sscanf(s, "%d.%d.%d.%d", &gfxmode, &gfxinvert, &ScreenRotation, &IOrefresh) != 4 || |
|---|
| 159 | gfxmode < 0 || gfxmode > 2 || gfxinvert < 0 || gfxinvert > 1 || |
|---|
| 160 | ScreenRotation < 0 || ScreenRotation > 255 || IOrefresh < 0 || IOrefresh > 255) { |
|---|
| 161 | error("%s: bad Mode '%s' from %s", Name, s, cfg_source()); |
|---|
| 162 | return -1; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | if (LUI_LCDmode(devNum, gfxmode, gfxinvert, ScreenRotation, IOrefresh) > 0) { |
|---|
| 166 | error("Error LUI_LCDmode"); |
|---|
| 167 | return -1; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | switch (ScreenRotation) { |
|---|
| 171 | case 0:{ |
|---|
| 172 | DCOLS = 320; |
|---|
| 173 | DROWS = 240; |
|---|
| 174 | break; |
|---|
| 175 | } |
|---|
| 176 | case 1:{ |
|---|
| 177 | DCOLS = 240; |
|---|
| 178 | DROWS = 320; |
|---|
| 179 | break; |
|---|
| 180 | } |
|---|
| 181 | case 2:{ |
|---|
| 182 | DCOLS = 320; |
|---|
| 183 | DROWS = 240; |
|---|
| 184 | break; |
|---|
| 185 | } |
|---|
| 186 | case 3:{ |
|---|
| 187 | DCOLS = 240; |
|---|
| 188 | DROWS = 320; |
|---|
| 189 | break; |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | s = cfg_get(section, "Font", "6x8"); |
|---|
| 194 | if (s == NULL || *s == '\0') { |
|---|
| 195 | error("%s: no '%s.Font' entry from %s", Name, section, cfg_source()); |
|---|
| 196 | return -1; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | XRES = -1; |
|---|
| 200 | YRES = -1; |
|---|
| 201 | if (sscanf(s, "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) { |
|---|
| 202 | error("%s: bad Font '%s' from %s", Name, s, cfg_source()); |
|---|
| 203 | return -1; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | /* Fixme: provider other fonts someday... */ |
|---|
| 207 | if (XRES != 6 && YRES != 8) { |
|---|
| 208 | error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source()); |
|---|
| 209 | return -1; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | if (cfg_number(section, "Contrast", 128, 0, 255, &contrast) > 0) { |
|---|
| 213 | drv_LUIse_contrast(contrast); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | if (cfg_number(section, "Backlight", 0, 0, 1, &backlight) > 0) { |
|---|
| 217 | drv_LUIse_backlight(backlight); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | s = cfg_get(section, "Backpicture", NULL); |
|---|
| 221 | if (s == NULL || *s == '\0') { |
|---|
| 222 | error("%s: no '%s.Backpicture' entry from %s", Name, section, cfg_source()); |
|---|
| 223 | } else { |
|---|
| 224 | drv_LUIse_clear(); |
|---|
| 225 | if (LUI_BMPfile(devNum, 1, 0, 0, 0, 0, DCOLS, DROWS, s)) { |
|---|
| 226 | error("%s: Sorry unable to load: %s", Name, s); |
|---|
| 227 | return -1; |
|---|
| 228 | } |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | return 0; |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | /****************************************/ |
|---|
| 236 | /*** plugins ***/ |
|---|
| 237 | /****************************************/ |
|---|
| 238 | |
|---|
| 239 | static void plugin_contrast(RESULT * result, RESULT * arg1) |
|---|
| 240 | { |
|---|
| 241 | double contrast; |
|---|
| 242 | |
|---|
| 243 | contrast = drv_LUIse_contrast(R2N(arg1)); |
|---|
| 244 | SetResult(&result, R_NUMBER, &contrast); |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | static void plugin_backlight(RESULT * result, RESULT * arg1) |
|---|
| 248 | { |
|---|
| 249 | double backlight; |
|---|
| 250 | |
|---|
| 251 | backlight = drv_LUIse_backlight(R2N(arg1)); |
|---|
| 252 | SetResult(&result, R_NUMBER, &backlight); |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | /****************************************/ |
|---|
| 257 | /*** exported functions ***/ |
|---|
| 258 | /****************************************/ |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | /* list models */ |
|---|
| 262 | int drv_LUIse_list(void) |
|---|
| 263 | { |
|---|
| 264 | printf("generic"); |
|---|
| 265 | return 0; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | /* initialize driver & display */ |
|---|
| 269 | int drv_LUIse_init(const char *section, const int quiet) |
|---|
| 270 | { |
|---|
| 271 | int ret; |
|---|
| 272 | |
|---|
| 273 | info("%s: %s", Name, "$Rev$"); |
|---|
| 274 | |
|---|
| 275 | /* real worker functions */ |
|---|
| 276 | drv_generic_graphic_real_blit = drv_LUIse_blit; |
|---|
| 277 | |
|---|
| 278 | /* start display */ |
|---|
| 279 | if ((ret = drv_LUIse_start(section)) != 0) |
|---|
| 280 | return ret; |
|---|
| 281 | |
|---|
| 282 | /* initialize generic graphic driver */ |
|---|
| 283 | if ((ret = drv_generic_graphic_init(section, Name)) != 0) |
|---|
| 284 | return ret; |
|---|
| 285 | |
|---|
| 286 | if (!quiet) { |
|---|
| 287 | char buffer[40]; |
|---|
| 288 | qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); |
|---|
| 289 | if (drv_generic_graphic_greet(buffer, NULL)) { |
|---|
| 290 | sleep(3); |
|---|
| 291 | drv_generic_graphic_clear(); |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | /* register plugins */ |
|---|
| 296 | AddFunction("LCD::contrast", 1, plugin_contrast); |
|---|
| 297 | AddFunction("LCD::backlight", 1, plugin_backlight); |
|---|
| 298 | |
|---|
| 299 | return 0; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | /* close driver & display */ |
|---|
| 303 | /* use this function for a graphic display */ |
|---|
| 304 | int drv_LUIse_quit(const int quiet) |
|---|
| 305 | { |
|---|
| 306 | |
|---|
| 307 | info("%s: shutting down.", Name); |
|---|
| 308 | |
|---|
| 309 | /* clear display */ |
|---|
| 310 | drv_LUIse_clear(); |
|---|
| 311 | |
|---|
| 312 | /* set default for Contrast, ScreenRotation, gfxmode, gfxinvert, IOrefresh */ |
|---|
| 313 | LUI_SetContrast(devNum, 128); |
|---|
| 314 | LUI_LCDmode(devNum, 0, 0, 0, 2); |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | /* say goodbye... */ |
|---|
| 318 | if (!quiet) { |
|---|
| 319 | drv_generic_graphic_greet("goodbye!", NULL); |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | drv_generic_graphic_quit(); |
|---|
| 323 | |
|---|
| 324 | debug("closing connection"); |
|---|
| 325 | LUI_CloseDevice(devNum); |
|---|
| 326 | |
|---|
| 327 | return (0); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | /* use this one for a graphic display */ |
|---|
| 331 | DRIVER drv_LUIse = { |
|---|
| 332 | .name = Name, |
|---|
| 333 | .list = drv_LUIse_list, |
|---|
| 334 | .init = drv_LUIse_init, |
|---|
| 335 | .quit = drv_LUIse_quit, |
|---|
| 336 | }; |
|---|