Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #include "board.h"
00090 #include "string.h"
00091
00092
00093
00094
00095
00096 COMPILER_SECTION("sdram_region")
00097 static uint16_t gIsiBuffer[640 * 480 * 2];
00098
00099 #define ISI_BASE gIsiBuffer
00100
00101
00102 #define TWCK 400000
00103
00104 #define BOARD_ID_TWI_ISI ID_TWIHS0
00105
00106 #define BOARD_BASE_TWI_ISI TWIHS0
00107
00108
00109 #define ISI_MAX_PREV_BUFFER 1
00110
00111
00112 #define BOARD_PINS_TWI_ISI PINS_TWI0
00113
00114 #define LCD_NORMAL_MODE 0
00115 #define LCD_REVERSE_MODE 1 // Row/column exchange
00116 #define LCD_MODE ILI9488_EBIMODE
00117
00118
00119
00120
00121
00122
00123 const Pin pinsTWI[] = BOARD_PINS_TWI_ISI;
00124 const Pin pin_ISI_RST = BOARD_ISI_RST;
00125 const Pin pin_ISI_PWD = BOARD_ISI_PWD;
00126 const Pin pPinsISI[]= {BOARD_ISI_PINS};
00127
00128
00129 static Twid twid;
00130
00131
00132 COMPILER_ALIGNED(32) ISI_FrameBufferDescriptors preBufDescList[ISI_MAX_PREV_BUFFER];
00133
00134
00135 static uint32_t wImageWidth, wImageHeight;
00136
00137
00138 static sensorOutputFormat_t wImageFormat;
00139
00140
00141 static uint32_t wDisplayWidth, wDisplayHeight;
00142
00143
00144 static uint8_t lcdDisplayMode = LCD_REVERSE_MODE;
00145
00146
00147 static sXdmad lcdEbiDma;
00148
00149 extern const sensorProfile_t ov2640Profile;
00150 extern const sensorProfile_t ov2643Profile;
00151 extern const sensorProfile_t ov5640Profile;
00152 extern const sensorProfile_t ov7740Profile;
00153 extern const sensorProfile_t ov9740Profile;
00154
00155
00156 static const sensorProfile_t *sensorsProfile[5] = {&ov2640Profile,
00157 &ov2643Profile,
00158 &ov5640Profile,
00159 &ov7740Profile,
00160 &ov9740Profile
00161 };
00162
00163
00164
00165
00166
00167
00168
00169 void TWIHS0_Handler(void)
00170 {
00171 TWID_Handler(&twid);
00172 }
00173
00174
00175
00176
00177 void XDMAC_Handler(void)
00178 {
00179 XDMAD_Handler(&lcdEbiDma);
00180 }
00181
00182
00183
00184
00185 void ISI_Handler(void)
00186 {
00187 uint32_t status,imr;
00188 status = ISI->ISI_SR;
00189 imr = ISI->ISI_IMR;
00190 if ((status & ISI_SR_PXFR_DONE) && (imr & ISI_IMR_PXFR_DONE)) {
00191 ISI_DmaChannelDisable(ISI_DMA_CHDR_P_CH_DIS);
00192 ISI_DisableInterrupt(ISI_IDR_PXFR_DONE);
00193 LCDD_UpdateWindow();
00194 ISI_DmaChannelEnable(ISI_DMA_CHER_P_CH_EN);
00195 ISI_EnableInterrupt(ISI_IER_PXFR_DONE);
00196 }
00197 }
00198
00199
00200
00201
00202 static void _twiInit(void)
00203 {
00204
00205 PIO_Configure(pinsTWI, PIO_LISTSIZE(pinsTWI));
00206
00207 PMC_EnablePeripheral(BOARD_ID_TWI_ISI);
00208
00209 TWI_ConfigureMaster(BOARD_BASE_TWI_ISI, TWCK, BOARD_MCK);
00210 TWID_Initialize(&twid, BOARD_BASE_TWI_ISI);
00211
00212
00213 NVIC_ClearPendingIRQ(TWIHS0_IRQn);
00214 NVIC_EnableIRQ(TWIHS0_IRQn);
00215 }
00216
00217
00218
00219
00220 static void _isiPckInit(void)
00221 {
00222
00223 PIO_Configure(pPinsISI, PIO_LISTSIZE(pPinsISI));
00224
00225
00226 REG_PMC_SCDR = PMC_SCER_PCK0;
00227
00228 PMC->PMC_PCK[0] = PMC_PCK_CSS_MCK | (4 << 4);
00229
00230 REG_PMC_SCER = PMC_SCER_PCK0;
00231
00232 while ((REG_PMC_SR & PMC_SR_PCKRDY0) == 0);
00233
00234
00235 PIO_Clear(&pin_ISI_PWD);
00236 PIO_Clear(&pin_ISI_RST);
00237 }
00238
00239
00240
00241
00242 static void _isi_AllocateFBD(void)
00243 {
00244 uint32_t i;
00245 for(i = 0; i < ISI_MAX_PREV_BUFFER; i++) {
00246 preBufDescList[i].Current = (uint32_t)ISI_BASE;
00247 preBufDescList[i].Control = ISI_DMA_P_CTRL_P_FETCH;
00248 preBufDescList[i].Next = (uint32_t)&preBufDescList[0];
00249 }
00250 }
00251
00252
00253
00254
00255 static void _lcd_Configure(void)
00256 {
00257 rect rc;
00258 LCDD_Initialize(LCD_MODE, &lcdEbiDma, lcdDisplayMode);
00259 LCDD_SetCavasBuffer((void*)gIsiBuffer, BOARD_LCD_HEIGHT * BOARD_LCD_WIDTH * 2);
00260
00261 rc.x = 0;
00262 rc.y = 0;
00263 if (lcdDisplayMode == LCD_REVERSE_MODE) {
00264 rc.width = BOARD_LCD_HEIGHT - 1;
00265 rc.height = BOARD_LCD_WIDTH - 1;
00266
00267
00268 } else {
00269 rc.width = BOARD_LCD_WIDTH - 1;
00270 rc.height = BOARD_LCD_HEIGHT - 1;
00271 }
00272 LCDD_SetUpdateWindowSize(rc);
00273 LCDD_DrawRectangleWithFill(0, 0, 0, rc.width - 1, rc.height - 1,
00274 RGB_24_TO_RGB565(COLOR_BLACK));
00275 LCDD_UpdateWindow();
00276 Wait(500);
00277 }
00278
00279
00280
00281
00282 static void _isiInit(void)
00283 {
00284 ISI_Y2R y2r;
00285
00286
00287 PMC_EnablePeripheral(ID_ISI);
00288
00289 _isi_AllocateFBD();
00290
00291 ISI_Reset();
00292
00293 ISI_SetBlank(0, 0);
00294
00295 ISI_SetSensorSize(wImageWidth, wImageHeight);
00296
00297
00298 if (lcdDisplayMode == LCD_REVERSE_MODE) {
00299
00300 wDisplayHeight = wImageHeight * 1000 / (wImageWidth * 1000 / BOARD_LCD_HEIGHT);
00301 wDisplayWidth = BOARD_LCD_HEIGHT;
00302 ISI_setPreviewSize(wDisplayWidth, wDisplayHeight);
00303
00304 } else {
00305
00306 wDisplayHeight = wImageHeight * 1000 / (wImageWidth * 1000 / BOARD_LCD_WIDTH);
00307 wDisplayWidth = BOARD_LCD_WIDTH;
00308 ISI_setPreviewSize(BOARD_LCD_WIDTH, wDisplayHeight );
00309 }
00310
00311 ISI_setInputStream(YUV_INPUT);
00312
00313 ISI_YCrCbFormat(ISI_CFG2_YCC_SWAP_MODE2);
00314
00315 ISI_calcScalerFactor();
00316
00317 ISI_setDmaInPreviewPath((uint32_t)&preBufDescList[0], ISI_DMA_P_CTRL_P_FETCH,
00318 (uint32_t)ISI_BASE);
00319
00320
00321 y2r.C0 = 0x95;
00322 y2r.C1 = 0xFF;
00323 y2r.C2 = 0x68;
00324 y2r.C3 = 0x32;
00325 y2r.C4 = 0xCC;
00326 y2r.Yoff = 1;
00327 y2r.Croff = 1;
00328 y2r.Cboff = 1;
00329 ISI_SetMatrix4Yuv2Rgb(&y2r);
00330 NVIC_ClearPendingIRQ(ISI_IRQn);
00331 NVIC_SetPriority(ISI_IRQn, 7);
00332 NVIC_EnableIRQ(ISI_IRQn);
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 extern int main( void )
00344 {
00345 uint8_t key;
00346 WDT_Disable(WDT);
00347
00348
00349 SCB_EnableICache();
00350 SCB_EnableDCache();
00351
00352
00353 printf("-- ISI Example %s --\n\r", SOFTPACK_VERSION);
00354 printf("-- %s\n\r", BOARD_NAME );
00355 printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);
00356
00357
00358 BOARD_ConfigureSdram();
00359
00360
00361 TimeTick_Configure();
00362
00363
00364 _lcd_Configure();
00365
00366
00367 _twiInit();
00368
00369
00370 _isiPckInit();
00371
00372 PIO_Set(&pin_ISI_RST);
00373
00374 printf("Press [0|1|2|3|4][5] to select supported sensor \n\r");
00375 printf("- '0' omnivision 2640 \n\r");
00376 printf("- '1' omnivision 2643 \n\r");
00377 printf("- '2' omnivision 5640 \n\r");
00378 printf("- '3' omnivision 7740 \n\r");
00379 printf("- '4' omnivision 9740 \n\r");
00380 for(;;) {
00381 key = DBG_GetChar();
00382 if ((key >= '0') && (key <='5')) {
00383 if (sensor_setup(&twid, sensorsProfile[key- '0'], VGA) != SENSOR_OK) {
00384 printf("-E- Sensor setup failed.");
00385 while (1);
00386 } else {
00387 break;
00388 }
00389 }
00390 }
00391
00392 sensor_get_output(&wImageFormat, &wImageWidth, &wImageHeight, VGA);
00393 printf("Sensor <%d, %d> \n\r", (int)wImageWidth, (int)wImageHeight );
00394 if (wImageFormat == MONO_12_BIT) {
00395 printf("-I- Monochrome sensor do not support in this example!");
00396 while (1);
00397 }
00398 if (wImageFormat == RAW_BAYER_12_BIT || wImageFormat == RAW_BAYER_10_BIT)
00399 wImageFormat = (sensorOutputFormat_t)RGB_INPUT;
00400 else
00401 wImageFormat = (sensorOutputFormat_t)YUV_INPUT;
00402
00403
00404 _isiInit();
00405
00406 printf("preview in RGB 565 mode\n\r");
00407 ISI_Enable();
00408 ISI_DisableInterrupt(0xFFFFFFFF);
00409 ISI_EnableInterrupt(ISI_IER_PXFR_DONE);
00410 ISI_DmaChannelDisable(ISI_DMA_CHDR_C_CH_DIS);
00411 SCB_CleanDCache_by_Addr((uint32_t *)preBufDescList, sizeof(preBufDescList));
00412 ISI_DmaChannelEnable(ISI_DMA_CHER_P_CH_EN);
00413 while (1);
00414 }