Skip to content

Oscar Software Framework Manual Camera Sensor Module

scs edited this page Jul 16, 2012 · 3 revisions

Go to Table of Contents.

Table of Contents

Camera Sensor Module (cam)

Description

The camera module provides the possibility to interact with the Micron MT9V032 CMOS sensor. This consists of functions to read and modify the camera registers over I2C and to capture pictures. It also contains the automatic management of double buffers, or buffers of even higher order.

On the target, the cam module interfaces directly with the frame capture device driver for the CMOS sensor. It translates the API methods to IOCTLs for the driver.

On the host, the module stores a copy of the register set of the sensor and keeps it up to date. Instead of accessing the driver for images, these must be loaded from the file system. For this reason, the cam module uses a file name reader to get the correct image file to load this time step and the bitmap module to load the images from the file system.

See the documentation for the frame capture device driver for specifics concerning the interface between this driver and the cam module.

Target Hardware Resource

  • Micron MT9V032 CMOS sensor over the mt9v032 driver (/dev/video0).
    • I2C interface
    • PPI interface and PPI DMA

Dependencies

  • log: For error logging.
Host only:
  • frd: To get the current file name of the image to be read this time step.

Usage

Following code segment demonstrates the usage of the cam module. It is a simple example of a typical program sequence, and does not cover all the functionality of the module. For the sake of simplicity, error checking as well as framework creation and destruction are neglected.

 OscCamPresetRegs(); /* (1) */
 
 OscCamGetShutterWidth(&shutterWidth); /* (2) */
 
 shutterWidth++;
 OscCamSetShutterWidth(shutterWidth); /* (3) */
 
 OscCamSetAreaOfInterest(0, 0, 128, 128); /* (4) */
 
 OscCamSetFrameBuffer(0, 128*128, frameBuffer1, TRUE); /* (5) */
 OscCamSetFrameBuffer(1, 128*128, frameBuffer2, TRUE);
 
 doubleBufferIDs[0] = 0;
 doubleBufferIDs[1] = 1;
 OscCamCreateMultiBuffer(2, doubleBufferIDs); /* (6) */
 
 
 OscCamSetupCapture(OSC_CAM_MULTI_BUFFER); /* (7) */
 OscGpioTriggerImage();
 
 OscCamReadPicture(OSC_CAM_MULTI_BUFFER, &pPic, 0, 0); /* (8) */
 
 /************** Use image in pPic ********************/
 ...
 /*****************************************************/
 
 OscCamReadLatestPicture(&pPic); /* (9) */
  1. Set the camera registers to the default configuration. This step is recommended but optional. If left out, the state of the camera can be preserved between instantiations of the camera module (useful e.g. for CGI programs)
  2. Read the shutter width register containing the exposure time from the camera sensor.
  3. Set a new value for the shutter width register.
  4. Set the current area of interest of the camera, i.e. the rectangular section of the image transferred to the frame buffer. In this case we select 128 x 128 pixels in the lower left corner of the image.
  5. Set the frame buffers used by the driver. This is where the data received by the CMOS sensor is written by the DMA. We set two frame buffers with the buffer IDs 0 and 1 to be able to do double-buffering.
  6. Create an automatically managed double buffer. This is optional and can be skipped for added flexibility at the cost of less comfort.. If a double buffer is created, the application does not need to keep track of which buffer to capture to next, but can just supply OSC_CAM_MULTI_BUFFER as frame buffer ID in all following calls to cam methods.
  7. Getting a picture from the camera is a two-step process. First, a new capture has to be set up. This initializes and starts the DMAs to write the next image data frame coming over the interface from the sensor to the specified frame buffer. This is a non-blocking method that does not wait until the capture is complete, so the application can do other tasks while waiting for the DMA to finish. The the GPIO module is invoked to signal to the camera module, that a new image should be acquired.
  8. This is the second step of the capture process and blocks until the image is fully in RAM. Optionally a timeout can be given to still guarantee reactivity of the application, even when waiting for an external trigger. The second optional argument is the maximum age of the image returned, i.e. if this call was made considerable after the image finished transferring to RAM, it will fail.
  9. If the application does not care about the actuality of the image, it can call OSCCamReadLatestPicture(), which just returns the newest valid image matching the area of interest configured.
Clone this wiki locally