ADC Niose test Connect four analog signals to your MBED. and then run the Windows app. The four traces are displayed on an oscilloscope like display. I have used a USB HID DEVICE link, so connections to D+, D- are required. The MBED code is otherwise quite basic, So you can modify it to your own test needs. Additionaly, there is a 16 bit count value, in my MBED code Mainly to test if MSB & LSB are correct.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBMouse.cpp Source File

USBMouse.cpp

00001 // USBMouse.c
00002 // USB device example: Relative mouse
00003 // Copyright (c) 2011 ARM Limited. All rights reserved.
00004 
00005 #include "stdint.h"
00006 #include "USBMouse.h"
00007 
00008 bool USBMouse::update(int16_t x, int16_t y, uint8_t button, int8_t z) {
00009     switch (mouse_type) {
00010         case REL_MOUSE:
00011             while (x > 127) {
00012                 if (!mouseSend(127, 0, button, z)) return false;
00013                 x = x - 127;
00014             }
00015             while (x < -128) {
00016                 if (!mouseSend(-128, 0, button, z)) return false;
00017                 x = x + 128;
00018             }
00019             while (y > 127) {
00020                 if (!mouseSend(0, 127, button, z)) return false;
00021                 y = y - 127;
00022             }
00023             while (y < -128) {
00024                 if (!mouseSend(0, -128, button, z)) return false;
00025                 y = y + 128;
00026             }
00027             return mouseSend(x, y, button, z);
00028         case ABS_MOUSE:
00029             HID_REPORT report;
00030 
00031             report.data[0] = x & 0xff;
00032             report.data[1] = (x >> 8) & 0xff;
00033             report.data[2] = y & 0xff;
00034             report.data[3] = (y >> 8) & 0xff;
00035             report.data[4] = -z;
00036             report.data[5] = button & 0x07;
00037 
00038             report.length = 6;
00039 
00040             return send(&report);
00041         default:
00042             return false;
00043     }
00044 }
00045 
00046 bool USBMouse::mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z) {
00047     HID_REPORT report;
00048     report.data[0] = buttons & 0x07;
00049     report.data[1] = x;
00050     report.data[2] = y;
00051     report.data[3] = -z; // >0 to scroll down, <0 to scroll up
00052 
00053     report.length = 4;
00054 
00055     return send(&report);
00056 }
00057 
00058 bool USBMouse::move(int16_t x, int16_t y) {
00059     return update(x, y, button, 0);
00060 }
00061 
00062 bool USBMouse::scroll(int8_t z) {
00063     return update(0, 0, button, z);
00064 }
00065 
00066 
00067 bool USBMouse::doubleClick() {
00068     if (!click(MOUSE_LEFT))
00069         return false;
00070     wait(0.1);
00071     return click(MOUSE_LEFT);
00072 }
00073 
00074 bool USBMouse::click(uint8_t button) {
00075     if (!update(0, 0, button, 0))
00076         return false;
00077     wait(0.01);
00078     return update(0, 0, 0, 0);
00079 }
00080 
00081 bool USBMouse::press(uint8_t button_) {
00082     button = button_ & 0x07;
00083     return update(0, 0, button, 0);
00084 }
00085 
00086 bool USBMouse::release(uint8_t button_) {
00087     button = (button & (~button_)) & 0x07;
00088     return update(0, 0, button, 0);
00089 }
00090 
00091 
00092 uint8_t * USBMouse::reportDesc() {
00093 
00094     if (mouse_type == REL_MOUSE) {
00095         static uint8_t reportDescriptor[] = {
00096             USAGE_PAGE(1),      0x01,       // Genric Desktop
00097             USAGE(1),           0x02,       // Mouse
00098             COLLECTION(1),      0x01,       // Application
00099             USAGE(1),           0x01,       // Pointer
00100             COLLECTION(1),      0x00,       // Physical
00101 
00102             REPORT_COUNT(1),    0x03,
00103             REPORT_SIZE(1),     0x01,
00104             USAGE_PAGE(1),      0x09,       // Buttons
00105             USAGE_MINIMUM(1),       0x1,
00106             USAGE_MAXIMUM(1),       0x3,
00107             LOGICAL_MINIMUM(1),     0x00,
00108             LOGICAL_MAXIMUM(1),     0x01,
00109             INPUT(1),           0x02,
00110             REPORT_COUNT(1),    0x01,
00111             REPORT_SIZE(1),     0x05,
00112             INPUT(1),           0x01,
00113 
00114             REPORT_COUNT(1),    0x03,
00115             REPORT_SIZE(1),     0x08,
00116             USAGE_PAGE(1),      0x01,
00117             USAGE(1),           0x30,       // X
00118             USAGE(1),           0x31,       // Y
00119             USAGE(1),           0x38,       // scroll
00120             LOGICAL_MINIMUM(1),     0x81,
00121             LOGICAL_MAXIMUM(1),     0x7f,
00122             INPUT(1),           0x06,       // Relative data
00123 
00124             END_COLLECTION(0),
00125             END_COLLECTION(0),
00126         };
00127         reportLength = sizeof(reportDescriptor);
00128         return reportDescriptor;
00129     } else if (mouse_type == ABS_MOUSE) {
00130         static uint8_t reportDescriptor[] = {
00131 
00132             USAGE_PAGE(1), 0x01,           // Generic Desktop
00133             USAGE(1), 0x02,                // Mouse
00134             COLLECTION(1), 0x01,           // Application
00135             USAGE(1), 0x01,                // Pointer
00136             COLLECTION(1), 0x00,           // Physical
00137 
00138             USAGE_PAGE(1), 0x01,            // Generic Desktop
00139             USAGE(1), 0x30,                 // X
00140             USAGE(1), 0x31,                 // Y
00141             LOGICAL_MINIMUM(1), 0x00,       // 0
00142             LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
00143             REPORT_SIZE(1), 0x10,
00144             REPORT_COUNT(1), 0x02,
00145             INPUT(1), 0x02,                 // Data, Variable, Absolute
00146 
00147             USAGE_PAGE(1), 0x01,            // Generic Desktop
00148             USAGE(1), 0x38,                 // scroll
00149             LOGICAL_MINIMUM(1), 0x81,       // -127
00150             LOGICAL_MAXIMUM(1), 0x7f,       // 127
00151             REPORT_SIZE(1), 0x08,
00152             REPORT_COUNT(1), 0x01,
00153             INPUT(1), 0x06,                 // Data, Variable, Relative
00154 
00155             USAGE_PAGE(1), 0x09,            // Buttons
00156             USAGE_MINIMUM(1), 0x01,
00157             USAGE_MAXIMUM(1), 0x03,
00158             LOGICAL_MINIMUM(1), 0x00,       // 0
00159             LOGICAL_MAXIMUM(1), 0x01,       // 1
00160             REPORT_COUNT(1), 0x03,
00161             REPORT_SIZE(1), 0x01,
00162             INPUT(1), 0x02,                 // Data, Variable, Absolute
00163             REPORT_COUNT(1), 0x01,
00164             REPORT_SIZE(1), 0x05,
00165             INPUT(1), 0x01,                 // Constant
00166 
00167             END_COLLECTION(0),
00168             END_COLLECTION(0)
00169         };
00170         reportLength = sizeof(reportDescriptor);
00171         return reportDescriptor;
00172     }
00173     return NULL;
00174 }
00175 
00176