00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 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 00117 *outputConf[SENDOR_SUPPORTED_OUTPUTS]; /** sensor settings */ 00118 } sensorProfile_t; 00119 00120 /*---------------------------------------------------------------------------- 00121 * Exported functions 00122 *----------------------------------------------------------------------------*/ 00123 extern sendorStatus_t sensor_twi_write_regs(Twid *pTwid, 00124 const sensorReg_t *pReglist); 00125 00126 extern sendorStatus_t sensor_twi_read_regs(Twid *pTwid, 00127 const sensorReg_t *pReglist); 00128 00129 extern sendorStatus_t sensor_setup(Twid *pTwid, 00130 const sensorProfile_t *sensor_profile, 00131 sensorOutputResolution_t resolution); 00132 00133 extern sendorStatus_t sensor_get_output(sensorOutputFormat_t *format, 00134 uint32_t *width, 00135 uint32_t *height, 00136 sensorOutputResolution_t resolution);