Image scroll Sample. This program uses GraphicsFramework library and Si1143 sensor.
Dependencies: GR-PEACH_video GraphicsFramework R_BSP SI1143 mbed-rtos mbed
Fork of RGA_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "rga_func.h" 00003 #include "Images/BinaryImage_RZ_A1H.h" 00004 #include "DisplayBace.h" 00005 #include "rtos.h" 00006 #include "SI1143.h" 00007 00008 /**** LCD Parameter **********/ 00009 #define LCD_DE_MODE (0) 00010 #define LCD_SYNC_MODE (1) 00011 00012 #define LCD_DOT_CLOCK (13.40f) // 13.4MHz 00013 00014 #define LCD_H_WIDTH (480u) 00015 #define LCD_H_BACK_PORCH (43u) 00016 #define LCD_H_FRONT_PORCH (52u) 00017 #define LCD_H_SYNC_WIDTH (41u) 00018 00019 #define LCD_V_WIDTH (272u) 00020 #define LCD_V_BACK_PORCH (12u) 00021 #define LCD_V_FRONT_PORCH (2u) 00022 #define LCD_V_SYNC_WIDTH (10u) 00023 00024 #define LCD_MODE (LCD_SYNC_MODE) 00025 00026 /*****************************/ 00027 00028 /* FRAME BUFFER Parameter */ 00029 #define FRAME_BUFFER_BYTE_PER_PIXEL (2) 00030 #define FRAME_BUFFER_STRIDE (((LCD_H_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) 00031 00032 enum { 00033 IMG_SETTING, 00034 IMG_START, 00035 IMG_RED, 00036 IMG_BLUE, 00037 IMG_YELLOW, 00038 IMG_GREEN 00039 }; 00040 00041 DigitalOut lcd_pwon(P7_15); 00042 DigitalOut lcd_blon(P8_1); 00043 DigitalOut touch_reset(P4_0); 00044 PwmOut lcd_cntrst(P8_15); 00045 DisplayBase Display; 00046 SI1143 sensor(I2C_SDA, I2C_SCL); 00047 00048 static const graphics_image_t* image_file[6] = { 00049 Setting_jpg_File, Start_jpg_File, red_jpg_File, blue_jpg_File, yellow_jpg_File, green_jpg_File 00050 }; 00051 00052 static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_V_WIDTH]__attribute((aligned(32))); /* 32 bytes aligned */ 00053 static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_V_WIDTH]__attribute((aligned(32))); /* 32 bytes aligned */ 00054 static frame_buffer_t frame_buffer_info; 00055 static volatile int32_t vsync_count = 0; 00056 static int sense_old[3] = {0, 0, 0}; 00057 static int sense_new[3] = {0, 0, 0}; 00058 static const graphics_image_t* image_old = image_file[IMG_START]; 00059 static const graphics_image_t* image_new = image_file[IMG_START]; 00060 00061 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) { 00062 /* Interrupt callback function for Vsync interruption */ 00063 if (vsync_count > 0) { 00064 vsync_count--; 00065 } 00066 } 00067 00068 static void Wait_Vsync(const int32_t wait_count) { 00069 /* Wait for the specified number of times Vsync occurs */ 00070 vsync_count = wait_count; 00071 while (vsync_count > 0) { 00072 /* Do nothing */ 00073 } 00074 } 00075 00076 static int Get_Direction(void) { 00077 int dire_sense[3]; 00078 int ret; 00079 // Read each led sensor 00080 sense_new[0] = sensor.get_ps1(2); 00081 sense_new[1] = sensor.get_ps2(2); 00082 sense_new[2] = sensor.get_ps3(2); 00083 00084 if ((sense_new[0] > 50) && (sense_new[1] > 50) && (sense_new[2] > 50)) { 00085 for (int cnt = 0; cnt < 3; cnt++) { 00086 dire_sense[cnt] = sense_new[cnt] - sense_old[cnt]; 00087 if (dire_sense[cnt] <= 50) { // less than 50 or minus 00088 dire_sense[cnt] = 0; 00089 } 00090 } 00091 if (((sense_old[0] - sense_old[1]) > 50) && ((sense_old[0] - sense_old[2]) > 50)) { 00092 /* sense1 to ... */ 00093 if ((dire_sense[1] > dire_sense[0]) && (dire_sense[1] > dire_sense[2])) { 00094 ret = DIREC_UP; 00095 } else if ((dire_sense[2] > dire_sense[0]) && (dire_sense[2] > dire_sense[1])) { 00096 ret = DIREC_RIGHT; 00097 } else { 00098 ret = DIREC_NON; 00099 } 00100 } else if (((sense_old[1] - sense_old[0]) > 50) && ((sense_old[1] - sense_old[2]) > 50)) { 00101 /* sense2 to ... */ 00102 if ((dire_sense[0] > dire_sense[1]) && (dire_sense[0] > dire_sense[2])) { 00103 ret = DIREC_DOWN; 00104 } else if ((dire_sense[2] > dire_sense[0]) && (dire_sense[2] > dire_sense[1])) { 00105 ret = DIREC_DOWN; 00106 } else { 00107 ret = DIREC_NON; 00108 } 00109 } else if (((sense_old[2] - sense_old[0]) > 50) && ((sense_old[2] - sense_old[1]) > 50)) { 00110 /* sense3 to ... */ 00111 if ((dire_sense[0] > dire_sense[1]) && (dire_sense[0] > dire_sense[2])) { 00112 ret = DIREC_LEFT; 00113 } else if ((dire_sense[1] > dire_sense[0]) && (dire_sense[1] > dire_sense[2])) { 00114 ret = DIREC_UP; 00115 } else { 00116 ret = DIREC_NON; 00117 } 00118 } else { 00119 ret = DIREC_NON; 00120 } 00121 } else { 00122 ret = DIREC_NON; 00123 } 00124 sense_old[0] = sense_new[0]; 00125 sense_old[1] = sense_new[1]; 00126 sense_old[2] = sense_new[2]; 00127 00128 00129 return ret; 00130 } 00131 00132 static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) { 00133 if (frmbuf_info->draw_buffer_index == 1) { 00134 frmbuf_info->draw_buffer_index = 0; 00135 } else { 00136 frmbuf_info->draw_buffer_index = 1; 00137 } 00138 } 00139 00140 static void Update_LCD_Display(frame_buffer_t * frmbuf_info) { 00141 Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0, 00142 (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]); 00143 Wait_Vsync(1); 00144 } 00145 00146 static void Draw_Image(int direction) { 00147 int work_width_pos; 00148 00149 if (direction == DIREC_RIGHT) { 00150 image_new = image_file[IMG_RED]; 00151 } else if (direction == DIREC_LEFT) { 00152 image_new = image_file[IMG_BLUE]; 00153 } else if (direction == DIREC_UP) { 00154 image_new = image_file[IMG_YELLOW]; 00155 } else if (direction == DIREC_DOWN) { 00156 image_new = image_file[IMG_GREEN]; 00157 } 00158 for (work_width_pos = 1; work_width_pos <= SCROLL_STEP_NUM; work_width_pos++) { 00159 /* Draw screen */ 00160 Swap_FrameBuffer(&frame_buffer_info); 00161 RGA_Func_Scroll(&frame_buffer_info, image_old, image_new, direction, (float32_t)work_width_pos / (float32_t)SCROLL_STEP_NUM); 00162 Update_LCD_Display(&frame_buffer_info); 00163 } 00164 image_old = image_new; 00165 } 00166 00167 int main(void) { 00168 /* Create DisplayBase object */ 00169 DisplayBase::graphics_error_t error; 00170 int direction = 0; 00171 00172 memset(user_frame_buffer, 0, sizeof(user_frame_buffer)); 00173 memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2)); 00174 frame_buffer_info.buffer_address[0] = user_frame_buffer; 00175 frame_buffer_info.buffer_address[1] = user_frame_buffer2; 00176 frame_buffer_info.buffer_count = 2; 00177 frame_buffer_info.show_buffer_index = 0; 00178 frame_buffer_info.draw_buffer_index = 0; 00179 frame_buffer_info.width = LCD_H_WIDTH; 00180 frame_buffer_info.byte_per_pixel = FRAME_BUFFER_BYTE_PER_PIXEL; 00181 frame_buffer_info.stride = LCD_H_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL; 00182 frame_buffer_info.height = LCD_V_WIDTH; 00183 frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565; 00184 00185 lcd_pwon = 0; 00186 lcd_blon = 0; 00187 touch_reset = 0; 00188 Thread::wait(100); 00189 00190 lcd_pwon = 1; 00191 lcd_blon = 1; 00192 touch_reset = 1; 00193 Thread::wait(100); 00194 00195 DisplayBase::lcd_config_t lcd_config; 00196 PinName lvds_pin[8] = { 00197 /* data pin */ 00198 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0 00199 }; 00200 DisplayBase::rect_t rect; 00201 00202 lcd_config.lcd_type = DisplayBase::LCD_TYPE_LVDS; 00203 lcd_config.intputClock = 66.67f; 00204 lcd_config.outputClock = LCD_DOT_CLOCK; 00205 lcd_config.lcd_outformat = DisplayBase::LCD_OUTFORMAT_RGB888; 00206 lcd_config.lcd_edge = DisplayBase::EDGE_RISING; 00207 #if(LCD_MODE) //SYNC Mode 00208 lcd_config.h_toatal_period = (LCD_H_BACK_PORCH + LCD_H_WIDTH + LCD_H_FRONT_PORCH); 00209 lcd_config.v_toatal_period = (LCD_V_BACK_PORCH + LCD_V_WIDTH + LCD_V_FRONT_PORCH); 00210 00211 lcd_config.h_disp_widht = (LCD_H_WIDTH); 00212 lcd_config.v_disp_widht = (LCD_V_WIDTH); 00213 lcd_config.h_back_porch = (LCD_H_BACK_PORCH); 00214 lcd_config.v_back_porch = (LCD_V_BACK_PORCH); 00215 00216 lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_2; 00217 lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_INVERTED; 00218 lcd_config.h_sync_width = LCD_H_SYNC_WIDTH; 00219 00220 lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_0; 00221 lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_INVERTED; 00222 lcd_config.v_sync_width = LCD_V_SYNC_WIDTH; 00223 00224 lcd_config.de_port = DisplayBase::LCD_TCON_PIN_3; 00225 lcd_config.de_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00226 #else //DE Mode 00227 lcd_config.h_toatal_period = (LCD_H_WIDTH + 80u); 00228 lcd_config.v_toatal_period = (LCD_V_WIDTH); 00229 00230 lcd_config.h_disp_widht = (LCD_H_WIDTH); 00231 lcd_config.v_disp_widht = (LCD_V_WIDTH); 00232 lcd_config.h_back_porch = (68u); 00233 lcd_config.v_back_porch = (18u); 00234 00235 lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_NON; 00236 lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00237 lcd_config.h_sync_width = 0; 00238 00239 lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_NON; 00240 lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00241 lcd_config.v_sync_width = 0; 00242 00243 lcd_config.de_port = DisplayBase::LCD_TCON_PIN_3; 00244 lcd_config.de_port_polarity = DisplayBase::SIG_POL_INVERTED; 00245 #endif 00246 00247 /* Graphics initialization process */ 00248 error = Display.Graphics_init(&lcd_config); 00249 if (error != DisplayBase::GRAPHICS_OK) { 00250 printf("Line %d, error %d\n", __LINE__, error); 00251 while (1); 00252 } 00253 00254 /* Interrupt callback function setting (Vsync signal output from scaler 0) */ 00255 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_Vsync); 00256 if (error != DisplayBase::GRAPHICS_OK) { 00257 printf("Line %d, error %d\n", __LINE__, error); 00258 while (1); 00259 } 00260 00261 Display.Graphics_Lvds_Port_Init(lvds_pin, 8); 00262 rect.vs = 0; 00263 rect.vw = LCD_V_WIDTH; 00264 rect.hs = 0; 00265 rect.hw = LCD_H_WIDTH; 00266 00267 Display.Graphics_Read_Setting( 00268 DisplayBase::GRAPHICS_LAYER_0, 00269 (void *)frame_buffer_info.buffer_address[0], 00270 FRAME_BUFFER_STRIDE, 00271 DisplayBase::GRAPHICS_FORMAT_RGB565, 00272 DisplayBase::WR_RD_WRSWA_32_16BIT, 00273 &rect 00274 ); 00275 00276 /* Display Start */ 00277 Set_RGAObject(&frame_buffer_info); 00278 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); 00279 lcd_cntrst.write(1.0); 00280 00281 // Setup the baseline 00282 RGA_Func_DrawTopScreen(&frame_buffer_info, image_file[IMG_SETTING]); 00283 printf("SI1143 Gesture Sensor setting...\n"); 00284 sensor.bias(1,5); 00285 Thread::wait(1000); 00286 RGA_Func_DrawTopScreen(&frame_buffer_info, image_file[IMG_START]); 00287 printf("SI1143 Gesture Sensor setting finished!\n"); 00288 00289 while (1) { 00290 /* Get coordinates */ 00291 direction = Get_Direction(); 00292 if (direction != 0) { 00293 Draw_Image(direction); 00294 } 00295 } 00296 }
Generated on Thu Jul 14 2022 22:34:42 by 1.7.2