Developing a Linux driver for a chip with I2C registers

November 20th, 2009
Comments Off

In the past I have always hauled around a simple i2c Linux app I wrote so I could read and write I2C registers when I tried to make sense of some confusing datasheet. This was in the dark ages before there was a standard I2C sub-system in Linux.

Recently while working on a touch screen driver for the TI TPS65070 chip (the combo analog chip for the way cool OMAP-L138 SoC), I came across i2c-tools from the folks over at lm-sensors. After a quick port to the SDK framework, I ran the i2cdetect tool and got the output:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- 08 -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
20: -- 21 -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

A number (like 21 or 48) means a chip was detects and since the datasheet said my chip had address 0×48, I was seeing a response I expected. UU means a driver is controlling the chip at that I2C address. You can see the I2C address <--> driver mapping using

ls /sys/bus/i2c/drivers/*

Next, I read the TPS65070 datasheet to see how to configure the chip to post an interrupt when the screen was touched. I needed to set a couple of I2C registers and for this simple test, I poll once a second.

# step 1 - enable the ADC, select TSC input to ADC
i2cset -y 1 0x48 0x07 0x8F

# step 2 - set tsc mode to detect touch
i2cset -y 1 0x48 0x08 0x05

# step 3 - poll tsc interrupt (bit 3) until it is set
while sleep 1 ; do i2cget -y 1 0x48 0x02 ; done

Example output:

0x00
0x00
0x08
0x00
0x00

As soon as I read the I2C interrupt register, the interrupt is cleared.

There is a series of steps request to read the X and Y locations, so I wrote a simple shell script

tsc_read ()
{
    # first parameter is ASCII charcter between 0 .. 7
    tsc_mode=$1
    # set the tsc mode
    i2cset -y 1 0x48 0x08 0x8$tsc_mode
    # start the conversion on ADC input TSC
    i2cset -y 1 0x48 0x07 0xCF
    # verify we are done (shell script should be slow enough)
    # check that bit 5 is set
    i2cget -y 1 0x48 0x07
    # read the A/D converted value
    i2cget -y 1 0x48 0x0A
    i2cget -y 1 0x48 0x09
}

And now to read the X and Y locations is easy

# step 4 - read X position
tsc_read 0

# step 5 -read Y position
tsc_read 1

Example output:

# tsc_read 0
0xaf
0x01
0xf6
# tsc_read 1
0xaf
0x01
0x83

meaning on a 10 bit A/D scale 0×000 … 0×3FF (x,y) = (0×1F6, 0×183)

Overall, I found the i2c-tools very helpful in validating I understand how to interact with the chip registers properly.

Uncategorized

Updated OMAP35x Evaluation SDK

November 12th, 2009
Comments Off

We are rolling an updated OMAP35x Evaluation SDK! The highlights are:

  • Based on latest PSP from TI (based on kernel 2.6.29)
  • Support for OneNand and NAND Mistral EVMs
  • Support for integration against latest DVSDK from TI.

As usual the Evaluation SDK is a great platform to evaluate how the RidgeRun SDK give you a better time to market by speeding up your development. The professional SDK from RidgeRun includes integration for GStreamer plugins, graphical environments for the target board, professional support from our engineers, development services, training, and much more.

You download the Evaluation SDK for OMAP35x from here.

Enjoy

Gstreamer, OMAP35x ,

Updated Leopard Evaluation SDK with Camera support!

November 12th, 2009

We have (finally!) released and updated Evaluation SDK for Leopard Board. The highlights are:

  • Kernel 2.6.29 based:
    • We have added the camera patches (VGA) so the camera works with v4l2 APIS (in particular it works with gstreamer, thanks Maria!).
    • Audio patches so input and output are working with alsa (thanks Cristina!).
  • DVSDK integration with the git kernel (thanks Maria!)
  • GStreamer integration: support for encoding/decoding mpeg4 and if you download the DM355s codec combo you can enable AAC/MP3 encoding decoding (thanks Cristina!).
  • We have tested the gstreamer elements are capable of RTSP streaming.

Known issues (we will be fixing them soon):

  • No support for NAND flashing from uboot. Recommended boot modes are NFS and SD card.
  • Network interface doesn’t set a default MAC address, so an uboot network operation is required before booting.
  • Network interface issues may cause the board to lost connection over NFS.
  • Garbage on the screen during CPU overload (flickering).
  • No support for FB interface from the TIDmaiVideoSink

Even the known issues list is long we think we should have them fix soon, and want to share the new features ASAP.

Special thanks for this efforts to María Rodriguez and Cristina Murillo, our two interns from ITCR and now full time engineers, and to Miguel Aguilar, our engineer supervising their work.

Download from here.

Enjoy.

Gstreamer, LeopardBoard , ,

Making your life easier with Vala

November 8th, 2009
Comments Off

We have been watching Vala for a while now. It’s a really cool idea (and if you have programmed GObject before you know what I’m talking about).

Well, we have finally spare the time to integrate support for Vala on the RidgeRun SDK, thanks to the support by the latest automake version. This allow us to easily write vala code for the target platform and the SDK will take care of the cross compilation (and proper vala bindings for the cross compiled libraries).

There are two main points where using vala will greatly speed our customers development capabilities:

  • GStreamer: developing GStreamer applications is a lot easier if you use object oriented languages, but our experience so far using C++ bindings doesn’t provide the more elegant code possible, and when it comes to integrate it with other technologies like dbus, things start to turn complex. Vala could also be used to develop gstreamer plugins.
  • DBus: doing glib marshals is a bit of a pain. Vala does dbus interactions as beauty as they should be.

Of course there are tons of other APIs where vala will help us that we haven’t play around yet (sqlite, clutter, WebKit, etc). We are really excited about the possibilities!

If you have never see vala code, here is a simple snippet of a gst pipeline for playing audio.

using Gst;

public void main (string[] args) {
    Element src;
    Element sink;
    Pipeline pipeline;

    // Initializing GStreamer
    Gst.init (ref args);

    // Creating pipeline and elements
    // NOTE: The return type of the pipeline construction method is Element,
    // not Pipeline, so we have to cast
    pipeline = (Pipeline) new Pipeline ("test");
    src = ElementFactory.make ("audiotestsrc", "my_src");
    sink = ElementFactory.make ("autoaudiosink", "my_sink");

    // Adding elements to pipeline
    pipeline.add_many (src, sink);

    // Linking source to sink
    src.link (sink);

    // Setting waveform to square
    src.set ("wave", 1);

    // Set pipeline state to PLAYING
    pipeline.set_state (State.PLAYING);

    // Creating a GLib main loop with a default context
    var loop = new MainLoop (null, false);

    // Start GLib mainloop
    loop.run ();
}

Gstreamer

AAC/MP3 Codecs support for DM355 with GStreamer

November 3rd, 2009
Comments Off

Cristina has finished her graduation project with the Leopard board, and now we have (almost) completely AAC-LC and MP3 encode/decode support with the gstreamer plugin.

We have tested the encoders to properly generated standalone AAC or MP3 files, as well as muxplex them into a mp4/quicktime container format. The only remaining issue is related to the the encoders being unable to be used at the same time as the alsa capture driver (Cristina already ask Ittiam about the problem, but we haven’t got any feedback yet). In any case the issue is reproducible with Ittiam’s command line demo apps, so we don’t think is a gst issue.

As usual the beauty of a gstreamer solution is on the simplicity of the examples:

Encoding AAC audio into a quicktime container (two steps due the encoder bug):

gst-launch alsasrc ! audio/x-raw-int, width=16, depth=16,  endianness=1234,
channels=2, rate=44100, signed=true ! filesink location=/audio.pcm
 gst-launch -e filesrc location=/audio.pcm ! audio/x-raw-int, width=16,
depth=16,  endianness=1234, channels=2, rate=44100, signed=true !
dmaienc_aac ! qtmux ! filesink location=/audio.m4a

Decoding the AAC audio from quicktime container:

gst-launch filesrc location=/audio.mp4 ! qtdemux ! dmaidec_aac ! alsasink

Encoding AAC audio elementary stream:

gst-launch filesrc location=/audio.pcm ! audio/x-raw-int, width=16,
depth=16,  endianness=1234, channels=2, rate=44100, signed=true !
dmaienc_aac outputformat=2  ! filesink location=/audio.aac

Decoding AAC elementary stream:

gst-launch filesrc location=/audio.aac ! aacparse ! dmaidec_aac ! alsasink

Encoding MP3 elementary stream:

gst-launch -e filesrc location=/audio.pcm ! audio/x-raw-int, width=16,
depth=16,  endianness=1234, channels=2, rate=44100, signed=true !
dmaienc_mp3 ! filesink location=/audio.mp3

Decoding MP3 audio:

gst-launch filesrc location=/audio.mp3 ! mp3parse ! dmaidec_mp3 ! alsasink

The support for these features is available on DDOMPE’s branch, and will likely be available on the 2.0 release of the gst-ti-dmai plugin.

Enjoy.

Davinci, Gstreamer, LeopardBoard , ,

GStreamer TI plugins 1.01 Release is out

November 3rd, 2009
Comments Off

Thanks to the help and hard work from Todd Fischer and Diego Chaverri during this testing cycle, we just completed the testing of the 1.01 release of the GStreamer TI plugin. Thanks to everyone how contributed!

Now we are starting preparations to merge the changes for the 2.0 release. We will be publishing an updated roadmap and feature matrix on the Davinci wiki soon.

Download the 1.01 release from here.

Gstreamer

Using GStreamer with Darwin Streaming Server as RTSP server

October 27th, 2009

A frequent customer request is “how do I stream the video over the network?”.

There are some solutions out there that aren’t FOSS and if you try to extend the demo to do what you really need to do… you start running on issues. That’s the reason we push GStreamer based solutions, where the design allow simple and fast design and prototype of streaming media solutions.

We have been looking for some time to provide a FOSS solution for an RTSP server, and when we found the gst-rstsp-server, we were really happy. Kapil expended some time extending it to work for a customer scenario, but unfortunately we run into some out-of-memory situations quickly due to some design decisions on the code that assume more memory that what is typically available in embedded devices.

Then Diego stumble upon an article from some MIT folks where they used the Darwin Streaming Server (DSS) as RTSP server. This GStreamer+DSS approach have some advantages:

  • The DSS core is only C++ code with no external dependencies.
  • The DSS code base is used on production systems for media streaming.
  • We take advantage of GStreamer on where it really shines and let DSS handling the RTSP part only. Glue-less integration is possible between DSS and GStreamer.

But we also have disadvantages:

  • It’s limited to the sdp file approach. For more complex streaming scenarios it may fall short.
  • It may be that DSS is over killer.

As the article points out, they used DSS running on a PC machine, not on the Nokia device. We need to run DSS from the board, so we just rolled up our sleeves and got to work. After a couple of hours and some help from community patches to build DSS on Linux machine we finally got DSS cross compiling using RidgeRun’s SDK and running the streaming core reliable on any of our boards.

We were successful streamed video from a Leopard VGA camera using the following pipeline (using DDOMPE branch):

gst-launch v4l2src always-copy=false ! dmaiaccel ! queue ! dmaienc_mpeg4 !
rtpmp4vpay ! udpsink port=5434 -v

We require the -v option so we can get the codec_data information generated by the encoder and passed on the caps of the sink pad of the dmaienc_mpeg4 element. This information needs to be put in the sdp file as detailed below.

And the following sdp file on /streaming/movies/leopardlivecamera.sdp:

v=0
o=- 132 362358265 IN IP4 127.0.0.0
s=QuickTime
t=0 0
a=range:npt=now-
a=control:rtsp://127.0.0.1/stream.sdp
m=video 5434 RTP/AVP 96
c=IN IP4 127.0.0.1
b=AS:6000
a=rtpmap:96 MP4V-ES/90000
a=fmtp:96 profile-level-id=5;config=000001010000012000845d4c28a021e0a21f
a=mpeg4-esid:201
a=cliprect:0,0,640,480
a=framesize:96 480-640

I’m not a dsp syntax expert, so I generated the sdp file with the help of the QuickTime Broadcaster and then just adjusted the parameters to the resolution of the camera, the config string with the information from the codec_data (obtained from the pipeline), and the IP addresses to pickup the stream from the localhost.

With this setup, we are able to stream from the camera into a local port and then having the DSS running on the same board serving the RTSP clients. To connect all you need is:

vlc rtsp://10.251.101.140/leopardlivecamera.sdp

Where the 10.251.101.140 IP is obviously the address of the board we are running from.

The only issues we notice so far seem related to latency of the video, but probably some tweaking of the parameters will solve the issue.

The CPU consumption of DSS is good, and the memory consumed is low, so we got a good start.

Enjoy!

Davinci, Gstreamer, LeopardBoard , , ,

The Hawk is coming…

October 25th, 2009
Comments Off

Some news surface last week about the hawkboard.

We are looking forward on RidgeRun to get our hands in doing some work with it. We already sign up two students from the Costa Rica Institute of Technology to do their internship project with us developing algorithms with the powerful DSP available on this boards during Q1/Q2 of next year. We will be applying next week to be part of the early adopter program.

The L138 already have support for GStreamer on a branch of arago-project, but this would be a good opportunity to push for stabilization of it (and maybe include it on 2.0 release of the gst-ti project?). We could have some nice demos (as Cristina and Maria did for Leopard board) with extended DSP algorithms as elements on the pipe.

Education, Gstreamer, L13x, hawkboard , , , ,

Talking about Embedded Software development at CUC (Costa Rica)

October 25th, 2009
Comments Off

Thanks to the kind invitation from Claudio Navarro (director of the “programming school”), Diego was invited to speak at the Colegio Universitario de Cartago (CUC) in Costa Rica about the work we do at RidgeRun programming embedded systems during last week.

They are on the process of refreshing their study plan, and now considering including some elements based on the feedback provided by the industry. We hope to see the CUC students doing some work with embedded in the future, as the ITCR is doing.

Education ,

Using Gstreamer with Leopard Board Camera

October 22nd, 2009

Maria and Cristina has been working hard this semester on the Leopard Board. They are interns from the Costa Rica Institute of Technology (and soon full time members of our team).

Maria has modified (hacked?) the Leopard camera driver for 2.6.29 to play nicely with the v4l2src. The original driver is actually a hack in the way it works (YUV sensor attached to the Bayesian interface), so we require a bit of creativity to make it respond properly to the v4l2 APIS.

Cristina has added support for the DM355s codecs to gstreamer on Diego’s branch, providing DM355 gstreamer support for AAC and MP3 encoding (finally!). We are on the final test stages for the audio decoding as well. WMA was on the plans, but the Ittiams codecs haven’t been very cooperative. Cristina also added the support for the audio codec for the Leopard to the kernel.

So, as a proof of concept they just recorded the following video. The video was recorded with:

gst-launch -e v4l2src num-buffers=100 always-copy=false ! dmaiaccel ! queue
! dmaienc_mpeg4 ! qtmux ! filesink location=/test.mp4

One more thing. The camera currently have a bug, so as you will notice is recording only at 10fps.

Updated: I forgot to mention a couple things: it uses the VGA camera (we don’t have support for the other sensors yet), and we also have a demo for RTSP streaming, blogging on that later tonight.

Download the video here.

If you have a browser with HTML5 support, you may see the video below:

Enjoy.

Davinci, Education, Gstreamer, LeopardBoard