I was working on writing a Modbus Communication Driver for the 7395 and ran into some interesting behavior.
The device I needed to communicate with used the binary style protocol with CRC. This of course means that your data payload can and will have Null chars 0x00. Unfortunately, C/C++ functions that deal with strings or arrays of char will treat the first 0x00 as the end of the data and terminate at that point regardless of the actual size of the string.
At first, I wrote my own functions to ignore null chars by using a length parameter. This seemed to work well enough but I noticed that the data going over the port wasn't always right. Specifically, if I printed the chars with printf (using %x for each character), the data would be as expected. If I did not use printf I would get data that was consistently not what I was loading into the array.
It appeared that by observing the data I could affect it's content!
It actually turns out that this is true. The reason is that the %x argument in my printf (used to print a variable in hex format) was doing an in place cast from char to unsigned integer, thus if I did printf then broadcast the data it would be transmitted as expected.
I wound up reimplementing most of my code to use an array of integer in the first place to avoid this problem but still who would have thought?
Adventures in Embedded Development
Monday, November 29, 2010
Thursday, November 4, 2010
Yet another patch to TSLIB
Once you get everything running on the TS-TPC-73xx you'll probably notice some strange behavior from your touchscreen when you're trying to interact with applications.
When you first open a QT app and tap a widget, the mouse pointer doesn't seem to have a pre-defined location so everything works like it should that first tap. If you watch what is going on in ts_test you can see that you'll get a few readings at the place you tap with pressure=255 then when you let up you will see a final reading at those X,Y coordinates and pressure=0.
Now when you tap on again what you actually get is this:
$Timestamp: OLD Xpos OLD Ypos 255
$Timestamp: OLD Xpos OLD Ypos 0
$Timestamp: NEW Xpos NEW Ypos 255
$Timestamp: NEW Xpos NEW Ypos 255
$Timestamp: NEW Xpos NEW Ypos 255
$Timestamp: NEW Xpos NEW Ypos 0
To fix it I modified the dejitter filter. In dejitter.c do the following
Change this:
if (djt->nr == 1)
samp [count] = *s;
To this:
if (djt->nr == 1){
samp [count].tv = s->tv;
samp [count].x = s->x;
samp [count].y = s->y;
samp [count].pressure = 0;
}
Of course for this to work you need to make sure that you call the dejitter filter in your ts.conf file (if you use the settings I did this will already be taken care of for you).
When you first open a QT app and tap a widget, the mouse pointer doesn't seem to have a pre-defined location so everything works like it should that first tap. If you watch what is going on in ts_test you can see that you'll get a few readings at the place you tap with pressure=255 then when you let up you will see a final reading at those X,Y coordinates and pressure=0.
Now when you tap on again what you actually get is this:
$Timestamp: OLD Xpos OLD Ypos 255
$Timestamp: OLD Xpos OLD Ypos 0
$Timestamp: NEW Xpos NEW Ypos 255
$Timestamp: NEW Xpos NEW Ypos 255
$Timestamp: NEW Xpos NEW Ypos 255
$Timestamp: NEW Xpos NEW Ypos 0
To fix it I modified the dejitter filter. In dejitter.c do the following
Change this:
if (djt->nr == 1)
samp [count] = *s;
To this:
if (djt->nr == 1){
samp [count].tv = s->tv;
samp [count].x = s->x;
samp [count].y = s->y;
samp [count].pressure = 0;
}
Of course for this to work you need to make sure that you call the dejitter filter in your ts.conf file (if you use the settings I did this will already be taken care of for you).
Sunday, October 24, 2010
Getting TSLIB and QT Embedded on TS-TPC-7395 Debian Lenny EABI Howto
Getting everything working on Lenny/EABI is a totally different ballgame than getting it running on Etch/OABI. This guide is assuming that you are doing your development on a Ubuntu 10.10 machine (either actual hardware or in a VirtualBox VM).
The first thing you need to do is get an EABI cross compiler. Technologic provides one on it's website but it really didn't work well for me. Much better is this one:
http://freaknet.org/martin/crosstool/packages/arm-ep9312-linux-gnueabi-gcc-g++-4.1.1-glibc-2.4-crosstool_0.42-1_i686.deb
Once you download it, go ahead and double click to install via Ubuntu's software center software. Once you have the compiler installed you need a few other packages from the repositories if you don't already have them. To get what you need run the following in your terminal:
The stock TSLIB won't work for the 7390/95. You need to get a patched version. You can also run the patch on a stock version yourself. See my post http://smcrook.blogspot.com/2010/10/tslib-patchfile-text-and-link-to.html for more details.
I'm going to assume that you've downloaded the prepatched TSLIB for the rest of the guide.
Unzip Patched TSLIB in ~/Downloads
Edit ~/.bashrc and /root/.bashrc add the following
In terminal (Note: The patched TSLIB comes in a .zip file so when you unzip it it creates a second tslib-1.0 folder in the hierarchy)
Edit config.h and comment out rpc_malloc near the end of the file
Download QT Everywhere 4.5.3 from nokia
Apply TS7390/95 Color patch Per Donal's guide
Save the file and quit your text editor.
Back in your terminal:
Before you can use TSLIB you need to run ts_calibrate on your board and set up the proper environment variables. For more information I have a step by step guide here (This was originally for Etch/OABI but it will work for Lenny as well) http://smcrook.blogspot.com/2010/10/getting-tslib-working.html
The first thing you need to do is get an EABI cross compiler. Technologic provides one on it's website but it really didn't work well for me. Much better is this one:
http://freaknet.org/martin/crosstool/packages/arm-ep9312-linux-gnueabi-gcc-g++-4.1.1-glibc-2.4-crosstool_0.42-1_i686.deb
Once you download it, go ahead and double click to install via Ubuntu's software center software. Once you have the compiler installed you need a few other packages from the repositories if you don't already have them. To get what you need run the following in your terminal:
$ sudo apt-get install automake libtool build-essential
The stock TSLIB won't work for the 7390/95. You need to get a patched version. You can also run the patch on a stock version yourself. See my post http://smcrook.blogspot.com/2010/10/tslib-patchfile-text-and-link-to.html for more details.
I'm going to assume that you've downloaded the prepatched TSLIB for the rest of the guide.
Unzip Patched TSLIB in ~/Downloads
Edit ~/.bashrc and /root/.bashrc add the following
export PATH=$PATH:/usr/arm-ep9312-linux-arm-gnueabi/bin
alias arm-ep9312-linux-gnueabi-gcc='/usr/arm-ep9312-linux-arm-gnueabi/bin/gcc'
alias arm-ep9312-linux-gnueabi-g++='/usr/arm-ep9312-linux-arm-gnueabi/bin/g++'
alias arm-ep9312-linux-gnueabi-ar='/usr/arm-ep9312-linux-arm-gnueabi/bin/ar'
alias arm-ep9312-linux-gnueabi-objcopy='/usr/arm-ep9312-linux-arm-gnueabi/bin/objcopy'
alias arm-ep9312-linux-gnueabi-strip='/usr/arm-ep9312-linux-arm-gnueabi/bin/strip'
In terminal (Note: The patched TSLIB comes in a .zip file so when you unzip it it creates a second tslib-1.0 folder in the hierarchy)
$ cd ~/Downloads/tslib-1.0/tslib-1.0
$ sudo sh configure CC=arm-ep9312-linux-gnueabi-gcc CXX=arm-ep9312-linux-gnueabi-g++ PLUGIN_DIR=/usr/local/linux-arm-eabi/plugins -prefix=/usr/local/linux-arm-eabi -host=arm-linux
Edit config.h and comment out rpc_malloc near the end of the file
$ sudo make
$ sudo make install
Download QT Everywhere 4.5.3 from nokia
$ cd ~/Downloads
$ tar -xzvf qt-embedded-linux-src-4.5.3.tar.gz
$ cd qt-embedded-linux-src-4.5.3/
$ export QTDIR=$PWD
$ export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
$ cd /src/gui/embedded
$ gedit qscreenlinuxfb_qws.cpp
Apply TS7390/95 Color patch Per Donal's guide
$ cd $QTDIR/mkspecs/qws/linux-arm-gnueabi-g++
$ gedit qmake.conf
Replace the contents of the file with this:
#
# qmake configuration for building with arm-none-linux-gnueabi-g++
#
include(../../common/g++.conf)
include(../../common/linux.conf)
include(../../common/qws.conf)
QMAKE_INCDIR += /usr/local/linux-arm-eabi/include
QMAKE_LIBDIR += /usr/local/linux-arm-eabi/lib
# modifications to g++.conf
QMAKE_CC = arm-ep9312-linux-gnueabi-gcc
QMAKE_CXX = arm-ep9312-linux-gnueabi-g++
QMAKE_LINK = arm-ep9312-linux-gnueabi-g++
QMAKE_LINK_SHLIB = arm-ep9312-linux-gnueabi-g++
# modifications to linux.conf
QMAKE_AR = arm-ep9312-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-ep9312-linux-gnueabi-objcopy
QMAKE_STRIP = arm-ep9312-linux-gnueabi-strip
load(qt_config)
Save the file and quit your text editor.
Back in your terminal:
$ cd $QTDIRAs with the Etch/OABI guides, this will install the ARM compiled QT Embedded in /usr/local/Trolltech. For details on loading QT Embedded on the 7395 check out another of Donal's Guides
$ ./configure -embedded arm -xplatform qws/linux-arm-g++ -no-qvfb -depths all -qt-mouse-tslib -qt-kbd-usb -I/usr/local/arm/tslib/include -L/usr/local/arm/tslib/lib
$ make
$ sudo make install
Before you can use TSLIB you need to run ts_calibrate on your board and set up the proper environment variables. For more information I have a step by step guide here (This was originally for Etch/OABI but it will work for Lenny as well) http://smcrook.blogspot.com/2010/10/getting-tslib-working.html
TSLIB patchfile text and link to prepatched version.
Here is the patch that needs to be applied to TSLIB to get it to run on the TS-TPC-7390 and TS-TPC-7395. You can run this patch on a stock version and you should be good to go. You can also get a pre-patched version from Donal O'connor Here: http://automon.donaloconnor.net/files/tslib-1.0.zip
If you want to run the patch yourself, here is the text of the patch file you need to create (As far as I know, Blogger doesn't have a way to do file uploads so you'll need to copy and paste this into a text file then run the patch command).
If you want to run the patch yourself, here is the text of the patch file you need to create (As far as I know, Blogger doesn't have a way to do file uploads so you'll need to copy and paste this into a text file then run the patch command).
--- tslib-1.0/plugins/input-raw.c 2006-08-24 23:02:54.000000000 +0200
+++ tslib-1.0.1/plugins/input-raw.c 2008-10-24 09:55:28.000000000 +0200
@@ -97,13 +97,24 @@
case BTN_TOUCH:
if (ev.value == 0) {
/* pen up */
- samp->x = 0;
- samp->y = 0;
+ /* use last i->current_x and i->current_y values */
+ samp->x = i->current_x;
+ samp->y = i->current_y;
samp->pressure = 0;
samp->tv = ev.time;
samp++;
total++;
}
+ else if (ev.value == 1) {
+ /* pen down */
+ /* use last i->current_x and i->current_y values */
+ samp->x = i->current_x;
+ samp->y = i->current_y;
+ samp->pressure = 1;
+ samp->tv = ev.time;
+ samp++;
+ total++;
+ }
break;
}
break;
Wednesday, October 20, 2010
Building QT Apps for TS-TPC-7395
Sure building the demo apps for QT embedded is easy enough but it's a little confusing if you're not experienced with QT on how to go about creating a new project that will compile for the 7395 on your Linux box. Here's what you need to do:
First let's edit your user's .bashrc file so that we can call qmake without having to specify the entire path:
Open ~/.bashrc in the text editor of your choice and add the following to it:
So let's say you have a simple 'Hello World' QT application with just a main.cpp file. How do you compile it?
In your terminal:
Now you will have a binary file that you can transfer over to your 7395 and run.
To run your program, kill the X server (if one is running) via ctrl+alt+backspace (or if you don't have a keyboard hooked up you can always kill the process via a terminal).
Then just navigate to the directory containing your binary and run it like this:
First let's edit your user's .bashrc file so that we can call qmake without having to specify the entire path:
Open ~/.bashrc in the text editor of your choice and add the following to it:
alias ts-qmake='/usr/local/Trolltech/QtEmbedded-4.5.3-arm/bin/qmake'Once that's done you can call qmake for the Arm-Compiled QT Embedded as ts-qmake
So let's say you have a simple 'Hello World' QT application with just a main.cpp file. How do you compile it?
In your terminal:
$ cd ~/YOUR-PROJECT-DIRECTORY
$ ts-qmake -project
$ ts-qmake
$ make
Now you will have a binary file that you can transfer over to your 7395 and run.
To run your program, kill the X server (if one is running) via ctrl+alt+backspace (or if you don't have a keyboard hooked up you can always kill the process via a terminal).
Then just navigate to the directory containing your binary and run it like this:
$ ./YOURBINARY -qws
Upgrading TS-TPC-7395 to Debian Lenny with EABI
Not long after getting the stock Etch/OABI distro running with Qt embedded, I tried the QT Embedded Widgets demo apps.
For the curious, you can check out a windows demo of the various available widgets through this package here:
http://qt.nokia.com/files/embedded-widget-demos/qt-embedded-widgets-catalog/view
Unfortunately, the OABI Debian/QT Embedded is a bit sluggish on the 7395 hardware. I spoke with Donal O'Connor via email and he suggested going the EABI route as I'd likely see the performance of the QT/E apps double.
So far I've gotten the new distro running. I'm working on compiling TSlib at the moment but for now here's a guide on how to get Lenny/EABI Running.
First you need to get some files from ftp.embeddedarm.com . Once there, go to the TS-TPC-7395 (or 7390 they're basically the same machine). You will need one of the binary dd sd-card images (I chose 512mbsd-jun282010 but really any of them should be fine). Also you need to go to the distributions folder and get the Debian-Lenny-EABI distribution.
To install follow these steps:
My jump drive is named JUMP DRIVE and was mounted at /dev/sdb (linked to /media/JUMP\ DRIVE . The SD card was /dev/sdc. You will need to change device names and mount points to fit your circumstances but these are the general steps you need to take from here:
In a terminal:
This should take a few minutes then you will see your command prompt come back signaling that the job is finished.
Now lets see if everything worked out. Remove then reinsert the SD Card. You should see Ubuntu mount 2 filesystems. They will be named 1.6MB Filesystem and 482MB Filesystem respectively.
Now your sd card will have some pretty crazy partition names (mostly just long strings of numbers, nothing too memorable. What you want to do now is figure out in the terminal which is which.
To do so do this:
Here you should see your jump drive, and 2 random devices. What you need to do here is cd into one of them and see which of the two filesystems it is with the ls command.
Once you've found the 482mb filesystem in the terminal change your directory to it. Now do:
Now you need to un-tar the Lenny Filesystem you downloaded to the 482mb Filesystem. You can use the command line or you can use the GUI and move it over. In either case you will need sudo privileges.
Once you have the Lenny files on the SD Card you can either boot the 7395 off of this card as is or make the Lenny root partition bigger to use up any available unpartitioned space on the SD card.
If you want to expand the filesystem, Ubuntu's GParted won't work as it crashes when confronted with a device with a JFS filesystem. What you need to do is download the GParted Live CD and resize the filesystem from there.
Depending on the base image you dd'ed from you may find that when you boot up you are confronted with nothing but a blinking cursor followed by a blank screen. If that happens to you, simply connect the 7395 to a serial port on your pc while it is booting. You will see the boot sequence then be given an ash shell prompt. Type exit and the full Debian distro will boot. You will now see things going on with the screen on the 7395 and you can carry on as normal.
For the curious, you can check out a windows demo of the various available widgets through this package here:
http://qt.nokia.com/files/embedded-widget-demos/qt-embedded-widgets-catalog/view
Unfortunately, the OABI Debian/QT Embedded is a bit sluggish on the 7395 hardware. I spoke with Donal O'Connor via email and he suggested going the EABI route as I'd likely see the performance of the QT/E apps double.
So far I've gotten the new distro running. I'm working on compiling TSlib at the moment but for now here's a guide on how to get Lenny/EABI Running.
First you need to get some files from ftp.embeddedarm.com . Once there, go to the TS-TPC-7395 (or 7390 they're basically the same machine). You will need one of the binary dd sd-card images (I chose 512mbsd-jun282010 but really any of them should be fine). Also you need to go to the distributions folder and get the Debian-Lenny-EABI distribution.
To install follow these steps:
1. Place the files you downloaded on a USB jump drive or other external storage
2. Boot the Ubuntu 10.10 live cd
3. When Ubuntu finishes loading, click on your jump drive in the file explorer to mount it.
4. Un BZ2 the dd file
5. Insert your SD-Card
6. Find where Ubuntu is mounting your SD card (it will vary depending on the number of hard drives and other things you have installed in your system) opening GParted (System->Administration->Gparted Partition Editor). Once there you can look at your storage devices and it should be easy to deduce which /dev is the SD card.
My jump drive is named JUMP DRIVE and was mounted at /dev/sdb (linked to /media/JUMP\ DRIVE . The SD card was /dev/sdc. You will need to change device names and mount points to fit your circumstances but these are the general steps you need to take from here:
In a terminal:
$ cd /media/JUMP\ DRIVE/
$ dd if=512mbsd-jun282010.dd of=/dev/sdc
This should take a few minutes then you will see your command prompt come back signaling that the job is finished.
Now lets see if everything worked out. Remove then reinsert the SD Card. You should see Ubuntu mount 2 filesystems. They will be named 1.6MB Filesystem and 482MB Filesystem respectively.
Now your sd card will have some pretty crazy partition names (mostly just long strings of numbers, nothing too memorable. What you want to do now is figure out in the terminal which is which.
To do so do this:
$ cd /media
$ ls
Here you should see your jump drive, and 2 random devices. What you need to do here is cd into one of them and see which of the two filesystems it is with the ls command.
Once you've found the 482mb filesystem in the terminal change your directory to it. Now do:
$ rm -rf *
Now you need to un-tar the Lenny Filesystem you downloaded to the 482mb Filesystem. You can use the command line or you can use the GUI and move it over. In either case you will need sudo privileges.
Once you have the Lenny files on the SD Card you can either boot the 7395 off of this card as is or make the Lenny root partition bigger to use up any available unpartitioned space on the SD card.
If you want to expand the filesystem, Ubuntu's GParted won't work as it crashes when confronted with a device with a JFS filesystem. What you need to do is download the GParted Live CD and resize the filesystem from there.
Depending on the base image you dd'ed from you may find that when you boot up you are confronted with nothing but a blinking cursor followed by a blank screen. If that happens to you, simply connect the 7395 to a serial port on your pc while it is booting. You will see the boot sequence then be given an ash shell prompt. Type exit and the full Debian distro will boot. You will now see things going on with the screen on the 7395 and you can carry on as normal.
Tuesday, October 19, 2010
Getting TSLIB working
I emailed Donal O'Connor last night to ask if he had a compiled copy of TSLIB. He sent me his zip file this morning and I was able to get it working with the TS-TPC-7395.
Here is what I did:
On the development VM, Unzip the compiled TSLIB
On the 7395
$ mkdir /usr/local/linux-arm
$ chown -R eclipse:eclipse /usr/local/linux-arm
Back in the Dev VM
$ cp -r linux-arm/ /usr/local/
$ scp -r linux-arm/ eclipse@192.168.0.50:/usr/local/
Back on the 7395
$ vi /root/.bashrc
Add the following lines to ./bashrc
export TSLIB_TSEVENTTYPE=H3600
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/usr/local/linux-arm/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/local/linux-arm/lib/ts
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/linux-arm/lib/:/usr/local/lib:/usr/local/Trolltech/QtEmbedded-4.5.3-arm/lib/
$ export QWS_MOUSE_PROTO=Tslib
Back in the terminal:
$ su (reload bashrc)$ cd /usr/local/linux-arm/etc$ cp ts.conf ts.conf.old$ rm ts.conf$ vi ts.conf
Add the following lines to the new file (Do not add any blank lines!)
module_raw input
module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear
Save the document and exit
$chmod 777 /dev/input/event0$cd /usr/local/linux-arm/bin$ ./ts_calibrate
Subscribe to:
Posts (Atom)