From 36b9cd6acd0607f0b9ae8b58ef74a12786faf938 Mon Sep 17 00:00:00 2001 From: reinelt Date: Mon, 28 Mar 2005 19:39:23 +0000 Subject: [lcd4linux @ 2005-03-28 19:39:14 by reinelt] HD44780/I2C patch from Luis merged (still does not work for me) git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@519 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- drv_generic_i2c.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 drv_generic_i2c.c (limited to 'drv_generic_i2c.c') diff --git a/drv_generic_i2c.c b/drv_generic_i2c.c new file mode 100644 index 0000000..5a01cdd --- /dev/null +++ b/drv_generic_i2c.c @@ -0,0 +1,155 @@ +/* $Id: drv_generic_i2c.c,v 1.1 2005/03/28 19:39:23 reinelt Exp $ + * + * generic driver helper for i2c displays + * + * Copyright (C) 2005 Luis F. Correia + * 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. + * + * + * $Log: drv_generic_i2c.c,v $ + * Revision 1.1 2005/03/28 19:39:23 reinelt + * HD44780/I2C patch from Luis merged (still does not work for me) + * + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "debug.h" +#include "qprintf.h" +#include "cfg.h" +#include "udelay.h" +#include "drv_generic_i2c.h" + +static char *Driver=""; +static char *Section=""; +static int i2c_device; + +static void my_i2c_smbus_write_byte_data(const int device, const unsigned char data) +{ + struct i2c_smbus_ioctl_data args; + args.read_write = I2C_SMBUS_WRITE; + args.command = data; + args.size = I2C_SMBUS_BYTE; + args.data = 0; + ioctl(device,I2C_SMBUS,&args); +} + +static void my_i2c_smbus_read_byte_data(const int device, const unsigned char data) +{ + struct i2c_smbus_ioctl_data args; + args.read_write = I2C_SMBUS_READ; + args.command = data; + args.size = I2C_SMBUS_BYTE; + args.data = 0; + ioctl(device,I2C_SMBUS,&args); +} + +int drv_generic_i2c_open (const char *section, const char *driver) +{ + int dev; + char *bus,*device; + + //SIGNAL_ENABLE = 0x40; + //SIGNAL_RW = 0x10; + //SIGNAL_RS = 0x20; + + udelay_init(); + + bus = cfg_get(section, "Port", NULL); + device = cfg_get(section, "Device", NULL); + dev = atoi(device); + info ("%s: initializing I2C bus %s",driver,bus); + info ("device %d",dev); + if ((i2c_device = open(bus,O_WRONLY)) < 0) { + error("%s: I2C bus %s open failed !\n",driver,bus); + return -1; + } + + info ("%s: initializing I2C slave device 0x%x",driver,dev); + if (ioctl(i2c_device,I2C_SLAVE, dev ) < 0) { + error("%s: error initializing device 0x%x\n",driver,dev); + close(i2c_device); + return -1; + } + + return 0; +} + + +int drv_generic_i2c_close (void) +{ + + close(i2c_device); + + return 0; +} + +unsigned char drv_generic_i2c_wire (const char *name, const char *deflt) +{ + unsigned char w; + char wire[256]; + char *s; + + qprintf(wire, sizeof(wire), "Wire.%s", name); + s=cfg_get (Section, wire, deflt); + if(strlen(s)==3 && strncasecmp(s,"DB",2)==0 && s[2]>='0' && s[2]<='7') { + w=s[2]-'0'; + } else if(strcasecmp(s,"GND")==0) { + w=0; + } else { + error ("%s: unknown signal <%s> for wire <%s>", Driver, s, name); + error ("%s: should be DB0..7 or GND", Driver); + return 0xff; + } + free(s); + if (w==0) { + info ("%s: wiring: [DISPLAY:%s]<==>[i2c:GND]", Driver, name); + } else { + info ("%s: wiring: [DISPLAY:%s]<==>[i2c:DB%d]", Driver, name, w); + } + + w=1<