LCDKuro

From NAS-Central Buffalo - The Linkstation Wiki
Revision as of 16:43, 24 September 2006 by RussK (Talk)

Jump to: navigation, search

For the 8/1-9/30 2006 Contest


Contents

Goals and Wishlist for LCDKuro

This project is to add an LCD display device to the kurobox. The display will be used to provide useful information and a handy console for logging in with a keyboard.

The goals I have set for this project are

  • Provide a small console with a LCD display and a keyboard that can be used for logging in and running command line commands
  • Provide the typical LCDProc functionality Lcdproc now.gif
  • I would like to be able to provide multiple virtual consoles selected with alt-Fkey like on many typical linux distributions. This would ideally include switching between the console logins and the LCDProc functionality.
  • I would like to have the LEDs on the side of my chosen LCD device to provide some useful information, e.g. flashing for disk activity, mimic the kurobox's LEDs, blink when new mail arrives, blink when a new topic is posted to the kurobox forums, whatever.

Hardware

Crystalfontz CFA635-TMF LCD Display

I have chosen the Crystalfontz CFA635-TMF (CFA635TMFKU1) for this project. It's a 20x4 display with a USB interface, has good support in LCDProc, has some nifty buttons that might prove useful and most of all, it looks cool. It is designed to fit in a typical 5-1/4 half-height PC bay on the front panel of a PC case. I am thinking I will install the display in a small box and attach it directly onto the keyboard or set it next to the keyboard. I ordered one through the crystalfontz web site ... it includes a USB cable with the proper connector. The total cost of $81.50 includes $9.00 for shipping. This seems a bit high, but considering the cool factor of the envisioned product, I can live with it. CFA-635 TMF Front Backlight On 430.jpg


USB Keyboard

I already own a USB keyboard I am going to use for this project - if you don't have one, I think they can be had for around $10.

Software

LCDProc

The latest version of LCDProc is 0.5.0 as of 4/15/2006. I use gentoo on my kurobox, and the latest version of LCDProc available in portage is 0.4.5 which is 2 years old. As it turns out, I am using the CVS nightly build lcdproc-CVS-current-20060923 for the project, because it fixes a bug in 0.5.0.

  • Virtual Console

Someone has created a virtual console driver for LCDProc - this will come in handy for logging in to the LCD device and running command-line commands. The virtual console client for LCDProc is called lcdvc. The nightly build also fixes a bug in lcdvc, so that's another good reason for using the nightly build.

There is some talk about LCDProc 0.5.1 coming out soon. If LCDProc 0.5.1 (or better) is out as you read this, you may want to use the stable release instead of the nightly build.

Kernel Keyboard support

Using a keyboard on the kurobox requires support in the kernel. This support is not provided in the regular kurobox kernels, so a custom kernel will have to be built or possibly just a module.

At the start of the project, I discovered my kernel does not have USB Keyboard support. In my .config file I had:

 #
 # USB HID Boot Protocol drivers
 #
 # CONFIG_USB_KBD is not set

I am using Sylver's 2.6.17.1 uImage kernel I so I prepared the kernel source per his instructions he graciously provided in the kurobox forums. This is what I did to create a new kernel and keyboard modules:

# cd /usr/src
# wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.1.tar.bz2
# wget http://genbako.vodapone.com/kurobox-sources-2.6.17.patch
# wget http://www.holtmann.org/linux/kernel/patch-2.6.17-mh1.gz
# tar xjf linux-2.6.17.1.tar.bz2
# cd linux-2.6.17.1
# patch -Np1 < ../kurobox-sources-2.6.17.patch
# gzcat ../patch-2.6.17-mh1.gz | patch -Np1
# vi (or nano) Makefile # add -mh1 to EXTRAVERSION = .1, result: EXTRAVERSION = .1-mh1
# cp /boot/.config .config
# export ARCH=ppc
# make oldconfig # this step may be uneccessary but I did it anyway
# make menuconfig
# select Device Drivers -> USB support
# # navigate down to USB Human Interface Device (full HID) support
# # press 'M' to select support as a kernel module
# # Exit
# # Exit
# # Device Drivers -> Input Device Support
# # navigate down to Event Interface
# # press 'M' to select support as a kernel modules
# # Exit
# # Exit
# # Exit  Yes (Save configuration)
# make vmlinux && make modules && make modules_install

Also, to be sure since I didn't know which compiler Sylver used to build the kernel, I re-built my uImage kernel like this (I use Nijino's uboot):

# wget http://www.kurobox.com/sylver/u-boot/mkimage
# chmod 0755 mkimage
# mv mkimage /usr/bin/
# make uImage
# mv /boot/uImage /boot/uImage.bak
# cp arch/ppc/boot/images/uImage /boot/
# mv /boot/System.map /boot/System.map.bak
# mv /boot/.config /boot/.config.bak
# cp System.map /boot
# cp .config /boot

The newly built usb module is usbhid. With the new module in place in /lib/modules/kernel/2.6.17.1-mh1_kuro-box (from make modules_install), the driver can be checked with the following command:

# modprobe usbhid
# modprobe evdev
# # now plug in your keyboard
# dmesg
usb 2-1: new low speed USB device using ohci_hcd and address 3
usb 2-1: configuration #1 chosen from 1 choice
input: Logitech USB Receiver as /class/input/input2
input: USB HID v1.10 Keyboard [Logitech USB Receiver] on usb-0000:00:0e.0-1
input: Logitech USB Receiver as /class/input/input3
input: USB HID v1.10 Mouse [Logitech USB Receiver] on usb-0000:00:0e.0-1
# ls -ltr /dev/input
total 0
crw-rw---- 1 root root 13, 33 Sep 13 20:58 mouse1
crw-rw---- 1 root root 13,  2 Sep 13 20:58 js2
crw-rw---- 1 root root 13,  1 Sep 13 20:58 js1
crw-rw---- 1 root root 13,  0 Sep 13 20:58 js0
crw-rw---- 1 root root 13, 35 Sep 13 20:58 mouse3
crw-rw---- 1 root root 13, 34 Sep 13 20:58 mouse2
crw-r--r-- 1 root root 13, 63 Sep 13 20:58 mice
crw-rw---- 1 root root 13,  3 Sep 13 20:58 js3
crw-r--r-- 1 root root 13, 32 Sep 14 20:42 mouse0
crw------- 1 root root 13, 65 Sep 14 20:42 event1
crw------- 1 root root 13, 64 Sep 14 20:42 event0


My dmesg is now showing a keyboard and a mouse (I'm using a wireless logitec combo, I won't be using the mouse for this project). And, I have event0 in /dev/input. Now check to see if the keyboard is working ...

# od -c /dev/input/event0 # and press some keys
0000000   E  \f   <   _  \0 002 350 235  \0 001  \0   %  \0  \0  \0 001
0000020   E  \f   <   _  \0 002 350 245  \0  \0  \0  \0  \0  \0  \0  \0
0000040   E  \f   <   _  \0 004 334   u  \0 001  \0   %  \0  \0  \0  \0
0000060   E  \f   <   _  \0 004 334   }  \0  \0  \0  \0  \0  \0  \0  \0
0000100   E  \f   <   _  \0 005   x 263  \0 001  \0   $  \0  \0  \0 001
0000120   E  \f   <   _  \0 005   x 273  \0  \0  \0  \0  \0  \0  \0  \0
0000140   E  \f   <   _  \0 006   4   #  \0 001  \0   $  \0  \0  \0  \0
0000160   E  \f   <   _  \0 006   4   *  \0  \0  \0  \0  \0  \0  \0  \0
0000200   E  \f   <   _  \0 006 320   ]  \0 001  \0   %  \0  \0  \0 001
0000220   E  \f   <   _  \0 006 320   e  \0  \0  \0  \0  \0  \0  \0  \0
#

Kernel support for the Display

The day the display arrived. Wow, it looks great. I connected the display to my kurobox with the provided USB cable. Output in dmesg:

usb 2-1: new full speed USB device using ohci_hcd and address 5
usb 2-1: configuration #1 chosen from 1 choice

That's it. I did not expect more than that. It lit up and looked just like the picture above. Next step is to get LCDProc talking to the display.

The display also requires support in the kernel. The display uses a USB->Serial converter chip from FTDI. The driver is ftdi_sio. To get support from the kernel, a module can be built. Back to /usr/src/linux-<YourVersionHere>/:

# export ARCH=ppc
# make menuconfig
# Select Device Drivers -> USB Support -> USB Serial Converter support -> "M" -> USB FTDI Single Port Serial Driver (EXPERIMENTAL) (NEW). -> "M" ... Exit Exit Exit Exit Exit Yes
# make modules && make modules_install
# modprobe ftdi_sio
# dmesg
usbcore: registered new driver usbserial
drivers/usb/serial/usb-serial.c: USB Serial Driver core
drivers/usb/serial/usb-serial.c: USB Serial support registered for FTDI USB Serial Device
usbcore: registered new driver ftdi_sio
drivers/usb/serial/ftdi_sio.c: v1.4.3:USB FTDI Serial Converters Driver

Now plugging in the display again ... dmesg:

usb 2-1: new full speed USB device using ohci_hcd and address 6
usb 2-1: configuration #1 chosen from 1 choice
ftdi_sio 2-1:1.0: FTDI USB Serial Device converter detected
drivers/usb/serial/ftdi_sio.c: Detected FT8U232AM
usb 2-1: FTDI USB Serial Device converter now attached to ttyUSB0

There's the magic ... "converter now attached to ttyUSB0". I now have these in my /dev directory:

# ls -l /dev/tts/USB0
lrwxrwxrwx 1 root root 10 Sep  7 22:53 /dev/tts/USB0 -> ../ttyUSB0
# ls -l /dev/ttyUSB0
crw-rw---- 1 root tty 188, 0 Sep  7 22:53 /dev/ttyUSB0

Time to add myself to the tty group. I use vigr to edit the group file and add myself to the tty group. This might help avoid permission problems later when using the device:

tty:x:5:russ

Making it all work

Endian Issue with LCDProc

9/9/06 I found I could not get LCDproc up and running. It did work on my AMD64 box. I captured the output of the serial packet driver example program with usbmon and I saw byte-swapping issues. After looking at the code, it was fairly simple to fix, the only issue was a CRC word in the packet protocol. I fixed my copy and sent a patch to the LCDProc mailing list. The developers of LCDProc fixed their CVS version the same day and asked me to try their nightly build. Their nightly build is on sourceforge. Now that's what is so awesome about opensource software!

9/18/06 I am using the latest nightly build and it is working fine for me. I will post the configuration files here when they are complete.

TBD.

Virtual Consoles

I have learned that linux virtual consoles have associated devices /dev/vcs and /dev/vcsa. See "man vcs". My kurobox running gentoo had only /dev/vcs and /dev/vcsa. My reference desktop running gentoo also has /dev/vcs1, vcs2, vcs3, ... and /dev/vcsa1, etc. I had a look at the /usr/sbin/MAKEDEV script and ran "MAKEDEV console" (covering my eyes). After the dust settled, I had 64 /dev/vcs devices and 64 /dev/vcsa devices. That ought to cover me for this project!

Afterwards, I ran these commands to fix up permissions:

  • cd /dev
  • chmod g+rw vcs*
  • chmod g+rw tty*
  • chmod g+rw console


LCDProc virtual console client "lcdvc"

Someone has written a virtual console client. This client is perfect for LCDKuro.

  • Download and build lcdvc
# wget http://www.robijn.net/lcdproc/lcdvc/lcdvc-20040229.tgz
# tar xzf lcdvc-20040229.tgz

I had problems with lcdvc. I discovered I needed a patch (with my compiler (gcc 4.1.1) on the kurobox) to handle the fact that apparently a 'char' variable is implicitly unsigned. The patch for lcdvc is as follows - it is extremely simple (just change a variable c from "char" to "int"):

--- lcdvc/lcdvc.c       2003-04-30 19:42:08.000000000 -0400
+++ lcdvc-patched/lcdvc.c       2006-09-14 21:11:30.000000000 -0400
@@ -93,7 +93,7 @@

 int process_command_line( int argc, char ** argv )
 {
-       char c;
+       int c;
        char * p;
        int temp_int;
        int error = 0;

Summary of kernel drivers in .config

The following items necessary for the project are in my .config:

CONFIG_INPUT_EVDEV=m
CONFIG_INPUT_KEYBOARD=y
CONFIG_USB_KBD=m
CONFIG_USB_SERIAL=m
CONFIG_USB_SERIAL_FTDI_SIO=m


References