1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2013, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
31 /*----------------------------------------------------------------------------
\r
33 *----------------------------------------------------------------------------*/
\r
37 /*----------------------------------------------------------------------------
\r
39 *----------------------------------------------------------------------------*/
\r
44 void ISI_Enable(void)
\r
46 REG_ISI_CR |= ISI_CR_ISI_EN;
\r
47 while( (REG_ISI_SR & ISI_CR_ISI_EN)!=ISI_CR_ISI_EN);
\r
48 REG_ISI_DMA_CHER |= ISI_DMA_CHER_P_CH_EN | ISI_DMA_CHER_C_CH_EN;
\r
53 * \brief Disable ISI
\r
55 void ISI_Disable(void)
\r
57 REG_ISI_CR |= ISI_CR_ISI_DIS;
\r
58 REG_ISI_DMA_CHDR |= ISI_DMA_CHDR_P_CH_DIS;
\r
63 * \brief Enable ISI interrupt
\r
64 * \param flag of interrupt to enable
\r
66 void ISI_EnableInterrupt(uint32_t flag)
\r
73 * \brief Disable ISI interrupt
\r
74 * \param flag of interrupt to disable
\r
76 void ISI_DisableInterrupt(uint32_t flag)
\r
84 * \brief Return ISI status register
\r
85 * \return Status of ISI register
\r
87 uint32_t ISI_StatusRegister(void)
\r
94 * \brief Enable Codec path for capture next frame
\r
96 void ISI_CodecPathFull(void)
\r
98 // The codec path is enabled and the next frame is captured.
\r
99 // Both codec and preview datapaths are working simultaneously
\r
100 REG_ISI_CR |= ISI_CR_ISI_CDC;
\r
101 REG_ISI_CFG1 |= ISI_CFG1_FULL;
\r
106 * \brief Set frame rate
\r
107 * \param frate frame rate capture
\r
109 void ISI_SetFrame(uint32_t frate)
\r
112 TRACE_ERROR("FRate too big\n\r");
\r
115 REG_ISI_CFG1 |= ISI_CFG1_FRATE(frate);
\r
120 * \brief Get the number of byte per pixels
\r
121 * \param bmpRgb BMP type can be YUV or RGB
\r
123 uint8_t ISI_BytesForOnePixel(uint8_t bmpRgb)
\r
125 uint8_t nbByte_Pixel;
\r
127 if (bmpRgb == RGB) {
\r
128 if ((REG_ISI_CFG2 & ISI_CFG2_RGB_MODE) == ISI_CFG2_RGB_MODE){
\r
129 // RGB: 5:6:5 16bits/pixels
\r
133 // RGB: 8:8:8 24bits/pixels
\r
138 // YUV: 2 pixels for 4 bytes
\r
141 return nbByte_Pixel;
\r
148 void ISI_Reset(void)
\r
150 uint32_t timeout=0;
\r
152 // Resets the image sensor interface.
\r
153 // Finish capturing the current frame and then shut down the module.
\r
154 REG_ISI_CR = ISI_CR_ISI_SRST | ISI_CR_ISI_DIS;
\r
155 // wait Software reset has completed successfully.
\r
156 while( (!(REG_ISI_SR & ISI_SR_SRST))
\r
157 && (timeout < 0x5000) ){
\r
160 if( timeout == 0x5000 ) {
\r
161 TRACE_ERROR("ISI-Reset timeout\n\r");
\r
166 * \brief ISI initialize
\r
167 * \param pVideo structure of video driver
\r
169 void ISI_Init(pIsi_Video pVideo)
\r
171 uint32_t hRatio, vRatio;
\r
174 // SLD pixel clock periods to wait before the beginning of a line.
\r
175 // SFD lines are skipped at the beginning of the frame.
\r
176 REG_ISI_CFG1 |= ISI_CFG1_SLD(pVideo->Hblank) + ISI_CFG1_SFD(pVideo->Vblank);
\r
177 REG_ISI_CFG1 |=ISI_CFG1_DISCR;
\r
178 TRACE_DEBUG("ISI_CFG1=0x%X\n\r", REG_ISI_CFG1);
\r
180 // IM_VSIZE: Vertical size of the Image sensor [0..2047]
\r
181 // Vertical size = IM_VSIZE + 1
\r
182 // IM_HSIZE: Horizontal size of the Image sensor [0..2047]
\r
183 // Horizontal size = IM_HSIZE + 1
\r
184 // YCC_SWAP : YCC image data
\r
185 REG_ISI_CFG2 = ISI_CFG2_IM_VSIZE(pVideo->codec_vsize - 1)
\r
186 + ISI_CFG2_IM_HSIZE(pVideo->codec_hsize - 1);
\r
188 if (pVideo->rgb_or_yuv == RGB) {
\r
189 REG_ISI_CFG2 |= ISI_CFG2_COL_SPACE | ISI_CFG2_RGB_MODE ;
\r
192 REG_ISI_CFG2|= ISI_CFG2_YCC_SWAP_MODE2 ;
\r
194 TRACE_DEBUG("ISI_CFG2=0x%X\n\r", REG_ISI_CFG2);
\r
196 // Vertical Preview size = PREV_VSIZE + 1 (480 max only in RGB mode).
\r
197 // Horizontal Preview size = PREV_HSIZE + 1 (640 max only in RGB mode).
\r
199 if( (pVideo->lcd_vsize > 480) || (pVideo->lcd_hsize > 640)) {
\r
200 TRACE_ERROR("Size LCD bad define %d, %d\n\r",pVideo->lcd_vsize ,pVideo->lcd_hsize);
\r
201 REG_ISI_PSIZE = ((480 - 1) ) + (((640-1) << 16) );
\r
204 REG_ISI_PSIZE = ((pVideo->lcd_vsize -1)) + (((pVideo->lcd_hsize -1) << 16) );
\r
206 // DEC_FACTOR is 8-bit width, range is from 16 to 255.
\r
207 // Values from 0 to 16 do not perform any decimation.
\r
208 //REG_ISI_PDECF = (16 * pVideo->codec_hsize)/640;
\r
209 hRatio = (16 * pVideo->codec_hsize)/(pVideo->lcd_hsize);
\r
210 vRatio = (16 * pVideo->codec_vsize)/(pVideo->lcd_vsize);
\r
211 REG_ISI_PDECF = (hRatio > vRatio )? vRatio: hRatio;
\r
213 if (REG_ISI_PDECF < 16) REG_ISI_PDECF = 16;
\r
215 REG_ISI_DMA_P_DSCR = pVideo->Isi_fbd_base;
\r
216 REG_ISI_DMA_P_CTRL = ISI_DMA_P_CTRL_P_FETCH;
\r
217 REG_ISI_DMA_P_ADDR = pVideo->lcd_fb_addr;
\r
219 REG_ISI_DMA_C_DSCR = pVideo->codec_fbd_base;
\r
220 REG_ISI_DMA_C_CTRL = ISI_DMA_C_CTRL_C_FETCH;
\r
221 REG_ISI_DMA_C_ADDR = pVideo->codec_fb_addr;
\r
223 // C0: Color Space Conversion Matrix Coefficient C0
\r
224 // C1: Color Space Conversion Matrix Coefficient C1
\r
225 // C2: Color Space Conversion Matrix Coefficient C2
\r
226 // C3: Color Space Conversion Matrix Coefficient C3
\r
227 REG_ISI_Y2R_SET0 = ISI_Y2R_SET0_C0(0x95)
\r
228 + ISI_Y2R_SET0_C1(0xFF)
\r
229 + ISI_Y2R_SET0_C2(0x68)
\r
230 + ISI_Y2R_SET0_C3(0x32);
\r
232 // C4: Color Space Conversion Matrix coefficient C4
\r
233 // Yoff: Color Space Conversion Luminance 128 offset
\r
234 // Croff: Color Space Conversion Red Chrominance 16 offset
\r
235 // Cboff: Color Space Conversion Blue Chrominance 16 offset
\r
236 REG_ISI_Y2R_SET1 = ISI_Y2R_SET1_C4(0xCC)
\r
237 + ISI_Y2R_SET1_Yoff
\r
238 + ISI_Y2R_SET1_Croff
\r
239 + ISI_Y2R_SET1_Cboff;
\r