GR-PEACH barcode reader. This program uses ZBar bar code reader. ZBar is licensed under the GNU LGPL 2.1 to enable development of both open source and commercial projects.

Dependencies:   GR-PEACH_video mbed zbar_010

Fork of GR-PEACH_Camera_in by Renesas

How to use

  1. Push USER_BUTTON0, then output the result to terminal.

License

The ZBar Bar Code Reader is Copyright (C) 2007-2009 Jeff Brown <spadix@users.sourceforge.net> The QR Code reader is Copyright (C) 1999-2009 Timothy B. Terriberry <tterribe@xiph.org>

You can redistribute this library and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

ISAAC is based on the public domain implementation by Robert J. Jenkins Jr., and is itself public domain.

Portions of the bit stream reader are copyright (C) The Xiph.Org Foundation 1994-2008, and are licensed under a BSD-style license.

The Reed-Solomon decoder is derived from an implementation (C) 1991-1995 Henry Minsky (hqm@ua.com, hqm@ai.mit.edu), and is licensed under the LGPL with permission.

know how

please see this page.

Committer:
RyoheiHagimoto
Date:
Tue Apr 19 02:20:12 2016 +0000
Revision:
4:acf2a0fc3f27
Parent:
2:8fd6cd76716a
Add copying.txt and license.txt

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