From 1fe4406f374291ab2e86e95a97341fd9c475fcb8 Mon Sep 17 00:00:00 2001 From: Jun Wako Date: Fri, 24 Apr 2015 16:26:14 +0900 Subject: 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 --- .../libraries/tests/usb/device/audio/main.cpp | 40 ++++++++++++ .../libraries/tests/usb/device/basic/main.cpp | 28 +++++++++ .../libraries/tests/usb/device/keyboard/main.cpp | 21 +++++++ .../libraries/tests/usb/device/midi/main.cpp | 73 ++++++++++++++++++++++ .../tests/usb/device/mouse_keyboard/main.cpp | 22 +++++++ .../libraries/tests/usb/device/raw_hid/main.cpp | 26 ++++++++ .../libraries/tests/usb/device/serial/main.cpp | 18 ++++++ 7 files changed, 228 insertions(+) create mode 100644 tool/mbed/mbed-sdk/libraries/tests/usb/device/audio/main.cpp create mode 100644 tool/mbed/mbed-sdk/libraries/tests/usb/device/basic/main.cpp create mode 100644 tool/mbed/mbed-sdk/libraries/tests/usb/device/keyboard/main.cpp create mode 100644 tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp create mode 100644 tool/mbed/mbed-sdk/libraries/tests/usb/device/mouse_keyboard/main.cpp create mode 100644 tool/mbed/mbed-sdk/libraries/tests/usb/device/raw_hid/main.cpp create mode 100644 tool/mbed/mbed-sdk/libraries/tests/usb/device/serial/main.cpp (limited to 'tool/mbed/mbed-sdk/libraries/tests/usb') 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 + +#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