Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-os-lychee DisplayApp_Base
main.cpp
00001 #include "mbed.h" 00002 #include "EasyAttach_CameraAndLCD.h" 00003 #include "JPEG_Converter.h" 00004 #include "dcache-control.h" 00005 #include "DisplayApp.h" 00006 #include "FATFileSystem.h" 00007 00008 /**** User Selection *********/ 00009 /** JPEG out setting **/ 00010 #define JPEG_ENCODE_QUALITY (55) /* JPEG encode quality (min:1, max:75 (Considering the size of JpegBuffer, about 75 is the upper limit.)) */ 00011 #define VFIELD_INT_SKIP_CNT (1) /* A guide for GR-LYCHEE. 0:60fps, 1:30fps, 2:20fps, 3:15fps, 4:12fps, 5:10fps */ 00012 /*****************************/ 00013 00014 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128 00015 in accordance with the frame buffer burst transfer mode. */ 00016 #define VIDEO_PIXEL_HW (640u) /* VGA */ 00017 #define VIDEO_PIXEL_VW (480u) /* VGA */ 00018 00019 #define FRAME_BUFFER_STRIDE (((VIDEO_PIXEL_HW * 2) + 31u) & ~31u) 00020 #define FRAME_BUFFER_HEIGHT (VIDEO_PIXEL_VW) 00021 00022 DisplayBase Display; 00023 00024 #if defined(__ICCARM__) 00025 #pragma data_alignment=32 00026 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]@ ".mirrorram"; 00027 #pragma data_alignment=32 00028 static uint8_t JpegBuffer[2][1024 * 64]; 00029 static uint8_t JpegBuffer_Send[1024 * 64]; 00030 #else 00031 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(32))); 00032 static uint8_t JpegBuffer[2][1024 * 64]__attribute((aligned(32))); 00033 static uint8_t JpegBuffer_Send[1024 * 64]__attribute((aligned(32))); 00034 #endif 00035 static size_t jcu_encode_size[2]; 00036 static JPEG_Converter Jcu; 00037 static int jcu_buf_index_write = 0; 00038 static int jcu_buf_index_write_done = 0; 00039 static int jcu_buf_index_read = 0; 00040 static volatile int jcu_encoding = 0; 00041 static volatile int image_change = 0; 00042 static DisplayApp display_app; 00043 static int Vfield_Int_Cnt = 0; 00044 00045 static void JcuEncodeCallBackFunc(JPEG_Converter::jpeg_conv_error_t err_code) 00046 { 00047 if (err_code == JPEG_Converter::JPEG_CONV_OK) { 00048 jcu_buf_index_write_done = jcu_buf_index_write; 00049 image_change = 1; 00050 } 00051 jcu_encoding = 0; 00052 } 00053 00054 static void snapshot(void) 00055 { 00056 00057 while ((jcu_encoding == 1) || (image_change == 0)) { 00058 Thread::wait(1); 00059 } 00060 jcu_buf_index_read = jcu_buf_index_write_done; 00061 memcpy(JpegBuffer_Send, JpegBuffer[jcu_buf_index_read],1024 * 64); 00062 image_change = 0; 00063 00064 display_app.SendJpeg(JpegBuffer_Send, (uint32_t)jcu_encode_size[jcu_buf_index_read]); 00065 } 00066 00067 static void WaitGetCommand(void) 00068 { 00069 int flag; 00070 bool blink_on = 0; 00071 bool blink_flag = 0; 00072 char command; 00073 DigitalOut led1(LED1); 00074 DigitalOut led2(LED2); 00075 DigitalOut led3(LED3); 00076 DigitalOut led4(LED4); 00077 command = display_app.Getgetc(); 00078 00079 if(command=='1'){ 00080 snapshot(); //撮影処理 00081 } 00082 00083 else if(command == '4' or command == '5') 00084 { 00085 flag = 1; //走行処理 00086 blink_on = true; 00087 } 00088 00089 /*走行処理*/ 00090 if(command == '4'){ 00091 led1 = 1; 00092 }else if (command == '5'){ 00093 blink_flag = !blink_flag; 00094 led1 = 0; 00095 if(blink_on == true and blink_flag == true){ 00096 led2 = !led2; 00097 } 00098 wait(1); 00099 } 00100 00101 /*if (PcApp.readable()) { 00102 command = PcApp.getc();*/ 00103 00104 00105 /* 00106 00107 } else if (data == '3') { 00108 flag = 4; //音声出力処理 00109 00110 } else if (data == '2') { 00111 flag = 5; //ライト点灯処理 00112 } 00113 */ 00114 00115 00116 } 00117 00118 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) 00119 { 00120 if (Vfield_Int_Cnt < VFIELD_INT_SKIP_CNT) { 00121 Vfield_Int_Cnt++; 00122 return; 00123 } 00124 Vfield_Int_Cnt = 0; 00125 00126 //Interrupt callback function 00127 if (jcu_encoding == 0) { 00128 JPEG_Converter::bitmap_buff_info_t bitmap_buff_info; 00129 JPEG_Converter::encode_options_t encode_options; 00130 00131 bitmap_buff_info.width = VIDEO_PIXEL_HW; 00132 bitmap_buff_info.height = VIDEO_PIXEL_VW; 00133 bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422; 00134 bitmap_buff_info.buffer_address = (void *)user_frame_buffer0; 00135 00136 encode_options.encode_buff_size = sizeof(JpegBuffer[0]); 00137 encode_options.p_EncodeCallBackFunc = &JcuEncodeCallBackFunc; 00138 encode_options.input_swapsetting = JPEG_Converter::WR_RD_WRSWA_32_16_8BIT; 00139 00140 jcu_encoding = 1; 00141 if (jcu_buf_index_read == jcu_buf_index_write) { 00142 jcu_buf_index_write ^= 1; // toggle 00143 } 00144 jcu_encode_size[jcu_buf_index_write] = 0; 00145 dcache_invalid(JpegBuffer[jcu_buf_index_write], sizeof(JpegBuffer[0])); 00146 if (Jcu.encode(&bitmap_buff_info, JpegBuffer[jcu_buf_index_write], 00147 &jcu_encode_size[jcu_buf_index_write], &encode_options) != JPEG_Converter::JPEG_CONV_OK) { 00148 jcu_encode_size[jcu_buf_index_write] = 0; 00149 jcu_encoding = 0; 00150 } 00151 } 00152 } 00153 00154 static void Start_Video_Camera(void) 00155 { 00156 // Initialize the background to black 00157 for (uint32_t i = 0; i < sizeof(user_frame_buffer0); i += 2) { 00158 user_frame_buffer0[i + 0] = 0x10; 00159 user_frame_buffer0[i + 1] = 0x80; 00160 } 00161 00162 // Interrupt callback function setting (Field end signal for recording function in scaler 0) 00163 Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VFIELD, 0, IntCallbackFunc_Vfield); 00164 00165 // Video capture setting (progressive form fixed) 00166 Display.Video_Write_Setting( 00167 DisplayBase::VIDEO_INPUT_CHANNEL_0, 00168 DisplayBase::COL_SYS_NTSC_358, 00169 (void *)user_frame_buffer0, 00170 FRAME_BUFFER_STRIDE, 00171 DisplayBase::VIDEO_FORMAT_YCBCR422, 00172 DisplayBase::WR_RD_WRSWA_32_16BIT, 00173 VIDEO_PIXEL_VW, 00174 VIDEO_PIXEL_HW 00175 ); 00176 EasyAttach_CameraStart(Display, DisplayBase::VIDEO_INPUT_CHANNEL_0); 00177 } 00178 00179 int main(void) 00180 { 00181 Jcu.SetQuality(JPEG_ENCODE_QUALITY); 00182 00183 EasyAttach_Init(Display); 00184 Start_Video_Camera(); 00185 00186 while (1) { 00187 WaitGetCommand(); 00188 } 00189 }
Generated on Wed Jul 13 2022 00:28:47 by
1.7.2