The out-of-the-box demo application flashed on all display modules before they are shipped.
Dependencies: DMBasicGUI DMSupport
main.cpp
00001 /****************************************************************************** 00002 * Includes 00003 *****************************************************************************/ 00004 00005 #include "mbed.h" 00006 #include "mbed_interface.h" 00007 #include "rtos.h" 00008 #include "EthernetInterface.h" 00009 #include "HTTPServer.h" 00010 #include "USBHostMSD.h" 00011 #include "USBHostMouse.h" 00012 #include "USBHostKeyboard.h" 00013 00014 #include "DMBoard.h" 00015 00016 #include "AppLauncherSpecial.h" 00017 #include "meas.h" 00018 00019 #include "AppNetworkSettings.h" 00020 #include "AppStatus.h" 00021 #include "AppTouchCalibration.h" 00022 #include "AppColorPicker.h" 00023 #include "AppImageViewer.h" 00024 #include "AppSlideShow.h" 00025 #include "AppRTCSettings.h" 00026 #include "AppUSBStatus.h" 00027 #include "AppDraw.h" 00028 #include "image_data.h" 00029 #include "Resource.h" 00030 00031 #include "lpc_swim.h" 00032 #include "lpc_helvr10.h" 00033 #include "lpc_winfreesystem14x16.h" 00034 00035 /****************************************************************************** 00036 * Typedefs and defines 00037 *****************************************************************************/ 00038 00039 typedef enum { 00040 Res_ok, 00041 Res_cancel, 00042 Res_arrow_up, 00043 Res_arrow_down, 00044 Res_arrow_left, 00045 Res_arrow_right, 00046 Res_repeat, 00047 Res_digits, 00048 Res_background, 00049 Res_about, 00050 Res_ColorPickerApp, 00051 Res_ImageViewerApp, 00052 Res_SlideshowApp, 00053 Res_SettingsApp, 00054 Res_StatusApp, 00055 //Res_TouchTestApp, 00056 Res_RtcApp, 00057 Res_USBStatusApp, 00058 Res_DrawingApp, 00059 //Res_CalibrationApp, 00060 NumResources, 00061 } resorces_t; 00062 00063 /****************************************************************************** 00064 * Local variables 00065 *****************************************************************************/ 00066 00067 static Resource* RESOURCES[NumResources] = {0}; 00068 00069 /****************************************************************************** 00070 * Global variables 00071 *****************************************************************************/ 00072 00073 EthernetInterface eth; 00074 bool ethInitialized = false; 00075 bool ethUsingDHCP = true; 00076 bool haveUSBMSD = false; 00077 00078 /****************************************************************************** 00079 * Local functions 00080 *****************************************************************************/ 00081 00082 static void prepareResources() 00083 { 00084 Display* disp = DMBoard::instance().display(); 00085 00086 // select which images to use based on display size 00087 if (disp->width() == 480) { 00088 RESOURCES[Res_ok ] = new Resource(img_480x272_ok, img_size_480x272_ok, 40, 40); 00089 RESOURCES[Res_cancel ] = new Resource(img_480x272_cancel, img_size_480x272_cancel, 40, 40); 00090 RESOURCES[Res_arrow_up ] = new Resource(img_480x272_arrow_up, img_size_480x272_arrow_up, 52, 52); 00091 RESOURCES[Res_arrow_down ] = new Resource(img_480x272_arrow_down, img_size_480x272_arrow_down, 52, 52); 00092 RESOURCES[Res_arrow_left ] = new Resource(img_480x272_arrow_left, img_size_480x272_arrow_left, 52, 52); 00093 RESOURCES[Res_arrow_right] = new Resource(img_480x272_arrow_right, img_size_480x272_arrow_right, 52, 52); 00094 RESOURCES[Res_repeat ] = new Resource(img_480x272_repeat, img_size_480x272_repeat, 40, 40); 00095 RESOURCES[Res_digits ] = new Resource(img_numbers_16b, img_size_numbers_16b, 13, 242); 00096 00097 RESOURCES[Res_ColorPickerApp] = new Resource(img_480x272_super_mono_3d_part2_19, img_size_480x272_super_mono_3d_part2_19, 64, 64); 00098 RESOURCES[Res_ImageViewerApp] = new Resource(img_480x272_super_mono_3d_48, img_size_480x272_super_mono_3d_48, 64, 64); 00099 RESOURCES[Res_SlideshowApp ] = new Resource(img_480x272_super_mono_3d_87, img_size_480x272_super_mono_3d_87, 64, 64); 00100 RESOURCES[Res_SettingsApp ] = new Resource(img_480x272_super_mono_3d_93, img_size_480x272_super_mono_3d_93, 64, 64); 00101 RESOURCES[Res_StatusApp ] = new Resource(img_480x272_super_mono_3d_part2_68, img_size_480x272_super_mono_3d_part2_68, 64, 64); 00102 RESOURCES[Res_RtcApp ] = new Resource(img_480x272_super_mono_3d_02, img_size_480x272_super_mono_3d_02, 64, 64); 00103 RESOURCES[Res_USBStatusApp ] = new Resource(img_480x272_super_mono_3d_57, img_size_480x272_super_mono_3d_57, 64, 64); 00104 RESOURCES[Res_DrawingApp ] = new Resource(img_480x272_super_mono_3d_22, img_size_480x272_super_mono_3d_22, 64, 64); 00105 RESOURCES[Res_background ] = new Resource(img_480x272_background, img_size_480x272_background, 364, 57); 00106 RESOURCES[Res_about ] = new Resource(img_480x272_about, img_size_480x272_about, 240, 245); 00107 00108 swim_set_default_font(&font_helvr10); 00109 } else { 00110 RESOURCES[Res_ok ] = new Resource(img_800x480_ok, img_size_800x480_ok, 64, 64); 00111 RESOURCES[Res_cancel ] = new Resource(img_800x480_cancel, img_size_800x480_cancel, 64, 64); 00112 RESOURCES[Res_arrow_up ] = new Resource("/qspi/800x480_arrow_up.raw", 128, 128); 00113 RESOURCES[Res_arrow_down ] = new Resource("/qspi/800x480_arrow_down.raw", 128, 128); 00114 RESOURCES[Res_arrow_left ] = new Resource("/qspi/800x480_arrow_left.raw", 128, 128); 00115 RESOURCES[Res_arrow_right] = new Resource("/qspi/800x480_arrow_right.raw", 128, 128); 00116 RESOURCES[Res_repeat ] = new Resource(img_800x480_repeat, img_size_800x480_repeat, 64, 64); 00117 RESOURCES[Res_digits ] = new Resource(img_numbers_20b, img_size_numbers_20b, 16, 322); 00118 00119 RESOURCES[Res_ColorPickerApp] = new Resource("/qspi/800x480_super-mono-3d-part2-19.raw", 64, 64); 00120 RESOURCES[Res_ImageViewerApp] = new Resource("/qspi/800x480_super-mono-3d-48.raw", 64, 64); 00121 RESOURCES[Res_SlideshowApp ] = new Resource("/qspi/800x480_super-mono-3d-87.raw", 64, 64); 00122 RESOURCES[Res_SettingsApp ] = new Resource("/qspi/800x480_super-mono-3d-93.raw", 64, 64); 00123 RESOURCES[Res_StatusApp ] = new Resource("/qspi/800x480_super-mono-3d-part2-68.raw", 64, 64); 00124 RESOURCES[Res_RtcApp ] = new Resource("/qspi/800x480_super-mono-3d-02.raw", 64, 64); 00125 RESOURCES[Res_USBStatusApp ] = new Resource("/qspi/800x480_super-mono-3d-57.raw", 64, 64); 00126 RESOURCES[Res_DrawingApp ] = new Resource("/qspi/800x480_super-mono-3d-22.raw", 64, 64); 00127 RESOURCES[Res_background ] = new Resource("/qspi/800x480_background.raw", 548, 80); 00128 RESOURCES[Res_about ] = new Resource("/qspi/800x480_about.raw", 420, 429); 00129 00130 swim_set_default_font(&font_winfreesys14x16); 00131 } 00132 } 00133 00134 void aliveTask(void) 00135 { 00136 DMBoard* board = &DMBoard::instance(); 00137 00138 while(true) 00139 { 00140 board->setLED(DMBoard::Led4, false); 00141 board->setLED(DMBoard::Led1, true); 00142 ThisThread::sleep_for(300); 00143 board->setLED(DMBoard::Led1, false); 00144 board->setLED(DMBoard::Led2, true); 00145 ThisThread::sleep_for(300); 00146 board->setLED(DMBoard::Led2, false); 00147 board->setLED(DMBoard::Led3, true); 00148 ThisThread::sleep_for(300); 00149 board->setLED(DMBoard::Led3, false); 00150 board->setLED(DMBoard::Led4, true); 00151 ThisThread::sleep_for(300); 00152 } 00153 } 00154 00155 #if defined(DM_BOARD_USE_DISPLAY) 00156 00157 typedef enum { 00158 ColorPickerApp, 00159 ImageViewerApp, 00160 SlideshowApp, 00161 SettingsApp, 00162 StatusApp, 00163 TouchTestApp, 00164 RtcApp, 00165 USBStatusApp, 00166 DrawingApp, 00167 CalibrationApp = AppLauncherSpecial::CalibrationApp, 00168 Placeholder, 00169 } myapps_t; 00170 00171 static App* launchApp(uint32_t id) 00172 { 00173 App* a = NULL; 00174 switch ((myapps_t)id) { 00175 case CalibrationApp: 00176 a = new AppTouchCalibration(); 00177 ((AppTouchCalibration*)a)->addResource(AppTouchCalibration::Resource_Ok_button, RESOURCES[Res_ok]); 00178 break; 00179 case SettingsApp: 00180 a = new AppNetworkSettings(); 00181 ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_Ok_button, RESOURCES[Res_ok]); 00182 ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_Cancel_button, RESOURCES[Res_cancel]); 00183 ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_ArrowUp_button, RESOURCES[Res_arrow_up]); 00184 ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_ArrowDown_button, RESOURCES[Res_arrow_down]); 00185 ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_ArrowLeft_button, RESOURCES[Res_arrow_left]); 00186 ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_ArrowRight_button, RESOURCES[Res_arrow_right]); 00187 ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_Digits, RESOURCES[Res_digits]); 00188 break; 00189 case ColorPickerApp: 00190 a = new AppColorPicker(); 00191 ((AppColorPicker*)a)->addResource(AppColorPicker::Resource_Ok_button, RESOURCES[Res_ok]); 00192 break; 00193 case ImageViewerApp: 00194 a = new AppImageViewer(); 00195 ((AppImageViewer*)a)->addResource(AppImageViewer::Resource_Ok_button, RESOURCES[Res_ok]); 00196 break; 00197 case SlideshowApp: 00198 { 00199 // Select folder for the slideshow based on display size 00200 Display* d = DMBoard::instance().display(); 00201 if (d->width() == 480) { 00202 a = new AppSlideShow("/qspi/slides.txt", "/qspi/480x272", 0, 0); 00203 } else { 00204 a = new AppSlideShow("/qspi/slides.txt", "/qspi/800x480", 0, 0); 00205 } 00206 00207 ((AppSlideShow*)a)->addResource(AppSlideShow::Resource_Ok_button, RESOURCES[Res_ok]); 00208 ((AppSlideShow*)a)->addResource(AppSlideShow::Resource_Repeat_button, RESOURCES[Res_repeat]); 00209 } 00210 break; 00211 case StatusApp: 00212 a = new AppStatus(); 00213 ((AppStatus*)a)->addResource(AppStatus::Resource_Ok_button, RESOURCES[Res_ok]); 00214 ((AppStatus*)a)->addResource(AppStatus::Resource_About_image, RESOURCES[Res_about]); 00215 break; 00216 case RtcApp: 00217 a = new AppRTCSettings(); 00218 ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_Ok_button, RESOURCES[Res_ok]); 00219 ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_Cancel_button, RESOURCES[Res_cancel]); 00220 ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_ArrowUp_button, RESOURCES[Res_arrow_up]); 00221 ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_ArrowDown_button, RESOURCES[Res_arrow_down]); 00222 ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_ArrowLeft_button, RESOURCES[Res_arrow_left]); 00223 ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_ArrowRight_button, RESOURCES[Res_arrow_right]); 00224 ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_Digits, RESOURCES[Res_digits]); 00225 break; 00226 case USBStatusApp: 00227 a = new AppUSBStatus(); 00228 ((AppUSBStatus*)a)->addResource(AppUSBStatus::Resource_Ok_button, RESOURCES[Res_ok]); 00229 break; 00230 case DrawingApp: 00231 a = new AppDraw(); 00232 ((AppDraw*)a)->addResource(AppDraw::Resource_Ok_button, RESOURCES[Res_ok]); 00233 break; 00234 default: 00235 break; 00236 } 00237 return a; 00238 } 00239 00240 #define SWIM_TASK_PREFIX "[SWIM] " 00241 void swimTask(void) 00242 { 00243 RtosLog* log = DMBoard::instance().logger(); 00244 Display* disp = DMBoard::instance().display(); 00245 00246 log->printf(SWIM_TASK_PREFIX"swimTask started\n"); 00247 00248 int iconsize = (disp->width()==480) ? 64 : 128; 00249 AppLauncherSpecial launcher(iconsize, iconsize); 00250 launcher.addResource(AppLauncherSpecial::Resource_Background, RESOURCES[Res_background]); 00251 00252 if (launcher.setup()) { 00253 launcher.addImageButton(SettingsApp, "Network", 0x2d5c, RESOURCES[Res_SettingsApp ]); 00254 launcher.addImageButton(DrawingApp, "Drawing", 0x2d5c, RESOURCES[Res_DrawingApp ]); 00255 launcher.addImageButton(SlideshowApp, "Slideshow", 0x2d5c, RESOURCES[Res_SlideshowApp ]); 00256 launcher.addImageButton(ColorPickerApp, "Color Picker", 0x2d5c, RESOURCES[Res_ColorPickerApp]); 00257 launcher.addImageButton(ImageViewerApp, "Image Viewer", 0x2d5c, RESOURCES[Res_ImageViewerApp]); 00258 launcher.addImageButton(StatusApp, "About", 0x2d5c, RESOURCES[Res_StatusApp ]); 00259 launcher.addImageButton(USBStatusApp, "USB Status", 0x2d5c, RESOURCES[Res_USBStatusApp ]); 00260 launcher.addImageButton(RtcApp, "Clock", 0x2d5c, RESOURCES[Res_RtcApp ]); 00261 00262 launcher.setAppCreatorFunc(launchApp); 00263 log->printf(SWIM_TASK_PREFIX"Starting menu system\n"); 00264 launcher.runToCompletion(); 00265 launcher.teardown(); 00266 } else { 00267 log->printf(SWIM_TASK_PREFIX"Failed to prepare menu system\n"); 00268 } 00269 00270 // Should never end up here 00271 mbed_die(); 00272 } 00273 00274 #endif //DM_BOARD_USE_DISPLAY 00275 00276 00277 #define NET_TASK_PREFIX "[NET] " 00278 00279 void netTask(void) 00280 { 00281 RtosLog* log = DMBoard::instance().logger(); 00282 log->printf(NET_TASK_PREFIX"EthernetInterface Setting up...\r\n"); 00283 nsapi_error_t net_err = eth.connect(); 00284 00285 if (net_err != NSAPI_ERROR_OK) { 00286 log->printf(NET_TASK_PREFIX"EthernetInterface connect Error %d\r\n", net_err); 00287 } 00288 else { 00289 ethInitialized = true; 00290 ethUsingDHCP = true; 00291 00292 log->printf(NET_TASK_PREFIX"IP Address is %s\r\n", eth.get_ip_address()); 00293 log->printf(NET_TASK_PREFIX"NetMask is %s\r\n", eth.get_netmask()); 00294 log->printf(NET_TASK_PREFIX"Gateway Address is %s\r\n", eth.get_gateway()); 00295 log->printf(NET_TASK_PREFIX"Ethernet Setup OK\r\n"); 00296 00297 HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler 00298 FSHandler::mount("/mci", "/"); 00299 HTTPServerAddHandler<FSHandler>("/"); 00300 00301 HTTPServerStart(80); 00302 } 00303 } 00304 00305 static volatile int8_t mouse_button, mouse_x, mouse_y, mouse_z; 00306 static uint16_t cursor_x=0, cursor_y=0, mouse_max_x = 0, mouse_max_y = 0; 00307 void mouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) 00308 { 00309 mouse_button = buttons; 00310 mouse_x = x; 00311 mouse_y = y; 00312 mouse_z = z; 00313 00314 if (mouse_max_x == 0) { 00315 mouse_max_x = DMBoard::instance().display()->width() - 1; 00316 } 00317 if (mouse_max_y == 0) { 00318 mouse_max_y = DMBoard::instance().display()->height() - 1; 00319 } 00320 00321 if (x < 0) { 00322 if (cursor_x > -x) { 00323 cursor_x += x; 00324 } else { 00325 cursor_x = 0; 00326 } 00327 } else { 00328 if ((cursor_x + x) > mouse_max_x) { 00329 cursor_x = mouse_max_x; 00330 } else { 00331 cursor_x += x; 00332 } 00333 } 00334 y = y/8; 00335 if (y < 0) { 00336 if (cursor_y > -y) { 00337 cursor_y += y; 00338 } else { 00339 cursor_y = 0; 00340 } 00341 } else { 00342 if ((cursor_y + y) > mouse_max_y) { 00343 cursor_y = mouse_max_y; 00344 } else { 00345 cursor_y += y; 00346 } 00347 } 00348 00349 //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y); 00350 LPC_LCD->CRSR_XY = (cursor_x & 0x3FF) | ((cursor_y & 0x3FF) << 16); 00351 } 00352 00353 #define LCD_CURSOR_32x32 0 00354 #define LCD_CURSOR_64x64 1 00355 #define CURSOR_SIZE LCD_CURSOR_32x32 00356 #define CURSOR_H_SIZE 32 00357 #define CURSOR_V_SIZE 32 00358 #define CURSOR_NUM 0 00359 #define CURSOR_H_OFS (10) 00360 #define CURSOR_V_OFS (6) 00361 00362 const unsigned char __attribute__ ((aligned(4))) Cursor[(CURSOR_H_SIZE / 4) * CURSOR_V_SIZE] = 00363 { 00364 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00365 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00366 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00367 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00368 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00369 0xAA, 0xAA, 0xAA, 0xFA, 0xAA, 0xAA, 0xAA, 0xAA, 00370 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, 00371 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, 00372 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, 00373 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, 00374 0xAA, 0xAA, 0xAB, 0xFF, 0xEA, 0xAA, 0xAA, 0xAA, 00375 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xAA, 0xAA, 0xAA, 00376 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, 00377 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, 00378 0xAA, 0xAB, 0xFB, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 00379 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 00380 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 00381 0xAA, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 00382 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 00383 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 00384 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 00385 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, 00386 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, 00387 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, 00388 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, 00389 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, 00390 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, 00391 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00392 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00393 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00394 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00395 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA 00396 }; 00397 00398 void prepareCursor(bool enable) { 00399 //Chip_LCD_Cursor_Disable(LPC_LCD, 0); 00400 LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4); 00401 00402 if (enable) { 00403 //Chip_LCD_Cursor_Config(LPC_LCD, LCD_CURSOR_32x32, true); 00404 LPC_LCD->CRSR_CFG = ((true ? 1 : 0) << 1) | CURSOR_SIZE; 00405 00406 //Chip_LCD_Cursor_WriteImage(LPC_LCD, 0, (void *) Cursor); 00407 { 00408 int i, j; 00409 uint32_t *fifoptr, *crsr_ptr = (uint32_t *) Cursor; 00410 00411 /* Check if Cursor Size was configured as 32x32 or 64x64*/ 00412 if (CURSOR_SIZE == LCD_CURSOR_32x32) { 00413 i = CURSOR_NUM * 64; 00414 j = i + 64; 00415 } 00416 else { 00417 i = 0; 00418 j = 256; 00419 } 00420 fifoptr = (uint32_t *) &(LPC_LCD->CRSR_IMG[0]); 00421 00422 /* Copy Cursor Image content to FIFO */ 00423 for (; i < j; i++) { 00424 00425 *fifoptr = *crsr_ptr; 00426 crsr_ptr++; 00427 fifoptr++; 00428 } 00429 } 00430 00431 //Chip_LCD_Cursor_SetClip(LPC_LCD, CURSOR_H_OFS, CURSOR_V_OFS); 00432 LPC_LCD->CRSR_CLIP = (CURSOR_H_OFS & 0x3F) | ((CURSOR_V_OFS & 0x3F) << 8); 00433 00434 //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y); 00435 00436 //Chip_LCD_Cursor_Enable(LPC_LCD, 0); 00437 LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4) | 1; 00438 } 00439 } 00440 00441 00442 #define CIRCBUFF_SIZE 256 00443 static volatile uint8_t circbuff[CIRCBUFF_SIZE]; 00444 static volatile uint32_t circbuff_read = 0; 00445 static uint32_t circbuff_write = 0; 00446 void keyEvent(uint8_t key) 00447 { 00448 circbuff[circbuff_write%CIRCBUFF_SIZE] = key; 00449 circbuff_write++; 00450 } 00451 00452 bool msdConnected = false; 00453 bool keyboardConnected = false; 00454 bool mouseConnected = false; 00455 00456 #define USB_TASK_PREFIX "[USB] " 00457 #define USB_CONNECTION_EVENT (1<<4) 00458 void usbTask(void) 00459 { 00460 USBHostMSD* msd = new USBHostMSD("usb"); 00461 USBHostKeyboard* keyboard = new USBHostKeyboard(); 00462 USBHostMouse* mouse = new USBHostMouse(); 00463 USBHost* host = USBHost::getHostInst(); 00464 EventFlags connectionEvent; 00465 host->signalOnConnections(&connectionEvent, USB_CONNECTION_EVENT); 00466 00467 RtosLog* log = DMBoard::instance().logger(); 00468 00469 log->printf(USB_TASK_PREFIX"usbTask started\n"); 00470 00471 prepareCursor(false); 00472 00473 while (true) { 00474 // wait for connect/disconnect message from USBHost 00475 connectionEvent.wait_any(USB_CONNECTION_EVENT); 00476 log->printf(USB_TASK_PREFIX"got USB event\n"); 00477 00478 if (msd->connected()) { 00479 if (!msdConnected) { 00480 msdConnected = true; 00481 haveUSBMSD = true; 00482 log->printf(USB_TASK_PREFIX"USB MassStorage Device - Connected\n"); 00483 } 00484 } else { 00485 if (msdConnected) { 00486 msdConnected = false; 00487 haveUSBMSD = false; 00488 log->printf(USB_TASK_PREFIX"USB MassStorage Device - Ejected\n"); 00489 } 00490 00491 if (msd->connect()) { 00492 msdConnected = true; 00493 haveUSBMSD = true; 00494 log->printf(USB_TASK_PREFIX"USB MassStorage Device - Connected\n"); 00495 } 00496 } 00497 00498 if (keyboard->connected()) { 00499 if (!keyboardConnected) { 00500 keyboardConnected = true; 00501 log->printf(USB_TASK_PREFIX"USB Keyboard - Connected\n"); 00502 keyboard->attach(keyEvent); 00503 } 00504 } else { 00505 if (keyboardConnected) { 00506 keyboardConnected = false; 00507 log->printf(USB_TASK_PREFIX"USB Keyboard - Ejected\n"); 00508 } 00509 if (keyboard->connect()) { 00510 keyboardConnected = true; 00511 log->printf(USB_TASK_PREFIX"USB Keyboard - Connected\n"); 00512 keyboard->attach(keyEvent); 00513 } 00514 } 00515 00516 if (mouse->connected()) { 00517 if (!mouseConnected) { 00518 mouseConnected = true; 00519 log->printf(USB_TASK_PREFIX"USB Mouse - Connected\n"); 00520 mouse->attachEvent(mouseEvent); 00521 prepareCursor(true); 00522 } 00523 } else { 00524 if (mouseConnected) { 00525 prepareCursor(false); 00526 mouseConnected = false; 00527 log->printf(USB_TASK_PREFIX"USB Mouse - Ejected\n"); 00528 } 00529 if (mouse->connect()) { 00530 mouseConnected = true; 00531 log->printf(USB_TASK_PREFIX"USB Mouse - Connected\n"); 00532 mouse->attachEvent(mouseEvent); 00533 prepareCursor(true); 00534 } 00535 } 00536 } 00537 } 00538 00539 00540 00541 /****************************************************************************** 00542 * Main function 00543 *****************************************************************************/ 00544 int main() 00545 { 00546 DMBoard::BoardError err; 00547 DMBoard* board = &DMBoard::instance(); 00548 RtosLog* log = board->logger(); 00549 err = board->init(); 00550 if (err != DMBoard::Ok) { 00551 log->printf("Failed to initialize the board, got error %d\r\n", err); 00552 log->printf("\nTERMINATING\n"); 00553 ThisThread::sleep_for(2000); // allow RtosLog to flush messages 00554 mbed_die(); 00555 } 00556 00557 // select which images to use based on display size 00558 prepareResources(); 00559 00560 board->buzzer(440,50); 00561 ThisThread::sleep_for(30); 00562 board->buzzer(660,50); 00563 ThisThread::sleep_for(30); 00564 board->buzzer(440,50); 00565 00566 log->printf("\n\n---\nDemo flashed on new Display Modules.\nBuilt: " __DATE__ " at " __TIME__ "\n\n"); 00567 00568 00569 Thread tAlive; 00570 tAlive.start(aliveTask); 00571 #if defined(DM_BOARD_USE_DISPLAY) 00572 Thread tSwim(osPriorityNormal, 8192); 00573 tSwim.start(swimTask); 00574 #endif 00575 Thread tNetwork(osPriorityNormal, 8192); 00576 tNetwork.start(netTask); 00577 Thread tUSBHandler(osPriorityNormal, 8192); 00578 tUSBHandler.start(usbTask); 00579 00580 while(1) { 00581 // Wait forever (in 1h increments) to prevent the tAlive, tSwim, 00582 // tNetwork and tUSBHandler thread from being garbage collected. 00583 ThisThread::sleep_for(3600*1000); 00584 } 00585 }
Generated on Wed Jul 13 2022 05:17:56 by 1.7.2