Example using the support package for LPC4088 DisplayModule

Dependencies:   DMBasicGUI DMSupport

Example using a lot of the features in the software package for the LPC4088 Display Module.

This project can be selected as a template when creating a new project based on the LPC4088 Display Module.

Information

This project works on the 4.3" display modules.

Some of the apps works on the 5" display modules. The ImageViewer and Slideshow app will show the images distorted as it does not take the resolution into consideration.

Information

The USB Status app is disabled. The Image viewer looks for images in the root of SD cards, USB memory sticks or the file system on the QSPI flash. The Slideshow app expects to find a slideshow script in /mci/elec14/ea_logo.txt.

This is what it looks like on the 4.3" display:

/media/uploads/embeddedartists/everything_cap_000.png /media/uploads/embeddedartists/everything_cap_001.png /media/uploads/embeddedartists/everything_cap_003.png /media/uploads/embeddedartists/everything_cap_004.png /media/uploads/embeddedartists/everything_cap_006.png /media/uploads/embeddedartists/everything_cap_008.png

Committer:
alindvall
Date:
Tue Apr 28 11:49:03 2015 +0000
Revision:
29:be8b784873f5
Parent:
27:4fe24decabf9
Child:
30:e1cded731965
Updated to latest version of the DMSupport library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:dfad71908d59 1 /******************************************************************************
embeddedartists 0:dfad71908d59 2 * Includes
embeddedartists 0:dfad71908d59 3 *****************************************************************************/
embeddedartists 0:dfad71908d59 4
embeddedartists 0:dfad71908d59 5 #include "mbed.h"
embeddedartists 0:dfad71908d59 6 #include "mbed_interface.h"
embeddedartists 0:dfad71908d59 7 #include "rtos.h"
embeddedartists 26:f07df116f3c9 8
embeddedartists 26:f07df116f3c9 9 #include "dm_board_config.h"
embeddedartists 0:dfad71908d59 10
embeddedartists 26:f07df116f3c9 11 #if defined(DM_BOARD_USE_ETHERNET)
embeddedartists 26:f07df116f3c9 12 #include "EthernetInterface.h"
embeddedartists 26:f07df116f3c9 13 #include "HTTPServer.h"
embeddedartists 26:f07df116f3c9 14 #include "mbed_rpc.h"
embeddedartists 26:f07df116f3c9 15 #endif
embeddedartists 26:f07df116f3c9 16 #if defined(DM_BOARD_USE_USB_DEVICE)
embeddedartists 26:f07df116f3c9 17 #include "USBMSD_RAMFS.h"
embeddedartists 26:f07df116f3c9 18 #include "USBSerial.h"
embeddedartists 26:f07df116f3c9 19 #include "USBKeyboard.h"
embeddedartists 26:f07df116f3c9 20 #include "AppUSBMouse.h"
embeddedartists 26:f07df116f3c9 21 #endif
embeddedartists 26:f07df116f3c9 22 #if defined(DM_BOARD_USE_USB_HOST)
embeddedartists 26:f07df116f3c9 23 #include "USBHostMSD.h"
embeddedartists 26:f07df116f3c9 24 #include "USBHostMouse.h"
embeddedartists 26:f07df116f3c9 25 #include "USBHostKeyboard.h"
embeddedartists 26:f07df116f3c9 26 #endif
embeddedartists 0:dfad71908d59 27 #include "DMBoard.h"
embeddedartists 0:dfad71908d59 28
embeddedartists 2:070e9c054796 29 #include "AppLauncher.h"
embeddedartists 2:070e9c054796 30 #include "meas.h"
embeddedartists 2:070e9c054796 31
embeddedartists 13:57e65aba9802 32 #include "AppNetworkSettings.h"
embeddedartists 13:57e65aba9802 33 #include "AppStatus.h"
embeddedartists 7:c8bef6a4b019 34 #include "AppTouchCalibration.h"
embeddedartists 7:c8bef6a4b019 35 #include "AppColorPicker.h"
embeddedartists 7:c8bef6a4b019 36 #include "AppImageViewer.h"
embeddedartists 7:c8bef6a4b019 37 #include "AppSlideShow.h"
embeddedartists 18:715f542538b3 38 #include "AppRTCSettings.h"
embeddedartists 24:768f5958c308 39 //#include "AppUSBStatus.h"
embeddedartists 24:768f5958c308 40 #include "AppDraw.h"
embeddedartists 7:c8bef6a4b019 41 #include "image_data.h"
alindvall 27:4fe24decabf9 42 #include "Resource.h"
embeddedartists 7:c8bef6a4b019 43
embeddedartists 2:070e9c054796 44
embeddedartists 0:dfad71908d59 45 /******************************************************************************
embeddedartists 0:dfad71908d59 46 * Typedefs and defines
embeddedartists 0:dfad71908d59 47 *****************************************************************************/
embeddedartists 0:dfad71908d59 48
embeddedartists 26:f07df116f3c9 49 /* Size of RAM file system exposed to PC as USB MassStorage */
embeddedartists 26:f07df116f3c9 50 #define RAM_FS_SIZE (20*1024*1024)
embeddedartists 0:dfad71908d59 51
embeddedartists 0:dfad71908d59 52 /******************************************************************************
embeddedartists 0:dfad71908d59 53 * Local variables
embeddedartists 0:dfad71908d59 54 *****************************************************************************/
embeddedartists 0:dfad71908d59 55
alindvall 27:4fe24decabf9 56 static Resource resOkButton(img_ok, img_size_ok, 40, 40);
alindvall 27:4fe24decabf9 57 static Resource resRepeatButton(img_repeat, img_size_repeat, 40, 40);
alindvall 27:4fe24decabf9 58
embeddedartists 0:dfad71908d59 59 /******************************************************************************
embeddedartists 0:dfad71908d59 60 * Global variables
embeddedartists 0:dfad71908d59 61 *****************************************************************************/
embeddedartists 0:dfad71908d59 62
embeddedartists 26:f07df116f3c9 63 #if defined(DM_BOARD_USE_ETHERNET)
embeddedartists 26:f07df116f3c9 64 EthernetInterface eth;
embeddedartists 26:f07df116f3c9 65 bool ethInitialized = false;
embeddedartists 26:f07df116f3c9 66 bool ethUsingDHCP = true;
embeddedartists 26:f07df116f3c9 67 #endif
embeddedartists 26:f07df116f3c9 68 #if defined(DM_BOARD_USE_USB_HOST)
embeddedartists 26:f07df116f3c9 69 bool haveUSBMSD = false;
embeddedartists 26:f07df116f3c9 70 #endif
embeddedartists 26:f07df116f3c9 71
embeddedartists 26:f07df116f3c9 72 #if defined(DM_BOARD_USE_USB_DEVICE)
embeddedartists 26:f07df116f3c9 73 //#define DEMO_USB_DEVICE_MOUSE
embeddedartists 26:f07df116f3c9 74 //#define DEMO_USB_DEVICE_SERIAL
embeddedartists 26:f07df116f3c9 75 #define DEMO_USB_DEVICE_MSD
embeddedartists 26:f07df116f3c9 76 #endif
embeddedartists 2:070e9c054796 77
embeddedartists 0:dfad71908d59 78 /******************************************************************************
embeddedartists 0:dfad71908d59 79 * Local functions
embeddedartists 0:dfad71908d59 80 *****************************************************************************/
embeddedartists 0:dfad71908d59 81
embeddedartists 0:dfad71908d59 82 void aliveTask(void const* args)
embeddedartists 0:dfad71908d59 83 {
embeddedartists 0:dfad71908d59 84 DMBoard* board = &DMBoard::instance();
embeddedartists 0:dfad71908d59 85
embeddedartists 0:dfad71908d59 86 while(true)
embeddedartists 0:dfad71908d59 87 {
embeddedartists 0:dfad71908d59 88 board->setLED(DMBoard::Led4, false);
embeddedartists 0:dfad71908d59 89 board->setLED(DMBoard::Led1, true);
embeddedartists 0:dfad71908d59 90 Thread::wait(300);
embeddedartists 0:dfad71908d59 91 board->setLED(DMBoard::Led1, false);
embeddedartists 0:dfad71908d59 92 board->setLED(DMBoard::Led2, true);
embeddedartists 0:dfad71908d59 93 Thread::wait(300);
embeddedartists 0:dfad71908d59 94 board->setLED(DMBoard::Led2, false);
embeddedartists 0:dfad71908d59 95 board->setLED(DMBoard::Led3, true);
embeddedartists 0:dfad71908d59 96 Thread::wait(300);
embeddedartists 0:dfad71908d59 97 board->setLED(DMBoard::Led3, false);
embeddedartists 0:dfad71908d59 98 board->setLED(DMBoard::Led4, true);
embeddedartists 0:dfad71908d59 99 Thread::wait(300);
embeddedartists 0:dfad71908d59 100 }
embeddedartists 0:dfad71908d59 101 }
embeddedartists 0:dfad71908d59 102
embeddedartists 0:dfad71908d59 103 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 2:070e9c054796 104
embeddedartists 7:c8bef6a4b019 105 typedef enum {
embeddedartists 7:c8bef6a4b019 106 ColorPickerApp,
embeddedartists 7:c8bef6a4b019 107 ImageViewerApp,
embeddedartists 7:c8bef6a4b019 108 SlideshowApp,
embeddedartists 7:c8bef6a4b019 109 SettingsApp,
embeddedartists 13:57e65aba9802 110 StatusApp,
embeddedartists 7:c8bef6a4b019 111 TouchTestApp,
embeddedartists 18:715f542538b3 112 RtcApp,
embeddedartists 24:768f5958c308 113 USBStatusApp,
embeddedartists 24:768f5958c308 114 DrawingApp,
embeddedartists 26:f07df116f3c9 115 USBMouseApp,
embeddedartists 7:c8bef6a4b019 116 CalibrationApp = AppLauncher::CalibrationApp,
embeddedartists 7:c8bef6a4b019 117 Placeholder,
embeddedartists 7:c8bef6a4b019 118 } myapps_t;
embeddedartists 7:c8bef6a4b019 119
embeddedartists 7:c8bef6a4b019 120 static App* launchApp(uint32_t id)
embeddedartists 7:c8bef6a4b019 121 {
embeddedartists 7:c8bef6a4b019 122 App* a = NULL;
embeddedartists 7:c8bef6a4b019 123 switch ((myapps_t)id) {
embeddedartists 7:c8bef6a4b019 124 case CalibrationApp:
embeddedartists 7:c8bef6a4b019 125 a = new AppTouchCalibration();
alindvall 27:4fe24decabf9 126 ((AppTouchCalibration*)a)->addResource(AppTouchCalibration::Resource_Ok_button, &resOkButton);
embeddedartists 7:c8bef6a4b019 127 break;
embeddedartists 7:c8bef6a4b019 128 case SettingsApp:
embeddedartists 13:57e65aba9802 129 a = new AppNetworkSettings();
embeddedartists 7:c8bef6a4b019 130 break;
embeddedartists 7:c8bef6a4b019 131 case ColorPickerApp:
embeddedartists 7:c8bef6a4b019 132 a = new AppColorPicker();
alindvall 27:4fe24decabf9 133 ((AppColorPicker*)a)->addResource(AppColorPicker::Resource_Ok_button, &resOkButton);
embeddedartists 7:c8bef6a4b019 134 break;
embeddedartists 7:c8bef6a4b019 135 case ImageViewerApp:
embeddedartists 7:c8bef6a4b019 136 a = new AppImageViewer();
embeddedartists 7:c8bef6a4b019 137 break;
embeddedartists 7:c8bef6a4b019 138 case SlideshowApp:
embeddedartists 24:768f5958c308 139 a = new AppSlideShow("/mci/elec14/ea_logo.txt", "/mci/elec14", 0, 0);
alindvall 27:4fe24decabf9 140 ((AppSlideShow*)a)->addResource(AppSlideShow::Resource_Ok_button, &resOkButton);
alindvall 27:4fe24decabf9 141 ((AppSlideShow*)a)->addResource(AppSlideShow::Resource_Repeat_button, &resRepeatButton);
embeddedartists 7:c8bef6a4b019 142 break;
embeddedartists 13:57e65aba9802 143 case StatusApp:
embeddedartists 13:57e65aba9802 144 a = new AppStatus();
embeddedartists 13:57e65aba9802 145 break;
embeddedartists 18:715f542538b3 146 case RtcApp:
embeddedartists 18:715f542538b3 147 a = new AppRTCSettings();
embeddedartists 18:715f542538b3 148 break;
embeddedartists 24:768f5958c308 149 case USBStatusApp:
embeddedartists 24:768f5958c308 150 //a = new AppUSBStatus();
embeddedartists 24:768f5958c308 151 break;
embeddedartists 24:768f5958c308 152 case DrawingApp:
embeddedartists 24:768f5958c308 153 a = new AppDraw();
embeddedartists 24:768f5958c308 154 break;
embeddedartists 26:f07df116f3c9 155 #if defined(DM_BOARD_USE_USB_DEVICE) && defined(DEMO_USB_DEVICE_MOUSE)
embeddedartists 26:f07df116f3c9 156 case USBMouseApp:
embeddedartists 26:f07df116f3c9 157 a = new AppUSBMouse();
embeddedartists 26:f07df116f3c9 158 break;
embeddedartists 26:f07df116f3c9 159 #endif
embeddedartists 7:c8bef6a4b019 160 default:
embeddedartists 7:c8bef6a4b019 161 break;
embeddedartists 7:c8bef6a4b019 162 }
embeddedartists 7:c8bef6a4b019 163 return a;
embeddedartists 7:c8bef6a4b019 164 }
embeddedartists 7:c8bef6a4b019 165
embeddedartists 2:070e9c054796 166 #define SWIM_TASK_PREFIX "[SWIM] "
embeddedartists 2:070e9c054796 167 void swimTask(void const* args)
embeddedartists 2:070e9c054796 168 {
embeddedartists 2:070e9c054796 169 RtosLog* log = DMBoard::instance().logger();
embeddedartists 2:070e9c054796 170
embeddedartists 2:070e9c054796 171 log->printf(SWIM_TASK_PREFIX"swimTask started\n");
embeddedartists 4:37a60b9bdb99 172
embeddedartists 2:070e9c054796 173 AppLauncher launcher;
embeddedartists 7:c8bef6a4b019 174
embeddedartists 7:c8bef6a4b019 175
embeddedartists 2:070e9c054796 176 if (launcher.setup()) {
embeddedartists 24:768f5958c308 177 launcher.addImageButton(SettingsApp, "Network", WHITE, img_preferences_system_network, img_size_preferences_system_network);
embeddedartists 24:768f5958c308 178 launcher.addImageButton(DrawingApp, "Drawing", WHITE, img_bijiben, img_size_bijiben);
embeddedartists 24:768f5958c308 179 launcher.addImageButton(SlideshowApp, "Slideshow", WHITE, img_multimedia_photo_manager, img_size_multimedia_photo_manager);
embeddedartists 7:c8bef6a4b019 180 //launcher.addImageButton(TouchGFXApp, "TouchGFX");
embeddedartists 7:c8bef6a4b019 181 //launcher.addImageButton(EmWinApp, "emWin");
embeddedartists 24:768f5958c308 182 launcher.addImageButton(ColorPickerApp, "Color Picker", WHITE, img_preferences_color, img_size_preferences_color);
embeddedartists 24:768f5958c308 183 launcher.addImageButton(ImageViewerApp, "Image Viewer", WHITE, img_multimedia_photo_manager, img_size_multimedia_photo_manager);
embeddedartists 24:768f5958c308 184 launcher.addImageButton(StatusApp, "About", WHITE, img_utilities_system_monitor, img_size_utilities_system_monitor);
embeddedartists 26:f07df116f3c9 185 #if defined(DM_BOARD_USE_USB_DEVICE) && defined(DEMO_USB_DEVICE_MOUSE)
embeddedartists 26:f07df116f3c9 186 launcher.addImageButton(USBMouseApp, "USB Mouse", WHITE, img_unetbootin, img_size_unetbootin);
embeddedartists 26:f07df116f3c9 187 #else
embeddedartists 24:768f5958c308 188 launcher.addImageButton(Placeholder, "USB Status", WHITE, img_unetbootin, img_size_unetbootin);
embeddedartists 26:f07df116f3c9 189 #endif
embeddedartists 24:768f5958c308 190 launcher.addImageButton(RtcApp, "Clock", WHITE, img_preferences_system_time, img_size_preferences_system_time);
embeddedartists 4:37a60b9bdb99 191
embeddedartists 7:c8bef6a4b019 192 launcher.setAppCreatorFunc(launchApp);
embeddedartists 2:070e9c054796 193 log->printf(SWIM_TASK_PREFIX"Starting menu system\n");
embeddedartists 2:070e9c054796 194 launcher.runToCompletion();
embeddedartists 2:070e9c054796 195 launcher.teardown();
embeddedartists 2:070e9c054796 196 } else {
embeddedartists 4:37a60b9bdb99 197 log->printf(SWIM_TASK_PREFIX"Failed to prepare menu system\n");
embeddedartists 2:070e9c054796 198 }
embeddedartists 2:070e9c054796 199
embeddedartists 2:070e9c054796 200 // Should never end up here
embeddedartists 2:070e9c054796 201 mbed_die();
embeddedartists 2:070e9c054796 202 }
embeddedartists 2:070e9c054796 203
embeddedartists 0:dfad71908d59 204 #endif //DM_BOARD_USE_DISPLAY
embeddedartists 0:dfad71908d59 205
embeddedartists 26:f07df116f3c9 206 #if defined(DM_BOARD_USE_ETHERNET)
embeddedartists 0:dfad71908d59 207
embeddedartists 26:f07df116f3c9 208 #define NET_TASK_PREFIX "[NET] "
embeddedartists 26:f07df116f3c9 209 void netTask(void const* args)
embeddedartists 26:f07df116f3c9 210 {
embeddedartists 26:f07df116f3c9 211 RtosLog* log = DMBoard::instance().logger();
embeddedartists 26:f07df116f3c9 212 log->printf(NET_TASK_PREFIX"EthernetInterface Setting up...\r\n");
embeddedartists 26:f07df116f3c9 213 if(eth.init()!=0) { //for DHCP Server
embeddedartists 26:f07df116f3c9 214 //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address
embeddedartists 26:f07df116f3c9 215 log->printf(NET_TASK_PREFIX"EthernetInterface Initialize Error \r\n");
embeddedartists 26:f07df116f3c9 216 mbed_die();
embeddedartists 26:f07df116f3c9 217 }
embeddedartists 26:f07df116f3c9 218 while (eth.connect() != 0) {
embeddedartists 26:f07df116f3c9 219 Thread::wait(1000);
embeddedartists 26:f07df116f3c9 220 }
embeddedartists 26:f07df116f3c9 221
embeddedartists 26:f07df116f3c9 222 ethInitialized = true;
embeddedartists 26:f07df116f3c9 223 ethUsingDHCP = true;
embeddedartists 26:f07df116f3c9 224
embeddedartists 26:f07df116f3c9 225 log->printf(NET_TASK_PREFIX"IP Address is %s\r\n", eth.getIPAddress());
embeddedartists 26:f07df116f3c9 226 log->printf(NET_TASK_PREFIX"NetMask is %s\r\n", eth.getNetworkMask());
embeddedartists 26:f07df116f3c9 227 log->printf(NET_TASK_PREFIX"Gateway Address is %s\r\n", eth.getGateway());
embeddedartists 26:f07df116f3c9 228 log->printf(NET_TASK_PREFIX"Ethernet Setup OK\r\n");
embeddedartists 0:dfad71908d59 229
embeddedartists 26:f07df116f3c9 230 HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler
embeddedartists 26:f07df116f3c9 231 FSHandler::mount("/usb", "/");
embeddedartists 26:f07df116f3c9 232 HTTPServerAddHandler<FSHandler>("/");
embeddedartists 26:f07df116f3c9 233 //HTTPServerAddHandler<RPCHandler>("/rpc");
embeddedartists 26:f07df116f3c9 234 //lcd.locate(0,0);
embeddedartists 26:f07df116f3c9 235 //lcd.printf("%s",eth.getIPAddress());
embeddedartists 26:f07df116f3c9 236 HTTPServerStart(80);
embeddedartists 26:f07df116f3c9 237 }
embeddedartists 26:f07df116f3c9 238 #endif //DM_BOARD_USE_ETHERNET
embeddedartists 0:dfad71908d59 239
embeddedartists 26:f07df116f3c9 240 #if defined(DM_BOARD_USE_USB_HOST)
embeddedartists 26:f07df116f3c9 241 static volatile int mouse_button, mouse_x, mouse_y, mouse_z;
embeddedartists 13:57e65aba9802 242 static uint16_t cursor_x=0, cursor_y=0;
embeddedartists 1:15ea03d72dd7 243 void mouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z)
embeddedartists 1:15ea03d72dd7 244 {
embeddedartists 1:15ea03d72dd7 245 mouse_button = buttons;
embeddedartists 1:15ea03d72dd7 246 mouse_x = x;
embeddedartists 1:15ea03d72dd7 247 mouse_y = y;
embeddedartists 1:15ea03d72dd7 248 mouse_z = z;
embeddedartists 13:57e65aba9802 249
embeddedartists 13:57e65aba9802 250 if (x < 0) {
embeddedartists 13:57e65aba9802 251 if (cursor_x > -x) {
embeddedartists 13:57e65aba9802 252 cursor_x += x;
embeddedartists 13:57e65aba9802 253 } else {
embeddedartists 13:57e65aba9802 254 cursor_x = 0;
embeddedartists 13:57e65aba9802 255 }
embeddedartists 13:57e65aba9802 256 } else {
embeddedartists 13:57e65aba9802 257 if ((cursor_x + x) >= 480) {
embeddedartists 13:57e65aba9802 258 cursor_x = 479;
embeddedartists 13:57e65aba9802 259 } else {
embeddedartists 13:57e65aba9802 260 cursor_x += x;
embeddedartists 13:57e65aba9802 261 }
embeddedartists 13:57e65aba9802 262 }
embeddedartists 26:f07df116f3c9 263
embeddedartists 13:57e65aba9802 264 if (y < 0) {
embeddedartists 13:57e65aba9802 265 if (cursor_y > -y) {
embeddedartists 13:57e65aba9802 266 cursor_y += y;
embeddedartists 13:57e65aba9802 267 } else {
embeddedartists 13:57e65aba9802 268 cursor_y = 0;
embeddedartists 13:57e65aba9802 269 }
embeddedartists 13:57e65aba9802 270 } else {
embeddedartists 13:57e65aba9802 271 if ((cursor_y + y) >= 272) {
embeddedartists 13:57e65aba9802 272 cursor_y = 271;
embeddedartists 13:57e65aba9802 273 } else {
embeddedartists 13:57e65aba9802 274 cursor_y += y;
embeddedartists 13:57e65aba9802 275 }
embeddedartists 13:57e65aba9802 276 }
embeddedartists 13:57e65aba9802 277
embeddedartists 13:57e65aba9802 278 //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y);
embeddedartists 13:57e65aba9802 279 LPC_LCD->CRSR_XY = (cursor_x & 0x3FF) | ((cursor_y & 0x3FF) << 16);
embeddedartists 13:57e65aba9802 280 }
embeddedartists 13:57e65aba9802 281
embeddedartists 13:57e65aba9802 282 #define LCD_CURSOR_32x32 0
embeddedartists 13:57e65aba9802 283 #define LCD_CURSOR_64x64 1
embeddedartists 13:57e65aba9802 284 #define CURSOR_SIZE LCD_CURSOR_32x32
embeddedartists 13:57e65aba9802 285 #define CURSOR_H_SIZE 32
embeddedartists 13:57e65aba9802 286 #define CURSOR_V_SIZE 32
embeddedartists 13:57e65aba9802 287 #define CURSOR_NUM 0
embeddedartists 13:57e65aba9802 288 #define CURSOR_H_OFS (10)
embeddedartists 13:57e65aba9802 289 #define CURSOR_V_OFS (6)
embeddedartists 13:57e65aba9802 290
embeddedartists 13:57e65aba9802 291 const unsigned char __attribute__ ((aligned(4))) Cursor[(CURSOR_H_SIZE / 4) * CURSOR_V_SIZE] =
embeddedartists 13:57e65aba9802 292 {
embeddedartists 13:57e65aba9802 293 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 294 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 295 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 296 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 297 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 298 0xAA, 0xAA, 0xAA, 0xFA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 299 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 300 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 301 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 302 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 303 0xAA, 0xAA, 0xAB, 0xFF, 0xEA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 304 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 305 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 306 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 307 0xAA, 0xAB, 0xFB, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 308 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 309 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 310 0xAA, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 311 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 312 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 313 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 314 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 315 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 316 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 317 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 318 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 319 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 320 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 321 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 322 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 323 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 324 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
embeddedartists 13:57e65aba9802 325 };
embeddedartists 13:57e65aba9802 326
embeddedartists 13:57e65aba9802 327 void prepareCursor(bool enable) {
embeddedartists 26:f07df116f3c9 328 //Chip_LCD_Cursor_Disable(LPC_LCD, 0);
embeddedartists 13:57e65aba9802 329 LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4);
embeddedartists 13:57e65aba9802 330
embeddedartists 13:57e65aba9802 331 if (enable) {
embeddedartists 13:57e65aba9802 332 //Chip_LCD_Cursor_Config(LPC_LCD, LCD_CURSOR_32x32, true);
embeddedartists 13:57e65aba9802 333 LPC_LCD->CRSR_CFG = ((true ? 1 : 0) << 1) | CURSOR_SIZE;
embeddedartists 13:57e65aba9802 334
embeddedartists 13:57e65aba9802 335 //Chip_LCD_Cursor_WriteImage(LPC_LCD, 0, (void *) Cursor);
embeddedartists 13:57e65aba9802 336 {
embeddedartists 13:57e65aba9802 337 int i, j;
embeddedartists 13:57e65aba9802 338 uint32_t *fifoptr, *crsr_ptr = (uint32_t *) Cursor;
embeddedartists 13:57e65aba9802 339
embeddedartists 13:57e65aba9802 340 /* Check if Cursor Size was configured as 32x32 or 64x64*/
embeddedartists 13:57e65aba9802 341 if (CURSOR_SIZE == LCD_CURSOR_32x32) {
embeddedartists 13:57e65aba9802 342 i = CURSOR_NUM * 64;
embeddedartists 13:57e65aba9802 343 j = i + 64;
embeddedartists 13:57e65aba9802 344 }
embeddedartists 13:57e65aba9802 345 else {
embeddedartists 13:57e65aba9802 346 i = 0;
embeddedartists 13:57e65aba9802 347 j = 256;
embeddedartists 13:57e65aba9802 348 }
embeddedartists 13:57e65aba9802 349 fifoptr = (uint32_t *) &(LPC_LCD->CRSR_IMG[0]);
embeddedartists 13:57e65aba9802 350
embeddedartists 13:57e65aba9802 351 /* Copy Cursor Image content to FIFO */
embeddedartists 13:57e65aba9802 352 for (; i < j; i++) {
embeddedartists 13:57e65aba9802 353
embeddedartists 13:57e65aba9802 354 *fifoptr = *crsr_ptr;
embeddedartists 13:57e65aba9802 355 crsr_ptr++;
embeddedartists 13:57e65aba9802 356 fifoptr++;
embeddedartists 13:57e65aba9802 357 }
embeddedartists 13:57e65aba9802 358 }
embeddedartists 13:57e65aba9802 359
embeddedartists 13:57e65aba9802 360 //Chip_LCD_Cursor_SetClip(LPC_LCD, CURSOR_H_OFS, CURSOR_V_OFS);
embeddedartists 13:57e65aba9802 361 LPC_LCD->CRSR_CLIP = (CURSOR_H_OFS & 0x3F) | ((CURSOR_V_OFS & 0x3F) << 8);
embeddedartists 13:57e65aba9802 362
embeddedartists 13:57e65aba9802 363 //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y);
embeddedartists 13:57e65aba9802 364
embeddedartists 13:57e65aba9802 365 //Chip_LCD_Cursor_Enable(LPC_LCD, 0);
embeddedartists 13:57e65aba9802 366 LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4) | 1;
embeddedartists 13:57e65aba9802 367 }
embeddedartists 1:15ea03d72dd7 368 }
embeddedartists 1:15ea03d72dd7 369
embeddedartists 1:15ea03d72dd7 370
embeddedartists 1:15ea03d72dd7 371 #define CIRCBUFF_SIZE 256
embeddedartists 24:768f5958c308 372 static volatile uint8_t circbuff[CIRCBUFF_SIZE];
embeddedartists 24:768f5958c308 373 static volatile uint32_t circbuff_read = 0;
embeddedartists 1:15ea03d72dd7 374 static uint32_t circbuff_write = 0;
embeddedartists 1:15ea03d72dd7 375 void keyEvent(uint8_t key)
embeddedartists 1:15ea03d72dd7 376 {
embeddedartists 1:15ea03d72dd7 377 circbuff[circbuff_write%CIRCBUFF_SIZE] = key;
embeddedartists 1:15ea03d72dd7 378 circbuff_write++;
embeddedartists 1:15ea03d72dd7 379 }
embeddedartists 1:15ea03d72dd7 380
embeddedartists 1:15ea03d72dd7 381
embeddedartists 26:f07df116f3c9 382 #define USBH_TASK_PREFIX "[USBH] "
embeddedartists 26:f07df116f3c9 383 #define USBH_CONNECTION_EVENT (1<<4)
embeddedartists 26:f07df116f3c9 384 void usbHostTask(void const* args)
embeddedartists 18:715f542538b3 385 {
embeddedartists 18:715f542538b3 386 bool msdConnected = false;
embeddedartists 18:715f542538b3 387 bool keyboardConnected = false;
embeddedartists 18:715f542538b3 388 bool mouseConnected = false;
embeddedartists 18:715f542538b3 389
embeddedartists 18:715f542538b3 390 USBHostMSD* msd = new USBHostMSD("usb");
embeddedartists 18:715f542538b3 391 USBHostKeyboard* keyboard = new USBHostKeyboard();
embeddedartists 18:715f542538b3 392 USBHostMouse* mouse = new USBHostMouse();
embeddedartists 18:715f542538b3 393 USBHost* host = USBHost::getHostInst();
embeddedartists 26:f07df116f3c9 394 host->signalOnConnections(Thread::gettid(), USBH_CONNECTION_EVENT);
embeddedartists 18:715f542538b3 395
embeddedartists 18:715f542538b3 396 RtosLog* log = DMBoard::instance().logger();
embeddedartists 18:715f542538b3 397
embeddedartists 26:f07df116f3c9 398 log->printf(USBH_TASK_PREFIX"Started\n");
embeddedartists 18:715f542538b3 399
embeddedartists 18:715f542538b3 400 prepareCursor(false);
embeddedartists 18:715f542538b3 401
embeddedartists 18:715f542538b3 402 while (true) {
embeddedartists 18:715f542538b3 403 // wait for connect/disconnect message from USBHost
embeddedartists 26:f07df116f3c9 404 Thread::signal_wait(USBH_CONNECTION_EVENT);
embeddedartists 26:f07df116f3c9 405 log->printf(USBH_TASK_PREFIX"got USB event\n");
embeddedartists 18:715f542538b3 406
embeddedartists 18:715f542538b3 407 if (msd->connected()) {
embeddedartists 18:715f542538b3 408 if (!msdConnected) {
embeddedartists 18:715f542538b3 409 msdConnected = true;
embeddedartists 18:715f542538b3 410 haveUSBMSD = true;
embeddedartists 26:f07df116f3c9 411 log->printf(USBH_TASK_PREFIX"USB MassStorage Device - Connected\n");
embeddedartists 18:715f542538b3 412 }
embeddedartists 18:715f542538b3 413 } else {
embeddedartists 18:715f542538b3 414 if (msdConnected) {
embeddedartists 18:715f542538b3 415 msdConnected = false;
embeddedartists 18:715f542538b3 416 haveUSBMSD = false;
embeddedartists 26:f07df116f3c9 417 log->printf(USBH_TASK_PREFIX"USB MassStorage Device - Ejected\n");
embeddedartists 18:715f542538b3 418 }
embeddedartists 18:715f542538b3 419
embeddedartists 18:715f542538b3 420 if (msd->connect()) {
embeddedartists 18:715f542538b3 421 msdConnected = true;
embeddedartists 18:715f542538b3 422 haveUSBMSD = true;
embeddedartists 26:f07df116f3c9 423 log->printf(USBH_TASK_PREFIX"USB MassStorage Device - Connected\n");
embeddedartists 18:715f542538b3 424 }
embeddedartists 18:715f542538b3 425 }
embeddedartists 18:715f542538b3 426
embeddedartists 18:715f542538b3 427 if (keyboard->connected()) {
embeddedartists 18:715f542538b3 428 if (!keyboardConnected) {
embeddedartists 18:715f542538b3 429 keyboardConnected = true;
embeddedartists 26:f07df116f3c9 430 log->printf(USBH_TASK_PREFIX"USB Keyboard - Connected\n");
embeddedartists 18:715f542538b3 431 keyboard->attach(keyEvent);
embeddedartists 18:715f542538b3 432 }
embeddedartists 18:715f542538b3 433 } else {
embeddedartists 18:715f542538b3 434 if (keyboardConnected) {
embeddedartists 18:715f542538b3 435 keyboardConnected = false;
embeddedartists 26:f07df116f3c9 436 log->printf(USBH_TASK_PREFIX"USB Keyboard - Ejected\n");
embeddedartists 18:715f542538b3 437 }
embeddedartists 18:715f542538b3 438 if (keyboard->connect()) {
embeddedartists 18:715f542538b3 439 keyboardConnected = true;
embeddedartists 26:f07df116f3c9 440 log->printf(USBH_TASK_PREFIX"USB Keyboard - Connected\n");
embeddedartists 18:715f542538b3 441 keyboard->attach(keyEvent);
embeddedartists 18:715f542538b3 442 }
embeddedartists 18:715f542538b3 443 }
embeddedartists 18:715f542538b3 444
embeddedartists 18:715f542538b3 445 if (mouse->connected()) {
embeddedartists 18:715f542538b3 446 if (!mouseConnected) {
embeddedartists 18:715f542538b3 447 mouseConnected = true;
embeddedartists 26:f07df116f3c9 448 log->printf(USBH_TASK_PREFIX"USB Mouse - Connected\n");
embeddedartists 18:715f542538b3 449 mouse->attachEvent(mouseEvent);
embeddedartists 18:715f542538b3 450 prepareCursor(true);
embeddedartists 18:715f542538b3 451 }
embeddedartists 18:715f542538b3 452 } else {
embeddedartists 18:715f542538b3 453 if (mouseConnected) {
embeddedartists 18:715f542538b3 454 prepareCursor(false);
embeddedartists 18:715f542538b3 455 mouseConnected = false;
embeddedartists 26:f07df116f3c9 456 log->printf(USBH_TASK_PREFIX"USB Mouse - Ejected\n");
embeddedartists 18:715f542538b3 457 }
embeddedartists 18:715f542538b3 458 if (mouse->connect()) {
embeddedartists 18:715f542538b3 459 mouseConnected = true;
embeddedartists 26:f07df116f3c9 460 log->printf(USBH_TASK_PREFIX"USB Mouse - Connected\n");
embeddedartists 18:715f542538b3 461 mouse->attachEvent(mouseEvent);
embeddedartists 18:715f542538b3 462 prepareCursor(true);
embeddedartists 18:715f542538b3 463 }
embeddedartists 18:715f542538b3 464 }
embeddedartists 18:715f542538b3 465 }
embeddedartists 18:715f542538b3 466 }
embeddedartists 18:715f542538b3 467
embeddedartists 26:f07df116f3c9 468 #endif //DM_BOARD_USE_USB_HOST
embeddedartists 26:f07df116f3c9 469
embeddedartists 26:f07df116f3c9 470 #if defined(DM_BOARD_USE_USB_DEVICE)
embeddedartists 26:f07df116f3c9 471
embeddedartists 26:f07df116f3c9 472 #define USBD_TASK_PREFIX "[USBD] "
embeddedartists 26:f07df116f3c9 473 //#define USBD_CONNECTION_EVENT (1<<4)
embeddedartists 26:f07df116f3c9 474 void usbDeviceTask(void const* args)
embeddedartists 26:f07df116f3c9 475 {
embeddedartists 26:f07df116f3c9 476 DMBoard* board = &DMBoard::instance();
embeddedartists 26:f07df116f3c9 477 RtosLog* log = board->logger();
embeddedartists 26:f07df116f3c9 478
embeddedartists 26:f07df116f3c9 479 log->printf(USBD_TASK_PREFIX"Started\n");
embeddedartists 26:f07df116f3c9 480
embeddedartists 26:f07df116f3c9 481 // Possibilities:
embeddedartists 26:f07df116f3c9 482 // - MassStorage
embeddedartists 26:f07df116f3c9 483 // * RAM file system
embeddedartists 26:f07df116f3c9 484 // a) For editing of settings or registry
embeddedartists 26:f07df116f3c9 485 // b) To give user an html file with information
embeddedartists 26:f07df116f3c9 486 // c) For BIOS updating
embeddedartists 26:f07df116f3c9 487 // * Expose MCI file system
embeddedartists 26:f07df116f3c9 488 // - Serial
embeddedartists 26:f07df116f3c9 489 // * Let RtosLogger use the USBDevice serial port instead to
embeddedartists 26:f07df116f3c9 490 // allow prints during debugging
embeddedartists 26:f07df116f3c9 491 // - Mouse
embeddedartists 26:f07df116f3c9 492 // * Use the display as a "trackpad"
embeddedartists 26:f07df116f3c9 493 // - Keyboard
embeddedartists 26:f07df116f3c9 494 // * Could be used by the RtosLogger (for fun)
embeddedartists 26:f07df116f3c9 495 // * Write our logo in ASCII art (for fun)
embeddedartists 26:f07df116f3c9 496 // - Audio?
embeddedartists 26:f07df116f3c9 497 // - CDC?
embeddedartists 26:f07df116f3c9 498
embeddedartists 26:f07df116f3c9 499 #if defined(DEMO_USB_DEVICE_MSD)
embeddedartists 26:f07df116f3c9 500 // USBDevice: MassStorage - Expose a 5MB RAM file system
embeddedartists 26:f07df116f3c9 501 //
embeddedartists 26:f07df116f3c9 502 // Notes:
embeddedartists 26:f07df116f3c9 503 // * Copying the large file to the PC at ca 512Kbyte per second
embeddedartists 26:f07df116f3c9 504 // * Copying a large file to the board at ca 800Kbyte per second
embeddedartists 26:f07df116f3c9 505 void* fsmem = malloc(RAM_FS_SIZE);
embeddedartists 26:f07df116f3c9 506 if (fsmem == NULL) {
embeddedartists 26:f07df116f3c9 507 log->printf("Failed to allocate memory for RAM file system\n");
embeddedartists 26:f07df116f3c9 508 mbed_die();
embeddedartists 26:f07df116f3c9 509 }
embeddedartists 26:f07df116f3c9 510 RAMFileSystem ramfs((uint32_t)fsmem, RAM_FS_SIZE, "ram");
embeddedartists 26:f07df116f3c9 511 USBMSD_RAMFS usbmsd(&ramfs);
embeddedartists 26:f07df116f3c9 512 ramfs.format();
embeddedartists 26:f07df116f3c9 513
embeddedartists 26:f07df116f3c9 514 // Create test file that user can modify
embeddedartists 26:f07df116f3c9 515 FILE* f = fopen("/ram/message.txt", "w");
embeddedartists 26:f07df116f3c9 516 if (f != NULL) {
embeddedartists 26:f07df116f3c9 517 fwrite("Hello World!\n", 1, 13, f);
embeddedartists 26:f07df116f3c9 518 fclose(f);
embeddedartists 26:f07df116f3c9 519 }
embeddedartists 26:f07df116f3c9 520
embeddedartists 26:f07df116f3c9 521 // Create benchmark file
embeddedartists 26:f07df116f3c9 522 uint32_t benchSize = RAM_FS_SIZE - 1*1024*1024;
embeddedartists 26:f07df116f3c9 523 log->printf(USBD_TASK_PREFIX"Generating %dMB benchmarking file...\n", benchSize/(1024*1024));
embeddedartists 26:f07df116f3c9 524 char buff[512+1] = {0};
embeddedartists 26:f07df116f3c9 525 for (int i = 0; i < 512; i++) {
embeddedartists 26:f07df116f3c9 526 buff[i] = i;
embeddedartists 26:f07df116f3c9 527 }
embeddedartists 26:f07df116f3c9 528 f = fopen("/ram/bench.bin", "w");
embeddedartists 26:f07df116f3c9 529 if (f != NULL) {
embeddedartists 26:f07df116f3c9 530 for (int i = 0; i < (benchSize/512); i++) {
embeddedartists 26:f07df116f3c9 531 fwrite(buff, 1, 512, f);
embeddedartists 26:f07df116f3c9 532 }
embeddedartists 26:f07df116f3c9 533 fclose(f);
embeddedartists 26:f07df116f3c9 534 }
embeddedartists 26:f07df116f3c9 535 log->printf(USBD_TASK_PREFIX"Finished generating /ram/bench.bin\n");
embeddedartists 26:f07df116f3c9 536
embeddedartists 26:f07df116f3c9 537 while (true) {
embeddedartists 26:f07df116f3c9 538 if (usbmsd.connect()) {
embeddedartists 26:f07df116f3c9 539 log->printf(USBD_TASK_PREFIX"USB MassStorage - Connected\n");
embeddedartists 26:f07df116f3c9 540 log->printf(USBD_TASK_PREFIX"Press USER button to disconnect USB MassStorage!\n");
embeddedartists 26:f07df116f3c9 541 while (!board->buttonPressed()) {
embeddedartists 26:f07df116f3c9 542 Thread::wait(50);
embeddedartists 26:f07df116f3c9 543 }
embeddedartists 26:f07df116f3c9 544 log->printf(USBD_TASK_PREFIX"User requested USB disconnect\n");
embeddedartists 26:f07df116f3c9 545 usbmsd.disconnect();
embeddedartists 26:f07df116f3c9 546 while (board->buttonPressed()) {
embeddedartists 26:f07df116f3c9 547 Thread::wait(50);
embeddedartists 26:f07df116f3c9 548 }
embeddedartists 26:f07df116f3c9 549 log->printf(USBD_TASK_PREFIX"USB disconnected\n");
embeddedartists 26:f07df116f3c9 550
embeddedartists 26:f07df116f3c9 551 {
embeddedartists 26:f07df116f3c9 552 log->printf("Reading /ram/message.txt:\n");
embeddedartists 26:f07df116f3c9 553 f = fopen("/ram/message.txt", "r");
embeddedartists 26:f07df116f3c9 554 if (f != NULL) {
embeddedartists 26:f07df116f3c9 555 while (true) {
embeddedartists 26:f07df116f3c9 556 size_t num = fread(buff, 1, 512, f);
embeddedartists 26:f07df116f3c9 557 if (num > 0) {
embeddedartists 26:f07df116f3c9 558 buff[num] = '\0';
embeddedartists 26:f07df116f3c9 559 log->printf(buff);
embeddedartists 26:f07df116f3c9 560 } else {
embeddedartists 26:f07df116f3c9 561 break;
embeddedartists 26:f07df116f3c9 562 }
embeddedartists 26:f07df116f3c9 563 }
embeddedartists 26:f07df116f3c9 564 fclose(f);
embeddedartists 26:f07df116f3c9 565 log->printf("\nEOF\n");
embeddedartists 26:f07df116f3c9 566 } else {
embeddedartists 26:f07df116f3c9 567 log->printf("Failed to read /ram/message.txt\n");
embeddedartists 26:f07df116f3c9 568 }
embeddedartists 26:f07df116f3c9 569 }
embeddedartists 26:f07df116f3c9 570
embeddedartists 26:f07df116f3c9 571 log->printf("\n"USBD_TASK_PREFIX"Press USER button to connect USB MassStorage again!\n");
embeddedartists 26:f07df116f3c9 572 while (!board->buttonPressed()) {
embeddedartists 26:f07df116f3c9 573 Thread::wait(50);
embeddedartists 26:f07df116f3c9 574 }
embeddedartists 26:f07df116f3c9 575 while (board->buttonPressed()) {
embeddedartists 26:f07df116f3c9 576 Thread::wait(50);
embeddedartists 26:f07df116f3c9 577 }
embeddedartists 26:f07df116f3c9 578 log->printf(USBD_TASK_PREFIX"User requested to connect USB again\n");
embeddedartists 26:f07df116f3c9 579 }
embeddedartists 26:f07df116f3c9 580 }
embeddedartists 26:f07df116f3c9 581 #endif // #if defined(DEMO_USB_DEVICE_MSD)
embeddedartists 26:f07df116f3c9 582
embeddedartists 26:f07df116f3c9 583 #if defined(DEMO_USB_DEVICE_SERIAL)
embeddedartists 26:f07df116f3c9 584 // USBDevice: Serial (see http://developer.mbed.org/handbook/USBSerial)
embeddedartists 26:f07df116f3c9 585 // http://developer.mbed.org/questions/5872/User-Friendly-Installation-of-USBSerial-/
embeddedartists 26:f07df116f3c9 586 //
embeddedartists 26:f07df116f3c9 587 // Notes:
embeddedartists 26:f07df116f3c9 588 // * Works, but a reset (e.g. Alt-B) requires the USB cable to be ejected+inserted
embeddedartists 26:f07df116f3c9 589 // for the PC to see the COM port again. It does not help to restart the Terminal
embeddedartists 26:f07df116f3c9 590 // program
embeddedartists 26:f07df116f3c9 591 // * Unplugging the USB cable after the terminal program on the PC has connected
embeddedartists 26:f07df116f3c9 592 // and then plugging it in again does not work. The terminal program will not see
embeddedartists 26:f07df116f3c9 593 // the port until after a bord reset.
embeddedartists 26:f07df116f3c9 594 // Update: This seems to be the Terminal Program's fault. Restarting the terminal
embeddedartists 26:f07df116f3c9 595 // program will make the port appear again.
embeddedartists 26:f07df116f3c9 596 // * It is possible to have the cable connected before powering up as well as connecting
embeddedartists 26:f07df116f3c9 597 // the cable after powering up.
embeddedartists 26:f07df116f3c9 598 #if defined(DM_BOARD_USE_USBSERIAL_IN_RTOSLOG)
embeddedartists 26:f07df116f3c9 599 int counter = 0;
embeddedartists 26:f07df116f3c9 600 while(true) {
embeddedartists 26:f07df116f3c9 601 Thread::wait(1000);
embeddedartists 26:f07df116f3c9 602 log->printf(USBD_TASK_PREFIX"Counter %3d\n", counter++);
embeddedartists 26:f07df116f3c9 603 }
embeddedartists 26:f07df116f3c9 604 #else
embeddedartists 26:f07df116f3c9 605 USBSerial s;
embeddedartists 26:f07df116f3c9 606 int counter = 0;
embeddedartists 26:f07df116f3c9 607 while(true) {
embeddedartists 26:f07df116f3c9 608 Thread::wait(1000);
embeddedartists 26:f07df116f3c9 609 s.printf(USBD_TASK_PREFIX"Counter %3d\n", counter++);
embeddedartists 26:f07df116f3c9 610 }
embeddedartists 26:f07df116f3c9 611 #endif
embeddedartists 26:f07df116f3c9 612 #endif // #if defined(DEMO_USB_DEVICE_SERIAL)
embeddedartists 26:f07df116f3c9 613
embeddedartists 26:f07df116f3c9 614 #if defined(DEMO_USB_DEVICE_MOUSE)
embeddedartists 26:f07df116f3c9 615 // Notes:
embeddedartists 26:f07df116f3c9 616 // * If the USBMouse class is used after this then the USBKeyboard stops working.
embeddedartists 26:f07df116f3c9 617 // if both are to be used then the USBMouseKeyboard class must be used instead.
embeddedartists 26:f07df116f3c9 618 USBKeyboard keyb;
embeddedartists 26:f07df116f3c9 619 while(true) {
embeddedartists 26:f07df116f3c9 620 while (!board->buttonPressed()) {
embeddedartists 26:f07df116f3c9 621 Thread::wait(50);
embeddedartists 26:f07df116f3c9 622 }
embeddedartists 26:f07df116f3c9 623 keyb.printf("Hello World!\n");
embeddedartists 26:f07df116f3c9 624 while (board->buttonPressed()) {
embeddedartists 26:f07df116f3c9 625 Thread::wait(50);
embeddedartists 26:f07df116f3c9 626 }
embeddedartists 26:f07df116f3c9 627 }
embeddedartists 26:f07df116f3c9 628 #endif // #if defined(DEMO_USB_DEVICE_MOUSE)
embeddedartists 26:f07df116f3c9 629 }
embeddedartists 26:f07df116f3c9 630 #endif
embeddedartists 26:f07df116f3c9 631
embeddedartists 18:715f542538b3 632
embeddedartists 14:73f6c425b2b5 633 #define REGTEST "[REG] "
embeddedartists 14:73f6c425b2b5 634 static void testRegistry()
embeddedartists 14:73f6c425b2b5 635 {
embeddedartists 14:73f6c425b2b5 636 Registry* reg = DMBoard::instance().registry();
embeddedartists 14:73f6c425b2b5 637 RtosLog* log = DMBoard::instance().logger();
embeddedartists 14:73f6c425b2b5 638 char* key;
embeddedartists 14:73f6c425b2b5 639 char* val;
embeddedartists 14:73f6c425b2b5 640 Registry::RegistryError err;
embeddedartists 14:73f6c425b2b5 641
embeddedartists 14:73f6c425b2b5 642 log->printf(REGTEST"Before:\n");
embeddedartists 14:73f6c425b2b5 643 for (int i = 0; i < reg->numEntries(); i++) {
embeddedartists 14:73f6c425b2b5 644 err = reg->entryAt(i, &key, &val);
embeddedartists 14:73f6c425b2b5 645 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 646 log->printf(REGTEST" [%2d] '%s' = '%s'\n", i, key, val);
embeddedartists 14:73f6c425b2b5 647 free(key);
embeddedartists 14:73f6c425b2b5 648 free(val);
embeddedartists 14:73f6c425b2b5 649 } else {
embeddedartists 14:73f6c425b2b5 650 log->printf(REGTEST" [%2d] got error %d\n", i, err);
embeddedartists 14:73f6c425b2b5 651 }
embeddedartists 14:73f6c425b2b5 652 }
embeddedartists 14:73f6c425b2b5 653
embeddedartists 14:73f6c425b2b5 654 log->printf(REGTEST"Getting existing value:\n");
embeddedartists 14:73f6c425b2b5 655 err = reg->getValue("IP Address", &val);
embeddedartists 14:73f6c425b2b5 656 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 657 log->printf(REGTEST" Existing 'IP Address' = '%s'\n", val);
embeddedartists 14:73f6c425b2b5 658 free(val);
embeddedartists 14:73f6c425b2b5 659 } else {
embeddedartists 14:73f6c425b2b5 660 log->printf(REGTEST" Existing 'IP Address' got error %d\n", err);
embeddedartists 14:73f6c425b2b5 661 }
embeddedartists 14:73f6c425b2b5 662
embeddedartists 14:73f6c425b2b5 663 log->printf(REGTEST"Getting missing value:\n");
embeddedartists 14:73f6c425b2b5 664 err = reg->getValue("X78g4dfwx", &val);
embeddedartists 14:73f6c425b2b5 665 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 666 log->printf(REGTEST" Missing 'X78g4dfwx' = '%s'\n", val);
embeddedartists 14:73f6c425b2b5 667 free(val);
embeddedartists 14:73f6c425b2b5 668 } else if (err == Registry::NoSuchKeyError) {
embeddedartists 14:73f6c425b2b5 669 log->printf(REGTEST" Missing 'X78g4dfwx' was missing.\n", err);
embeddedartists 14:73f6c425b2b5 670 } else {
embeddedartists 14:73f6c425b2b5 671 log->printf(REGTEST" Existing 'X78g4dfwx' got error %d\n", err);
embeddedartists 14:73f6c425b2b5 672 }
embeddedartists 14:73f6c425b2b5 673
embeddedartists 14:73f6c425b2b5 674 log->printf(REGTEST"Updating value:\n");
embeddedartists 14:73f6c425b2b5 675 err = reg->getValue("EATest", &val);
embeddedartists 14:73f6c425b2b5 676 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 677 log->printf(REGTEST" Old value for 'EATest' = '%s'\n", val);
embeddedartists 14:73f6c425b2b5 678 char buf[32];
embeddedartists 14:73f6c425b2b5 679 sprintf(buf, "%d", atoi(val)+1);
embeddedartists 14:73f6c425b2b5 680 free(val);
embeddedartists 14:73f6c425b2b5 681 err = reg->setValue("EATest", buf);
embeddedartists 14:73f6c425b2b5 682 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 683 log->printf(REGTEST" Updated 'EATest' to '%s'\n", buf);
embeddedartists 14:73f6c425b2b5 684 } else {
embeddedartists 14:73f6c425b2b5 685 log->printf(REGTEST" Failed to update 'EATest', got error %d\n", err);
embeddedartists 14:73f6c425b2b5 686 }
embeddedartists 14:73f6c425b2b5 687 } else if (err == Registry::NoSuchKeyError) {
embeddedartists 14:73f6c425b2b5 688 log->printf(REGTEST" No value for 'EATest', adding one\n", err);
embeddedartists 14:73f6c425b2b5 689 err = reg->setValue("EATest", "-3");
embeddedartists 14:73f6c425b2b5 690 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 691 log->printf(REGTEST" Set 'EATest' to '0'\n");
embeddedartists 14:73f6c425b2b5 692 } else {
embeddedartists 14:73f6c425b2b5 693 log->printf(REGTEST" Failed to set 'EATest', got error %d\n", err);
embeddedartists 14:73f6c425b2b5 694 }
embeddedartists 14:73f6c425b2b5 695 } else {
embeddedartists 14:73f6c425b2b5 696 log->printf(REGTEST" Failed to read 'EATest' got error %d\n", err);
embeddedartists 14:73f6c425b2b5 697 }
embeddedartists 14:73f6c425b2b5 698
embeddedartists 14:73f6c425b2b5 699 log->printf(REGTEST"Storing values persistently\n");
embeddedartists 14:73f6c425b2b5 700 err = reg->store();
embeddedartists 14:73f6c425b2b5 701 if (err != Registry::Ok) {
embeddedartists 14:73f6c425b2b5 702 log->printf(REGTEST" Failed to store values, got error %d\n", err);
embeddedartists 14:73f6c425b2b5 703 }
embeddedartists 14:73f6c425b2b5 704
embeddedartists 14:73f6c425b2b5 705 log->printf(REGTEST"After:\n");
embeddedartists 14:73f6c425b2b5 706 for (int i = 0; i < reg->numEntries(); i++) {
embeddedartists 14:73f6c425b2b5 707 err = reg->entryAt(i, &key, &val);
embeddedartists 14:73f6c425b2b5 708 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 709 log->printf(REGTEST" [%2d] '%s' = '%s'\n", i, key, val);
embeddedartists 14:73f6c425b2b5 710 free(key);
embeddedartists 14:73f6c425b2b5 711 free(val);
embeddedartists 14:73f6c425b2b5 712 } else {
embeddedartists 14:73f6c425b2b5 713 log->printf(REGTEST" [%2d] got error %d\n", i, err);
embeddedartists 14:73f6c425b2b5 714 }
embeddedartists 14:73f6c425b2b5 715 }
embeddedartists 14:73f6c425b2b5 716 }
embeddedartists 14:73f6c425b2b5 717
embeddedartists 0:dfad71908d59 718 /******************************************************************************
embeddedartists 0:dfad71908d59 719 * Main function
embeddedartists 0:dfad71908d59 720 *****************************************************************************/
embeddedartists 0:dfad71908d59 721 int main()
embeddedartists 0:dfad71908d59 722 {
embeddedartists 0:dfad71908d59 723 DMBoard::BoardError err;
embeddedartists 0:dfad71908d59 724 DMBoard* board = &DMBoard::instance();
embeddedartists 0:dfad71908d59 725 RtosLog* log = board->logger();
embeddedartists 0:dfad71908d59 726 err = board->init();
embeddedartists 0:dfad71908d59 727 if (err != DMBoard::Ok) {
embeddedartists 0:dfad71908d59 728 log->printf("Failed to initialize the board, got error %d\r\n", err);
embeddedartists 16:77f4f42eb6a7 729 log->printf("\nTERMINATING\n");
embeddedartists 16:77f4f42eb6a7 730 wait_ms(2000); // allow RtosLog to flush messages
embeddedartists 0:dfad71908d59 731 mbed_die();
embeddedartists 0:dfad71908d59 732 }
embeddedartists 0:dfad71908d59 733
embeddedartists 11:4830c7689843 734 board->buzzer(440,50);
embeddedartists 11:4830c7689843 735 wait_ms(30);
embeddedartists 11:4830c7689843 736 board->buzzer(660,50);
embeddedartists 11:4830c7689843 737 wait_ms(30);
embeddedartists 11:4830c7689843 738 board->buzzer(440,50);
embeddedartists 11:4830c7689843 739
embeddedartists 0:dfad71908d59 740 log->printf("\n\n---\nMulti-threaded demo\nBuilt: " __DATE__ " at " __TIME__ "\n\n");
embeddedartists 0:dfad71908d59 741
embeddedartists 16:77f4f42eb6a7 742 //testRegistry();
embeddedartists 14:73f6c425b2b5 743
embeddedartists 14:73f6c425b2b5 744
embeddedartists 0:dfad71908d59 745 Thread tAlive(aliveTask);
embeddedartists 0:dfad71908d59 746 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 2:070e9c054796 747 Thread tSwim(swimTask, NULL, osPriorityNormal, 8192);
embeddedartists 26:f07df116f3c9 748 #endif
embeddedartists 26:f07df116f3c9 749 #if defined(DM_BOARD_USE_ETHERNET)
embeddedartists 0:dfad71908d59 750 Thread tNetwork(netTask, NULL, osPriorityNormal, 8192);
embeddedartists 26:f07df116f3c9 751 #endif
embeddedartists 26:f07df116f3c9 752 #if defined(DM_BOARD_USE_USB_HOST)
embeddedartists 26:f07df116f3c9 753 Thread tUSBHandler(usbHostTask, NULL, osPriorityNormal, 8192);
embeddedartists 26:f07df116f3c9 754 #elif defined(DM_BOARD_USE_USB_DEVICE)
embeddedartists 26:f07df116f3c9 755 Thread tUSBDev(usbDeviceTask, NULL, osPriorityNormal, 8192);
embeddedartists 26:f07df116f3c9 756 #endif
embeddedartists 26:f07df116f3c9 757
embeddedartists 18:715f542538b3 758 while(1) {
embeddedartists 26:f07df116f3c9 759 Thread::wait(5000);
embeddedartists 18:715f542538b3 760 time_t seconds = time(NULL);
embeddedartists 18:715f542538b3 761 log->printf("Time: %s\n", ctime(&seconds));
embeddedartists 18:715f542538b3 762 }
embeddedartists 0:dfad71908d59 763 }