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 /* Write one to this field to enable the module. */
\r
47 REG_ISI_CR |= ISI_CR_ISI_EN;
\r
48 /* Software must poll ENABLE field in the ISI_STATUS register to verify that the command
\r
49 has successfully completed.*/
\r
50 while( (REG_ISI_SR & ISI_SR_ENABLE) != ISI_SR_ENABLE);
\r
54 * \brief Enable ISI Dma channel
\r
55 * \param channel to be enabled
\r
57 void ISI_DmaChannelEnable(uint32_t channel)
\r
59 REG_ISI_DMA_CHER |= channel;
\r
63 * \brief Disable ISI Dma channel
\r
64 * \param channel to be disabled
\r
66 void ISI_DmaChannelDisable(uint32_t channel)
\r
68 REG_ISI_DMA_CHDR |=channel;
\r
72 * \brief Disable ISI
\r
74 void ISI_Disable(void)
\r
76 /* Write one to this field to disable the module */
\r
77 REG_ISI_CR |= ISI_CR_ISI_DIS;
\r
78 /* Software must poll DIS_DONE field in the ISI_STATUS register to verify that the command
\r
79 has successfully completed.*/
\r
80 while( (REG_ISI_SR & ISI_SR_DIS_DONE) != ISI_SR_DIS_DONE);
\r
85 * \brief Enable ISI interrupt
\r
86 * \param flag of interrupt to enable
\r
88 void ISI_EnableInterrupt(uint32_t flag)
\r
94 * \brief Disable ISI interrupt
\r
95 * \param flag of interrupt to disable
\r
97 void ISI_DisableInterrupt(uint32_t flag)
\r
103 * \brief Return ISI status register
\r
104 * \return Status of ISI register
\r
106 uint32_t ISI_StatusRegister(void)
\r
108 return(REG_ISI_SR);
\r
112 * \brief Enable Codec path for capture next frame
\r
114 void ISI_CodecPathFull(void)
\r
116 /* The codec path is enabled and the next frame is captured.
\r
117 Both codec and preview datapaths are working simultaneously */
\r
118 REG_ISI_CR |= ISI_CR_ISI_CDC;
\r
119 REG_ISI_CFG1 |= ISI_CFG1_FULL;
\r
123 * \brief Set frame rate
\r
124 * \param frate frame rate capture
\r
126 void ISI_SetFrame(uint32_t frate)
\r
129 TRACE_ERROR("FRate too big\n\r");
\r
132 REG_ISI_CFG1 |= ISI_CFG1_FRATE(frate);
\r
136 * \brief Get the number of byte per pixels
\r
137 * \param bmpRgb BMP type can be YUV or RGB
\r
139 uint8_t ISI_BytesForOnePixel(uint8_t bmpRgb)
\r
141 uint8_t nbByte_Pixel;
\r
143 if (bmpRgb == RGB) {
\r
144 if ((REG_ISI_CFG2 & ISI_CFG2_RGB_MODE) == ISI_CFG2_RGB_MODE){
\r
145 // RGB: 5:6:5 16bits/pixels
\r
149 // RGB: 8:8:8 24bits/pixels
\r
154 // YUV: 2 pixels for 4 bytes
\r
157 return nbByte_Pixel;
\r
164 void ISI_Reset(void)
\r
166 uint32_t timeout=0;
\r
168 /* Resets the image sensor interface.
\r
169 Finish capturing the current frame and then shut down the module.*/
\r
170 REG_ISI_CR = ISI_CR_ISI_SRST | ISI_CR_ISI_DIS;
\r
171 /* wait Software reset has completed successfully. */
\r
172 while( (!(REG_ISI_SR & ISI_SR_SRST))
\r
173 && (timeout < 0x5000) ){
\r
176 if( timeout == 0x500000 ) {
\r
177 TRACE_ERROR("ISI-Reset timeout\n\r");
\r
182 * \brief ISI initialize
\r
183 * \param pVideo structure of video driver
\r
185 void ISI_Init(pIsi_Video pVideo)
\r
187 uint32_t hRatio, vRatio;
\r
190 // SLD pixel clock periods to wait before the beginning of a line.
\r
191 // SFD lines are skipped at the beginning of the frame.
\r
192 REG_ISI_CFG1 |= ISI_CFG1_SLD(pVideo->Hblank) + ISI_CFG1_SFD(pVideo->Vblank);
\r
193 TRACE_DEBUG("ISI_CFG1=0x%X\n\r", REG_ISI_CFG1);
\r
195 // IM_VSIZE: Vertical size of the Image sensor [0..2047]
\r
196 // Vertical size = IM_VSIZE + 1
\r
197 // IM_HSIZE: Horizontal size of the Image sensor [0..2047]
\r
198 // Horizontal size = IM_HSIZE + 1
\r
199 // YCC_SWAP : YCC image data
\r
200 REG_ISI_CFG2 = ISI_CFG2_IM_VSIZE(pVideo->codec_vsize - 1)
\r
201 + ISI_CFG2_IM_HSIZE(pVideo->codec_hsize - 1);
\r
203 if (pVideo->rgb_or_yuv == RGB) {
\r
204 REG_ISI_CFG2 |= ISI_CFG2_COL_SPACE | ISI_CFG2_RGB_MODE ;
\r
207 REG_ISI_CFG2|= ISI_CFG2_YCC_SWAP(2) ;
\r
209 TRACE_DEBUG("ISI_CFG2=0x%X\n\r", REG_ISI_CFG2);
\r
211 // Vertical Preview size = PREV_VSIZE + 1 (480 max only in RGB mode).
\r
212 // Horizontal Preview size = PREV_HSIZE + 1 (640 max only in RGB mode).
\r
214 if( (pVideo->lcd_vsize > 480) || (pVideo->lcd_hsize > 800)) {
\r
215 TRACE_ERROR("Size LCD bad define %u, %u\n\r",(unsigned int)pVideo->lcd_vsize ,(unsigned int)pVideo->lcd_hsize);
\r
216 REG_ISI_PSIZE = ((480 - 1) ) + (((800-1) << 16) );
\r
219 REG_ISI_PSIZE = ((pVideo->lcd_vsize -1)) + (((pVideo->lcd_hsize -1) << 16) );
\r
222 // DEC_FACTOR is 8-bit width, range is from 16 to 255.
\r
223 // Values from 0 to 16 do not perform any decimation.
\r
224 //REG_ISI_PDECF = (16 * pVideo->codec_hsize)/640;
\r
225 hRatio = (16 * pVideo->codec_hsize)/(pVideo->lcd_hsize);
\r
226 vRatio = (16 * pVideo->codec_vsize)/(pVideo->lcd_vsize);
\r
227 REG_ISI_PDECF = (hRatio > vRatio )? vRatio: hRatio;
\r
229 if (REG_ISI_PDECF < 16) REG_ISI_PDECF = 16;
\r
231 REG_ISI_DMA_P_DSCR = pVideo->Isi_fbd_base;
\r
232 REG_ISI_DMA_P_CTRL = ISI_DMA_P_CTRL_P_FETCH;
\r
233 REG_ISI_DMA_P_ADDR = pVideo->lcd_fb_addr;
\r
235 REG_ISI_DMA_C_DSCR = pVideo->codec_fbd_base;
\r
236 REG_ISI_DMA_C_CTRL = ISI_DMA_C_CTRL_C_FETCH;
\r
237 REG_ISI_DMA_C_ADDR = pVideo->codec_fb_addr;
\r
239 // C0: Color Space Conversion Matrix Coefficient C0
\r
240 // C1: Color Space Conversion Matrix Coefficient C1
\r
241 // C2: Color Space Conversion Matrix Coefficient C2
\r
242 // C3: Color Space Conversion Matrix Coefficient C3
\r
243 REG_ISI_Y2R_SET0 = ISI_Y2R_SET0_C0(0x95)
\r
244 + ISI_Y2R_SET0_C1(0xFF)
\r
245 + ISI_Y2R_SET0_C2(0x68)
\r
246 + ISI_Y2R_SET0_C3(0x32);
\r
248 // C4: Color Space Conversion Matrix coefficient C4
\r
249 // Yoff: Color Space Conversion Luminance 128 offset
\r
250 // Croff: Color Space Conversion Red Chrominance 16 offset
\r
251 // Cboff: Color Space Conversion Blue Chrominance 16 offset
\r
252 REG_ISI_Y2R_SET1 = ISI_Y2R_SET1_C4(0xCC)
\r
253 + ISI_Y2R_SET1_Yoff
\r
254 + ISI_Y2R_SET1_Croff
\r
255 + ISI_Y2R_SET1_Cboff;
\r