Micon Car Rally / Mbed 2 deprecated CameraModule_Test

Dependencies:   GR-PEACH_video mbed

Fork of Operation_Test by Micon Car Rally

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //------------------------------------------------------------------//
00002 //Supported MCU:   RZ/A1H
00003 //File Contents:   Camera Module Test Program (GR-PEACH version on the Micon Car)
00004 //Version number:  Ver.1.00
00005 //Date:            2017.07.13
00006 //Copyright:       Renesas Electronics Corporation
00007 //------------------------------------------------------------------//
00008  
00009 //This program supports the following boards:
00010 //* GR-PEACH(E version)
00011 //* Camera module (SC-310)
00012  
00013 //Include
00014 //------------------------------------------------------------------//
00015 #include "mbed.h"
00016 #include "iodefine.h"
00017 #include "DisplayBace.h"
00018  
00019 //Define
00020 //------------------------------------------------------------------//
00021 
00022 //Define(NTSC-Video)
00023 //------------------------------------------------------------------//
00024 #define VIDEO_INPUT_CH          (DisplayBase::VIDEO_INPUT_CHANNEL_0)
00025 #define VIDEO_INT_TYPE          (DisplayBase::INT_TYPE_S0_VFIELD)
00026 #define DATA_SIZE_PER_PIC       (2u)
00027 
00028 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
00029     in accordance with the frame buffer burst transfer mode. */
00030 #define PIXEL_HW                (320u)  /* QVGA */
00031 #define PIXEL_VW                (240u)  /* QVGA */
00032 #define VIDEO_BUFFER_STRIDE     (((PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
00033 #define VIDEO_BUFFER_HEIGHT     (PIXEL_VW)
00034 
00035 //Constructor
00036 //------------------------------------------------------------------//
00037 DigitalIn   push_sw(P2_13);             /* SW1 on the Motor Drive board */
00038 
00039 //Prototype
00040 //------------------------------------------------------------------//
00041 unsigned int pushsw_get( void );
00042 
00043 //Prototype(NTSC-video)
00044 //------------------------------------------------------------------//
00045 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type);
00046 static void WaitVfield(const int32_t wait_count);
00047 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type);
00048 static void WaitVsync(const int32_t wait_count);
00049 
00050 
00051 //Globle(NTSC-video)
00052 //------------------------------------------------------------------//
00053 static uint8_t FrameBuffer_Video_A[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16)));  //16 bytes aligned!;
00054 static uint8_t FrameBuffer_Video_B[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16)));  //16 bytes aligned!;
00055 static volatile int32_t vsync_count;
00056 static volatile int32_t vfield_count;
00057 
00058 //Main
00059 //------------------------------------------------------------------//
00060 int main( void )
00061 {
00062     /* NTSC-Video */
00063     DisplayBase::graphics_error_t error;
00064     uint8_t * write_buff_addr = FrameBuffer_Video_A;
00065     uint8_t * save_buff_addr  = FrameBuffer_Video_B;
00066 
00067     /* Create DisplayBase object */
00068     DisplayBase Display;
00069 
00070     /* Graphics initialization process */
00071     error = Display.Graphics_init(NULL);
00072     if (error != DisplayBase::GRAPHICS_OK) {
00073         printf("Line %d, error %d\n", __LINE__, error);
00074         while (1);
00075     }
00076 
00077     error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL);
00078     if( error != DisplayBase::GRAPHICS_OK ) {
00079         while(1);
00080     }
00081 
00082     /* Interrupt callback function setting (Vsync signal input to scaler 0) */
00083     error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VI_VSYNC, 0, IntCallbackFunc_Vsync);
00084     if (error != DisplayBase::GRAPHICS_OK) {
00085         printf("Line %d, error %d\n", __LINE__, error);
00086         while (1);
00087     }
00088     /* Video capture setting (progressive form fixed) */
00089     error = Display.Video_Write_Setting(
00090                 VIDEO_INPUT_CH,
00091                 DisplayBase::COL_SYS_NTSC_358,
00092                 write_buff_addr,
00093                 VIDEO_BUFFER_STRIDE,
00094                 DisplayBase::VIDEO_FORMAT_YCBCR422,
00095                 DisplayBase::WR_RD_WRSWA_32_16BIT,
00096                 PIXEL_VW,
00097                 PIXEL_HW
00098             );
00099     if (error != DisplayBase::GRAPHICS_OK) {
00100         printf("Line %d, error %d\n", __LINE__, error);
00101         while (1);
00102     }
00103 
00104     /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */
00105     error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield);
00106     if (error != DisplayBase::GRAPHICS_OK) {
00107         printf("Line %d, error %d\n", __LINE__, error);
00108         while (1);
00109     }
00110 
00111     /* Video write process start */
00112     error = Display.Video_Start (VIDEO_INPUT_CH);
00113     if (error != DisplayBase::GRAPHICS_OK) {
00114         printf("Line %d, error %d\n", __LINE__, error);
00115         while (1);
00116     }
00117 
00118     /* Video write process stop */
00119     error = Display.Video_Stop (VIDEO_INPUT_CH);
00120     if (error != DisplayBase::GRAPHICS_OK) {
00121         printf("Line %d, error %d\n", __LINE__, error);
00122         while (1);
00123     }
00124 
00125     /* Video write process start */
00126     error = Display.Video_Start (VIDEO_INPUT_CH);
00127     if (error != DisplayBase::GRAPHICS_OK) {
00128         printf("Line %d, error %d\n", __LINE__, error);
00129         while (1);
00130     }
00131 
00132     /* Wait vsync to update resister */
00133     WaitVsync(1);
00134 
00135     /* Wait 2 Vfield(Top or bottom field) */
00136     WaitVfield(2);
00137 
00138     while(1) {
00139 
00140         /* SW check */
00141         if ( pushsw_get() ) {
00142             WaitVfield( 2 );
00143             if (write_buff_addr == FrameBuffer_Video_A) {
00144                 write_buff_addr = FrameBuffer_Video_B;
00145                 save_buff_addr  = FrameBuffer_Video_A;
00146             } else {
00147                 write_buff_addr = FrameBuffer_Video_A;
00148                 save_buff_addr  = FrameBuffer_Video_B;
00149             }
00150             /* Change write buffer */
00151             error = Display.Video_Write_Change(
00152                         VIDEO_INPUT_CH,
00153                         write_buff_addr,
00154                         VIDEO_BUFFER_STRIDE);
00155             if (error != DisplayBase::GRAPHICS_OK) {
00156                 while (1);
00157             }
00158         }
00159     }
00160 }
00161 
00162 
00163 //pushsw_get(on Motor drive board)
00164 //------------------------------------------------------------------//
00165 unsigned int pushsw_get( void )
00166 {
00167     return (~push_sw) & 0x1;            /* Read ports with switches */
00168 }
00169 
00170 
00171 //******************************************************************//
00172 // @brief       Interrupt callback function
00173 // @param[in]   int_type    : VDC5 interrupt type
00174 // @retval      None
00175 //*******************************************************************/
00176 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type)
00177 {
00178     if (vfield_count > 0) {
00179         vfield_count--;
00180     }
00181 }
00182 
00183 //******************************************************************//
00184 // @brief       Wait for the specified number of times Vsync occurs
00185 // @param[in]   wait_count          : Wait count
00186 // @retval      None
00187 //*******************************************************************/
00188 static void WaitVfield(const int32_t wait_count)
00189 {
00190     vfield_count = wait_count;
00191     while (vfield_count > 0) {
00192         /* Do nothing */
00193     }
00194 }
00195 
00196 //******************************************************************//
00197 // @brief       Interrupt callback function for Vsync interruption
00198 // @param[in]   int_type    : VDC5 interrupt type
00199 // @retval      None
00200 //*******************************************************************/
00201 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type)
00202 {
00203     if (vsync_count > 0) {
00204         vsync_count--;
00205     }
00206 }
00207 
00208 //******************************************************************//
00209 // @brief       Wait for the specified number of times Vsync occurs
00210 // @param[in]   wait_count          : Wait count
00211 // @retval      None
00212 //*******************************************************************/
00213 static void WaitVsync(const int32_t wait_count)
00214 {
00215     vsync_count = wait_count;
00216     while (vsync_count > 0) {
00217         /* Do nothing */
00218     }
00219 }
00220 
00221 //------------------------------------------------------------------//
00222 // End of file
00223 //------------------------------------------------------------------//