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 uint8_t gIsiBuffer[640 * 480];
00098 COMPILER_SECTION("sdram_region")
00099 static uint16_t gDisplayBuffer[320 * 240];
00100 static uint16_t lut[256];
00101
00102 #define ISI_BASE gIsiBuffer
00103 #define DISPLAY_BASE gDisplayBuffer
00104
00105
00106 #define TWCK 400000
00107
00108 #define BOARD_ID_TWI_ISI ID_TWIHS0
00109
00110 #define BOARD_BASE_TWI_ISI TWIHS0
00111 #define CAMX_MT9V022_SLAVE_ADDR (0x30>>1)
00112
00113
00114 #define ISI_MAX_PREV_BUFFER 1
00115
00116
00117 #define BOARD_PINS_TWI_ISI PINS_TWI0
00118
00119 #define LCD_NORMAL_MODE 0
00120 #define LCD_REVERSE_MODE 1 // Row/column exchange
00121 #define LCD_MODE ILI9488_EBIMODE
00122
00123
00124
00125
00126 extern const sensorProfile_t mt9v022Profile;
00127
00128
00129 const Pin pinsTWI[] = BOARD_PINS_TWI_ISI;
00130 const Pin pin_ISI_RST = BOARD_ISI_RST;
00131 const Pin pin_ISI_PWD = BOARD_ISI_PWD;
00132 const Pin pPinsISI[]= {BOARD_ISI_PINS};
00133
00134
00135 static Twid twid;
00136
00137
00138 ISI_FrameBufferDescriptors preBufDescList;
00139
00140
00141 static uint32_t wImageWidth, wImageHeight;
00142
00143
00144 static sensorOutputFormat_t wImageFormat;
00145
00146
00147 static uint8_t lcdDisplayMode = LCD_REVERSE_MODE;
00148
00149
00150 static sXdmad lcdEbiDma;
00151
00152
00153
00154
00155
00156
00157
00158 void TWIHS0_Handler(void)
00159 {
00160 TWID_Handler(&twid);
00161 }
00162
00163
00164
00165
00166 void XDMAC_Handler(void)
00167 {
00168 XDMAD_Handler(&lcdEbiDma);
00169 }
00170
00171 static void y2rgb565(void)
00172 {
00173 uint16_t i, j;
00174 uint8_t *s;
00175 uint16_t *p;
00176
00177 s = (uint8_t*)ISI_BASE;
00178 p = (uint16_t*)DISPLAY_BASE;
00179
00180 for (i = 0; i < wImageWidth; i++) {
00181 for (j = 0; j < wImageHeight; j++) {
00182 *p++ = lut[*s];
00183 s++;
00184 }
00185 }
00186 }
00187
00188
00189
00190
00191 void ISI_Handler(void)
00192 {
00193 uint32_t status,imr;
00194
00195 status = ISI->ISI_SR;
00196 imr = ISI->ISI_IMR;
00197 if ((status & ISI_SR_PXFR_DONE) && (imr & ISI_IMR_PXFR_DONE)) {
00198 if (ISI->ISI_DMA_P_ADDR != (uint32_t)ISI_BASE + (wImageWidth * wImageHeight ))
00199 return;
00200 ISI_DisableInterrupt(ISI_IDR_PXFR_DONE);
00201 ISI_DmaChannelDisable(ISI_DMA_CHDR_P_CH_DIS);
00202 y2rgb565();
00203 LCDD_UpdateWindow();
00204 ISI_setDmaInPreviewPath((uint32_t)&preBufDescList,
00205 ISI_DMA_P_CTRL_P_FETCH, (uint32_t)ISI_BASE);
00206 ISI_DmaChannelEnable(ISI_DMA_CHER_P_CH_EN);
00207 ISI_EnableInterrupt(ISI_IER_PXFR_DONE);
00208 }
00209 }
00210
00211
00212
00213
00214 static void _twiInit(void)
00215 {
00216
00217 PIO_Configure(pinsTWI, PIO_LISTSIZE(pinsTWI));
00218
00219 PMC_EnablePeripheral(BOARD_ID_TWI_ISI);
00220
00221 TWI_ConfigureMaster(BOARD_BASE_TWI_ISI, TWCK, BOARD_MCK);
00222 TWID_Initialize(&twid, BOARD_BASE_TWI_ISI);
00223
00224
00225 NVIC_ClearPendingIRQ(TWIHS0_IRQn);
00226 NVIC_EnableIRQ(TWIHS0_IRQn);
00227 }
00228
00229
00230
00231
00232 static void _isiPckInit(void)
00233 {
00234
00235 PIO_Configure(pPinsISI, PIO_LISTSIZE(pPinsISI));
00236
00237
00238 REG_PMC_SCDR = PMC_SCER_PCK0;
00239
00240 PMC->PMC_PCK[0] = PMC_PCK_CSS_PLLA_CLK | (9 << 4);
00241
00242 REG_PMC_SCER = PMC_SCER_PCK0;
00243
00244 while ((REG_PMC_SR & PMC_SR_PCKRDY0) == 0);
00245
00246 PIO_Clear(&pin_ISI_PWD);
00247 PIO_Clear(&pin_ISI_RST);
00248 }
00249
00250
00251
00252
00253
00254 static void _lcd_Configure(void)
00255 {
00256 rect rc;
00257
00258 LCDD_Initialize(LCD_MODE, &lcdEbiDma, lcdDisplayMode);
00259 LCDD_SetCavasBuffer((void*)gDisplayBuffer, wImageWidth * wImageHeight * 2);
00260 rc.x = 0;
00261 rc.y = 0;
00262 rc.width = wImageWidth - 1;
00263 rc.height = wImageHeight - 1;
00264 LCDD_SetUpdateWindowSize(rc);
00265 LCDD_DrawRectangleWithFill(0, 0, 0, rc.width -1, rc.height -1,
00266 RGB_24_TO_RGB565(COLOR_BLACK));
00267 LCDD_UpdateWindow();
00268 Wait(500);
00269 }
00270
00271
00272
00273
00274 static void _isiInit(void)
00275 {
00276
00277 PMC_EnablePeripheral(ID_ISI);
00278
00279 ISI_Reset();
00280
00281 ISI_SetBlank(0, 0);
00282
00283 ISI_SetSensorSize(wImageWidth/2, wImageHeight);
00284
00285 ISI_setPreviewSize(wImageWidth/2, wImageHeight);
00286
00287 ISI_calcScalerFactor();
00288
00289 ISI_setInputStream(RGB_INPUT);
00290 ISI_RgbPixelMapping(1);
00291
00292 preBufDescList.Current = (uint32_t)ISI_BASE;
00293 preBufDescList.Control = ISI_DMA_P_CTRL_P_FETCH;
00294 preBufDescList.Next = (uint32_t)&preBufDescList;
00295 ISI_setDmaInPreviewPath((uint32_t)&preBufDescList, ISI_DMA_P_CTRL_P_FETCH,(uint32_t)ISI_BASE);
00296 NVIC_ClearPendingIRQ(ISI_IRQn);
00297 NVIC_SetPriority(ISI_IRQn, 5);
00298 NVIC_EnableIRQ(ISI_IRQn);
00299 }
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 extern int main(void)
00310 {
00311 uint8_t reg = 0x0;
00312 uint8_t val = 0xFD;
00313 uint16_t i;
00314
00315 WDT_Disable(WDT);
00316
00317
00318 SCB_EnableICache();
00319 SCB_EnableDCache();
00320
00321
00322 printf("-- ISI Gray Example %s --\n\r", SOFTPACK_VERSION);
00323 printf("-- %s\n\r", BOARD_NAME);
00324 printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);
00325
00326
00327 BOARD_ConfigureSdram();
00328
00329
00330 TimeTick_Configure();
00331
00332
00333 _twiInit();
00334
00335
00336 _isiPckInit();
00337
00338 PIO_Set(&pin_ISI_RST);
00339
00340 TWID_Write(&twid, CAMX_MT9V022_SLAVE_ADDR, 0x03, 1, ®, 1, 0);
00341 TWID_Write(&twid, CAMX_MT9V022_SLAVE_ADDR, 1, 1, &val, 1, 0);
00342 if (sensor_setup(&twid, &mt9v022Profile, QVGA) != SENSOR_OK) {
00343 printf("-E- Sensor setup failed.");
00344 while (1);
00345 }
00346
00347
00348 sensor_get_output(&wImageFormat, &wImageWidth, &wImageHeight, QVGA);
00349
00350
00351 _lcd_Configure();
00352
00353
00354 for(i = 0; i < 256; i++)
00355 lut[i] = ((i >> 3) << 11) | ((i >> 2) << 5) | (i >> 3);
00356
00357
00358 _isiInit();
00359
00360 ISI_Enable();
00361 ISI_DisableInterrupt(0xFFFFFFFF);
00362 ISI_EnableInterrupt(ISI_IER_PXFR_DONE);
00363 ISI_DmaChannelDisable(ISI_DMA_CHDR_C_CH_DIS);
00364 SCB_CleanInvalidateDCache();
00365
00366 ISI_DmaChannelEnable(ISI_DMA_CHER_P_CH_EN);
00367
00368 printf("preview in RGB 565 mode\n\r");
00369 while (1);
00370 }
00371