Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:44

0001 /* ---------------------------------------------------------------------------- */
0002 /*                  Atmel Microcontroller Software Support                      */
0003 /*                       SAM Software Package License                           */
0004 /* ---------------------------------------------------------------------------- */
0005 /* Copyright (c) 2015, Atmel Corporation                                        */
0006 /*                                                                              */
0007 /* All rights reserved.                                                         */
0008 /*                                                                              */
0009 /* Redistribution and use in source and binary forms, with or without           */
0010 /* modification, are permitted provided that the following condition is met:    */
0011 /*                                                                              */
0012 /* - Redistributions of source code must retain the above copyright notice,     */
0013 /* this list of conditions and the disclaimer below.                            */
0014 /*                                                                              */
0015 /* Atmel's name may not be used to endorse or promote products derived from     */
0016 /* this software without specific prior written permission.                     */
0017 /*                                                                              */
0018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
0019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
0020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
0021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
0022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
0023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
0024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
0025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
0026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
0027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
0028 /* ---------------------------------------------------------------------------- */
0029 
0030 /*----------------------------------------------------------------------------
0031  *        Headers
0032  *----------------------------------------------------------------------------*/
0033 #include "board.h"
0034 
0035 
0036 /*---------------------------------------------------------------------------
0037  *         Definition
0038  *---------------------------------------------------------------------------*/
0039 #define SENDOR_SUPPORTED_OUTPUTS 7
0040 
0041 /** terminating list entry for register in configuration file */
0042 #define SENSOR_REG_TERM         0xFF
0043 /** terminating list entry for value in configuration file */
0044 #define SENSOR_VAL_TERM         0xFF
0045 
0046 /*----------------------------------------------------------------------------
0047  *        Types
0048  *----------------------------------------------------------------------------*/
0049 
0050 /** Sensor type */
0051 typedef enum _sensorType {
0052     SENSOR_COMS = 0,
0053     SENSOR_CCD
0054 } sensorType_t;
0055 
0056 /** Sensor status or return code */
0057 typedef enum _sensorStatus {
0058     SENSOR_OK = 0,        /**< Operation is successful */
0059     SENSOR_TWI_ERROR,
0060     SENSOR_ID_ERROR,
0061     SENSOR_RESOLUTION_NOT_SUPPORTED
0062 } sendorStatus_t;
0063 
0064 /** Sensor TWI mode */
0065 typedef enum _sensorTwiMode {
0066     SENSOR_TWI_REG_BYTE_DATA_BYTE = 0,
0067     SENSOR_TWI_REG_2BYTE_DATA_BYTE,
0068     SENSOR_TWI_REG_BYTE_DATA_2BYTE
0069 } sensorTwiMode_t;
0070 
0071 /** Sensor resolution */
0072 typedef enum _sensorResolution {
0073     QVGA = 0,
0074     VGA,
0075     SVGA,
0076     XGA,
0077     WXGA,
0078     UVGA
0079 } sensorOutputResolution_t;
0080 
0081 /** Sensor output format */
0082 typedef enum _sensorOutputFormat {
0083     RAW_BAYER_12_BIT = 0,
0084     RAW_BAYER_10_BIT,
0085     YUV_422_8_BIT,
0086     YUV_422_10_BIT,
0087     MONO_12_BIT
0088 } sensorOutputFormat_t;
0089 
0090 /** define a structure for sensor register initialization values */
0091 typedef struct _sensor_reg {
0092     uint16_t reg; /* Register to be written */
0093     uint16_t val; /* value to be written */
0094 } sensorReg_t;
0095 
0096 typedef struct _sensor_output {
0097     uint8_t type;                              /** Index 0: normal, 1: AF setting*/
0098     sensorOutputResolution_t output_resolution; /** sensor output resolution */
0099     sensorOutputFormat_t output_format;         /** sensor output format */
0100     uint8_t supported;                          /** supported for current output_resolution*/
0101     uint32_t output_width;                      /** output width */
0102     uint32_t output_height;                     /** output height */
0103     const sensorReg_t *output_setting;          /** sensor registers setting */
0104 } sensorOutput_t;
0105 
0106 /** define a structure for sensor profile */
0107 typedef struct _sensor_profile {
0108     sensorType_t cmos_ccd;        /** Sensor type for CMOS sensor or CCD */
0109     sensorTwiMode_t twi_inf_mode; /** TWI interface mode  */
0110     uint32_t twi_slave_addr;      /** TWI slave address */
0111     uint16_t pid_high_reg;        /** Register address for product ID high byte */
0112     uint16_t pid_low_reg;         /** Register address for product ID low byte*/
0113     uint16_t pid_high;            /** product ID high byte */
0114     uint16_t pid_low;             /** product ID low byte */
0115     uint16_t version_mask;        /** version mask */
0116     const sensorOutput_t
0117         *outputConf[SENDOR_SUPPORTED_OUTPUTS]; /** sensor settings */
0118 } sensorProfile_t;
0119 
0120 /*----------------------------------------------------------------------------
0121  *        Exported functions
0122  *----------------------------------------------------------------------------*/
0123 extern sendorStatus_t sensor_twi_write_regs(Twid *pTwid,
0124         const sensorReg_t *pReglist);
0125 
0126 extern sendorStatus_t sensor_twi_read_regs(Twid *pTwid,
0127         const sensorReg_t *pReglist);
0128 
0129 extern sendorStatus_t sensor_setup(Twid *pTwid,
0130         const sensorProfile_t *sensor_profile,
0131         sensorOutputResolution_t resolution);
0132 
0133 extern sendorStatus_t sensor_get_output(sensorOutputFormat_t *format,
0134         uint32_t *width,
0135         uint32_t *height,
0136         sensorOutputResolution_t resolution);