- Main Page
- Modules
- Data Structures
- Files
- Directories

# Camera fast two timers

## Files
file | e_calc.c
| Calculate the timing for the camera (two timers).

file | e_po3030k.h
| PO3030k library header (two timers).

file | e_timers.c
| Manage camera's interrupts (two timers).

## Detailed Description

## Introduction

This driver expose most of the Po3030k camera interfaces. Some functions are usefull, some other not. But since this is not up to the driver to decide if a function is needed, I've exported almost all.

The architecture is quite simple. The driver keep a array where every known camera register is keept in memory. The configuration function only alter this array. When you call, for example e_po3030k_config_cam(), nothing is written on the camera, but only in the internal register representation.

To effectively write the register, you must call e_po3030k_write_cam_registers(). This is typically done after every configuration call and before acquire the first picture.

## Default settings

The camera is, by default, configured with the followin settings:

- Automatic white balance control
- Automatic exposure control
- Automatic flicker detection ( 50Hz and 60Hz )

There is no default setting for the image size and color.

## Performances

The maximum framerate ( without doing anything else than acquiring the picture ) vary with the subsampling and the color mode. Here are some framerates:

- Size: 640x480, Subsampling: 16x16, RGB565: 4.3 fps
- Size: 16x480, Subsampling: 16x16, RGB565: 4.3 fps
- Size: 480x16, Subsampling: 16x16: RGB565: 4.3fps
- Size: 64x64, Subsampling: 4x4, RGB565: 4.3 fps
- Size: 32x32, Subsampling: 2x2, RGB565: 2.6 fps
- Size: 16x16, No Subsampling, RGB565: 1.3 fps
- Size: 640x480, Subsampling: 16x16, GREYSCALE: 8.6 fps
- Size: 16x480, Subsampling: 16x16, GREYSCALE: 8.6 fps
- Size: 480x16, Subsampling: 16x16, GREYSCALE: 8.6 fps
- Size: 64x64, Subsampling: 4x4, GREYSCALE: 8.6 fps
- Size: 32x32, Subsampling: 2x2, GREYSCALE: 4.3 fps
- Size: 16x16, No subsampling, GREYSCALE: 2.2 fps

## Important note

This driver is extremly sensible to interrupt latency, thus it use interrupt priority to be sure that the latencies are kepts low. The Timer4 and Timer5 interrupt priority are set at level 6 and interrupt nesting is enabled. The Timer4 interrupt use the "push.s" and "pop.s" instructions. You should not have any code using thoses two instructions when you use the camera. This include the _ISRFAST C macro. If you use them, some random and really hard to debug behavior will happen. You have been warned !

## Examples

### Basic example

    #include "e_po3030k.h"

    char buffer[2*40*40];
    int main(void) {

            e_po3030k_init_cam();
            e_po3030k_config_cam((ARRAY_WIDTH -160)/2,(ARRAY_HEIGHT-160)/2,
                             160,160,4,4,RGB_565_MODE);
            e_po3030k_write_cam_registers();

            e_po3030k_launch_capture(buffer);
            while(!e_po3030k_is_img_ready());

            // buffer contain a 40*40 RGB picture now
            ( insert usefull code here )

            return 0;
    }

This example tell de driver to aquire 160x160 pixel picture from the camera 4x subsampling, thus resulting with a 40x40 pixel. The buffer as a size of 40*40*2 because RGB565 is a two bytes per pixel data format.

### More advanced example

    #include "e_po3030k.h"

    char buffer[160*2];
    int main(void) {
            e_po3030k_init_cam();
            e_po3030k_config_cam((ARRAY_WIDTH - 320)/2,(ARRAY_HEIGHT - 32)/2,
                            320,8,2,4,GREY_SCALE_MODE);
            e_po3030k_set_mirror(1,1);
            e_po3030ke_set_ref_exposure(100);

            e_po3030k_write_cam_registers();

            e_po3030k_launch_capture(buffer);
            while(!e_po3030k_is_img_ready());

            // Here buffer contain a 160x2 greyscale picture

            return 0;
    }

This example configure the camera to aquire a 320x8 pixel picture, but subsampled 2x in width and 4x in heigth, thus resulting in a 160*2 linear greyscale picture. It "emulate" a linear camera. This example tell the camera to to enable the vertical and horizontal mirror, and to set the average exposure to 100.