May 15, 2013

OV5642 auto-focus on i.MX6

Before

before

After

after



Source is here.

‘Nuff said?

Probably not.

More detail is probably useful.

A word of thanks

Before the details, I’d first like to thank the folks at Ray Business Technologies for helping put this together. They have a strong team of embedded developers with competency in embedded Linux, i.MX6, and gstreamer and we wouldn’t have gotten this done without their help.

Okay, more details

For those of you using our Omnivision OV5642 parallel camera module, you may have noticed that it doesn’t do auto focus, but defaults to a long-range (infinite) focal length.

This doesn’t mean that the hardware doesn’t support it, only that the drivers supplied by Freescale were missing some key pieces.

The camera modules themselves contain a voice coil motor controlling the lense assembly and the OV5642 contains a micro-controller that knows how to drive it.

What was missing were:

How to test

We’re not going to delve too far into the details about this, but there’s a simple gstreamer utility that you can use to test it in this package:

It should compile and run on Yocto, Timesys or LTIB distributions using a command-line something like this:
~/gstcamera$ export RFS=$HOME/ltib-01.01/rootfs
~/gstcamera$ arm-fsl-linux-gnueabi-gcc 
               -L${RFS}/usr/lib/ 
               -I${RFS}/usr/include/gstreamer-0.10/ 
               -I${RFS}/usr/include/glib-2.0 
               -I${RFS}/usr/lib/glib-2.0/include/ 
               -I${RFS}/usr/include/libxml2 
               -o gstcamera 
               gstcamera.cpp 
               -lsupc++ -lpthread -lgstreamer-0.10 
               -lgobject-2.0 -lgthread-2.0 
               -lgmodule-2.0 -lglib-2.0 -lxml2 -lz
This app is a very simple wrapper around some gstreamer bits and is a total hack. It uses the gst_parse_launch() routine to parse the command line a.la. gst-launch and totally hijacks the camera file descriptor to perform the ioctl calls for auto-focus and manual focus.

Typical usage is:
~/$ gstcamera mfw_v4lsrc ! mfw_v4lsink
AF
SP0
SP255
 or  to exit
The commands supported include:
  • AF – triggers auto-focus
  • SPn – Set focus to Position n where n in the range [0..255]. 0 is furthest focal length. 255 is nearest.

Limitations

Note that this patch only applies to the OV5642 module and only in the non-Android kernel branch at the moment. Support for the OV5640 MIPI module and Android support will be added soon.

Stay tuned for more…