aboutsummaryrefslogtreecommitdiffstats
path: root/tool/mbed/mbed-sdk/libraries/tests/usb/device
diff options
context:
space:
mode:
authorJun Wako <wakojun@gmail.com>2015-04-24 16:26:14 +0900
committerJun Wako <wakojun@gmail.com>2015-04-24 16:26:14 +0900
commit1fe4406f374291ab2e86e95a97341fd9c475fcb8 (patch)
tree1be0e16b4b07b5a31ea97ec50a9eb13a288c3d27 /tool/mbed/mbed-sdk/libraries/tests/usb/device
parenta20ef7052c6e937d2f7672dd59456e55a5c08296 (diff)
downloadfirmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.tar.gz
firmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.tar.bz2
firmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.zip
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk' 7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5 git-subtree-dir: tmk_core git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
Diffstat (limited to 'tool/mbed/mbed-sdk/libraries/tests/usb/device')
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/usb/device/audio/main.cpp40
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/usb/device/basic/main.cpp28
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/usb/device/keyboard/main.cpp21
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp73
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/usb/device/mouse_keyboard/main.cpp22
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/usb/device/raw_hid/main.cpp26
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/usb/device/serial/main.cpp18
7 files changed, 228 insertions, 0 deletions
diff --git a/tool/mbed/mbed-sdk/libraries/tests/usb/device/audio/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/usb/device/audio/main.cpp
new file mode 100644
index 000000000..e18891032
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/usb/device/audio/main.cpp
@@ -0,0 +1,40 @@
+// Playback example with the USBAUDIO library
+
+#include "mbed.h"
+#include "USBAudio.h"
+
+// frequency: 48 kHz
+#define FREQ_SPK 48000
+#define FREQ_MIC 48000
+
+// 2channels: stereo
+#define NB_CHA_SPK 2
+#define NB_CHA_MIC 2
+
+// length computed: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there are two channels, the length will be 48 * 2 * 2
+#define LENGTH_AUDIO_PACKET_SPK (FREQ_SPK / 500) * NB_CHA_SPK
+#define LENGTH_AUDIO_PACKET_MIC (FREQ_MIC / 500) * NB_CHA_MIC
+
+// USBAudio object
+USBAudio audio(FREQ_SPK, NB_CHA_SPK, FREQ_MIC, NB_CHA_MIC, 0xab45, 0x0378);
+
+int main() {
+ // buffer of int
+ int buf_in[LENGTH_AUDIO_PACKET_SPK/sizeof(int)];
+ int buf_out[LENGTH_AUDIO_PACKET_MIC/sizeof(int)];
+ int * stream_out = buf_in;
+ int * stream_in = buf_out;
+ int * tmp = NULL;
+
+ while (1) {
+ // read and write one audio packet each frame
+ audio.readWrite((uint8_t *)stream_in, (uint8_t *)stream_out);
+
+ // swap the buffers
+ tmp = stream_in;
+ stream_in = stream_out;
+ stream_out = tmp;
+ }
+}
+
+
diff --git a/tool/mbed/mbed-sdk/libraries/tests/usb/device/basic/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/usb/device/basic/main.cpp
new file mode 100644
index 000000000..9f786559f
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/usb/device/basic/main.cpp
@@ -0,0 +1,28 @@
+#include <math.h>
+
+#include "mbed.h"
+#include "USBMouse.h"
+
+USBMouse mouse(ABS_MOUSE);
+
+int main(void) {
+ int x_center = (X_MAX_ABS - X_MIN_ABS)/2;
+ int y_center = (Y_MAX_ABS - Y_MIN_ABS)/2;
+ int16_t x_screen = 0;
+ int16_t y_screen = 0;
+
+ int32_t x_origin = x_center;
+ int32_t y_origin = y_center;
+ int32_t radius = 5000;
+ int32_t angle = 0;
+
+ while (1) {
+ x_screen = x_origin + cos((double)angle*3.14/180.0)*radius;
+ y_screen = y_origin + sin((double)angle*3.14/180.0)*radius;
+ printf("cos: %f, sin: %f\r\n", cos((double)angle*3.14/180.0)*radius, sin((double)angle)*radius);
+
+ mouse.move(x_screen, y_screen);
+ angle += 3;
+ wait(0.01);
+ }
+}
diff --git a/tool/mbed/mbed-sdk/libraries/tests/usb/device/keyboard/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/usb/device/keyboard/main.cpp
new file mode 100644
index 000000000..3c4cbf15a
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/usb/device/keyboard/main.cpp
@@ -0,0 +1,21 @@
+#include "mbed.h"
+#include "USBKeyboard.h"
+
+//LED1: NUM_LOCK
+//LED2: CAPS_LOCK
+//LED3: SCROLL_LOCK
+BusOut leds(LED1, LED2, LED3);
+
+//USBKeyboard
+USBKeyboard keyboard;
+
+int main(void) {
+ while (1) {
+ keyboard.mediaControl(KEY_VOLUME_DOWN);
+ keyboard.printf("Hello World from Mbed\r\n");
+ keyboard.keyCode('s', KEY_CTRL);
+ keyboard.keyCode(KEY_CAPS_LOCK);
+ leds = keyboard.lockStatus();
+ wait(1);
+ }
+}
diff --git a/tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp
new file mode 100644
index 000000000..b0a6cd381
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "USBMIDI.h"
+
+USBMIDI midi;
+Serial pc(USBTX, USBRX);
+
+// MIDI IN
+void transmitMessage(MIDIMessage msg) {
+ switch (msg.type()) {
+ case MIDIMessage::NoteOnType:
+ wait(0.1);
+ midi.write(MIDIMessage::NoteOn(msg.key()));
+ break;
+ case MIDIMessage::NoteOffType:
+ wait(0.1);
+ midi.write(MIDIMessage::NoteOff(msg.key()));
+ break;
+ case MIDIMessage::ProgramChangeType:
+ wait(0.1);
+ midi.write(MIDIMessage::ProgramChange(msg.program()));
+ break;
+ case MIDIMessage::SysExType:
+ wait(0.1);
+ unsigned char tmp[64];
+ for(int i=0;i<msg.length-1;i++) {
+ tmp[i]=msg.data[i+1];
+ }
+ midi.write(MIDIMessage::SysEx(tmp,msg.length-1));
+ break;
+ default:
+ break;
+ }
+}
+
+int main(void)
+{
+ wait(5);
+ // MIDI OUT
+
+ // set piano
+ midi.write(MIDIMessage::ProgramChange(1));
+ wait(0.1);
+
+ // play A
+ midi.write(MIDIMessage::NoteOn(21));
+ wait(0.1);
+ midi.write(MIDIMessage::NoteOff(21));
+ wait(0.1);
+
+ // GM reset
+ unsigned char gm_reset[]={0xF0,0x7E,0x7F,0x09,0x01,0xF7};
+ midi.write(MIDIMessage::SysEx(gm_reset,6));
+ wait(0.1);
+
+ // GM Master volume max
+ unsigned char gm_master_vol_max[]={0xF0,0x7F,0x7F,0x04,0x01,0x7F,0x7F,0xF7};
+ midi.write(MIDIMessage::SysEx(gm_master_vol_max,8));
+ wait(0.1);
+
+ // GS reset
+ unsigned char gs_reset[]={0xF0,0x41,0x10,0x42,0x12,0x40,0x00,0x7F,0x00,0x41,0xF7};
+ midi.write(MIDIMessage::SysEx(gs_reset,11));
+ wait(0.1);
+
+ // GS Master volume max
+ unsigned char gs_master_vol_max[]={0xF0,0x41,0x10,0x42,0x12,0x40,0x00,0x04,0x7F,0x3D,0xF7};
+ midi.write(MIDIMessage::SysEx(gs_master_vol_max,11));
+ wait(0.1);
+
+ midi.attach(transmitMessage);
+
+ while(1);
+}
diff --git a/tool/mbed/mbed-sdk/libraries/tests/usb/device/mouse_keyboard/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/usb/device/mouse_keyboard/main.cpp
new file mode 100644
index 000000000..1daae66de
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/usb/device/mouse_keyboard/main.cpp
@@ -0,0 +1,22 @@
+#include "mbed.h"
+#include "USBMouseKeyboard.h"
+
+//LED1: NUM_LOCK
+//LED2: CAPS_LOCK
+//LED3: SCROLL_LOCK
+BusOut leds(LED1, LED2, LED3);
+
+//USBMouseKeyboard
+USBMouseKeyboard key_mouse;
+
+int main(void) {
+ while (1) {
+ key_mouse.mediaControl(KEY_VOLUME_DOWN);
+ key_mouse.printf("Hello World from Mbed\r\n");
+ key_mouse.keyCode('s', KEY_CTRL);
+ key_mouse.move(20, 0);
+ key_mouse.keyCode(KEY_SCROLL_LOCK);
+ leds = key_mouse.lockStatus();
+ wait(1);
+ }
+}
diff --git a/tool/mbed/mbed-sdk/libraries/tests/usb/device/raw_hid/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/usb/device/raw_hid/main.cpp
new file mode 100644
index 000000000..0a5d69cfe
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/usb/device/raw_hid/main.cpp
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#include "USBHID.h"
+
+//We declare a USBHID device
+USBHID hid;
+
+//This report will contain data to be sent
+HID_REPORT send_report;
+
+Ticker tic;
+
+void tic_handler();
+void tic_handler() {
+ hid.send(&send_report);
+}
+
+int main(void) {
+ //Fill the report
+ for(int i = 0; i < 64; i++)
+ send_report.data[i] = i;
+ send_report.length = 64;
+
+ tic.attach(tic_handler, 1);
+
+ while (1);
+}
diff --git a/tool/mbed/mbed-sdk/libraries/tests/usb/device/serial/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/usb/device/serial/main.cpp
new file mode 100644
index 000000000..73e52bbfa
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/usb/device/serial/main.cpp
@@ -0,0 +1,18 @@
+#include "mbed.h"
+#include "USBSerial.h"
+
+//Virtual serial port over USB
+USBSerial serial;
+DigitalOut l1(LED1);
+
+int main(void) {
+ int i = 0;
+
+ while(1)
+ {
+ l1 = !l1;
+ printf("Hello\r\n");
+ serial.printf("I am a virtual serial port: %d\r\n", i++);
+ wait(0.1);
+ }
+}