Camera in sample for GR-PEACH. This sample works on GR-LYCHEE besides GR-PEACH.

Video Links on how to setup and run Camera_in Application:

Your video will be live at: https://youtu.be/XNH8jLhjeS4 Part1 of 1

Camera in sample for GR-PEACH or GR-LYCHEE. While USER_BUTTON0 is pressed, it will save the camera image(default is jpeg fotmat) to USB memory or SD card.
If both USB and SD are inserted, GR-PEACH or GR-LYCHEE connect to the previously detected device.

The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Please refer to following link about Audio/Camera Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

You can configure this sample application via the following definitions. If you set to 1, it will save the video file as a AVI format:

main.cpp

/**** User Selection *********/
#define SAVE_FILE_TYPE         (0)     /* Select  0(Image(.jpg)) or 1(Movie(.avi)) */
/*****************************/


  • USB channel available in this sample program
    By default, the GR-PEACH's USB connector (USB0) is configured to be used. When using USB0, please close GR-PEACH's JP3.
    /media/uploads/RyoheiHagimoto/usb.jpg


    Or, you can use the Audio/Camera Shield's USB connector (USB1). When using USB1, you need to close JP1 of Audio/Camera Shield.
    /media/uploads/dkato/audiocamerashield_jp1.jpg


  • Specify each configuration
    To specify camera and LCD, add camera-type and lcd-type to mbed_app.json.
    For details, please refer to mbed-gr-libs / README.md.

mbed_app.json

{
    "config": {
        "camera":{
            "help": "0:disable 1:enable",
            "value": "1"
        },
        "camera-type":{
            "help": "Please see mbed-gr-libs/README.md",
            "value": "CAMERA_CVBS"
        },
        "lcd":{
            "help": "0:disable 1:enable",
            "value": "0"
        },
        "lcd-type":{
            "help": "Please see mbed-gr-libs/README.md",
            "value": "GR_PEACH_4_3INCH_SHIELD"
        },
        "usb-host-ch":{
            "help": "(for GR-PEACH) 0:ch0 1:ch1",
            "value": "1"
        },
        "audio-camera-shield":{
            "help": "(for GR-PEACH) 0:not use 1:use",
            "value": "1"
        }
    }
}
Committer:
dkato
Date:
Mon Apr 18 07:14:02 2016 +0000
Revision:
1:aaa4b3e0f03c
Parent:
0:2f1caf4ce924
Child:
2:9d98159fa9c9
Supports IAR.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:2f1caf4ce924 1 #include "mbed.h"
dkato 0:2f1caf4ce924 2 #include "DisplayBace.h"
dkato 0:2f1caf4ce924 3 #include "USBHostMSD.h"
dkato 0:2f1caf4ce924 4 #include "bitmap.h"
dkato 0:2f1caf4ce924 5 #if defined(TARGET_RZ_A1H)
dkato 0:2f1caf4ce924 6 #include "usb_host_setting.h"
dkato 0:2f1caf4ce924 7 #else
dkato 0:2f1caf4ce924 8 #define USB_HOST_CH 0
dkato 0:2f1caf4ce924 9 #endif
dkato 0:2f1caf4ce924 10
dkato 0:2f1caf4ce924 11 #define VIDEO_CVBS (0) /* Analog Video Signal */
dkato 0:2f1caf4ce924 12 #define VIDEO_CMOS_CAMERA (1) /* Digital Video Signal */
dkato 0:2f1caf4ce924 13 #define VIDEO_YCBCR422 (0)
dkato 0:2f1caf4ce924 14 #define VIDEO_RGB888 (1)
dkato 0:2f1caf4ce924 15 #define VIDEO_RGB565 (2)
dkato 0:2f1caf4ce924 16
dkato 0:2f1caf4ce924 17 /**** User Selection *********/
dkato 0:2f1caf4ce924 18 #define VIDEO_INPUT_METHOD (VIDEO_CVBS) /* Select VIDEO_CVBS or VIDEO_CMOS_CAMERA */
dkato 0:2f1caf4ce924 19 #define VIDEO_INPUT_FORMAT (VIDEO_RGB888) /* Select VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565 */
dkato 0:2f1caf4ce924 20 #define USE_VIDEO_CH (0) /* Select 0 or 1 If selecting VIDEO_CMOS_CAMERA, should be 0.) */
dkato 0:2f1caf4ce924 21 #define VIDEO_PAL (0) /* Select 0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
dkato 0:2f1caf4ce924 22 /*****************************/
dkato 0:2f1caf4ce924 23
dkato 0:2f1caf4ce924 24 #if USE_VIDEO_CH == (0)
dkato 0:2f1caf4ce924 25 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_0)
dkato 0:2f1caf4ce924 26 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S0_VFIELD)
dkato 0:2f1caf4ce924 27 #else
dkato 0:2f1caf4ce924 28 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_1)
dkato 0:2f1caf4ce924 29 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S1_VFIELD)
dkato 0:2f1caf4ce924 30 #endif
dkato 0:2f1caf4ce924 31
dkato 0:2f1caf4ce924 32 #if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 )
dkato 0:2f1caf4ce924 33 #define DATA_SIZE_PER_PIC (2u)
dkato 0:2f1caf4ce924 34 #else
dkato 0:2f1caf4ce924 35 #define DATA_SIZE_PER_PIC (4u)
dkato 0:2f1caf4ce924 36 #endif
dkato 0:2f1caf4ce924 37
dkato 0:2f1caf4ce924 38 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
dkato 0:2f1caf4ce924 39 in accordance with the frame buffer burst transfer mode. */
dkato 0:2f1caf4ce924 40 #define PIXEL_HW (320u) /* QVGA */
dkato 0:2f1caf4ce924 41 #define PIXEL_VW (240u) /* QVGA */
dkato 0:2f1caf4ce924 42 #define VIDEO_BUFFER_STRIDE (((PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
dkato 0:2f1caf4ce924 43 #define VIDEO_BUFFER_HEIGHT (PIXEL_VW)
dkato 0:2f1caf4ce924 44
dkato 0:2f1caf4ce924 45 #if (USB_HOST_CH == 1) //Audio Camera Shield USB1
dkato 0:2f1caf4ce924 46 DigitalOut usb1en(P3_8);
dkato 0:2f1caf4ce924 47 #endif
dkato 0:2f1caf4ce924 48 DigitalOut led1(LED1);
dkato 0:2f1caf4ce924 49 DigitalIn button(USER_BUTTON0);
dkato 0:2f1caf4ce924 50
dkato 1:aaa4b3e0f03c 51 #if defined(__ICCARM__)
dkato 1:aaa4b3e0f03c 52 #pragma data_alignment=16
dkato 1:aaa4b3e0f03c 53 static uint8_t FrameBuffer_Video_A[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]@ ".mirrorram"; //16 bytes aligned!;
dkato 1:aaa4b3e0f03c 54 static uint8_t FrameBuffer_Video_B[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]@ ".mirrorram"; //16 bytes aligned!;
dkato 1:aaa4b3e0f03c 55 #pragma data_alignment=4
dkato 1:aaa4b3e0f03c 56 #else
dkato 0:2f1caf4ce924 57 static uint8_t FrameBuffer_Video_A[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!;
dkato 0:2f1caf4ce924 58 static uint8_t FrameBuffer_Video_B[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!;
dkato 1:aaa4b3e0f03c 59 #endif
dkato 0:2f1caf4ce924 60 static volatile int32_t vsync_count;
dkato 0:2f1caf4ce924 61 static volatile int32_t vfield_count;
dkato 0:2f1caf4ce924 62
dkato 0:2f1caf4ce924 63 /**************************************************************************//**
dkato 0:2f1caf4ce924 64 * @brief Interrupt callback function
dkato 0:2f1caf4ce924 65 * @param[in] int_type : VDC5 interrupt type
dkato 0:2f1caf4ce924 66 * @retval None
dkato 0:2f1caf4ce924 67 ******************************************************************************/
dkato 0:2f1caf4ce924 68 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type)
dkato 0:2f1caf4ce924 69 {
dkato 0:2f1caf4ce924 70 if (vfield_count > 0) {
dkato 0:2f1caf4ce924 71 vfield_count--;
dkato 0:2f1caf4ce924 72 }
dkato 0:2f1caf4ce924 73 }
dkato 0:2f1caf4ce924 74
dkato 0:2f1caf4ce924 75 /**************************************************************************//**
dkato 0:2f1caf4ce924 76 * @brief Wait for the specified number of times Vsync occurs
dkato 0:2f1caf4ce924 77 * @param[in] wait_count : Wait count
dkato 0:2f1caf4ce924 78 * @retval None
dkato 0:2f1caf4ce924 79 ******************************************************************************/
dkato 0:2f1caf4ce924 80 static void WaitVfield(const int32_t wait_count)
dkato 0:2f1caf4ce924 81 {
dkato 0:2f1caf4ce924 82 vfield_count = wait_count;
dkato 0:2f1caf4ce924 83 while (vfield_count > 0) {
dkato 0:2f1caf4ce924 84 /* Do nothing */
dkato 0:2f1caf4ce924 85 }
dkato 0:2f1caf4ce924 86 }
dkato 0:2f1caf4ce924 87
dkato 0:2f1caf4ce924 88 /**************************************************************************//**
dkato 0:2f1caf4ce924 89 * @brief Interrupt callback function for Vsync interruption
dkato 0:2f1caf4ce924 90 * @param[in] int_type : VDC5 interrupt type
dkato 0:2f1caf4ce924 91 * @retval None
dkato 0:2f1caf4ce924 92 ******************************************************************************/
dkato 0:2f1caf4ce924 93 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type)
dkato 0:2f1caf4ce924 94 {
dkato 0:2f1caf4ce924 95 if (vsync_count > 0) {
dkato 0:2f1caf4ce924 96 vsync_count--;
dkato 0:2f1caf4ce924 97 }
dkato 0:2f1caf4ce924 98 }
dkato 0:2f1caf4ce924 99
dkato 0:2f1caf4ce924 100 /**************************************************************************//**
dkato 0:2f1caf4ce924 101 * @brief Wait for the specified number of times Vsync occurs
dkato 0:2f1caf4ce924 102 * @param[in] wait_count : Wait count
dkato 0:2f1caf4ce924 103 * @retval None
dkato 0:2f1caf4ce924 104 ******************************************************************************/
dkato 0:2f1caf4ce924 105 static void WaitVsync(const int32_t wait_count)
dkato 0:2f1caf4ce924 106 {
dkato 0:2f1caf4ce924 107 vsync_count = wait_count;
dkato 0:2f1caf4ce924 108 while (vsync_count > 0) {
dkato 0:2f1caf4ce924 109 /* Do nothing */
dkato 0:2f1caf4ce924 110 }
dkato 0:2f1caf4ce924 111 }
dkato 0:2f1caf4ce924 112
dkato 0:2f1caf4ce924 113 /**************************************************************************//**
dkato 0:2f1caf4ce924 114 * @brief
dkato 0:2f1caf4ce924 115 * @param[in] void
dkato 0:2f1caf4ce924 116 * @retval None
dkato 0:2f1caf4ce924 117 ******************************************************************************/
dkato 0:2f1caf4ce924 118 int main(void)
dkato 0:2f1caf4ce924 119 {
dkato 0:2f1caf4ce924 120 DisplayBase::graphics_error_t error;
dkato 0:2f1caf4ce924 121 uint8_t * write_buff_addr = FrameBuffer_Video_A;
dkato 0:2f1caf4ce924 122 uint8_t * save_buff_addr = FrameBuffer_Video_B;
dkato 0:2f1caf4ce924 123
dkato 0:2f1caf4ce924 124 #if VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
dkato 0:2f1caf4ce924 125 DisplayBase::video_ext_in_config_t ext_in_config;
dkato 0:2f1caf4ce924 126 PinName cmos_camera_pin[11] = {
dkato 0:2f1caf4ce924 127 /* data pin */
dkato 0:2f1caf4ce924 128 P2_7, P2_6, P2_5, P2_4, P2_3, P2_2, P2_1, P2_0,
dkato 0:2f1caf4ce924 129 /* control pin */
dkato 0:2f1caf4ce924 130 P10_0, /* DV0_CLK */
dkato 0:2f1caf4ce924 131 P1_0, /* DV0_Vsync */
dkato 0:2f1caf4ce924 132 P1_1 /* DV0_Hsync */
dkato 0:2f1caf4ce924 133 };
dkato 0:2f1caf4ce924 134 #endif
dkato 0:2f1caf4ce924 135
dkato 0:2f1caf4ce924 136 /* Create DisplayBase object */
dkato 0:2f1caf4ce924 137 DisplayBase Display;
dkato 0:2f1caf4ce924 138
dkato 0:2f1caf4ce924 139 /* Graphics initialization process */
dkato 0:2f1caf4ce924 140 error = Display.Graphics_init(NULL);
dkato 0:2f1caf4ce924 141 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2f1caf4ce924 142 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 143 while (1);
dkato 0:2f1caf4ce924 144 }
dkato 0:2f1caf4ce924 145
dkato 0:2f1caf4ce924 146 #if VIDEO_INPUT_METHOD == VIDEO_CVBS
dkato 0:2f1caf4ce924 147 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL);
dkato 0:2f1caf4ce924 148 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:2f1caf4ce924 149 while(1);
dkato 0:2f1caf4ce924 150 }
dkato 0:2f1caf4ce924 151
dkato 0:2f1caf4ce924 152 #elif VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
dkato 0:2f1caf4ce924 153 /* MT9V111 camera input config */
dkato 0:2f1caf4ce924 154 ext_in_config.inp_format = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
dkato 0:2f1caf4ce924 155 ext_in_config.inp_pxd_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing data */
dkato 0:2f1caf4ce924 156 ext_in_config.inp_vs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Vsync signals */
dkato 0:2f1caf4ce924 157 ext_in_config.inp_hs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Hsync signals */
dkato 0:2f1caf4ce924 158 ext_in_config.inp_endian_on = DisplayBase::OFF; /* External input bit endian change on/off */
dkato 0:2f1caf4ce924 159 ext_in_config.inp_swap_on = DisplayBase::OFF; /* External input B/R signal swap on/off */
dkato 0:2f1caf4ce924 160 ext_in_config.inp_vs_inv = DisplayBase::SIG_POL_NOT_INVERTED; /* External input DV_VSYNC inversion control */
dkato 0:2f1caf4ce924 161 ext_in_config.inp_hs_inv = DisplayBase::SIG_POL_INVERTED; /* External input DV_HSYNC inversion control */
dkato 0:2f1caf4ce924 162 ext_in_config.inp_f525_625 = DisplayBase::EXTIN_LINE_525; /* Number of lines for BT.656 external input */
dkato 0:2f1caf4ce924 163 ext_in_config.inp_h_pos = DisplayBase::EXTIN_H_POS_CRYCBY; /* Y/Cb/Y/Cr data string start timing to Hsync reference */
dkato 0:2f1caf4ce924 164 ext_in_config.cap_vs_pos = 6; /* Capture start position from Vsync */
dkato 0:2f1caf4ce924 165 ext_in_config.cap_hs_pos = 150; /* Capture start position form Hsync */
dkato 0:2f1caf4ce924 166 ext_in_config.cap_width = 640; /* Capture width */
dkato 0:2f1caf4ce924 167 ext_in_config.cap_height = 468u; /* Capture height Max 468[line]
dkato 0:2f1caf4ce924 168 Due to CMOS(MT9V111) output signal timing and VDC5 specification */
dkato 0:2f1caf4ce924 169 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config);
dkato 0:2f1caf4ce924 170 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:2f1caf4ce924 171 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 172 while(1);
dkato 0:2f1caf4ce924 173 }
dkato 0:2f1caf4ce924 174
dkato 0:2f1caf4ce924 175 /* MT9V111 camera input port setting */
dkato 0:2f1caf4ce924 176 error = Display.Graphics_Dvinput_Port_Init(cmos_camera_pin, 11);
dkato 0:2f1caf4ce924 177 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:2f1caf4ce924 178 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 179 while (1);
dkato 0:2f1caf4ce924 180 }
dkato 0:2f1caf4ce924 181 #endif
dkato 0:2f1caf4ce924 182
dkato 0:2f1caf4ce924 183 /* Interrupt callback function setting (Vsync signal input to scaler 0) */
dkato 0:2f1caf4ce924 184 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VI_VSYNC, 0, IntCallbackFunc_Vsync);
dkato 0:2f1caf4ce924 185 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2f1caf4ce924 186 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 187 while (1);
dkato 0:2f1caf4ce924 188 }
dkato 0:2f1caf4ce924 189 /* Video capture setting (progressive form fixed) */
dkato 0:2f1caf4ce924 190 error = Display.Video_Write_Setting(
dkato 0:2f1caf4ce924 191 VIDEO_INPUT_CH,
dkato 0:2f1caf4ce924 192 #if VIDEO_PAL == 0
dkato 0:2f1caf4ce924 193 DisplayBase::COL_SYS_NTSC_358,
dkato 0:2f1caf4ce924 194 #else
dkato 0:2f1caf4ce924 195 DisplayBase::COL_SYS_PAL_443,
dkato 0:2f1caf4ce924 196 #endif
dkato 0:2f1caf4ce924 197 write_buff_addr,
dkato 0:2f1caf4ce924 198 VIDEO_BUFFER_STRIDE,
dkato 0:2f1caf4ce924 199 #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422
dkato 0:2f1caf4ce924 200 DisplayBase::VIDEO_FORMAT_YCBCR422,
dkato 0:2f1caf4ce924 201 DisplayBase::WR_RD_WRSWA_NON,
dkato 0:2f1caf4ce924 202 #elif VIDEO_INPUT_FORMAT == VIDEO_RGB565
dkato 0:2f1caf4ce924 203 DisplayBase::VIDEO_FORMAT_RGB565,
dkato 0:2f1caf4ce924 204 DisplayBase::WR_RD_WRSWA_32_16BIT,
dkato 0:2f1caf4ce924 205 #else
dkato 0:2f1caf4ce924 206 DisplayBase::VIDEO_FORMAT_RGB888,
dkato 0:2f1caf4ce924 207 DisplayBase::WR_RD_WRSWA_32BIT,
dkato 0:2f1caf4ce924 208 #endif
dkato 0:2f1caf4ce924 209 PIXEL_VW,
dkato 0:2f1caf4ce924 210 PIXEL_HW
dkato 0:2f1caf4ce924 211 );
dkato 0:2f1caf4ce924 212 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2f1caf4ce924 213 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 214 while (1);
dkato 0:2f1caf4ce924 215 }
dkato 0:2f1caf4ce924 216
dkato 0:2f1caf4ce924 217 /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */
dkato 0:2f1caf4ce924 218 error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield);
dkato 0:2f1caf4ce924 219 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2f1caf4ce924 220 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 221 while (1);
dkato 0:2f1caf4ce924 222 }
dkato 0:2f1caf4ce924 223
dkato 0:2f1caf4ce924 224 /* Video write process start */
dkato 0:2f1caf4ce924 225 error = Display.Video_Start (VIDEO_INPUT_CH);
dkato 0:2f1caf4ce924 226 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2f1caf4ce924 227 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 228 while (1);
dkato 0:2f1caf4ce924 229 }
dkato 0:2f1caf4ce924 230
dkato 0:2f1caf4ce924 231 /* Video write process stop */
dkato 0:2f1caf4ce924 232 error = Display.Video_Stop (VIDEO_INPUT_CH);
dkato 0:2f1caf4ce924 233 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2f1caf4ce924 234 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 235 while (1);
dkato 0:2f1caf4ce924 236 }
dkato 0:2f1caf4ce924 237
dkato 0:2f1caf4ce924 238 /* Video write process start */
dkato 0:2f1caf4ce924 239 error = Display.Video_Start (VIDEO_INPUT_CH);
dkato 0:2f1caf4ce924 240 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2f1caf4ce924 241 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 242 while (1);
dkato 0:2f1caf4ce924 243 }
dkato 0:2f1caf4ce924 244
dkato 0:2f1caf4ce924 245 /* Wait vsync to update resister */
dkato 0:2f1caf4ce924 246 WaitVsync(1);
dkato 0:2f1caf4ce924 247
dkato 0:2f1caf4ce924 248 /* Wait 2 Vfield(Top or bottom field) */
dkato 0:2f1caf4ce924 249 WaitVfield(2);
dkato 0:2f1caf4ce924 250
dkato 0:2f1caf4ce924 251 #if (USB_HOST_CH == 1) //Audio Shield USB1
dkato 0:2f1caf4ce924 252 //Audio Shield USB1 enable
dkato 0:2f1caf4ce924 253 usb1en = 1; //Outputs high level
dkato 0:2f1caf4ce924 254 Thread::wait(5);
dkato 0:2f1caf4ce924 255 usb1en = 0; //Outputs low level
dkato 0:2f1caf4ce924 256 #endif
dkato 0:2f1caf4ce924 257 USBHostMSD msd("usb");
dkato 0:2f1caf4ce924 258 char file_name[32];
dkato 0:2f1caf4ce924 259 int file_name_index = 0;
dkato 0:2f1caf4ce924 260 int save_file_size;
dkato 0:2f1caf4ce924 261
dkato 0:2f1caf4ce924 262 while (1) {
dkato 0:2f1caf4ce924 263 /* button check */
dkato 0:2f1caf4ce924 264 if (button == 0) {
dkato 0:2f1caf4ce924 265 led1 = 1;
dkato 0:2f1caf4ce924 266 if (write_buff_addr == FrameBuffer_Video_A) {
dkato 0:2f1caf4ce924 267 write_buff_addr = FrameBuffer_Video_B;
dkato 0:2f1caf4ce924 268 save_buff_addr = FrameBuffer_Video_A;
dkato 0:2f1caf4ce924 269 } else {
dkato 0:2f1caf4ce924 270 write_buff_addr = FrameBuffer_Video_A;
dkato 0:2f1caf4ce924 271 save_buff_addr = FrameBuffer_Video_B;
dkato 0:2f1caf4ce924 272 }
dkato 0:2f1caf4ce924 273
dkato 0:2f1caf4ce924 274 /* Change write buffer */
dkato 0:2f1caf4ce924 275 error = Display.Video_Write_Change(
dkato 0:2f1caf4ce924 276 VIDEO_INPUT_CH,
dkato 0:2f1caf4ce924 277 write_buff_addr,
dkato 0:2f1caf4ce924 278 VIDEO_BUFFER_STRIDE);
dkato 0:2f1caf4ce924 279 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2f1caf4ce924 280 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2f1caf4ce924 281 while (1);
dkato 0:2f1caf4ce924 282 }
dkato 0:2f1caf4ce924 283 /* Wait 2 Vfield(Top or bottom field) */
dkato 0:2f1caf4ce924 284 WaitVfield(2);
dkato 0:2f1caf4ce924 285
dkato 0:2f1caf4ce924 286 /* FrameBuffer_Video_AorB capture completed */
dkato 0:2f1caf4ce924 287 /* USB connect check */
dkato 0:2f1caf4ce924 288 while (!msd.connected()) {
dkato 0:2f1caf4ce924 289 if (!msd.connect()) {
dkato 0:2f1caf4ce924 290 Thread::wait(500);
dkato 0:2f1caf4ce924 291 } else {
dkato 0:2f1caf4ce924 292 break;
dkato 0:2f1caf4ce924 293 }
dkato 0:2f1caf4ce924 294 }
dkato 0:2f1caf4ce924 295
dkato 0:2f1caf4ce924 296 /* Data save */
dkato 0:2f1caf4ce924 297 #if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 )
dkato 0:2f1caf4ce924 298 /* Save ".bin" file */
dkato 0:2f1caf4ce924 299 sprintf(file_name, "/usb/video_%d.bin", file_name_index++);
dkato 0:2f1caf4ce924 300 FILE * fp = fopen(file_name, "w");
dkato 0:2f1caf4ce924 301 save_file_size = fwrite(save_buff_addr, sizeof(char), (VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT), fp);
dkato 0:2f1caf4ce924 302 fclose(fp);
dkato 0:2f1caf4ce924 303 #else
dkato 0:2f1caf4ce924 304 /* Save ".bmp" file */
dkato 0:2f1caf4ce924 305 sprintf(file_name, "/usb/video_%d.bmp", file_name_index++);
dkato 0:2f1caf4ce924 306
dkato 0:2f1caf4ce924 307 bitmap bitmapfile;
dkato 0:2f1caf4ce924 308 save_file_size = bitmapfile.Rgb888ToBmp(file_name, save_buff_addr, PIXEL_HW, PIXEL_VW);
dkato 0:2f1caf4ce924 309 #endif
dkato 0:2f1caf4ce924 310 printf("file name %s, file size %d\n", file_name, save_file_size);
dkato 0:2f1caf4ce924 311 led1 = 0;
dkato 0:2f1caf4ce924 312 }
dkato 0:2f1caf4ce924 313 }
dkato 0:2f1caf4ce924 314 }