Image Zoom In/out Sample. This program uses GraphicsFramework library and GP2Y0A21YK sensor. Please use distance sensor in the range of 10-30cm.
Dependencies: GR-PEACH_video GraphicsFramework R_BSP mbed-rtos mbed
Fork of RGA_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "rga_func.h" 00003 #include "DisplayBace.h" 00004 #include "rtos.h" 00005 00006 /**** LCD Parameter **********/ 00007 #define LCD_DE_MODE (0) 00008 #define LCD_SYNC_MODE (1) 00009 00010 #define LCD_DOT_CLOCK (13.40f) // 13.4MHz 00011 00012 #define LCD_H_WIDTH (480u) 00013 #define LCD_H_BACK_PORCH (43u) 00014 #define LCD_H_FRONT_PORCH (52u) 00015 #define LCD_H_SYNC_WIDTH (41u) 00016 00017 #define LCD_V_WIDTH (272u) 00018 #define LCD_V_BACK_PORCH (12u) 00019 #define LCD_V_FRONT_PORCH (2u) 00020 #define LCD_V_SYNC_WIDTH (10u) 00021 00022 #define LCD_MODE (LCD_SYNC_MODE) 00023 00024 /*****************************/ 00025 00026 /* FRAME BUFFER Parameter */ 00027 #define FRAME_BUFFER_BYTE_PER_PIXEL (2) 00028 #define FRAME_BUFFER_STRIDE (((LCD_H_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) 00029 00030 DigitalOut lcd_pwon(P7_15); 00031 DigitalOut lcd_blon(P8_1); 00032 DigitalOut touch_reset(P4_0); 00033 PwmOut lcd_cntrst(P8_15); 00034 DisplayBase Display; 00035 AnalogIn ain(A0); 00036 00037 static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_V_WIDTH]__attribute((aligned(32))); /* 32 bytes aligned */ 00038 static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_V_WIDTH]__attribute((aligned(32))); /* 32 bytes aligned */ 00039 static frame_buffer_t frame_buffer_info; 00040 static volatile int32_t vsync_count = 0; 00041 00042 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) { 00043 /* Interrupt callback function for Vsync interruption */ 00044 if (vsync_count > 0) { 00045 vsync_count--; 00046 } 00047 } 00048 00049 static void Wait_Vsync(const int32_t wait_count) { 00050 /* Wait for the specified number of times Vsync occurs */ 00051 vsync_count = wait_count; 00052 while (vsync_count > 0) { 00053 /* Do nothing */ 00054 } 00055 } 00056 00057 static float get_distance(void) { 00058 float tmp = 0; 00059 float data = 0; 00060 float distance = 0; 00061 int cnt; 00062 00063 for (cnt = 0; cnt < 10; cnt++) { 00064 if (ain == 0) { 00065 return 0; 00066 } 00067 tmp = tmp + ain; 00068 } 00069 data = tmp / 10; 00070 if ((data >= 0.121) && (data <= 0.970)) { 00071 distance = 26.663 * pow((data * 3.3), -1.25); 00072 } 00073 00074 return distance; 00075 } 00076 00077 static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) { 00078 if (frmbuf_info->draw_buffer_index == 1) { 00079 frmbuf_info->draw_buffer_index = 0; 00080 } else { 00081 frmbuf_info->draw_buffer_index = 1; 00082 } 00083 } 00084 00085 static void Update_LCD_Display(frame_buffer_t * frmbuf_info) { 00086 Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0, 00087 (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]); 00088 Wait_Vsync(1); 00089 } 00090 00091 int main(void) { 00092 /* Create DisplayBase object */ 00093 DisplayBase::graphics_error_t error; 00094 float distance; 00095 00096 memset(user_frame_buffer, 0, sizeof(user_frame_buffer)); 00097 memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2)); 00098 frame_buffer_info.buffer_address[0] = user_frame_buffer; 00099 frame_buffer_info.buffer_address[1] = user_frame_buffer2; 00100 frame_buffer_info.buffer_count = 2; 00101 frame_buffer_info.show_buffer_index = 0; 00102 frame_buffer_info.draw_buffer_index = 0; 00103 frame_buffer_info.width = LCD_H_WIDTH; 00104 frame_buffer_info.byte_per_pixel = FRAME_BUFFER_BYTE_PER_PIXEL; 00105 frame_buffer_info.stride = LCD_H_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL; 00106 frame_buffer_info.height = LCD_V_WIDTH; 00107 frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565; 00108 00109 lcd_pwon = 0; 00110 lcd_blon = 0; 00111 touch_reset = 0; 00112 Thread::wait(100); 00113 00114 lcd_pwon = 1; 00115 lcd_blon = 1; 00116 touch_reset = 1; 00117 Thread::wait(100); 00118 00119 DisplayBase::lcd_config_t lcd_config; 00120 PinName lvds_pin[8] = { 00121 /* data pin */ 00122 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0 00123 }; 00124 DisplayBase::rect_t rect; 00125 00126 lcd_config.lcd_type = DisplayBase::LCD_TYPE_LVDS; 00127 lcd_config.intputClock = 66.67f; 00128 lcd_config.outputClock = LCD_DOT_CLOCK; 00129 lcd_config.lcd_outformat = DisplayBase::LCD_OUTFORMAT_RGB888; 00130 lcd_config.lcd_edge = DisplayBase::EDGE_RISING; 00131 #if(LCD_MODE) //SYNC Mode 00132 lcd_config.h_toatal_period = (LCD_H_BACK_PORCH + LCD_H_WIDTH + LCD_H_FRONT_PORCH); 00133 lcd_config.v_toatal_period = (LCD_V_BACK_PORCH + LCD_V_WIDTH + LCD_V_FRONT_PORCH); 00134 00135 lcd_config.h_disp_widht = (LCD_H_WIDTH); 00136 lcd_config.v_disp_widht = (LCD_V_WIDTH); 00137 lcd_config.h_back_porch = (LCD_H_BACK_PORCH); 00138 lcd_config.v_back_porch = (LCD_V_BACK_PORCH); 00139 00140 lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_2; 00141 lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_INVERTED; 00142 lcd_config.h_sync_width = LCD_H_SYNC_WIDTH; 00143 00144 lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_0; 00145 lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_INVERTED; 00146 lcd_config.v_sync_width = LCD_V_SYNC_WIDTH; 00147 00148 lcd_config.de_port = DisplayBase::LCD_TCON_PIN_3; 00149 lcd_config.de_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00150 #else //DE Mode 00151 lcd_config.h_toatal_period = (LCD_H_WIDTH + 80u); 00152 lcd_config.v_toatal_period = (LCD_V_WIDTH); 00153 00154 lcd_config.h_disp_widht = (LCD_H_WIDTH); 00155 lcd_config.v_disp_widht = (LCD_V_WIDTH); 00156 lcd_config.h_back_porch = (68u); 00157 lcd_config.v_back_porch = (18u); 00158 00159 lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_NON; 00160 lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00161 lcd_config.h_sync_width = 0; 00162 00163 lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_NON; 00164 lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00165 lcd_config.v_sync_width = 0; 00166 00167 lcd_config.de_port = DisplayBase::LCD_TCON_PIN_3; 00168 lcd_config.de_port_polarity = DisplayBase::SIG_POL_INVERTED; 00169 #endif 00170 00171 /* Graphics initialization process */ 00172 error = Display.Graphics_init(&lcd_config); 00173 if (error != DisplayBase::GRAPHICS_OK) { 00174 printf("Line %d, error %d\n", __LINE__, error); 00175 while (1); 00176 } 00177 00178 /* Interrupt callback function setting (Vsync signal output from scaler 0) */ 00179 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_Vsync); 00180 if (error != DisplayBase::GRAPHICS_OK) { 00181 printf("Line %d, error %d\n", __LINE__, error); 00182 while (1); 00183 } 00184 00185 Display.Graphics_Lvds_Port_Init(lvds_pin, 8); 00186 rect.vs = 0; 00187 rect.vw = LCD_V_WIDTH; 00188 rect.hs = 0; 00189 rect.hw = LCD_H_WIDTH; 00190 00191 Display.Graphics_Read_Setting( 00192 DisplayBase::GRAPHICS_LAYER_0, 00193 (void *)frame_buffer_info.buffer_address[0], 00194 FRAME_BUFFER_STRIDE, 00195 DisplayBase::GRAPHICS_FORMAT_RGB565, 00196 DisplayBase::WR_RD_WRSWA_32_16BIT, 00197 &rect 00198 ); 00199 00200 /* Display Top Screen */ 00201 Set_RGAObject(&frame_buffer_info); 00202 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); 00203 lcd_cntrst.write(1.0); 00204 00205 int work_height_pos = ZOOM_MAX_NUM; 00206 while (1) { 00207 distance = get_distance(); 00208 /* range of use = 10-30[cm] */ 00209 if ((distance >= 10) && (distance <= 30)) { 00210 work_height_pos = ZOOM_MAX_NUM * (((float32_t)distance - 10) / (float32_t)20); 00211 } 00212 /* Draw screen */ 00213 Swap_FrameBuffer(&frame_buffer_info); 00214 RGA_Func_Zoom(&frame_buffer_info, work_height_pos); 00215 Update_LCD_Display(&frame_buffer_info); 00216 } 00217 }
Generated on Fri Jul 22 2022 17:36:14 by
1.7.2
