00001 /* ---------------------------------------------------------------------------- 00002 * SAM Software Package License 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2013, Atmel Corporation 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the disclaimer below. 00013 * 00014 * Atmel's name may not be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00020 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00023 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00026 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * ---------------------------------------------------------------------------- 00028 */ 00029 00030 /*---------------------------------------------------------------------------- 00031 * Headers 00032 *----------------------------------------------------------------------------*/ 00033 #include "board.h" 00034 00035 00036 /*--------------------------------------------------------------------------- 00037 * Definition 00038 *---------------------------------------------------------------------------*/ 00039 #define SENDOR_SUPPORTED_OUTPUTS 7 00040 00041 /** terminating list entry for register in configuration file */ 00042 #define SENSOR_REG_TERM 0xFF 00043 /** terminating list entry for value in configuration file */ 00044 #define SENSOR_VAL_TERM 0xFF 00045 00046 /*---------------------------------------------------------------------------- 00047 * Types 00048 *----------------------------------------------------------------------------*/ 00049 00050 /** Sensor type */ 00051 typedef enum _sensorType { 00052 SENSOR_COMS = 0, 00053 SENSOR_CCD 00054 }sensorType_t; 00055 00056 /** Sensor status or return code */ 00057 typedef enum _sensorStatus { 00058 SENSOR_OK = 0, /**< Operation is successful */ 00059 SENSOR_TWI_ERROR, 00060 SENSOR_ID_ERROR, 00061 SENSOR_RESOLUTION_NOT_SUPPORTED 00062 } sendorStatus_t; 00063 00064 /** Sensor TWI mode */ 00065 typedef enum _sensorTwiMode { 00066 SENSOR_TWI_REG_BYTE_DATA_BYTE = 0, 00067 SENSOR_TWI_REG_2BYTE_DATA_BYTE, 00068 SENSOR_TWI_REG_BYTE_DATA_2BYTE 00069 } sensorTwiMode_t; 00070 00071 /** Sensor resolution */ 00072 typedef enum _sensorResolution { 00073 QVGA = 0, 00074 VGA, 00075 SVGA, 00076 XGA, 00077 WXGA, 00078 UVGA 00079 } sensorOutputResolution_t; 00080 00081 /** Sensor output format */ 00082 typedef enum _sensorOutputFormat { 00083 RAW_BAYER_12_BIT = 0, 00084 RAW_BAYER_10_BIT, 00085 YUV_422_8_BIT, 00086 YUV_422_10_BIT, 00087 MONO_12_BIT 00088 } sensorOutputFormat_t; 00089 00090 /** define a structure for sensor register initialization values */ 00091 typedef struct _sensor_reg { 00092 uint16_t reg; /* Register to be written */ 00093 uint16_t val; /* value to be written */ 00094 }sensorReg_t; 00095 00096 typedef struct _sensor_output { 00097 uint8_t type ; /** Index 0: normal, 1: AF setting*/ 00098 sensorOutputResolution_t output_resolution; /** sensor output resolution */ 00099 sensorOutputFormat_t output_format; /** sensor output format */ 00100 uint8_t supported; /** supported for current output_resolution*/ 00101 uint32_t output_width; /** output width */ 00102 uint32_t output_height; /** output height */ 00103 const sensorReg_t *output_setting; /** sensor registers setting */ 00104 }sensorOutput_t; 00105 00106 /** define a structure for sensor profile */ 00107 typedef struct _sensor_profile { 00108 sensorType_t cmos_ccd; /** Sensor type for CMOS sensor or CCD */ 00109 sensorTwiMode_t twi_inf_mode; /** TWI interface mode */ 00110 uint32_t twi_slave_addr; /** TWI slave address */ 00111 uint16_t pid_high_reg; /** Register address for product ID high byte */ 00112 uint16_t pid_low_reg; /** Register address for product ID low byte*/ 00113 uint16_t pid_high; /** product ID high byte */ 00114 uint16_t pid_low; /** product ID low byte */ 00115 uint16_t version_mask; /** version mask */ 00116 const sensorOutput_t *outputConf[SENDOR_SUPPORTED_OUTPUTS]; /** sensor settings */ 00117 }sensorProfile_t; 00118 00119 /*---------------------------------------------------------------------------- 00120 * Exported functions 00121 *----------------------------------------------------------------------------*/ 00122 extern sendorStatus_t sensor_twi_write_regs(Twid * pTwid, 00123 const sensorReg_t * pReglist); 00124 00125 extern sendorStatus_t sensor_twi_read_regs(Twid * pTwid, 00126 const sensorReg_t * pReglist); 00127 00128 extern sendorStatus_t sensor_setup(Twid * pTwid, 00129 const sensorProfile_t *sensor_profile, 00130 sensorOutputResolution_t resolution); 00131 00132 extern sendorStatus_t sensor_get_output(sensorOutputFormat_t *format, 00133 uint32_t *width, 00134 uint32_t* height, 00135 sensorOutputResolution_t resolution);