/* $Id$ * $URL$ * * driver for TREFON USB LCD displays - http://www.trefon.de * * Copyright (C) 2005 Michael Reinelt * Copyright (C) 2005 The LCD4Linux Team * * This file is part of LCD4Linux. * * LCD4Linux is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * LCD4Linux is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ /* * * exported fuctions: * * struct DRIVER drv_Trefon * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include "debug.h" #include "cfg.h" #include "qprintf.h" #include "plugin.h" #include "widget.h" #include "widget_text.h" #include "widget_icon.h" #include "widget_bar.h" #include "drv.h" #include "drv_generic_text.h" #define LCD_USB_VENDOR 0xfff0 #define LCD_USB_DEVICE 0xfffe #define PKT_START 0x02 #define PKT_BACKLIGHT 0x01 #define PKT_DATA 0x02 #define PKT_CTRL 0x06 #define PKT_END 0xff static char Name[] = "TREFON"; static usb_dev_handle *lcd; static int interface; /****************************************/ /*** hardware dependant functions ***/ /****************************************/ static int drv_TF_open(void) { struct usb_bus *busses, *bus; struct usb_device *dev; lcd = NULL; info("%s: scanning USB for TREFON LCD...", Name); usb_set_debug(0); usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if ((dev->descriptor.idVendor == LCD_USB_VENDOR) && (dev->descriptor.idProduct == LCD_USB_DEVICE)) { info("%s: found TREFON USB LCD on bus %s device %s", Name, bus->dirname, dev->filename); lcd = usb_open(dev); if (usb_set_configuration(lcd, 1) < 0) { error("%s: usb_set_configuration() failed!", Name); return -1; } interface = 0; if (usb_claim_interface(lcd, interface) < 0) { error("%s: usb_claim_interface() failed!", Name); return -1; } return 0; } } } return -1; } static int drv_TF_close(void) { usb_release_interface(lcd, interface); usb_close(lcd); return 0; } static void drv_TF_send(unsigned char *data, int size) { unsigned char buffer[64]; /* the controller always wants a 64-byte packet */ memset(buffer, 0, 64); memcpy(buffer, data, size); /* Endpoint hardcoded to 2 */ usb_bulk_write(lcd, 2, (char *) buffer, 64, 2000); } static void drv_TF_command(const unsigned char cmd) { unsigned char buffer[4] = { PKT_START, PKT_CTRL, 0, PKT_END }; buffer[2] = cmd; drv_TF_send(buffer, 4); } static void drv_TF_clear(void) { drv_TF_command(0x01); } static void drv_TF_write(const int row, const int col, const char *data, const int len) { unsigned char buffer[64]; unsigned char *p; int pos = 0; if (DCOLS == 8 && DROWS == 1) { /* 8x1 Characters */ pos = row * 0x40 + col; } else if (DCOLS == 16 && DROWS == 2) { /* 16x2 Characters */ pos = row * 0x40 + col; } else if (DCOLS == 20 && DROWS == 4) { /* 20x4 Characters */ pos = row * 0x20 + col; } else { error("%s: internal error: DCOLS=%d DROWS=%d", Name, DCOLS, DROWS); return; } /* combine the GOTO and the data into one packet */ p = buffer; *p++ = PKT_START; *p++ = PKT_CTRL; /* Goto */ *p++ = 0x80 | pos; *p++ = PKT_DATA; /* Data */ *p++ = (char) len; for (pos = 0; pos < len; pos++) { *p++ = *data++; } *p++ = PKT_END; drv_TF_send(buffer, len + 5); } static void drv_TF_defchar(const int ascii, const unsigned char *matrix) { unsigned char buffer[14]; unsigned char *p; int i; p = buffer; *p++ = PKT_START; *p++ = PKT_CTRL; *p++ = 0x40 | 8 * ascii; *p++ = PKT_DATA; *p++ = 8; /* data length */ for (i = 0; i < 8; i++) { *p++ = *matrix++ & 0x1f; } *p++ = PKT_END; drv_TF_send(buffer, 14); } static int drv_TF_backlight(int backlight) { unsigned char buffer[4] = { PKT_START, PKT_BACKLIGHT, 0, PKT_END }; if (backlight < 0) backlight = 0; if (backlight > 1) backlight = 1; buffer[2] = backlight; drv_TF_send(buffer, 4); return backlight; } /* test for existing resolutions from TREFON USB-LCDs (TEXT-Mode only) */ int drv_TF_valid_resolution(int rows, int cols) { if (rows == 1 && cols == 8) { return 0; } else if (rows == 2 && cols == 16) { return 0; } else if (rows == 4 && cols == 20) { return 0; } return -1; } static int drv_TF_start(const char *section, const int quiet) { int backlight; int rows = -1, cols = -1; char *s; s = cfg_get(section, "Size", NULL); if (s == NULL || *s == '\0') { error("%s: no '%s.Size' entry from %s", Name, section, cfg_source()); return -1; } if (sscanf(s, "%dx%d", &cols, &rows) != 2 || drv_TF_valid_resolution(rows, cols) < 0) { error("%s: bad %s.Size '%s' (only 8x1/16x2/20x4) from %s", Name, section, s, cfg_source()); free(s); return -1; } DROWS = rows; DCOLS = cols; if (drv_TF_open() < 0) { error("%s: could not find a TREFON USB LCD", Name); return -1; } if (cfg_number(section, "Backlight", 1, 0, 1, &backlight) > 0) { drv_TF_backlight(backlight); } drv_TF_clear(); /* clear display */ if (!quiet) { char buffer[40]; qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); if (drv_generic_text_greet(buffer, "www.trefon.de")) { sleep(3); drv_TF_clear(); } } return 0; } /****************************************/ /*** plugins ***/ /****************************************/ static void plugin_backlight(RESULT * result, RESULT * arg1) { double backlight; backlight = drv_TF_backlight(R2N(arg1)); SetResult(&result, R_NUMBER, &backlight); } /****************************************/ /*** widget callbacks ***/ /****************************************/ /* using drv_generic_text_draw(W) */ /* using drv_generic_text_icon_draw(W) */ /* using drv_generic_text_bar_draw(W) */ /****************************************/ /*** exported functions ***/ /****************************************/ /* list models */ int drv_TF_list(void) { printf("TREFON USB LCD"); return 0; } /* initialize driver & display */ int drv_TF_init(const char *section, const int quiet) { WIDGET_CLASS wc; int asc255bug; int ret; info("%s: %s", Name, "$Rev$"); /* display preferences */ XRES = 5; /* pixel width of one char */ YRES = 8; /* pixel height of one char */ CHARS = 8; /* number of user-defineable characters */ CHAR0 = 1; /* ASCII of first user-defineable char */ GOTO_COST = 64; /* number of bytes a goto command requires */ /* real worker functions */ drv_generic_text_real_write = drv_TF_write; drv_generic_text_real_defchar = drv_TF_defchar; /* start display */ if ((ret = drv_TF_start(section, quiet)) != 0) return ret; /* initialize generic text driver */ if ((ret = drv_generic_text_init(section, Name)) != 0) return ret; /* initialize generic icon driver */ if ((ret = drv_generic_text_icon_init()) != 0) return ret; /* initialize generic bar driver */ if ((ret = drv_generic_text_bar_init(0)) != 0) return ret; /* add fixed chars to the bar driver */ /* most displays have a full block on ascii 255, but some have kind of */ /* an 'inverted P'. If you specify 'asc255bug 1 in the config, this */ /* char will not be used, but rendered by the bar driver */ cfg_number(section, "asc255bug", 0, 0, 1, &asc255bug); drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */ if (!asc255bug) drv_generic_text_bar_add_segment(255, 255, 255, 255); /* ASCII 255 = block */ /* register text widget */ wc = Widget_Text; wc.draw = drv_generic_text_draw; widget_register(&wc); /* register icon widget */ wc = Widget_Icon; wc.draw = drv_generic_text_icon_draw; widget_register(&wc); /* register bar widget */ wc = Widget_Bar; wc.draw = drv_generic_text_bar_draw; widget_register(&wc); /* register plugins */ AddFunction("LCD::backlight", 1, plugin_backlight); return 0; } /* close driver & display */ int drv_TF_quit(const int quiet) { info("%s: shutting down.", Name); drv_generic_text_quit(); /* clear display */ drv_TF_clear(); /* say goodbye... */ if (!quiet) { drv_generic_text_greet("goodbye!", NULL); } debug("closing USB connection"); drv_TF_close(); return (0); } DRIVER drv_Trefon = { .name = Name, .list = drv_TF_list, .init = drv_TF_init, .quit = drv_TF_quit, }; 12' href='#n212'>212 213 214
ef='#n214'>214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# Plugins conf part

AC_MSG_CHECKING([which plugins to compile])
AC_ARG_WITH(
  plugins, 
  [  --with-plugins=<list>   choose which plugins to compile.]
  [                        type --with-plugins=list for a list]	
  [                        of avaible plugins],
  plugins=$withval, 
  plugins=all
)

plugins=`echo $plugins|sed 's/,/ /g'`

for plugin in $plugins; do

   case $plugin in 
      !*) 
         val="no"
         driver=`echo $plugin|cut -c 2-`
         ;;
       *) 
         val="yes"
         ;;
   esac
	
   case "$plugin" in
      list)
         AC_MSG_RESULT([TO BE DONE...])
         AC_MSG_ERROR([run ./configure --with-plugins=...])
         ;;
      all)
         PLUGIN_APM="yes"
         PLUGIN_CPUINFO="yes"
         PLUGIN_DISKSTATS="yes"
         PLUGIN_DVB="yes"
         PLUGIN_EXEC="yes"
         PLUGIN_I2C_SENSORS="yes"
         PLUGIN_IMON="yes"
         PLUGIN_ISDN="yes"
         PLUGIN_LOADAVG="yes"
         PLUGIN_MEMINFO="yes"
         PLUGIN_MYSQL="yes"
         PLUGIN_NETDEV="yes"
         PLUGIN_POP3="yes"
         PLUGIN_PPP="yes"
         PLUGIN_PROC_STAT="yes"
         PLUGIN_SETI="yes"
         PLUGIN_UNAME="yes"
         PLUGIN_UPTIME="yes"
         PLUGIN_WIRELESS="yes"
         PLUGIN_XMMS="yes"   
         ;;
      apm)
         PLUGIN_APM=$val
         ;;
      cpuinfo)
         PLUGIN_CPUINFO=$val
         ;;
      diskstats)
         PLUGIN_DISKSTATS=$val
         ;;
      dvb)
         PLUGIN_DVB=$val
         ;;
      exec)
         PLUGIN_EXEC=$val
         ;;
      i2c_sensors)
         PLUGIN_I2C_SENSORS=$val
	 ;;
      imon)
         PLUGIN_IMON=$val
         ;;
      isdn)
         PLUGIN_ISDN=$val
         ;;
      loadavg)
         PLUGIN_LOADAVG=$val
         ;;
      meminfo)
         PLUGIN_MEMINFO=$val
         ;;
      mysql)
         PLUGIN_MYSQL=$val
         ;;
      netdev)
         PLUGIN_NETDEV=$val
         ;;
      pop3)
         PLUGIN_POP3=$val
         ;;
      ppp)
         PLUGIN_PPP=$val
         ;;
      proc_stat)
         PLUGIN_PROC_STAT=$val
         ;;
      seti)
         PLUGIN_SETI=$val
         ;;
      uname)
         PLUGIN_UNAME=$val
         ;;
      uptime)
         PLUGIN_UPTIME=$val
         ;;
      wireless)
         PLUGIN_WIRELESS=$val
         ;;
      xmms)
         PLUGIN_XMMS=$val
         ;;         
      *) 	
         AC_MSG_ERROR([Unknown plugin '$plugin'])
         ;;
   esac
done

AC_MSG_RESULT([done])
if test "$PLUGIN_APM" = "yes"; then
   PLUGINS="$PLUGINS plugin_apm.o"
   AC_DEFINE(PLUGIN_APM,1,[apm plugin])
fi
if test "$PLUGIN_CPUINFO" = "yes"; then
   PLUGINS="$PLUGINS plugin_cpuinfo.o"
   AC_DEFINE(PLUGIN_CPUINFO,1,[cpuinfo plugin])
fi
if test "$PLUGIN_DISKSTATS" = "yes"; then
   PLUGINS="$PLUGINS plugin_diskstats.o"
   AC_DEFINE(PLUGIN_DISKSTATS,1,[diskstats plugin])
fi
if test "$PLUGIN_DVB" = "yes"; then
   AC_CHECK_HEADERS(linux/dvb/frontend.h, [has_dvb_header=true], [has_dvb_header=false])
   if test "$has_dvb_header" = true; then
      PLUGINS="$PLUGINS plugin_dvb.o"
      AC_DEFINE(PLUGIN_DVB,1,[dvb plugin])
   else
      AC_MSG_WARN(linux/dvb/frontend.h header not found: dvb plugin disabled)
   fi   
fi
if test "$PLUGIN_EXEC" = "yes"; then
   PLUGINS="$PLUGINS plugin_exec.o"
   AC_DEFINE(PLUGIN_EXEC,1,[exec plugin])
fi
if test "$PLUGIN_I2C_SENSORS" = "yes"; then
   PLUGINS="$PLUGINS plugin_i2c_sensors.o"
   AC_DEFINE(PLUGIN_I2C_SENSORS,1,[i2c sensors plugin])
fi
if test "$PLUGIN_IMON" = "yes"; then
   PLUGINS="$PLUGINS plugin_imon.o"
   AC_DEFINE(PLUGIN_IMON,1,[imon plugin])
fi
if test "$PLUGIN_ISDN" = "yes"; then
   AC_CHECK_HEADERS(linux/isdn.h, [has_isdn_header=true], [has_isdn_header=false])
   if test "$has_dvb_header" = false; then
      AC_MSG_WARN(linux/isdn.h header not found: isdn plugin CPS disabled)
   fi   
   PLUGINS="$PLUGINS plugin_isdn.o"
   AC_DEFINE(PLUGIN_ISDN,1,[ISDN plugin])
fi
if test "$PLUGIN_LOADAVG" = "yes"; then
   PLUGINS="$PLUGINS plugin_loadavg.o"
   AC_DEFINE(PLUGIN_LOADAVG,1,[loadavg plugin])
fi
if test "$PLUGIN_MEMINFO" = "yes"; then
   PLUGINS="$PLUGINS plugin_meminfo.o"
   AC_DEFINE(PLUGIN_MEMINFO,1,[meminfo plugin])
fi
if test "$PLUGIN_MYSQL" = "yes"; then
   AC_CHECK_HEADERS(mysql/mysql.h, [has_mysql_header=true], [has_mysql_header=false])
   if test "$has_mysql_header" = true; then	
      AC_CHECK_LIB(mysqlclient, mysql_init, [has_mysql_lib=true], [has_mysql_lib=false])
      if test "$has_mysql_lib" = true; then
        PLUGINS="$PLUGINS plugin_mysql.o"
        AC_DEFINE(PLUGIN_MYSQL,1,[mysql plugin])
        PLUGINLIBS="$PLUGINLIBS -lmysqlclient"
      else
        AC_MSG_WARN(mysqlclient lib not found: mysql plugin disabled)
      fi
   else
      AC_MSG_WARN(mysql/mysql.h header not found: mysql plugin disabled)
   fi 
fi
if test "$PLUGIN_NETDEV" = "yes"; then
   PLUGINS="$PLUGINS plugin_netdev.o"
   AC_DEFINE(PLUGIN_NETDEV,1,[netdev plugin])
fi
if test "$PLUGIN_POP3" = "yes"; then
   PLUGINS="$PLUGINS plugin_pop3.o"
   AC_DEFINE(PLUGIN_POP3,1,[POP3 plugin])
fi
if test "$PLUGIN_PPP" = "yes"; then
   AC_CHECK_HEADERS(net/if_ppp.h, [has_ppp_header=true], [has_ppp_header=false])
   if test "$has_ppp_header" = true; then
   PLUGINS="$PLUGINS plugin_ppp.o"
   AC_DEFINE(PLUGIN_PPP,1,[ppp plugin])
   else
      AC_MSG_WARN(net/if_ppp.h header not found: ppp plugin disabled)
   fi 
fi
if test "$PLUGIN_PROC_STAT" = "yes"; then
   PLUGINS="$PLUGINS plugin_proc_stat.o"
   AC_DEFINE(PLUGIN_PROC_STAT,1,[proc_stat plugin])
fi
if test "$PLUGIN_SETI" = "yes"; then
   PLUGINS="$PLUGINS plugin_seti.o"
   AC_DEFINE(PLUGIN_SETI,1,[seti plugin])
fi
if test "$PLUGIN_UNAME" = "yes"; then
   PLUGINS="$PLUGINS plugin_uname.o"
   AC_DEFINE(PLUGIN_UNAME,1,[uname plugin])
fi
if test "$PLUGIN_UPTIME" = "yes"; then
   PLUGINS="$PLUGINS plugin_uptime.o"
   AC_DEFINE(PLUGIN_UPTIME,1,[uptime plugin])
fi
if test "$PLUGIN_WIRELESS" = "yes"; then
   PLUGINS="$PLUGINS plugin_wireless.o"
   AC_DEFINE(PLUGIN_WIRELESS,1,[wireless plugin])
fi
if test "$PLUGIN_XMMS" = "yes"; then
   PLUGINS="$PLUGINS plugin_xmms.o"
   AC_DEFINE(PLUGIN_XMMS,1,[xmms plugin])
fi

#if test "$PLUGIN_" = "yes"; then
#   PLUGINS="$PLUGINS plugin_.o"
#   AC_DEFINE(PLUGIN_,1,[plugin])
#fi

if test "$PLUGINS" = ""; then
   AC_MSG_ERROR([You should include at least one plugin...])
#else
#   AC_MSG_ERROR($PLUGINS)
fi
   
AC_SUBST(PLUGINS)
AC_SUBST(PLUGINLIBS)