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:
embeddedartists
Date:
Mon Mar 09 16:21:26 2015 +0100
Revision:
26:f07df116f3c9
Parent:
24:768f5958c308
Child:
27:4fe24decabf9
- Added USBDevice examples
- Added AppUSBMouse to control PC mouse from display module
- Updated versions of DMSupport and DMBasicGUI libraries
- Minor formatting changes

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