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

# e_registers.c File Reference

Manage po3030k registers (two timers). More...

`#include "../../I2C/e_I2C_protocol.h"`
`#include "e_po3030k.h"`

## Defines
#define | MCLK ((long) 14745600)
#define | MCLK_P_NS 0.067816840278
#define | ARRAY_ORIGINE_X 210
#define | ARRAY_ORIGINE_Y 7
#define | BASE_D1 0
#define | BASE_D2 0
#define | BASE_D3 0
#define | BASE_D4 0
#define | DEVICE_ID 0xDC
#define | FRAME_WIDTH 0x0353
#define | FRAME_HEIGTH 0x01e8
#define | WINDOW_X1_BASE 9
#define | WINDOW_Y1_BASE 13
#define | WINDOW_X2_BASE 17
#define | WINDOW_Y2_BASE 21
#define | BIAS_BASE 25
#define | COLGAIN_BASE 29
#define | INTEGR_BASE 39
#define | SPEED_ADDR (45 - BASE_D1)
#define | MIRROR_BASE 47
#define | SAMPLING_ADDR ( 51 - BASE_D2 )
#define | ADCOFF_BASE ( 53 - BASE_D2 )
#define | FLICKM_BASE ( 55 - BASE_D2 )
#define | FLICKP_BASE 59
#define | COLOR_M_ADDR (67 - BASE_D3)
#define | MODE_R5G6B5 0x08
#define | MODE_YUV 0x02
#define | MODE_GRAYSCALE 0x0c
#define | SEPIA_BASE 69
#define | LENSG_BASE 73
#define | EDGE_BASE 79
#define | GAMMA_BASE 83
#define | COLOR_COEF_BASE 107
#define | CBCRGAIN_BASE 125
#define | BRICTR_BASE 129
#define | SEPIATONE_BASE 133
#define | VSYNCSTART_BASE (145 - BASE_D4)
#define | VSYNCSTOP_BASE (149 - BASE_D4)
#define | VSYNCCOL_BASE (153 - BASE_D4)
#define | WW_BASE 157
#define | AWVAETOL_BASE 159
#define | AESPEED_BASE 161
#define | EXPOSURE_BASE 163
#define | REFREPO_BASE 169
#define | MINMAXEXP_BASE 175
#define | MINMAXAWB_BASE 183
#define | WEIGHWIN_BASE 195
#define | AWBAEENABLE_BASE 211
#define | GAMMASELCOL_BASE 215
#define | NB_REGISTERS (sizeof(cam_reg)/(2*sizeof(cam_reg[0])))
## Functions
void | e_po3030k_write_cam_registers (void)
void | e_po3030k_read_cam_registers (void)
int | e_po3030k_set_color_mode (int mode)
int | e_po3030k_set_sampling_mode (int mode)
int | e_po3030k_set_speed (int mode)
int | e_po3030k_set_wx (unsigned int start, unsigned int stop)
int | e_po3030k_set_wy (unsigned int start, unsigned int stop)
int | e_po3030k_set_vsync (unsigned int start, unsigned int stop, unsigned int col)
void | e_po3030k_set_mirror (int vertical, int horizontal)
int | e_po3030k_set_register (unsigned char adr, unsigned char value)
int | e_po3030k_get_register (unsigned char adr, unsigned char *value)
void | e_po3030k_set_bias (unsigned char pixbias, unsigned char opbias)
int | e_po3030k_set_color_gain (unsigned char global, unsigned char red, unsigned char green1, unsigned char green2, unsigned char blue)
void | e_po3030k_set_integr_time (unsigned long time)
void | e_po3030k_set_adc_offset (unsigned char offset)
void | e_po3030k_set_sepia (int status)
void | e_po3030k_set_lens_gain (unsigned char red, unsigned char green, unsigned char blue)
void | e_po3030k_set_edge_prop (unsigned char gain, unsigned char tresh)
void | e_po3030k_set_gamma_coef (unsigned char array[12], char color)
void | e_po3030k_write_gamma_coef (void)
int | e_po3030k_sync_register_array (unsigned char start, unsigned char stop)
void | e_po3030k_SetColorMatrix (unsigned char array[3 *3])
void | e_po3030k_set_cb_cr_gain (unsigned char cg11c, unsigned char cg22c)
void | e_po3030k_set_brigh_contr (unsigned char bright, unsigned char contrast)
void | e_po3030k_set_sepia_tone (unsigned char cb, unsigned char cr)
void | e_po3030k_set_ww (unsigned char ww)
void | e_po3030k_set_awb_ae_tol (unsigned char awbm, unsigned char aem)
void | e_po3030k_set_ae_speed (unsigned char b, unsigned char d)
void | e_po3030k_set_exposure (long t)
void | e_po3030k_set_ref_exposure (unsigned char exp)
void | e_po3030k_set_max_min_exp (unsigned int max, unsigned int min)
void | e_po3030k_set_max_min_awb (unsigned char minb, unsigned char maxb, unsigned char minr, unsigned char maxr, unsigned char ratior, unsigned char ratiob)
int | e_po3030k_set_weight_win (unsigned int x1, unsigned int x2, unsigned int y1, unsigned int y2)
void | e_po3030k_set_awb_ae (int awb, int ae)
void | e_po3030k_set_flicker_mode (int manual)
void | e_po3030k_set_flicker_detection (int hz50, int hz60)
static long | po3030k_get_pixelclock (void)
int | e_po3030k_set_flicker_man_set (int hz50, int hz60, int fdm, int fk, int tol)
## Variables
static unsigned char | cam_reg []

## Detailed Description

Manage po3030k registers (two timers).

Author:
  Philippe Rétornaz

## Define Documentation

#define ADCOFF_BASE ( 53 - BASE_D2 )

#define AESPEED_BASE 161

#define ARRAY_ORIGINE_X 210

#define ARRAY_ORIGINE_Y 7

#define AWBAEENABLE_BASE 211

#define AWVAETOL_BASE 159

#define BASE_D1 0

#define BASE_D2 0

#define BASE_D3 0

#define BASE_D4 0

#define BIAS_BASE 25

#define BRICTR_BASE 129

#define CBCRGAIN_BASE 125

#define COLGAIN_BASE 29

#define COLOR_COEF_BASE 107

#define COLOR_M_ADDR (67 - BASE_D3)

#define DEVICE_ID 0xDC

#define EDGE_BASE 79

#define EXPOSURE_BASE 163

#define FLICKM_BASE ( 55 - BASE_D2 )

#define FLICKP_BASE 59

#define FRAME_HEIGTH 0x01e8

#define FRAME_WIDTH 0x0353

#define GAMMA_BASE 83

#define GAMMASELCOL_BASE 215

#define INTEGR_BASE 39

#define LENSG_BASE 73

#define MCLK ((long) 14745600)

#define MCLK_P_NS 0.067816840278

#define MINMAXAWB_BASE 183

#define MINMAXEXP_BASE 175

#define MIRROR_BASE 47

#define MODE_GRAYSCALE 0x0c

#define MODE_R5G6B5 0x08

#define MODE_YUV 0x02

#define NB_REGISTERS (sizeof(cam_reg)/(2*sizeof(cam_reg[0])))

#define REFREPO_BASE 169

#define SAMPLING_ADDR ( 51 - BASE_D2 )

#define SEPIA_BASE 69

#define SEPIATONE_BASE 133

#define SPEED_ADDR (45 - BASE_D1)

#define VSYNCCOL_BASE (153 - BASE_D4)

#define VSYNCSTART_BASE (145 - BASE_D4)

#define VSYNCSTOP_BASE (149 - BASE_D4)

#define WEIGHWIN_BASE 195

#define WINDOW_X1_BASE 9

#define WINDOW_X2_BASE 17

#define WINDOW_Y1_BASE 13

#define WINDOW_Y2_BASE 21

#define WW_BASE 157

## Function Documentation

int e_po3030k_get_register | ( | unsigned char | adr,
|  | unsigned char * | value |
| ) |  |  |

Get the register adr value

Parameters:

  | adr | The address
  | value | The pointer to the value to write to

Returns:
  Zero if register found, non-zero if not found

Warning:
  This function is sub-optimal, if you use it heavly add an internal function to register.c

See also:
  e_po3030k_set_register

void e_po3030k_read_cam_registers | ( | void |  | ) |

Read the camera register

See also:
  e_po3030k_write_cam_registers

void e_po3030k_set_adc_offset | ( | unsigned char | offset | ) |

Set the Analog to Digital Converter offset

Parameters:

  | offset | The offset

See also:
  Datasheet p.28

void e_po3030k_set_ae_speed | ( | unsigned char | b,
|  | unsigned char | d |
| ) |  |  |

Set AE speed

Parameters:

  | b | AE speed factor when exposure time is decreasing ( 4 lower bits only )
  | d | AE speed factor when exposure time is increasing ( 4 lower bits only )

See also:
  Datasheet p.44

void e_po3030k_set_awb_ae | ( | int | awb,
|  | int | ae |
| ) |  |  |

Enable/Disable AWB and AE

Parameters:

  | awb | 1 mean AWB enabled, 0 mean disabled
  | ae | 1 mean AE enabled, 0 mean disabled

See also:
  Datasheet p. 50

void e_po3030k_set_awb_ae_tol | ( | unsigned char | awbm,
|  | unsigned char | aem |
| ) |  |  |

Set AWB/AE tolerence margin

Parameters:

  | awbm | AWV Margin ( 4 lower bits only )
  | aem | AW Margin ( 4 lower bits only )

See also:
  Datasheet p.44

void e_po3030k_set_bias | ( | unsigned char | pixbias,
|  | unsigned char | opbias |
| ) |  |  |

Set the Pixel and amplificator bias Increasing the bias produce better image quality, but increase camera's power consumption

Parameters:

  | pixbias | The pixel bias
  | opbias | The Amplificator bias

See also:
  Datasheet p.22

void e_po3030k_set_brigh_contr | ( | unsigned char | bright,
|  | unsigned char | contrast |
| ) |  |  |

Set the Brightness & Contrast

Parameters:

  | bright | The Brightness ( signed 1+7bits fixed point format )
  | contrast | The Contrast

See also:
  Datasheet p. 40

void e_po3030k_set_cb_cr_gain | ( | unsigned char | cg11c,
|  | unsigned char | cg22c |
| ) |  |  |

Set The color gain ( Cb/Cr )

Parameters:

  | cg11c | Cb gain ( Sign[7] | Integer[6:5] | fractional[4:0] )
  | cg22c | Cr gain ( Sign[7] | Integer[6:5] | fractional[4:0] )

See also:
  Datasheet p. 40

int e_po3030k_set_color_gain | ( | unsigned char | global,
|  | unsigned char | red,
|  | unsigned char | green1,
|  | unsigned char | green2,
|  | unsigned char | blue |
| ) |  |  |

Set the gains of the camera

Parameters:

  | global | The global gain
  | red | The red pixel's gain (fixed point [2:6] format)
  | green1 | The green pixel near read one gain ([2:6] format)
  | green2 | The green pixel near blue one gain ([2:6] format)
  | blue | The blue pixel's gain ([2:6] format)

Returns:
  Zero if OK, non-zero if an error occur

See also:
  Datasheet p.23-24

int e_po3030k_set_color_mode | ( | int | mode | ) |

Set the camera color mode

Warning:
  This is an internal function, use e_po3030k_config_cam

Parameters:

  | mode | The color mode

Returns:
  Zero if OK, non-zero if an error occur

See also:
  Datasheet p. 31, e_po3030k_write_cam_registers and e_po3030k_config_cam

void e_po3030k_set_edge_prop | ( | unsigned char | gain,
|  | unsigned char | tresh |
| ) |  |  |

Set Edge properties

Parameters:

  | gain | Edge gain & moire factor (fixed point [2:3] format)
  | tresh | Edge Enhancement threshold

See also:
  Datasheet p.36

void e_po3030k_set_exposure | ( | long | t | ) |

Set exposure time

Parameters:

  | t | Exposure time, LSB is in 1/64 line time

Warning:
  Only writable if AE is disabled

See also:
  Datasheet p.45

void e_po3030k_set_flicker_detection | ( | int | hz50,
|  | int | hz60 |
| ) |  |  |

Set the 50/60Hz flicker detection

Parameters:

  | hz50 | Non-zero mean 50Hz flicker detection enabled (default disabled)
  | hz60 | Non-zero mean 60Hz flicker detection enabled (default disabled)

Warning:
  If Automatic mode is enabled and both 50Hz and 60Hz are disabled, camera will enable both. By default, the camera automatically detect 50 and 60Hz flicker.

See also:
  Datasheet p.29 e_po3030k_set_flicker_mode() e_po3030k_set_flicker_man_set()

int e_po3030k_set_flicker_man_set | ( | int | hz50,
|  | int | hz60,
|  | int | fdm,
|  | int | fk,
|  | int | tol |
| ) |  |  |

Set the camera's manual flicker's detection setting

Parameters:

  | hz50 | The Hz for the 50Hz detection
  | hz60 | The Hz for the 60Hz detection
  | fdm | Flicker duration mode
  | fk | Flicker count step
  | tol | Flicker tolerance

Warning:
  You must have set the mode ( image size, color ) before calling this function

Returns:
  Non-zero if an error occur, 0 if OK

See also:
  Datasheet p.29-30 e_po3030k_set_flicker_detection() e_po3030k_set_flicker_mode()

void e_po3030k_set_flicker_mode | ( | int | manual | ) |

Set flicker detection mode

Parameters:

  | manual | Non-zero mean manual mode is enabled ( default automatic mode enabled )

See also:
  Datasheet p.29 e_po3030k_set_flicker_detection() e_po3030k_set_flicker_man_set()

void e_po3030k_set_gamma_coef | ( | unsigned char | array[12],
|  | char | color |
| ) |  |  |

Set gamma coefficient

Warning:
  This feature need extra care from the user

Parameters:

  | array | Gamma coefficient array
  | color | First two bytes : - 0b01 => Green 0b00 => Red else => Blue

See also:
  Datasheet p. 38, 50, 57-58 and e_po3030k_WriteGammaCoef

void e_po3030k_set_integr_time | ( | unsigned long | time | ) |

Set the pixel intergration time This is counted in line-time interval. See dataseet p.25 for more information

Parameters:

  | time | The integration time ( fixed point [14:6] format )

See also:
  Datasheet p.25

void e_po3030k_set_lens_gain | ( | unsigned char | red,
|  | unsigned char | green,
|  | unsigned char | blue |
| ) |  |  |

Set lens shading gain

Parameters:

  | red | Lens gain for red pixel
  | green | Lens gain for green pixel
  | blue | Lens gain for blue pixel

See also:
  Datasheet p.36

void e_po3030k_set_max_min_awb | ( | unsigned char | minb,
|  | unsigned char | maxb,
|  | unsigned char | minr,
|  | unsigned char | maxr,
|  | unsigned char | ratior,
|  | unsigned char | ratiob |
| ) |  |  |

Set the minimum and maximum red and blue gain in AWB mode

Parameters:

  | minb | The minimum blue gain
  | maxb | The maximum blue gain
  | minr | The minimum red gain
  | maxr | The maximum red gain
  | ratior | The red gain ratio
  | ratiob | The blue gain ratio

See also:
  Datasheet p. 47-48

void e_po3030k_set_max_min_exp | ( | unsigned int | max,
|  | unsigned int | min |
| ) |  |  |

Set the minimum and maximum exposure time in AE mode

Parameters:

  | min | The minimum exposure time
  | max | The maximum exposure time

See also:
  Datasheet p.46-47

void e_po3030k_set_mirror | ( | int | vertical,
|  | int | horizontal |
| ) |  |  |

Enable/Disable horizontal or vertical mirror

Parameters:

  | vertical | Set to 1 when vertical mirror is enabled, 0 if disabled
  | horizontal | Set to 1 when horizontal mirror is enabled, 0 if disabled

See also:
  Datasheet p.27

void e_po3030k_set_ref_exposure | ( | unsigned char | exp | ) |

Set the reference exposure. The average brightness which the AE should have

Parameters:

  | exp | The target exposure level

See also:
  Datasheet p.45

int e_po3030k_set_register | ( | unsigned char | adr,
|  | unsigned char | value |
| ) |  |  |

Set the register adr to value value

Parameters:

  | adr | The address
  | value | The value

Returns:
  Zero if register found, non-zero if not found

Warning:
  This function is sub-optimal, if you use it heavly add an internal function to register.c

See also:
  e_po3030k_get_register

int e_po3030k_set_sampling_mode | ( | int | mode | ) |

Set the camera sampling mode

Warning:
  This is an internal function, use e_po3030k_config_cam

Parameters:

  | mode | The given sampling mode

Returns:
  Zero if OK, non-zero if an error occur

See also:
  Datasheet p. 28 and e_po3030k_config_cam

void e_po3030k_set_sepia | ( | int | status | ) |

Enable/Disable Sepia color

Parameters:

  | status | Set status to 1 to enable, 0 to disable

See also:
  Datasheet p.34 and 74

void e_po3030k_set_sepia_tone | ( | unsigned char | cb,
|  | unsigned char | cr |
| ) |  |  |

Set The color tone at sepia color condition

Parameters:

  | cb | Cb tone
  | cr | Cr tone

See also:
  e_po3030k_set_sepia and Datasheet p. 41 and 74

int e_po3030k_set_speed | ( | int | mode | ) |

Set the camera speed

Warning:
  This is an internal function, use e_po3030k_config_cam

Parameters:

  | mode | The given speed

Returns:
  Zero if OK, non-zero if unknow mode

See also:
  Datasheet p. 26 and e_po3030k_config_cam

int e_po3030k_set_vsync | ( | unsigned int | start,
|  | unsigned int | stop,
|  | unsigned int | col |
| ) |  |  |

Set the camera window VSYNC coordinate

Warning:
  This is an internal function, use e_po3030k_ConfigCam

Parameters:

  | start | The start row
  | stop | The stop row
  | col | The start/stop column

Returns:
  Zero if OK, non-zero if an error occur

See also:
  Datasheet p.42-43, e_po3030k_write_cam_registers and e_po3030k_config_cam

int e_po3030k_set_weight_win | ( | unsigned int | x1,
|  | unsigned int | x2,
|  | unsigned int | y1,
|  | unsigned int | y2 |
| ) |  |  |

Set the Weighting Window coordinate

Parameters:

  | x1 | The X1 coordinate
  | x2 | The X2 coordinate
  | y1 | The Y1 coordinate
  | y2 | The Y2 coordinate

Returns:
  Zero if OK, non-zero if an error occur

See also:
  Datasheet p. 49

void e_po3030k_set_ww | ( | unsigned char | ww | ) |

Set the Center weight (Back Light compensation) Control parameter

Parameters:

  | ww | Center weight ( 4 lower bits only )

See also:
  Datasheet p.44

int e_po3030k_set_wx | ( | unsigned int | start,
|  | unsigned int | stop |
| ) |  |  |

Set the camera window X coordinate

Warning:
  This is an internal function, use e_po3030k_ConfigCam

Parameters:

  | start | The start column
  | stop | The stop column

Returns:
  Zero if OK, non-zero if an error occur

See also:
  Datasheet p.20-21, e_po3030k_write_cam_registers, e_po3030k_set_wy and e_po3030k_config_cam

int e_po3030k_set_wy | ( | unsigned int | start,
|  | unsigned int | stop |
| ) |  |  |

Set the camera window Y coordinate

Warning:
  This is an internal function, use e_po3030k_ConfigCam

Parameters:

  | start | The start row
  | stop | The stop row

Returns:
  Zero if OK, non-zero if an error occur

See also:
  Datasheet p.20-21, e_po3030k_WriteCamRegisters, e_po3030k_SetWX and e_po3030k_ConfigCam

void e_po3030k_SetColorMatrix | ( | unsigned char | array[3 *3] | ) |

Set color correction coefficient

Parameters:

  | array | Color coefficient matrix (3x3), sign[7] | integer [6:5] | fractional [4:0]

See also:
  Datasheet p. 39

int e_po3030k_sync_register_array | ( | unsigned char | start,
|  | unsigned char | stop |
| ) |  |  |

Write every known register between address start and stop (inclusivly).

Warning:
  It's better to set the configuration with appropriate functions and then write all registers with e_po3030k_WriteCamRegisters

Parameters:

  | start | The beginning address of the write
  | stop | The last write address

Returns:
  The number of register written

See also:
  e_po3030k_write_cam_registers

void e_po3030k_write_cam_registers | ( | void |  | ) |

The Po3030k module keep in memory the state of each register the camera has. When you configure the camera, it only alter the internal register state, not the camera one. This function write the internal register state in the camera.

See also:
  e_po3030k_read_cam_registers

void e_po3030k_write_gamma_coef | ( | void |  | ) |

This special function write directly the Gamma coefficient and Gamma color select into camera register.

Warning:
  This function need extra care from the user

See also:
  e_po3030k_set_gamma_coef

static long po3030k_get_pixelclock | ( | void |  | ) | `[static]`

## Variable Documentation

unsigned char cam_reg[]`[static]`