![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test
Dependencies: GR-PEACH_video USBHost USBHost_custom
Fork of GR-PEACH_Camera_in by
main.cpp@0:2f1caf4ce924, 2015-06-26 (annotated)
- Committer:
- dkato
- Date:
- Fri Jun 26 02:26:08 2015 +0000
- Revision:
- 0:2f1caf4ce924
- Child:
- 1:aaa4b3e0f03c
first commit
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:2f1caf4ce924 | 51 | static uint8_t FrameBuffer_Video_A[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!; |
dkato | 0:2f1caf4ce924 | 52 | static uint8_t FrameBuffer_Video_B[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!; |
dkato | 0:2f1caf4ce924 | 53 | static volatile int32_t vsync_count; |
dkato | 0:2f1caf4ce924 | 54 | static volatile int32_t vfield_count; |
dkato | 0:2f1caf4ce924 | 55 | |
dkato | 0:2f1caf4ce924 | 56 | /**************************************************************************//** |
dkato | 0:2f1caf4ce924 | 57 | * @brief Interrupt callback function |
dkato | 0:2f1caf4ce924 | 58 | * @param[in] int_type : VDC5 interrupt type |
dkato | 0:2f1caf4ce924 | 59 | * @retval None |
dkato | 0:2f1caf4ce924 | 60 | ******************************************************************************/ |
dkato | 0:2f1caf4ce924 | 61 | static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) |
dkato | 0:2f1caf4ce924 | 62 | { |
dkato | 0:2f1caf4ce924 | 63 | if (vfield_count > 0) { |
dkato | 0:2f1caf4ce924 | 64 | vfield_count--; |
dkato | 0:2f1caf4ce924 | 65 | } |
dkato | 0:2f1caf4ce924 | 66 | } |
dkato | 0:2f1caf4ce924 | 67 | |
dkato | 0:2f1caf4ce924 | 68 | /**************************************************************************//** |
dkato | 0:2f1caf4ce924 | 69 | * @brief Wait for the specified number of times Vsync occurs |
dkato | 0:2f1caf4ce924 | 70 | * @param[in] wait_count : Wait count |
dkato | 0:2f1caf4ce924 | 71 | * @retval None |
dkato | 0:2f1caf4ce924 | 72 | ******************************************************************************/ |
dkato | 0:2f1caf4ce924 | 73 | static void WaitVfield(const int32_t wait_count) |
dkato | 0:2f1caf4ce924 | 74 | { |
dkato | 0:2f1caf4ce924 | 75 | vfield_count = wait_count; |
dkato | 0:2f1caf4ce924 | 76 | while (vfield_count > 0) { |
dkato | 0:2f1caf4ce924 | 77 | /* Do nothing */ |
dkato | 0:2f1caf4ce924 | 78 | } |
dkato | 0:2f1caf4ce924 | 79 | } |
dkato | 0:2f1caf4ce924 | 80 | |
dkato | 0:2f1caf4ce924 | 81 | /**************************************************************************//** |
dkato | 0:2f1caf4ce924 | 82 | * @brief Interrupt callback function for Vsync interruption |
dkato | 0:2f1caf4ce924 | 83 | * @param[in] int_type : VDC5 interrupt type |
dkato | 0:2f1caf4ce924 | 84 | * @retval None |
dkato | 0:2f1caf4ce924 | 85 | ******************************************************************************/ |
dkato | 0:2f1caf4ce924 | 86 | static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) |
dkato | 0:2f1caf4ce924 | 87 | { |
dkato | 0:2f1caf4ce924 | 88 | if (vsync_count > 0) { |
dkato | 0:2f1caf4ce924 | 89 | vsync_count--; |
dkato | 0:2f1caf4ce924 | 90 | } |
dkato | 0:2f1caf4ce924 | 91 | } |
dkato | 0:2f1caf4ce924 | 92 | |
dkato | 0:2f1caf4ce924 | 93 | /**************************************************************************//** |
dkato | 0:2f1caf4ce924 | 94 | * @brief Wait for the specified number of times Vsync occurs |
dkato | 0:2f1caf4ce924 | 95 | * @param[in] wait_count : Wait count |
dkato | 0:2f1caf4ce924 | 96 | * @retval None |
dkato | 0:2f1caf4ce924 | 97 | ******************************************************************************/ |
dkato | 0:2f1caf4ce924 | 98 | static void WaitVsync(const int32_t wait_count) |
dkato | 0:2f1caf4ce924 | 99 | { |
dkato | 0:2f1caf4ce924 | 100 | vsync_count = wait_count; |
dkato | 0:2f1caf4ce924 | 101 | while (vsync_count > 0) { |
dkato | 0:2f1caf4ce924 | 102 | /* Do nothing */ |
dkato | 0:2f1caf4ce924 | 103 | } |
dkato | 0:2f1caf4ce924 | 104 | } |
dkato | 0:2f1caf4ce924 | 105 | |
dkato | 0:2f1caf4ce924 | 106 | /**************************************************************************//** |
dkato | 0:2f1caf4ce924 | 107 | * @brief |
dkato | 0:2f1caf4ce924 | 108 | * @param[in] void |
dkato | 0:2f1caf4ce924 | 109 | * @retval None |
dkato | 0:2f1caf4ce924 | 110 | ******************************************************************************/ |
dkato | 0:2f1caf4ce924 | 111 | int main(void) |
dkato | 0:2f1caf4ce924 | 112 | { |
dkato | 0:2f1caf4ce924 | 113 | DisplayBase::graphics_error_t error; |
dkato | 0:2f1caf4ce924 | 114 | uint8_t * write_buff_addr = FrameBuffer_Video_A; |
dkato | 0:2f1caf4ce924 | 115 | uint8_t * save_buff_addr = FrameBuffer_Video_B; |
dkato | 0:2f1caf4ce924 | 116 | |
dkato | 0:2f1caf4ce924 | 117 | #if VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA |
dkato | 0:2f1caf4ce924 | 118 | DisplayBase::video_ext_in_config_t ext_in_config; |
dkato | 0:2f1caf4ce924 | 119 | PinName cmos_camera_pin[11] = { |
dkato | 0:2f1caf4ce924 | 120 | /* data pin */ |
dkato | 0:2f1caf4ce924 | 121 | P2_7, P2_6, P2_5, P2_4, P2_3, P2_2, P2_1, P2_0, |
dkato | 0:2f1caf4ce924 | 122 | /* control pin */ |
dkato | 0:2f1caf4ce924 | 123 | P10_0, /* DV0_CLK */ |
dkato | 0:2f1caf4ce924 | 124 | P1_0, /* DV0_Vsync */ |
dkato | 0:2f1caf4ce924 | 125 | P1_1 /* DV0_Hsync */ |
dkato | 0:2f1caf4ce924 | 126 | }; |
dkato | 0:2f1caf4ce924 | 127 | #endif |
dkato | 0:2f1caf4ce924 | 128 | |
dkato | 0:2f1caf4ce924 | 129 | /* Create DisplayBase object */ |
dkato | 0:2f1caf4ce924 | 130 | DisplayBase Display; |
dkato | 0:2f1caf4ce924 | 131 | |
dkato | 0:2f1caf4ce924 | 132 | /* Graphics initialization process */ |
dkato | 0:2f1caf4ce924 | 133 | error = Display.Graphics_init(NULL); |
dkato | 0:2f1caf4ce924 | 134 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:2f1caf4ce924 | 135 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:2f1caf4ce924 | 136 | while (1); |
dkato | 0:2f1caf4ce924 | 137 | } |
dkato | 0:2f1caf4ce924 | 138 | |
dkato | 0:2f1caf4ce924 | 139 | #if VIDEO_INPUT_METHOD == VIDEO_CVBS |
dkato | 0:2f1caf4ce924 | 140 | error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL); |
dkato | 0:2f1caf4ce924 | 141 | if( error != DisplayBase::GRAPHICS_OK ) { |
dkato | 0:2f1caf4ce924 | 142 | while(1); |
dkato | 0:2f1caf4ce924 | 143 | } |
dkato | 0:2f1caf4ce924 | 144 | |
dkato | 0:2f1caf4ce924 | 145 | #elif VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA |
dkato | 0:2f1caf4ce924 | 146 | /* MT9V111 camera input config */ |
dkato | 0:2f1caf4ce924 | 147 | ext_in_config.inp_format = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */ |
dkato | 0:2f1caf4ce924 | 148 | ext_in_config.inp_pxd_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing data */ |
dkato | 0:2f1caf4ce924 | 149 | ext_in_config.inp_vs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Vsync signals */ |
dkato | 0:2f1caf4ce924 | 150 | ext_in_config.inp_hs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Hsync signals */ |
dkato | 0:2f1caf4ce924 | 151 | ext_in_config.inp_endian_on = DisplayBase::OFF; /* External input bit endian change on/off */ |
dkato | 0:2f1caf4ce924 | 152 | ext_in_config.inp_swap_on = DisplayBase::OFF; /* External input B/R signal swap on/off */ |
dkato | 0:2f1caf4ce924 | 153 | ext_in_config.inp_vs_inv = DisplayBase::SIG_POL_NOT_INVERTED; /* External input DV_VSYNC inversion control */ |
dkato | 0:2f1caf4ce924 | 154 | ext_in_config.inp_hs_inv = DisplayBase::SIG_POL_INVERTED; /* External input DV_HSYNC inversion control */ |
dkato | 0:2f1caf4ce924 | 155 | ext_in_config.inp_f525_625 = DisplayBase::EXTIN_LINE_525; /* Number of lines for BT.656 external input */ |
dkato | 0:2f1caf4ce924 | 156 | 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 | 157 | ext_in_config.cap_vs_pos = 6; /* Capture start position from Vsync */ |
dkato | 0:2f1caf4ce924 | 158 | ext_in_config.cap_hs_pos = 150; /* Capture start position form Hsync */ |
dkato | 0:2f1caf4ce924 | 159 | ext_in_config.cap_width = 640; /* Capture width */ |
dkato | 0:2f1caf4ce924 | 160 | ext_in_config.cap_height = 468u; /* Capture height Max 468[line] |
dkato | 0:2f1caf4ce924 | 161 | Due to CMOS(MT9V111) output signal timing and VDC5 specification */ |
dkato | 0:2f1caf4ce924 | 162 | error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config); |
dkato | 0:2f1caf4ce924 | 163 | if( error != DisplayBase::GRAPHICS_OK ) { |
dkato | 0:2f1caf4ce924 | 164 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:2f1caf4ce924 | 165 | while(1); |
dkato | 0:2f1caf4ce924 | 166 | } |
dkato | 0:2f1caf4ce924 | 167 | |
dkato | 0:2f1caf4ce924 | 168 | /* MT9V111 camera input port setting */ |
dkato | 0:2f1caf4ce924 | 169 | error = Display.Graphics_Dvinput_Port_Init(cmos_camera_pin, 11); |
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 | #endif |
dkato | 0:2f1caf4ce924 | 175 | |
dkato | 0:2f1caf4ce924 | 176 | /* Interrupt callback function setting (Vsync signal input to scaler 0) */ |
dkato | 0:2f1caf4ce924 | 177 | error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VI_VSYNC, 0, IntCallbackFunc_Vsync); |
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 | /* Video capture setting (progressive form fixed) */ |
dkato | 0:2f1caf4ce924 | 183 | error = Display.Video_Write_Setting( |
dkato | 0:2f1caf4ce924 | 184 | VIDEO_INPUT_CH, |
dkato | 0:2f1caf4ce924 | 185 | #if VIDEO_PAL == 0 |
dkato | 0:2f1caf4ce924 | 186 | DisplayBase::COL_SYS_NTSC_358, |
dkato | 0:2f1caf4ce924 | 187 | #else |
dkato | 0:2f1caf4ce924 | 188 | DisplayBase::COL_SYS_PAL_443, |
dkato | 0:2f1caf4ce924 | 189 | #endif |
dkato | 0:2f1caf4ce924 | 190 | write_buff_addr, |
dkato | 0:2f1caf4ce924 | 191 | VIDEO_BUFFER_STRIDE, |
dkato | 0:2f1caf4ce924 | 192 | #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 |
dkato | 0:2f1caf4ce924 | 193 | DisplayBase::VIDEO_FORMAT_YCBCR422, |
dkato | 0:2f1caf4ce924 | 194 | DisplayBase::WR_RD_WRSWA_NON, |
dkato | 0:2f1caf4ce924 | 195 | #elif VIDEO_INPUT_FORMAT == VIDEO_RGB565 |
dkato | 0:2f1caf4ce924 | 196 | DisplayBase::VIDEO_FORMAT_RGB565, |
dkato | 0:2f1caf4ce924 | 197 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
dkato | 0:2f1caf4ce924 | 198 | #else |
dkato | 0:2f1caf4ce924 | 199 | DisplayBase::VIDEO_FORMAT_RGB888, |
dkato | 0:2f1caf4ce924 | 200 | DisplayBase::WR_RD_WRSWA_32BIT, |
dkato | 0:2f1caf4ce924 | 201 | #endif |
dkato | 0:2f1caf4ce924 | 202 | PIXEL_VW, |
dkato | 0:2f1caf4ce924 | 203 | PIXEL_HW |
dkato | 0:2f1caf4ce924 | 204 | ); |
dkato | 0:2f1caf4ce924 | 205 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:2f1caf4ce924 | 206 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:2f1caf4ce924 | 207 | while (1); |
dkato | 0:2f1caf4ce924 | 208 | } |
dkato | 0:2f1caf4ce924 | 209 | |
dkato | 0:2f1caf4ce924 | 210 | /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */ |
dkato | 0:2f1caf4ce924 | 211 | error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield); |
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 | /* Video write process start */ |
dkato | 0:2f1caf4ce924 | 218 | error = Display.Video_Start (VIDEO_INPUT_CH); |
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 stop */ |
dkato | 0:2f1caf4ce924 | 225 | error = Display.Video_Stop (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 start */ |
dkato | 0:2f1caf4ce924 | 232 | error = Display.Video_Start (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 | /* Wait vsync to update resister */ |
dkato | 0:2f1caf4ce924 | 239 | WaitVsync(1); |
dkato | 0:2f1caf4ce924 | 240 | |
dkato | 0:2f1caf4ce924 | 241 | /* Wait 2 Vfield(Top or bottom field) */ |
dkato | 0:2f1caf4ce924 | 242 | WaitVfield(2); |
dkato | 0:2f1caf4ce924 | 243 | |
dkato | 0:2f1caf4ce924 | 244 | #if (USB_HOST_CH == 1) //Audio Shield USB1 |
dkato | 0:2f1caf4ce924 | 245 | //Audio Shield USB1 enable |
dkato | 0:2f1caf4ce924 | 246 | usb1en = 1; //Outputs high level |
dkato | 0:2f1caf4ce924 | 247 | Thread::wait(5); |
dkato | 0:2f1caf4ce924 | 248 | usb1en = 0; //Outputs low level |
dkato | 0:2f1caf4ce924 | 249 | #endif |
dkato | 0:2f1caf4ce924 | 250 | USBHostMSD msd("usb"); |
dkato | 0:2f1caf4ce924 | 251 | char file_name[32]; |
dkato | 0:2f1caf4ce924 | 252 | int file_name_index = 0; |
dkato | 0:2f1caf4ce924 | 253 | int save_file_size; |
dkato | 0:2f1caf4ce924 | 254 | |
dkato | 0:2f1caf4ce924 | 255 | while (1) { |
dkato | 0:2f1caf4ce924 | 256 | /* button check */ |
dkato | 0:2f1caf4ce924 | 257 | if (button == 0) { |
dkato | 0:2f1caf4ce924 | 258 | led1 = 1; |
dkato | 0:2f1caf4ce924 | 259 | if (write_buff_addr == FrameBuffer_Video_A) { |
dkato | 0:2f1caf4ce924 | 260 | write_buff_addr = FrameBuffer_Video_B; |
dkato | 0:2f1caf4ce924 | 261 | save_buff_addr = FrameBuffer_Video_A; |
dkato | 0:2f1caf4ce924 | 262 | } else { |
dkato | 0:2f1caf4ce924 | 263 | write_buff_addr = FrameBuffer_Video_A; |
dkato | 0:2f1caf4ce924 | 264 | save_buff_addr = FrameBuffer_Video_B; |
dkato | 0:2f1caf4ce924 | 265 | } |
dkato | 0:2f1caf4ce924 | 266 | |
dkato | 0:2f1caf4ce924 | 267 | /* Change write buffer */ |
dkato | 0:2f1caf4ce924 | 268 | error = Display.Video_Write_Change( |
dkato | 0:2f1caf4ce924 | 269 | VIDEO_INPUT_CH, |
dkato | 0:2f1caf4ce924 | 270 | write_buff_addr, |
dkato | 0:2f1caf4ce924 | 271 | VIDEO_BUFFER_STRIDE); |
dkato | 0:2f1caf4ce924 | 272 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:2f1caf4ce924 | 273 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:2f1caf4ce924 | 274 | while (1); |
dkato | 0:2f1caf4ce924 | 275 | } |
dkato | 0:2f1caf4ce924 | 276 | /* Wait 2 Vfield(Top or bottom field) */ |
dkato | 0:2f1caf4ce924 | 277 | WaitVfield(2); |
dkato | 0:2f1caf4ce924 | 278 | |
dkato | 0:2f1caf4ce924 | 279 | /* FrameBuffer_Video_AorB capture completed */ |
dkato | 0:2f1caf4ce924 | 280 | /* USB connect check */ |
dkato | 0:2f1caf4ce924 | 281 | while (!msd.connected()) { |
dkato | 0:2f1caf4ce924 | 282 | if (!msd.connect()) { |
dkato | 0:2f1caf4ce924 | 283 | Thread::wait(500); |
dkato | 0:2f1caf4ce924 | 284 | } else { |
dkato | 0:2f1caf4ce924 | 285 | break; |
dkato | 0:2f1caf4ce924 | 286 | } |
dkato | 0:2f1caf4ce924 | 287 | } |
dkato | 0:2f1caf4ce924 | 288 | |
dkato | 0:2f1caf4ce924 | 289 | /* Data save */ |
dkato | 0:2f1caf4ce924 | 290 | #if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 ) |
dkato | 0:2f1caf4ce924 | 291 | /* Save ".bin" file */ |
dkato | 0:2f1caf4ce924 | 292 | sprintf(file_name, "/usb/video_%d.bin", file_name_index++); |
dkato | 0:2f1caf4ce924 | 293 | FILE * fp = fopen(file_name, "w"); |
dkato | 0:2f1caf4ce924 | 294 | save_file_size = fwrite(save_buff_addr, sizeof(char), (VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT), fp); |
dkato | 0:2f1caf4ce924 | 295 | fclose(fp); |
dkato | 0:2f1caf4ce924 | 296 | #else |
dkato | 0:2f1caf4ce924 | 297 | /* Save ".bmp" file */ |
dkato | 0:2f1caf4ce924 | 298 | sprintf(file_name, "/usb/video_%d.bmp", file_name_index++); |
dkato | 0:2f1caf4ce924 | 299 | |
dkato | 0:2f1caf4ce924 | 300 | bitmap bitmapfile; |
dkato | 0:2f1caf4ce924 | 301 | save_file_size = bitmapfile.Rgb888ToBmp(file_name, save_buff_addr, PIXEL_HW, PIXEL_VW); |
dkato | 0:2f1caf4ce924 | 302 | #endif |
dkato | 0:2f1caf4ce924 | 303 | printf("file name %s, file size %d\n", file_name, save_file_size); |
dkato | 0:2f1caf4ce924 | 304 | led1 = 0; |
dkato | 0:2f1caf4ce924 | 305 | } |
dkato | 0:2f1caf4ce924 | 306 | } |
dkato | 0:2f1caf4ce924 | 307 | } |