int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* SysTick end of count event each 10ms */ #ifndef YUVDEBUG unsigned int line; #endif RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); init_USART1(1048576); USART_puts(USART2,"\nLoaded,"); frame_done=0; /*Camera configuration */ // ****INIT the TW9910 in the following function if (DCMI_OV9655Config() == 0x00)//configures pins of DCMI,I2C and DMA and the camera settings, if it returns a positive response { //Successful int fr=0; USART_puts(USART2,"In TW9910\n"); /* Enable DMA transfer */ DMA_Cmd(DMA2_Stream1, ENABLE); /* Enable DCMI interface */ DCMI_Cmd(ENABLE); /* Start Image capture */ DCMI_CaptureCmd(ENABLE); while (1) { // int i; // Delay(50); if (frame_done) { char s[5]; int i; fr++; DCMI_CaptureCmd(DISABLE); #ifndef YUVDEBUG USART_puts(USART2,"\njpeg2\n"); huffman_start(IMG_HEIGHT & -8, IMG_WIDTH & -8); huffman_resetdc(); #endif #ifdef YUVDEBUG USART_puts(USART2,"\nNewFrame\n"); for(i=0;i<FULLIMAGESIZE*2;i++){ sprintf(s,",%x",imagearray[i]); USART_puts(USART2,s); } #endif #ifndef YUVDEBUG for (line=0; line<NUM_LINES; line++) { uint8_t* line_buffer=(uint8_t *)&(imagearray[line*(IMG_WIDTH*8*2)]); // encode the line using encoder encode_line_yuv(line_buffer, line); } // write .jpeg footer (end-of-image marker) huffman_stop(); #endif // /* print the frame counter */ // sprintf(s,",%d",fr); // USART_puts(USART2,s); //USART_puts(USART2,"\njpegends\n"); DCMI_CaptureCmd(ENABLE); frame_done = 0; } } } else {// Cant INIT the TW9910 USART_puts(USART2,"Cant Init TW9910"); /* Go to infinite loop */ while (1); } }
int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* SysTick end of count event each 10ms */ unsigned int line; enum { TYPE_UNKNOWN=0, TYPE_RGB24, TYPE_RGB16, TYPE_YUV, } image_type = TYPE_UNKNOWN; RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); init_USART1(1048576); USART_puts(USART2,"\nLoaded,"); image_type = TYPE_YUV; frame_done=0; // LIS302DL_Reset(); /* SET USER Key */ /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */ // EXTILine0_Config(); // /* Initialize the LCD */ // STM32f4_Discovery_LCD_Init(); // LCD_Clear(LCD_COLOR_WHITE); // LCD_SetTextColor(LCD_COLOR_BLUE); // DCMI_Control_IO_Init();//funtion to configure reset and power pins of the camera **dont need for tw9910 // LCD_DisplayStringLine(LINE(2), " Camera Init.."); /* OV9655 Camera Module configuration */ // ****INIT the TW9910 in the following function if (DCMI_OV9655Config() == 0x00)//configures pins of DCMI,I2C and DMA and the camera settings, if it returns a positive response { //Successful // int fr=0; USART_puts(USART2,"In TW9910\n"); // LCD_DisplayStringLine(LINE(2), " "); // LCD_SetDisplayWindow(0, 0, 320, 240); // LCD_WriteRAM_Prepare(); //initialise an array here for the Image and ensure it is set up in the DMA configuration /* Enable DMA transfer */ DMA_Cmd(DMA2_Stream1, ENABLE); /* Enable DCMI interface */ DCMI_Cmd(ENABLE); /* Start Image capture */ DCMI_CaptureCmd(ENABLE); /*init the picture count*/ //useless for tw9910 and our case //init_picture_count(); // a function to initialise a variable from a counter file in the sdcard to name the new bmp file and file-xxx.bmp while (1) { // int i; //Delay(50); // int i; //for(i=0;i<1000;i++); if (frame_done) { // char s[5]; // fr++; // USART_puts(USART2,"\nNewFrame\n"); // if (capture_Flag == ENABLE) { DCMI_CaptureCmd(DISABLE); USART_puts(USART2,"\njpeg2\n"); huffman_start(IMG_HEIGHT & -8, IMG_WIDTH & -8); huffman_resetdc(); // USART_puts(USART2,"\njpeg\n"); // // for(i=0;i<FULLIMAGESIZE;i++){ // sprintf(s,",%x",imagearray[i]); // USART_puts(USART2,s); // //USART_writebyte(USART2,&imagearray[i]); // // } // // USART_puts(USART2,"\nDone"); // capture_Flag = DISABLE; // // Capture_Image_TO_Bmp(); //// LCD_SetDisplayWindow(0, 0, 320, 240); //// LCD_WriteRAM_Prepare(); // capture_Flag = ENABLE; // } // USART_puts(USART2,"\njpeg2\n"); for (line=0; line<NUM_LINES; line++) { uint8_t* line_buffer=(uint8_t *)&(imagearray[line*(IMG_WIDTH*IMG_HEIGHT*2/NUM_LINES)]); // encode the line using appropriate encoder switch (image_type) { // case TYPE_RGB24: encode_line_rgb24(line_buffer, line); break; // case TYPE_RGB16: encode_line_rgb16(line_buffer, line); break; case TYPE_YUV: encode_line_yuv(line_buffer, line); break; case TYPE_UNKNOWN: default:break; // fprintf(stderr, "error: %s, unsupported encoder for input '%s'\n", argv[0], argv[1]); // exit(1); } } // write .jpeg footer (end-of-image marker) huffman_stop(); USART_puts(USART2,"\njpegends\n"); DCMI_CaptureCmd(ENABLE); frame_done = 0; //if(fr==2) //while(1); } } } else { // LCD_SetTextColor(LCD_COLOR_RED); // LCD_DisplayStringLine(LINE(2), "Camera Init.. fails"); // LCD_DisplayStringLine(LINE(4), "Check the Camera HW "); // LCD_DisplayStringLine(LINE(5), " and try again "); /* Go to infinite loop */ while (1); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); LIS302DL_Reset(); /* SET USER Key */ /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */ EXTILine0_Config(); /* Initialize the LCD */ STM32f4_Discovery_LCD_Init(); LCD_Clear(LCD_COLOR_WHITE); LCD_SetTextColor(LCD_COLOR_BLUE); DCMI_Control_IO_Init(); LCD_DisplayStringLine(LINE(2), " Camera Init.."); /* OV9655 Camera Module configuration */ if (DCMI_OV9655Config() == 0x00) { LCD_DisplayStringLine(LINE(2), " "); LCD_SetDisplayWindow(0, 0, 320, 240); LCD_WriteRAM_Prepare(); /* Start Image capture and Display on the LCD *****************************/ /* Enable DMA transfer */ DMA_Cmd(DMA2_Stream1, ENABLE); /* Enable DCMI interface */ DCMI_Cmd(ENABLE); /* Start Image capture */ DCMI_CaptureCmd(ENABLE); /*init the picture count*/ init_picture_count(); KeyPressFlg = 0; while (1) { /* Insert 100ms delay */ Delay(100); if (KeyPressFlg) { KeyPressFlg = 0; /* press user KEY take a photo */ if (capture_Flag == ENABLE) { DCMI_CaptureCmd(DISABLE); capture_Flag = DISABLE; Capture_Image_TO_Bmp(); LCD_SetDisplayWindow(0, 0, 320, 240); LCD_WriteRAM_Prepare(); DCMI_CaptureCmd(ENABLE); capture_Flag = ENABLE; } } } } else { LCD_SetTextColor(LCD_COLOR_RED); LCD_DisplayStringLine(LINE(2), "Camera Init.. fails"); LCD_DisplayStringLine(LINE(4), "Check the Camera HW "); LCD_DisplayStringLine(LINE(5), " and try again "); /* Go to infinite loop */ while (1); } }