SDG+USBHost(Mouse) Sample
Dependencies: Sound_Generator USBHost_custom
Fork of SDG_Mouse_Sample by
Information
Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.
What is this?
This program is a demonstration that sounds the sound by mouse operation by using USBHost(Mouse) and Sound Generator.
Settings
Close JP3 of GR-PEACH.
Operation
| operation | effect |
|---|---|
| Right click | Sounds |
| Left click | Reset to base tone (C) |
| Moves the mouse to the right | Lower the sound |
| Moves the mouse to the left | Higher the sound |
| Center cursor | Adjust the sensitivity. Reset the reference value in the click. |
Others
The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
概要
このプログラムは、USBHost(Mouse) + Sound Generatorで、マウス操作による擬似笛デモです。
設定
GR-PEACHのJP3をショートする必要があります。
操作方法
| 操作 | 内容 |
|---|---|
| 右クリック | 音出力開始 |
| 左クリック | 基準音(ド)にリセット |
| マウス右移動 | 高音になります |
| マウス左移動 | 低音になります |
| センターカーソル | 音高低の変化量調整(クリックで基準値にリセット) |
Others
mbedのシリアル通信(ボーレート等)のデフォルト設定は以下のリンクに示しています。
リンクを参考に、お使いのPCターミナルソフトの設定を変更して下さい。
mbedでのボーレートのデフォルト値は9600で、このサンプルではボーレート9600を使います。
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
Revision 9:7671b6a8c363, committed 2013-03-14
- Comitter:
- samux
- Date:
- Thu Mar 14 14:20:03 2013 +0000
- Parent:
- 8:93da8ea2708b
- Child:
- 10:0c11cf1cc218
- Commit message:
- use queue to wait end of transfer - use mailbox
Changed in this revision
--- a/USBHost/USBEndpoint.h Thu Mar 14 11:49:53 2013 +0000
+++ b/USBHost/USBEndpoint.h Thu Mar 14 14:20:03 2013 +0000
@@ -19,10 +19,11 @@
#include "FunctionPointer.h"
#include "USBHostTypes.h"
+#include "rtos.h"
class USBDeviceConnected;
-/**
+/**
* USBEndpoint class
*/
class USBEndpoint
@@ -137,6 +138,8 @@
inline uint8_t getIntfNb() { return intf_nb; };
USBDeviceConnected * dev;
+
+ Queue<uint8_t, 1> ep_queue;
private:
ENDPOINT_TYPE type;
--- a/USBHost/USBHost.cpp Thu Mar 14 11:49:53 2013 +0000
+++ b/USBHost/USBHost.cpp Thu Mar 14 14:20:03 2013 +0000
@@ -68,9 +68,9 @@
#endif
while(1) {
- osEvent evt = queue_usb_event.get();
+ osEvent evt = mail_usb_event.get();
- if (evt.status == osEventMessage) {
+ if (evt.status == osEventMail) {
l4 = !l4;
message_t * usb_msg = (message_t*)evt.value.p;
@@ -96,6 +96,7 @@
if (i == MAX_DEVICE_CONNECTED) {
USB_ERR("Too many device connected!!\r\n");
+ deviceInited[i] = false;
usb_mutex.unlock();
continue;
}
@@ -242,7 +243,7 @@
break;
}
- mpool_usb_event.free(usb_msg);
+ mail_usb_event.free(usb_msg);
}
}
}
@@ -317,13 +318,14 @@
if (ep->getType() != CONTROL_ENDPOINT) {
// callback on the processed td will be called from the usb_thread (not in ISR)
- message_t * usb_msg = mpool_usb_event.alloc();
+ message_t * usb_msg = mail_usb_event.alloc();
usb_msg->event_id = TD_PROCESSED_EVENT;
usb_msg->td_addr = (void *)td;
usb_msg->td_state = state;
- queue_usb_event.put(usb_msg);
+ mail_usb_event.put(usb_msg);
}
ep->setState(state);
+ ep->ep_queue.put((uint8_t*)1);
}
}
}
@@ -351,13 +353,13 @@
return;
}
- message_t * usb_msg = mpool_usb_event.alloc();
+ message_t * usb_msg = mail_usb_event.alloc();
usb_msg->event_id = DEVICE_CONNECTED_EVENT;
usb_msg->hub = hub;
usb_msg->port = port;
usb_msg->lowSpeed = lowSpeed;
usb_msg->hub_parent = hub_parent;
- queue_usb_event.put(usb_msg);
+ mail_usb_event.put(usb_msg);
}
/*
@@ -375,12 +377,12 @@
return;
}
- message_t * usb_msg = mpool_usb_event.alloc();
+ message_t * usb_msg = mail_usb_event.alloc();
usb_msg->event_id = DEVICE_DISCONNECTED_EVENT;
usb_msg->hub = hub;
usb_msg->port = port;
usb_msg->hub_parent = hub_parent;
- queue_usb_event.put(usb_msg);
+ mail_usb_event.put(usb_msg);
}
void USBHost::freeDevice(USBDeviceConnected * dev)
@@ -528,7 +530,7 @@
int index = findDevice(dev);
if (index != -1) {
USB_DBG("Resetting hub %d, port %d\n", dev->getHub(), dev->getPort());
- wait_ms(100);
+ Thread::wait(100);
if (dev->getHub() == 0) {
resetRootHub();
}
@@ -537,7 +539,7 @@
dev->getHubParent()->portReset(dev->getPort());
}
#endif
- wait_ms(100);
+ Thread::wait(100);
deviceReset[index] = true;
return USB_TYPE_OK;
}
@@ -689,6 +691,7 @@
// add a transfer on the TD linked list
USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len)
{
+ td_mutex.lock();
// allocate a TD which will be freed in TDcompletion
volatile HCTD * td = ed->getNextTD();
@@ -720,6 +723,8 @@
ed->queueTransfer();
printList(type);
enableList(type);
+
+ td_mutex.unlock();
return USB_TYPE_PROCESSING;
}
@@ -887,7 +892,6 @@
return USB_TYPE_OK;
}
-
// this method fills the USBDeviceConnected object: class,.... . It also add endpoints found in the descriptor.
void USBHost::parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len, IUSBEnumerator* pEnumerator)
{
@@ -985,11 +989,11 @@
USB_DBG_TRANSFER("----- %s %s [dev: %p - %s - hub: %d - port: %d - addr: %d - ep: %02X]------", type_str, (write) ? "WRITE" : "READ", dev, dev->getName(ep->getIntfNb()), dev->getHub(), dev->getPort(), dev->getAddress(), ep->getAddress());
#endif
+ usb_mutex.lock();
+
USB_TYPE res;
ENDPOINT_DIRECTION dir = (write) ? OUT : IN;
- usb_mutex.lock();
-
if (dev == NULL) {
USB_ERR("dev NULL");
usb_mutex.unlock();
@@ -1032,7 +1036,8 @@
if (blocking) {
- while((res = ep->getState()) == USB_TYPE_PROCESSING);
+ ep->ep_queue.get();
+ res = ep->getState();
USB_DBG_TRANSFER("%s TRANSFER res: %s on ep: %p\r\n", type_str, ep->getStateString(), ep);
@@ -1089,7 +1094,8 @@
control->setNextToken(TD_SETUP);
addTransfer(control, (uint8_t*)setupPacket, 8);
- while((res = control->getState()) == USB_TYPE_PROCESSING);
+ control->ep_queue.get();
+ res = control->getState();
USB_DBG_TRANSFER("CONTROL setup stage %s", control->getStateString());
@@ -1103,7 +1109,8 @@
control->setNextToken(token);
addTransfer(control, (uint8_t *)buf, length_transfer);
- while((res = control->getState()) == USB_TYPE_PROCESSING);
+ control->ep_queue.get();
+ res = control->getState();
#if DEBUG_TRANSFER
USB_DBG_TRANSFER("CONTROL %s stage %s", (write) ? "WRITE" : "READ", control->getStateString());
@@ -1130,7 +1137,8 @@
control->setNextToken(token);
addTransfer(control, NULL, 0);
- while((res = control->getState()) == USB_TYPE_PROCESSING);
+ control->ep_queue.get();
+ res = control->getState();
USB_DBG_TRANSFER("CONTROL ack stage %s", control->getStateString());
usb_mutex.unlock();
--- a/USBHost/USBHost.h Thu Mar 14 11:49:53 2013 +0000
+++ b/USBHost/USBHost.h Thu Mar 14 14:20:03 2013 +0000
@@ -133,7 +133,7 @@
* @param dev device which will be resetted
*/
USB_TYPE resetDevice(USBDeviceConnected * dev);
-
+
/**
* Get a device
*
@@ -197,7 +197,7 @@
* @param addr list of the TDs which have been completed
*/
virtual void transferCompleted(volatile uint32_t addr);
-
+
/**
* Virtual method called when a device has been connected
*
@@ -267,9 +267,9 @@
Thread usbThread;
void usb_process();
static void usb_process_static(void const * arg);
- MemoryPool<message_t, 10> mpool_usb_event;
- Queue<message_t, 10> queue_usb_event;
+ Mail<message_t, 10> mail_usb_event;
Mutex usb_mutex;
+ Mutex td_mutex;
// buffer for conf descriptor
uint8_t data[300];
@@ -349,7 +349,7 @@
* @param dev device to be freed
*/
void freeDevice(USBDeviceConnected * dev);
-
+
USB_TYPE controlTransfer( USBDeviceConnected * dev,
uint8_t requestType,
uint8_t request,
