| 1 | /* $Id$ |
|---|
| 2 | * $URL$ |
|---|
| 3 | * |
|---|
| 4 | * ST2205U-driven hacked picture frame driver. |
|---|
| 5 | * See http://picframe.spritesserver.nl/ for more info. |
|---|
| 6 | * |
|---|
| 7 | * Copyright (C) 2008 Jeroen Domburg <picframe@spritesmods.com> |
|---|
| 8 | * Modified from sample code by: |
|---|
| 9 | * Copyright (C) 2005 Michael Reinelt <michael@reinelt.co.at> |
|---|
| 10 | * Copyright (C) 2005, 2006, 2007 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net> |
|---|
| 11 | * |
|---|
| 12 | * This file is part of LCD4Linux. |
|---|
| 13 | * |
|---|
| 14 | * LCD4Linux is free software; you can redistribute it and/or modify |
|---|
| 15 | * it under the terms of the GNU General Public License as published by |
|---|
| 16 | * the Free Software Foundation; either version 2, or (at your option) |
|---|
| 17 | * any later version. |
|---|
| 18 | * |
|---|
| 19 | * LCD4Linux is distributed in the hope that it will be useful, |
|---|
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 22 | * GNU General Public License for more details. |
|---|
| 23 | * |
|---|
| 24 | * You should have received a copy of the GNU General Public License |
|---|
| 25 | * along with this program; if not, write to the Free Software |
|---|
| 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 27 | * |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | /* |
|---|
| 31 | * |
|---|
| 32 | * exported fuctions: |
|---|
| 33 | * |
|---|
| 34 | * struct DRIVER drv_st2205 |
|---|
| 35 | * |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include "config.h" |
|---|
| 39 | |
|---|
| 40 | #include <stdlib.h> |
|---|
| 41 | #include <stdio.h> |
|---|
| 42 | #include <unistd.h> |
|---|
| 43 | #include <string.h> |
|---|
| 44 | #include <errno.h> |
|---|
| 45 | |
|---|
| 46 | #include <st2205.h> |
|---|
| 47 | |
|---|
| 48 | #include "debug.h" |
|---|
| 49 | #include "cfg.h" |
|---|
| 50 | #include "qprintf.h" |
|---|
| 51 | #include "udelay.h" |
|---|
| 52 | #include "plugin.h" |
|---|
| 53 | #include "widget.h" |
|---|
| 54 | #include "widget_text.h" |
|---|
| 55 | #include "widget_icon.h" |
|---|
| 56 | #include "widget_bar.h" |
|---|
| 57 | #include "drv.h" |
|---|
| 58 | |
|---|
| 59 | #include "drv_generic_graphic.h" |
|---|
| 60 | |
|---|
| 61 | static char Name[] = "st2205"; |
|---|
| 62 | /* libst2205 handle */ |
|---|
| 63 | static st2205_handle *h; |
|---|
| 64 | /* Display data */ |
|---|
| 65 | static unsigned char *fb; |
|---|
| 66 | |
|---|
| 67 | static int drv_st2205_open(const char *section) |
|---|
| 68 | { |
|---|
| 69 | char *dev; |
|---|
| 70 | |
|---|
| 71 | dev = cfg_get(section, "Port", NULL); |
|---|
| 72 | if (dev == NULL || *dev == '\0') { |
|---|
| 73 | error("st2205: no '%s.Port' entry from %s", section, cfg_source()); |
|---|
| 74 | return -1; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | h = st2205_open(dev); |
|---|
| 78 | if (h == NULL) |
|---|
| 79 | return -1; |
|---|
| 80 | |
|---|
| 81 | return 0; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | static int drv_st2205_close(void) |
|---|
| 86 | { |
|---|
| 87 | st2205_close(h); |
|---|
| 88 | |
|---|
| 89 | return 0; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | static void drv_st2205_blit(const int row, const int col, const int height, const int width) |
|---|
| 94 | { |
|---|
| 95 | int r, c; |
|---|
| 96 | RGBA p; |
|---|
| 97 | for (r = row; r < row + height; r++) { |
|---|
| 98 | for (c = col; c < col + width; c++) { |
|---|
| 99 | p = drv_generic_graphic_rgb(r, c); |
|---|
| 100 | fb[(r * h->width + c) * 3 + 0] = p.R; |
|---|
| 101 | fb[(r * h->width + c) * 3 + 1] = p.G; |
|---|
| 102 | fb[(r * h->width + c) * 3 + 2] = p.B; |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | st2205_send_data(h, fb); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | /* start graphic display */ |
|---|
| 110 | static int drv_st2205_start2(const char *section) |
|---|
| 111 | { |
|---|
| 112 | char *s; |
|---|
| 113 | |
|---|
| 114 | s = cfg_get(section, "Font", "6x8"); |
|---|
| 115 | if (s == NULL || *s == '\0') { |
|---|
| 116 | error("%s: no '%s.Font' entry from %s", Name, section, cfg_source()); |
|---|
| 117 | return -1; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | XRES = -1; |
|---|
| 121 | YRES = -1; |
|---|
| 122 | if (sscanf(s, "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) { |
|---|
| 123 | error("%s: bad Font '%s' from %s", Name, s, cfg_source()); |
|---|
| 124 | return -1; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /* Fixme: provider other fonts someday... */ |
|---|
| 128 | if (XRES != 6 && YRES != 8) { |
|---|
| 129 | error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source()); |
|---|
| 130 | return -1; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | /* open communication with the display */ |
|---|
| 135 | if (drv_st2205_open(section) < 0) { |
|---|
| 136 | return -1; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | /* you surely want to allocate a framebuffer or something... */ |
|---|
| 140 | fb = malloc(h->height * h->width * 3); |
|---|
| 141 | |
|---|
| 142 | /* set width/height from st2205 firmware specs */ |
|---|
| 143 | DROWS = h->width; |
|---|
| 144 | DCOLS = h->height; |
|---|
| 145 | |
|---|
| 146 | return 0; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | /****************************************/ |
|---|
| 150 | /*** plugins ***/ |
|---|
| 151 | /****************************************/ |
|---|
| 152 | |
|---|
| 153 | static void plugin_backlight(RESULT * result, RESULT * arg1) |
|---|
| 154 | { |
|---|
| 155 | int bl_on; |
|---|
| 156 | bl_on = (R2N(arg1) == 0 ? 0 : 1); |
|---|
| 157 | st2205_backlight(h, bl_on); |
|---|
| 158 | SetResult(&result, R_NUMBER, &bl_on); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /****************************************/ |
|---|
| 163 | /*** widget callbacks ***/ |
|---|
| 164 | /****************************************/ |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | /* using drv_generic_text_draw(W) */ |
|---|
| 168 | /* using drv_generic_text_icon_draw(W) */ |
|---|
| 169 | /* using drv_generic_text_bar_draw(W) */ |
|---|
| 170 | /* using drv_generic_gpio_draw(W) */ |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | /****************************************/ |
|---|
| 174 | /*** exported functions ***/ |
|---|
| 175 | /****************************************/ |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | /* list models */ |
|---|
| 179 | int drv_st2205_list(void) |
|---|
| 180 | { |
|---|
| 181 | printf("generic"); |
|---|
| 182 | return 0; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | /* initialize driver & display */ |
|---|
| 187 | int drv_st2205_init2(const char *section, const int quiet) |
|---|
| 188 | { |
|---|
| 189 | int ret; |
|---|
| 190 | |
|---|
| 191 | /* real worker functions */ |
|---|
| 192 | drv_generic_graphic_real_blit = drv_st2205_blit; |
|---|
| 193 | |
|---|
| 194 | /* start display */ |
|---|
| 195 | if ((ret = drv_st2205_start2(section)) != 0) |
|---|
| 196 | return ret; |
|---|
| 197 | |
|---|
| 198 | /* initialize generic graphic driver */ |
|---|
| 199 | if ((ret = drv_generic_graphic_init(section, Name)) != 0) |
|---|
| 200 | return ret; |
|---|
| 201 | |
|---|
| 202 | if (!quiet) { |
|---|
| 203 | char buffer[40]; |
|---|
| 204 | qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); |
|---|
| 205 | if (drv_generic_graphic_greet(buffer, NULL)) { |
|---|
| 206 | sleep(3); |
|---|
| 207 | drv_generic_graphic_clear(); |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | /* register plugins */ |
|---|
| 212 | AddFunction("LCD::backlight", 1, plugin_backlight); |
|---|
| 213 | |
|---|
| 214 | return 0; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | /* close driver & display */ |
|---|
| 219 | int drv_st2205_quit2(const int quiet) |
|---|
| 220 | { |
|---|
| 221 | info("%s: shutting down.", Name); |
|---|
| 222 | |
|---|
| 223 | /* clear display */ |
|---|
| 224 | drv_generic_graphic_clear(); |
|---|
| 225 | |
|---|
| 226 | /* say goodbye... */ |
|---|
| 227 | if (!quiet) { |
|---|
| 228 | drv_generic_graphic_greet("goodbye!", NULL); |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | drv_generic_graphic_quit(); |
|---|
| 232 | |
|---|
| 233 | debug("closing connection"); |
|---|
| 234 | drv_st2205_close(); |
|---|
| 235 | |
|---|
| 236 | return (0); |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | DRIVER drv_st2205 = { |
|---|
| 241 | .name = Name, |
|---|
| 242 | .list = drv_st2205_list, |
|---|
| 243 | .init = drv_st2205_init2, |
|---|
| 244 | .quit = drv_st2205_quit2, |
|---|
| 245 | }; |
|---|