drivers: add lcd display support
Subsystems (5)
PATCH 1/1 drivers: add lcd display support
Please tell me if you agree.
Adds LCD Display support.
Adds ks0108 LCD controller support.
Adds cfag12864b LCD display support.
---
Documentation/drivers/lcddisplay/cfag12864b +367 -0
@@ -0,0 +1,367 @@ + =============================== + cfag12864b Driver Documentation + =============================== + +License: GPL +Author & Maintainer: Miguel Ojeda Sandonis <[email protected]> +Date: 2006-09-12 + + + +-------- +0. INDEX +-------- + + 1. DEVICE INFORMATION + 2. WIRING + 3. USER-SPACE PROGRAMMING + 3.1. ioctl and a 128*64 boolean matrix + 3.2. Direct writing + 4. USEFUL FILES + 4.1. cfag12864b.h + 4.2. bmpwriter.h + + + +--------------------- +1. DEVICE INFORMATION +--------------------- + +Manufacturer: Crystalfontz +Webpage: http://www.crystalfontz.com +Device Webpage: http://www.crystalfontz.com/products/12864b/ +Type: LCD Display +Width: 128 +Height: 64 +Colors: 2 +Controller: ks0108 +Controllers: 2 +Pages: 8 each controller +Addresses: 64 each page + + + +--------- +2. WIRING +--------- + +The cfag12864b LCD Display Series don't have a official wiring. + +The common wiring is done to the parallel port: + +http://www.skippari.net/lcd/sekalaista/crystalfontz_cfag12864B-TMI-V.png + +You can get help at Crystalfontz and LCDInfo forums. + + + +------------------------- +3. USER-SPACE PROGRAMMING +------------------------- + +Include a copy of the provided header: + + #include "cfag12864b.h" + +Open the device for writing, /dev/cfag12864b0: + + int fd = open("/dev/cfag12864b0",O_WRONLY); + +Then use simple ioctl calls to control it: + + ioctl(fdisplay,CFAG12864B_IOCOFF); /* Turn off (don't clear) */ + ioctl(fdisplay,CFAG12864B_IOCON); /* Turn on */ + ioctl(fdisplay,CFAG12864B_IOCCLEAR); /* Clear the display */ + +For writing to the display, you have two options: + + +3.1. ioctl & 128*64 boolean matrix +------------------------------------------------------- + +This method is easier, but you have to update the entire display +each time you want to change it. + +Note: + + CFAG12864B_FORMATSIZE == + CFAG12864B_WIDTH * CFAG12864B_HEIGHT == + 128 * 64 + +Declare the matrix and other one: + + unsigned char MyDrawing[CFAG12864B_WIDTH][CFAG12864B_HEIGHT]; + + unsigned char Buffer[CFAG12864B_FORMATSIZE]; + +Copy the 2d matrix to the buffer , like: + + for(i=0;i<CFAG12864B_WIDTH;++i) + for(j=0;j<CFAG12864B_HEIGHT;++j) + Buffer[i+j*CFAG12864B_WIDTH]=MyDrawing[i][j]; + +Call the ioctl: + + ioctl(fdisplay,CFAG12864B_IOCFORMAT,Buffer); + +Voila! Your drawing should appear on the screen. + + + +3.2. Direct writing +------------------- + +This methods allows you to change each byte of the device, +so you can achieve a higher update rate. + +The device size is 1024 == CFAG12864B_SIZE. + +You can write and seek the device. The first 512 bytes write to +the first k0108 controller (left display half) and the last 512 bytes +write to the second ks0108 controller (right display half). + +Each controller is divided into 8 pages. Each page has 64 bytes. + + Controller 0 Controller 1 + _________________________ +Page 0 |____________|____________| +Page 1 |____________|____________| +Page 2 |____________|____________| +Page 3 |____________|____________| +Page 4 |____________|____________| +Page 5 |____________|____________| +Page 6 |____________|____________| +Page 7 |____________|____________| + <--- 64 ---> + +You will understand how the device work executing some commands: + + # echo -n A > /dev/cfag12864b0 + # echo -n a > /dev/cfag12864b0 + # echo AAAAAA > /dev/cfag12864b0 + # echo 000000 > /dev/cfag12864b0 + # echo Hello world! > /dev/cfag12864b0 + # echo Hello world! Hello world! > /dev/cfag12864b0 + +After you understand it, code your functions to change specific bytes. + +Use write() and lseek() system calls, like: + + lseek(fdisplay,ipage*CFAG12864B_HEIGHT,SEEK_SET); + lseek(fdisplay,icontroller*CFAG12864B_SIZE/2,SEEK_SET); + + write(fdisplay,bufpage,CFAG12864B_HEIGHT); + write(fdisplay,bufcontroller,CFAG12864B_SIZE/2); + write(fdisplay,bufdisplay,CFAG12864B_SIZE); + + +--------------- +4. USEFUL FILES +--------------- + + +4.1 cfag12864b.h +---------------- + +You can use a copy of this header in your user-space programs. + +--- +/* + * Filename: cfag12864b.h + * Version: 0.1.0 + * Description: cfag12864b LCD Display Driver Header for user-space apps + * + * Author: Miguel Ojeda Sandonis <[email protected]> + * Date: 2006-09-12 + */ + +#ifndef _CFAG12864B_H_ +#define _CFAG12864B_H_ + +#include <sys/ioctl.h> + +#define CFAG12864B_WIDTH 128 +#define CFAG12864B_HEIGHT 64 +#define CFAG12864B_FORMATSIZE CFAG12864B_WIDTH*CFAG12864B_HEIGHT +#define CFAG12864B_SIZE 1024 + +#define CFAG12864B_IOC_MAGIC 0xFF + +#define CFAG12864B_IOCOFF _IO(CFAG12864B_IOC_MAGIC,0) +#define CFAG12864B_IOCON _IO(CFAG12864B_IOC_MAGIC,1) +#define CFAG12864B_IOCCLEAR _IO(CFAG12864B_IOC_MAGIC,2) +#define CFAG12864B_IOCFORMAT _IOW(CFAG12864B_IOC_MAGIC,3,void *) + +#endif // _CFAG12864B_H_ +--- + + + +4.2 Example BMP writer +---------------------- + +You can take ideas from this code. It reads a .bmp 128x64 2-colors file, +convert it to a boolean [128*64] buffer and then use +ioctl to display it on the screen. + +--- +/* + * Filename: bmpwriter.h + * Version: 0.1.0 + * Description: BMP Writer sample app + * + * Author: Miguel Ojeda Sandonis <[email protected]> + * Date: 2006-09-12 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include "cfag12864b.h" + +#define BMP_SIZE 1024 + +union dword +{ + unsigned int u32; + unsigned char u8[4]; +}; + +#define Bit(n) ((unsigned char)(1<<(n))) + +void BMP2Format( + unsigned char _Src[BMP_SIZE], + unsigned char _Dest[CFAG12864B_FORMATSIZE]) +{ + const unsigned int Width = CFAG12864B_WIDTH; + const unsigned int Height = CFAG12864B_HEIGHT; + const unsigned int Bits = 8; + + unsigned int Y,X,Bit; + + for(Y=0; Y<Height; ++Y) + for(X=0; X<Width/Bits; ++X) + for(Bit=0; Bit<Bits; ++Bit) + _Dest[X*Bits+Bit+(Height-Y-1)*Width] = + _Src[Y*Width/Bits+X]&Bit(Bits-Bit-1)?0:1; +} + +int main(int argc, char * argv[]) +{ + const unsigned int Width = CFAG12864B_WIDTH; + const unsigned int Height = CFAG12864B_HEIGHT; + const unsigned int Size = CFAG12864B_SIZE; + const unsigned int BPP = 1; + const unsigned int HeaderSize = 0x3E; + const unsigned int BMPSize = BMP_SIZE; + + unsigned char c; + unsigned int i,j; + union dword n; + + unsigned char Buffer_BMP[BMP_SIZE]; + unsigned char Buffer_Matrix[CFAG12864B_FORMATSIZE]; + + int fdisplay; + FILE * fbmp; + + // Check args + if(argc!=3) { + printf("%s: Bad number of arguments. Expected 3\n", + argv[0]); + return -1; + } + + // Open file + fbmp = fopen(argv[2],"rb"); + if(fbmp==NULL) { + printf("%s: Can't open %s\n",argv[0], argv[2]); + return -2; + } + + // Check file size + fseek(fbmp,0,SEEK_END); + i=ftell(fbmp); + if(i!=HeaderSize+Size) { + printf("%s: Bad file size. %i instead of %i\n", + argv[0], i, HeaderSize+Size); + fclose(fbmp); + return -3; + } + + // Check both magic BMP bytes + fseek(fbmp,0,SEEK_SET); + c = fgetc(fbmp); + if(c!='B') { + printf("%s: Bad first magic byte. '%c' instead of 'B'\n", + argv[0], c); + fclose(fbmp); + return -4; + } + c = fgetc(fbmp); + if(c!='M') { + printf("%s: Bad second magic byte. '%c' instead of 'M'\n", + argv[0], c); + fclose(fbmp); + return -5; + } + + // Check this is a 128x64 1-bpp BMP file + fseek(fbmp,0x12,SEEK_SET); + for(i=0; i<4; ++i) + n.u8[i] = fgetc(fbmp); + if(n.u32!=Width) { + printf("%s: Bad width. %i instead of %i\n", + argv[0], n.u32, Width); + fclose(fbmp); + return -6; + } + for(i=0; i<4; ++i) + n.u8[i] = fgetc(fbmp); + if(n.u32!=Height) { + printf("%s: Bad width. %i instead of %i\n", + argv[0], n.u32, Height); + fclose(fbmp); + return -7; + } + fseek(fbmp,0x1C,SEEK_SET); + c = fgetc(fbmp); + if(c!=BPP) { + printf("%s: Bad bpp. %i instead of %i\n", + argv[0], c, BPP); + fclose(fbmp); + return -8; + } + + // Get bitmap data + fseek(fbmp,0x3E,SEEK_SET); + fread(Buffer_BMP,1,BMPSize,fbmp); + fclose(fbmp); + + // Transform BMP data to 2D matrix + BMP2Format(Buffer_BMP,Buffer_Matrix); + + // Open file + fdisplay = open(argv[1],O_WRONLY); + if(fdisplay < 0) { + printf("%s: Can't open %s\n", argv[0], argv[1]); + return -9; + } + + // Send matrix + ioctl(fdisplay,CFAG12864B_IOCFORMAT,Buffer_Matrix); + + // Close file + close(fdisplay); + + return 0; +} +--- + + +EOF
Documentation/drivers/lcddisplay/lcddisplay +37 -0
@@ -0,0 +1,37 @@ + ================================= + LCD Display Drivers Documentation + ================================= + +License: GPL +Author & Maintainer: Miguel Ojeda Sandonis <[email protected]> +Date: 2006-09-12 + +-------- +0. INDEX +-------- + + 1. NEW DISPLAY DRIVERS + 2. GENERAL TIPS + + + +---------------------- +1. NEW DISPLAY DRIVERS +---------------------- + +Feel free to send me new display drivers. I will try to do my best. + +If you don't get any answer, send your patch directly to the linux-kernel ml. + + + +--------------- +2. GENERAL TIPS +--------------- + +- Divide your driver into the controller driver, like ks0108, + and the specific LCD display series driver, like cfag12864b. + +- Claim for your IO ports in the controller driver. + +EOF
Documentation/ioctl-number.txt +2 -0
@@ -191,3 +191,5 @@ Code Seq# Include File Comments <mailto:[email protected]> 0xF3 00-3F video/sisfb.h sisfb (in development) <mailto:[email protected]> +0xFF 00-1F linux/cfag12864b.h cfag12864b LCD Display Driver + <mailto:[email protected]>
drivers/Kconfig +2 -0
@@ -74,4 +74,6 @@ source "drivers/rtc/Kconfig" source "drivers/dma/Kconfig" +source "drivers/lcddisplay/Kconfig" + endmenu
drivers/lcddisplay/cfag12864b.c +558 -0
558 lines not on this page · raw message
drivers/lcddisplay/Kconfig +61 -0
61 lines not on this page · raw message
drivers/lcddisplay/ks0108.c +175 -0
175 lines not on this page · raw message
drivers/lcddisplay/lcddisplay.c +71 -0
71 lines not on this page · raw message
drivers/lcddisplay/Makefile +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the kernel LCD Display device drivers. +# + +obj-$(CONFIG_LCDDISPLAY) += lcddisplay.o +obj-$(CONFIG_KS0108) += ks0108.o +obj-$(CONFIG_CFAG12864B) += cfag12864b.o
drivers/Makefile +1 -0
@@ -76,3 +76,4 @@ obj-$(CONFIG_CRYPTO) += crypto/ obj-$(CONFIG_SUPERH) += sh/ obj-$(CONFIG_GENERIC_TIME) += clocksource/ obj-$(CONFIG_DMA_ENGINE) += dma/ +obj-$(CONFIG_LCDDISPLAY) += lcddisplay/
include/linux/cfag12864b.h +45 -0
45 lines not on this page · raw message
include/linux/ks0108.h +21 -0
@@ -0,0 +1,21 @@ +/* +* Filename: ks0108.h +* Version: 0.1.0 +* Description: ks0108 LCD Display Controller Driver Header +* License: GPL +* +* Author: Miguel Ojeda Sandonis <[email protected]> +* Date: 2006-09-12 +*/ + +#ifndef _KS0108_H_ +#define _KS0108_H_ + +extern void ks0108_writedata (unsigned char byte); +extern void ks0108_writecontrol (unsigned char byte); +extern void ks0108_displaystate (unsigned char state); +extern void ks0108_startline (unsigned char startline); +extern void ks0108_address (unsigned char address); +extern void ks0108_page (unsigned char page); + +#endif /* _KS0108_H_ */
include/linux/lcddisplay.h +19 -0
@@ -0,0 +1,19 @@ +/* +* Filename: lcddisplay.h +* Version: 0.1.0 +* Description: Display Class Header +* License: GPL +* +* Author: Miguel Ojeda Sandonis <[email protected]> +* Date: 2006-09-12 +*/ + +#ifndef _LCDDISPLAY_H_ +#define _LCDDISPLAY_H_ + +#include <linux/device.h> + +extern struct class * lcddisplay_class; + +#endif /* _LCDDISPLAY_H_ */ +
CREDITS +8 -0
@@ -2535,6 +2535,14 @@ S: Subiaco, 6008 S: Perth, Western Australia S: Australia +N: Miguel Ojeda Sandonis +E: [email protected] +D: Author: LCD Display Drivers (ks0108, cfag12864b) +D: Maintainer: LCD Display Drivers Tree (drivers/lcddisplay/*) +S: C/ Mieses 20, 9-B +S: Valladolid 47009 +S: Spain + N: Greg Page E: [email protected] D: IPX development and support
MAINTAINERS +5 -0
@@ -1707,6 +1707,11 @@ M: [email protected] L: [email protected] S: Maintained +LCD DISPLAY DRIVERS +P: Miguel Ojeda Sandonis +M: [email protected] +S: Maintained + LED SUBSYSTEM P: Richard Purdie M: [email protected]
Hi!
Quoted 13 lines
Please tell me if you agree.
Adds LCD Display support.
Adds ks0108 LCD controller support.
Adds cfag12864b LCD display support.Signed-off-by Miguel Ojeda Sandonis <[email protected]>diff -uprN -X linux-2.6.18-rc7/Documentation/dontdiff
linux-2.6.18-rc7-vanilla/drivers/lcddisplay/cfag12864b.clinux-2.6.18-rc7/drivers/lcddisplay/cfag12864b.c
drivers/lcddisplay/cfag12864b.c line 5
Quoted 5 lines
drivers/lcddisplay/cfag12864b.c +5
-0@@ -0,0 +1,558 @@ +/* +* Filename: cfag12864b.c +* Version: 0.1.0 +* Description: cfag12864b LCD Display Driver +* License: GPL
v2 or v2 and later?
drivers/lcddisplay/cfag12864b.c line 33
Quoted 1 line
drivers/lcddisplay/cfag12864b.c +1
-0+static const unsigned int cfag12864b_firstminor =0 ;
No need to initialize to zero.
drivers/lcddisplay/cfag12864b.c line 35
Quoted 2 lines
drivers/lcddisplay/cfag12864b.c +2
-0+static const unsigned int cfag12864b_ndevices =1 ; +static const char * cfag12864b_name =NAME ;
~- kill this space.
drivers/lcddisplay/cfag12864b.c line 50
Quoted 2 lines
drivers/lcddisplay/cfag12864b.c +2
-0+#define bit (n) ((unsigned char)(1<<(n))) +#define nobit (n) ((unsigned char)(~bit(n)))
Uh? We have generic functions for this.
drivers/lcddisplay/cfag12864b.c line 61
Quoted 1 line
drivers/lcddisplay/cfag12864b.c +1
-0+static unsigned char cfag12864b_state =0 ;
No zeros.
drivers/lcddisplay/cfag12864b.c line 70
Quoted 3 lines
drivers/lcddisplay/cfag12864b.c +3
-0+static void cfag12864b_e (unsigned char state) +{ +if (state)
~ missing space.
drivers/lcddisplay/cfag12864b.c line 74
Quoted 4 lines
drivers/lcddisplay/cfag12864b.c +4
-0+ cfag12864b_state |=bit (0 ); + else + cfag12864b_state &= nobit(0); +cfag12864b_set ();
This repeats few times, perhaps you could create helper for that?
drivers/lcddisplay/cfag12864b.c line 118
Quoted 7 lines
drivers/lcddisplay/cfag12864b.c +7
-0+static void cfag12864b_secondcontroller (unsigned char state) +{ +if (state) +cfag12864b_cs2 (0 ); +else +cfag12864b_cs2 (1 ); +}
Is this needed?
Quoted 6 lines
drivers/lcddisplay/cfag12864b.c +6
-0+/*if(address != tmpaddress) { +address = tmpaddress; +cfag12864b_address(address); +cfag12864b_nop(); +}*/ +
drivers/lcddisplay/cfag12864b.c line 286
Quoted 10 lines
drivers/lcddisplay/cfag12864b.c +10
-0+/*if(tmpcontroller == 0) { +if(address != tmpaddress) { +address = tmpaddress; +cfag12864b_address(address); +} +} +else { +cfag12864b_address(tmpaddress); +cfag12864b_nop(); +}*/
Remove unused code, do not comment it out.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Ack, thank you for your review!
Quoted 84 lines · Pavel Machek
Hi!
Quoted 13 lines
Please tell me if you agree.
Adds LCD Display support.
Adds ks0108 LCD controller support.
Adds cfag12864b LCD display support.Signed-off-by Miguel Ojeda Sandonis <[email protected]>diff -uprN -X linux-2.6.18-rc7/Documentation/dontdiff
linux-2.6.18-rc7-vanilla/drivers/lcddisplay/cfag12864b.clinux-2.6.18-rc7/drivers/lcddisplay/cfag12864b.cdrivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 5
Quoted 5 lines
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +5
-0@@ -0,0 +1,558 @@ +/* + * Filename: cfag12864b.c + * Version: 0.1.0 + * Description: cfag12864b LCD Display Driver + * License: GPLv2 or v2 and later?
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 6
Quoted 1 line
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +1
-0+static const unsigned int cfag12864b_firstminor = 0;No need to initialize to zero.
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 8
Quoted 2 lines
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +2
-0+static const unsigned int cfag12864b_ndevices = 1; +static const char * cfag12864b_name = NAME;~- kill this space.
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 10
Quoted 2 lines
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +2
-0+#define bit(n) ((unsigned char)(1<<(n))) +#define nobit(n) ((unsigned char)(~bit(n)))Uh? We have generic functions for this.
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 11
Quoted 1 line
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +1
-0+static unsigned char cfag12864b_state = 0;No zeros.
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 14
Quoted 3 lines
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +3
-0+static void cfag12864b_e(unsigned char state) +{ + if(state)~ missing space.
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 18
Quoted 4 lines
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +4
-0+ cfag12864b_state |= bit(0); + else + cfag12864b_state &= nobit(0); + cfag12864b_set();This repeats few times, perhaps you could create helper for that?
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 25
Quoted 7 lines
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +7
-0+static void cfag12864b_secondcontroller(unsigned char state) +{ + if(state) + cfag12864b_cs2(0); + else + cfag12864b_cs2(1); +}Is this needed?
Quoted 6 lines
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +6
-0+ /*if(address != tmpaddress) { + address = tmpaddress; + cfag12864b_address(address); + cfag12864b_nop(); + }*/ +drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 line 41
Quoted 10 lines
drivers/lcddisplay/cfag12864b.c 2006-09-13 05:03:29.000000000 +0200 renamed from drivers/lcddisplay/cfag12864b.c 1970-01-01 01:00:00.000000000 +0100 +10
-0+ /*if(tmpcontroller == 0) { + if(address != tmpaddress) { + address = tmpaddress; + cfag12864b_address(address); + } + } + else { + cfag12864b_address(tmpaddress); + cfag12864b_nop(); + }*/Remove unused code, do not comment it out.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html