OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_AT91SAM3U256_IAR/] [AT91Lib/] [peripherals/] [isi/] [isi2.c] - Blame information for rev 580

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 580 jeremybenn
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 *
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright notice,
12
 * this list of conditions and the disclaimer below.
13
 *
14
 * Atmel's name may not be used to endorse or promote products derived from
15
 * this software without specific prior written permission.
16
 *
17
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * ----------------------------------------------------------------------------
28
 */
29
 
30
//------------------------------------------------------------------------------
31
//         Headers
32
//------------------------------------------------------------------------------
33
 
34
#include <board.h>
35
#include <utility/trace.h>
36
#include <utility/video.h>
37
#include "isi.h"
38
 
39
#if defined (BOARD_ISI_V200)
40
 
41
//-----------------------------------------------------------------------------
42
/// Enable ISI
43
//-----------------------------------------------------------------------------
44
void ISI_Enable(void)
45
{
46
    AT91C_BASE_ISI->ISI_CTRL |= AT91C_ISI_EN_1;
47
    while( (AT91C_BASE_ISI->ISI_SR & AT91C_ISI_EN_1)!=AT91C_ISI_EN_1);
48
    AT91C_BASE_ISI->ISI_DMACHER |= AT91C_ISI_P_CH_EN_1;
49
}
50
 
51
//-----------------------------------------------------------------------------
52
/// Disable ISI
53
//-----------------------------------------------------------------------------
54
void ISI_Disable(void)
55
{
56
    AT91C_BASE_ISI->ISI_CTRL |= AT91C_ISI_DIS_1;
57
    AT91C_BASE_ISI->ISI_DMACHDR &= ~AT91C_ISI_P_CH_DIS_1;
58
}
59
 
60
//-----------------------------------------------------------------------------
61
/// Enable ISI interrupt
62
/// \param  flag of interrupt to enable
63
//-----------------------------------------------------------------------------
64
void ISI_EnableInterrupt(unsigned int flag)
65
{
66
    AT91C_BASE_ISI->ISI_IER = flag;
67
}
68
 
69
//-----------------------------------------------------------------------------
70
/// Disable ISI interrupt
71
/// \param  flag of interrupt to disable
72
//-----------------------------------------------------------------------------
73
void ISI_DisableInterrupt(unsigned int flag)
74
{
75
    AT91C_BASE_ISI->ISI_IDR = flag;
76
}
77
 
78
//-----------------------------------------------------------------------------
79
/// Return ISI status register
80
/// \return Status of ISI register
81
//-----------------------------------------------------------------------------
82
unsigned int ISI_StatusRegister(void)
83
{
84
    return(AT91C_BASE_ISI->ISI_SR);
85
}
86
 
87
//-----------------------------------------------------------------------------
88
/// Enable Codec path for capture next frame
89
//-----------------------------------------------------------------------------
90
void ISI_CodecPathFull(void)
91
{
92
    // The codec path is enabled and the next frame is captured.
93
    // Both codec and preview datapaths are working simultaneously
94
    AT91C_BASE_ISI->ISI_CTRL |= AT91C_ISI_CDC_1;
95
    AT91C_BASE_ISI->ISI_CFG1 |= AT91C_ISI_FULL;
96
}
97
 
98
//-----------------------------------------------------------------------------
99
/// Set frame rate
100
/// \param  frate frame rate capture
101
/// \return 
102
//-----------------------------------------------------------------------------
103
void ISI_SetFrame(unsigned int frate)
104
{
105
    if( frate > 7 ) {
106
        TRACE_ERROR("FRate too big\n\r");
107
        frate = 7;
108
    }
109
    AT91C_BASE_ISI->ISI_CFG1 |= ((frate<<8) & AT91C_ISI_FRATE);
110
}
111
 
112
//-----------------------------------------------------------------------------
113
/// Get the number of byte per pixels
114
/// \param  bmpRgb BMP type can be YUV or RGB
115
/// \return Number of byte for one pixel
116
//-----------------------------------------------------------------------------
117
unsigned char ISI_BytesForOnePixel(unsigned char bmpRgb)
118
{
119
    unsigned char nbByte_Pixel;
120
 
121
    if (bmpRgb == RGB) {
122
        if ((AT91C_BASE_ISI->ISI_CFG2 & AT91C_ISI_RGB_MODE) == AT91C_ISI_RGB_MODE_RGB_565){
123
            // RGB: 5:6:5 16bits/pixels
124
            nbByte_Pixel = 2;
125
        }
126
        else {
127
            // RGB: 8:8:8 24bits/pixels
128
            nbByte_Pixel = 3;
129
        }
130
    }
131
    else {
132
        // YUV: 2 pixels for 4 bytes
133
        nbByte_Pixel = 2;
134
    }
135
    return nbByte_Pixel;
136
}
137
 
138
//-----------------------------------------------------------------------------
139
/// Reset ISI
140
//-----------------------------------------------------------------------------
141
void ISI_Reset(void)
142
{
143
    unsigned int timeout=0;
144
 
145
    // Resets the image sensor interface.
146
    // Finish capturing the current frame and then shut down the module.
147
    AT91C_BASE_ISI->ISI_CTRL = AT91C_ISI_SRST_1 | AT91C_ISI_DIS_1;
148
    // wait Software reset has completed successfully.
149
    while( (!(volatile int)AT91C_BASE_ISI->ISI_SR & AT91C_ISI_SRST)
150
        && (timeout < 0x5000) ){
151
        timeout++;
152
    }
153
    if( timeout == 0x5000 ) {
154
        TRACE_ERROR("ISI-Reset timeout\n\r");
155
    }
156
}
157
 
158
//-----------------------------------------------------------------------------
159
/// ISI initialize
160
/// \param pVideo structure of video driver
161
//-----------------------------------------------------------------------------
162
void ISI_Init(AT91PS_VIDEO pVideo)
163
{
164
    ISI_Reset();
165
 
166
    // AT91C_ISI_HSYNC_POL    Horizontal synchronisation polarity
167
    // AT91C_ISI_VSYNC_POL    Vertical synchronisation polarity
168
    // AT91C_ISI_PIXCLK_POL   Pixel Clock Polarity
169
 
170
    // SLD pixel clock periods to wait before the beginning of a line.
171
    // SFD lines are skipped at the beginning of the frame.
172
    AT91C_BASE_ISI->ISI_CFG1 |= ((pVideo->Hblank << 16) & AT91C_ISI_SLD)
173
                              + ((pVideo->Vblank << 24) & AT91C_ISI_SFD);
174
    TRACE_DEBUG("ISI_CFG1=0x%X\n\r", AT91C_BASE_ISI->ISI_CFG1);
175
 
176
    // IM_VSIZE: Vertical size of the Image sensor [0..2047]
177
    // Vertical size = IM_VSIZE + 1
178
    // IM_HSIZE: Horizontal size of the Image sensor [0..2047]
179
    // Horizontal size = IM_HSIZE + 1
180
    // YCC_SWAP : YCC image data    
181
    AT91C_BASE_ISI->ISI_CFG2 = ((pVideo->codec_vsize-1) & AT91C_ISI_IM_VSIZE)
182
                            + (((pVideo->codec_hsize-1) << 16) & AT91C_ISI_IM_HSIZE)
183
                            + AT91C_ISI_YCC_SWAP_YCC_MODE2;
184
 
185
    if (pVideo->rgb_or_yuv == RGB) {
186
        AT91C_BASE_ISI->ISI_CFG2 |= AT91C_ISI_COL_SPACE | AT91C_ISI_RGB_MODE_RGB_565
187
            | AT91C_ISI_RGB_CFG_RGB_DEFAULT;
188
    }
189
    else {
190
    //    AT91C_BASE_HISI->ISI_CFG2 &=  ~AT91C_ISI_COL_SPACE;    
191
    }
192
    TRACE_DEBUG("ISI_CFG2=0x%X\n\r", AT91C_BASE_ISI->ISI_CFG2);
193
 
194
    // Vertical Preview size = PREV_VSIZE + 1 (480 max only in RGB mode).
195
    // Horizontal Preview size = PREV_HSIZE + 1 (640 max only in RGB mode).    
196
#if defined (AT91C_ID_LCDC)
197
    if( (pVideo->lcd_vsize > 480) || (pVideo->lcd_hsize > 640)) {
198
        TRACE_ERROR("Size LCD bad define\n\r");
199
        AT91C_BASE_ISI->ISI_PSIZE = ((BOARD_LCD_HEIGHT-1) & AT91C_ISI_PREV_VSIZE)
200
                                  + (((BOARD_LCD_WIDTH-1) << 16) & AT91C_ISI_PREV_HSIZE);
201
    }
202
    else {
203
 
204
        AT91C_BASE_ISI->ISI_PSIZE = ((pVideo->lcd_vsize -1) & AT91C_ISI_PREV_VSIZE)
205
                                  + (((pVideo->lcd_hsize -1) << 16) & AT91C_ISI_PREV_HSIZE);
206
    }
207
#endif
208
 
209
 
210
    // DEC_FACTOR is 8-bit width, range is from 16 to 255. 
211
    // Values from 0 to 16 do not perform any decimation.
212
    AT91C_BASE_ISI->ISI_PDECF = (16 * pVideo->codec_hsize) / pVideo->lcd_hsize;
213
 
214
    TRACE_DEBUG("codec_hsize: %d\n\r", pVideo->codec_hsize);
215
    TRACE_DEBUG("lcd_hsize: %d\n\r", pVideo->lcd_hsize);
216
    TRACE_DEBUG("ISI_PDECF: %d\n\r", AT91C_BASE_ISI->ISI_PDECF);
217
    if( AT91C_BASE_ISI->ISI_PDECF <16) {
218
        TRACE_ERROR("ISI_PDECF, forbidden value: %d\n\r", AT91C_BASE_ISI->ISI_PDECF);
219
        AT91C_BASE_ISI->ISI_PDECF = 16;
220
    }
221
 
222
    AT91C_BASE_ISI->ISI_DMAPDSCR = pVideo->Isi_fbd_base;
223
    AT91C_BASE_ISI->ISI_DMAPCTRL = AT91C_ISI_P_FETCH_ENABLE;
224
    AT91C_BASE_ISI->ISI_DMAPADDR = pVideo->lcd_fb_addr;
225
 
226
    // C0: Color Space Conversion Matrix Coefficient C0
227
    // C1: Color Space Conversion Matrix Coefficient C1
228
    // C2: Color Space Conversion Matrix Coefficient C2
229
    // C3: Color Space Conversion Matrix Coefficient C3
230
    AT91C_BASE_ISI->ISI_Y2RSET0  = ( (0x95<< 0) & AT91C_ISI_Y2R_C0)
231
                                 + ( (0xFF<< 8) & AT91C_ISI_Y2R_C1)
232
                                 + ( (0x68<<16) & AT91C_ISI_Y2R_C2)
233
                                 + ( (0x32<<24) & AT91C_ISI_Y2R_C3);
234
 
235
    // C4: Color Space Conversion Matrix coefficient C4
236
    // Yoff: Color Space Conversion Luminance 128 offset
237
    // Croff: Color Space Conversion Red Chrominance 16 offset
238
    // Cboff: Color Space Conversion Blue Chrominance 16 offset
239
    AT91C_BASE_ISI->ISI_Y2RSET1  = ( (0xCC<< 0) & AT91C_ISI_Y2R_C4)
240
                                 + ( AT91C_ISI_Y2R_YOFF_128)
241
                                 + ( AT91C_ISI_Y2R_CROFF_16)
242
                                 + ( AT91C_ISI_Y2R_CBOFF_16);
243
}
244
 
245
#endif // defined (BOARD_ISI_V200)
246
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.