/* $Id$ * $URL$ * * sample lcd4linux driver * * Copyright (C) 2005 Michael Reinelt * Copyright (C) 2005, 2006, 2007 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_Sample * */ #include "config.h" #include #include #include #include #include #include "debug.h" #include "cfg.h" #include "qprintf.h" #include "udelay.h" #include "plugin.h" #include "widget.h" #include "widget_text.h" #include "widget_icon.h" #include "widget_bar.h" #include "drv.h" /* text mode display? */ #include "drv_generic_text.h" /* graphic display? */ #include "drv_generic_graphic.h" /* GPO's? */ #include "drv_generic_gpio.h" /* serial port? */ #include "drv_generic_serial.h" /* parallel port? */ #include "drv_generic_parport.h" /* i2c bus? */ #ifdef WITH_I2C #include "drv_generic_i2c.h" #endif static char Name[] = "Sample"; /* for parallel port displays only */ /* use whatever lines you need */ static unsigned char SIGNAL_RS; static unsigned char SIGNAL_EX; /****************************************/ /*** hardware dependant functions ***/ /****************************************/ /* low-level parallel port stuff */ /* example for sending one byte over the wire */ static void drv_Sample_bang(const unsigned int data) { /* put data on DB1..DB8 */ drv_generic_parport_data(data & 0xff); /* set/clear some signals */ drv_generic_parport_control(SIGNAL_RS, SIGNAL_RS); /* data setup time (e.g. 200 ns) */ ndelay(200); /* send byte */ /* signal pulse width 500ns */ drv_generic_parport_toggle(SIGNAL_EX, 1, 500); /* wait for command completion (e.g. 100 us) */ udelay(100); } static int drv_Sample_open(const char *section) { /* open serial port */ /* don't mind about device, speed and stuff, this function will take care of */ if (drv_generic_serial_open(section, Name, 0) < 0) return -1; /* opening the parallel port is a bit more tricky: */ /* you have to do all the bit-banging yourself... */ if (drv_generic_parport_open(section, Name) != 0) { error("%s: could not initialize parallel port!", Name); return -1; } /* read the wiring from config */ if ((SIGNAL_EX = drv_generic_parport_wire_ctrl("EX", "STROBE")) == 0xff) return -1; if ((SIGNAL_RS = drv_generic_parport_wire_ctrl("RS", "INIT")) == 0xff) return -1; /* clear all signals */ drv_generic_parport_control(SIGNAL_EX | SIGNAL_RS, 0); /* set direction: write */ drv_generic_parport_direction(0); return 0; } static int drv_Sample_close(void) { /* close whatever port you'v
LCD4Linux Coding Style

We decided to use a common coding style to make patches and diffs 
easier to read and apply.

The style we use is based on Kernighan & Ritchie and the coding style 
of the linux kernel (see /usr/src/linux/Documentation/CodingStyle),
with some differences:

- we use a indentation level of 4 spaces (Linus prefers 8)
- we allow lines up to 150 chars (Linus uses 80)

The resulting indent command is:
indent -kr -l150

There's a script called 'indent.sh' that comes with the LCD4Linux 
source package; all it does is call indent with all .c and .h files.

It is always a good idea to call 'indent.sh' before any CVS operation,
this ensures that diffs and updates won't get mixed up because of
cosmetic changes.
/* display preferences */ XRES = 5; /* pixel width of one char */ YRES = 8; /* pixel height of one char */ CHARS = 8; /* number of user-defineable characters */ CHAR0 = 0; /* ASCII of first user-defineable char */ GOTO_COST = 2; /* number of bytes a goto command requires */ /* real worker functions */ drv_generic_text_real_write = drv_Sample_write; drv_generic_text_real_defchar = drv_Sample_defchar; /* remove unless you have GPO's */ drv_generic_gpio_real_set = drv_Sample_GPO; /* start display */ if ((ret = drv_Sample_start(section)) != 0) return ret; if (!quiet) { char buffer[40]; qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); if (drv_generic_text_greet(buffer, "www.bwct.de")) { sleep(3); drv_Sample_clear(); } } /* 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 */ drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */ /* initialize generic GPIO driver */ /* remove unless you have GPO's */ if ((ret = drv_generic_gpio_init(section, Name)) != 0) return ret; /* 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::contrast", 1, plugin_contrast); return 0; } /* initialize driver & display */ /* use this function for a graphic display */ int drv_Sample_init2(const char *section, const int quiet) { int ret; /* real worker functions */ drv_generic_graphic_real_blit = drv_Sample_blit; /* remove unless you have GPO's */ drv_generic_gpio_real_set = drv_Sample_GPO; /* start display */ if ((ret = drv_Sample_start2(section)) != 0) return ret; /* initialize generic graphic driver */ if ((ret = drv_generic_graphic_init(section, Name)) != 0) return ret; if (!quiet) { char buffer[40]; qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); if (drv_generic_graphic_greet(buffer, NULL)) { sleep(3); drv_generic_graphic_clear(); } } /* register plugins */ AddFunction("LCD::contrast", 1, plugin_contrast); return 0; } /* close driver & display */ /* use this function for a text display */ int drv_Sample_quit(const int quiet) { info("%s: shutting down.", Name); drv_generic_text_quit(); /* remove unless you have GPO's */ drv_generic_gpio_quit(); /* clear display */ drv_Sample_clear(); /* say goodbye... */ if (!quiet) { drv_generic_text_greet("goodbye!", NULL); } debug("closing connection"); drv_Sample_close(); return (0); } /* close driver & display */ /* use this function for a graphic display */ int drv_Sample_quit2(const int quiet) { info("%s: shutting down.", Name); /* clear display */ drv_generic_graphic_clear(); /* remove unless you have GPO's */ drv_generic_gpio_quit(); /* say goodbye... */ if (!quiet) { drv_generic_graphic_greet("goodbye!", NULL); } drv_generic_graphic_quit(); debug("closing connection"); drv_Sample_close(); return (0); } /* use this one for a text display */ DRIVER drv_Sample = { .name = Name, .list = drv_Sample_list, .init = drv_Sample_init, .quit = drv_Sample_quit, }; /* use this one for a graphic display */ DRIVER drv_Sample2 = { .name = Name, .list = drv_Sample_list, .init = drv_Sample_init2, .quit = drv_Sample_quit2, };