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:
Osamu Nakamura
Date:
Tue Mar 21 12:06:48 2017 +0900
Revision:
2:9d98159fa9c9
Parent:
1:aaa4b3e0f03c
Child:
3:2c8f1cf3333b
Introduced mbed OS 5 instead of mbed OS 2 (classic)

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