Renesas / Mbed OS SDG_Mouse_Sample

Dependencies:   Sound_Generator USBHost_custom

Fork of SDG_Mouse_Sample by GR-PEACH_producer_meeting

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.
/media/uploads/RyoheiHagimoto/sdg-mouse.jpg

Operation

operationeffect
Right clickSounds
Left clickReset to base tone (C)
Moves the mouse to the rightLower the sound
Moves the mouse to the leftHigher the sound
Center cursorAdjust 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をショートする必要があります。
/media/uploads/RyoheiHagimoto/sdg-mouse.jpg

操作方法

操作内容
右クリック音出力開始
左クリック基準音(ド)にリセット
マウス右移動高音になります
マウス左移動低音になります
センターカーソル音高低の変化量調整(クリックで基準値にリセット)

Others

mbedのシリアル通信(ボーレート等)のデフォルト設定は以下のリンクに示しています。
リンクを参考に、お使いのPCターミナルソフトの設定を変更して下さい。
mbedでのボーレートのデフォルト値は9600で、このサンプルではボーレート9600を使います。
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Revision:
30:ff42cc7a0d55
Parent:
29:181839dc8cb0
Child:
31:f6d9dbbc1481
--- a/USBHostHub/USBHostHub.cpp	Tue Mar 31 07:44:06 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,274 +0,0 @@
-/* mbed USBHost Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "USBHostHub.h"
-
-#if MAX_HUB_NB
-
-#include "USBHost.h"
-#include "dbg.h"
-
-#define GET_STATUS 0x00
-#define CLEAR_FEATURE 0x01
-#define GET_STATE 0x02
-#define SET_FEATURE 0x03
-#define GET_DESCRIPTOR 0x06
-
-#define PORT_CONNECTION_FEATURE     (0x00)
-#define PORT_ENABLE_FEATURE         (0x01)
-#define PORT_RESET_FEATURE          (0x04)
-#define PORT_POWER_FEATURE          (0x08)
-
-#define C_PORT_CONNECTION_FEATURE     (16)
-#define C_PORT_ENABLE_FEATURE         (17)
-#define C_PORT_RESET_FEATURE          (20)
-
-#define PORT_CONNECTION   (1 << 0)
-#define PORT_ENABLE       (1 << 1)
-#define PORT_SUSPEND      (1 << 2)
-#define PORT_OVER_CURRENT (1 << 3)
-#define PORT_RESET        (1 << 4)
-#define PORT_POWER        (1 << 8)
-#define PORT_LOW_SPEED    (1 << 9)
-
-#define C_PORT_CONNECTION   (1 << 16)
-#define C_PORT_ENABLE       (1 << 17)
-#define C_PORT_SUSPEND      (1 << 18)
-#define C_PORT_OVER_CURRENT (1 << 19)
-#define C_PORT_RESET        (1 << 20)
-
-USBHostHub::USBHostHub() {
-    host = NULL;
-    init();
-}
-
-void USBHostHub::init() {
-    dev_connected = false;
-    dev = NULL;
-    int_in = NULL;
-    dev_connected = false;
-    hub_intf = -1;
-    hub_device_found = false;
-    nb_port = 0;
-    hub_characteristics = 0;
-
-    for (int i = 0; i < MAX_HUB_PORT; i++) {
-        device_children[i] = NULL;
-    }
-}
-
-void USBHostHub::setHost(USBHost * host_) {
-    host = host_;
-}
-
-bool USBHostHub::connected()
-{
-    return dev_connected;
-}
-
-bool USBHostHub::connect(USBDeviceConnected * dev)
-{
-    if (dev_connected) {
-        return true;
-    }
-
-    if(host->enumerate(dev, this)) {
-        init();
-        return false;
-    }
-
-    if (hub_device_found) {
-        this->dev = dev;
-
-        int_in = dev->getEndpoint(hub_intf, INTERRUPT_ENDPOINT, IN);
-
-        if (!int_in) {
-            init();
-            return false;
-        }
-
-        USB_INFO("New HUB: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, hub_intf);
-        dev->setName("Hub", hub_intf);
-        host->registerDriver(dev, hub_intf, this, &USBHostHub::disconnect);
-
-        int_in->attach(this, &USBHostHub::rxHandler);
-
-        // get HUB descriptor
-        host->controlRead(  dev,
-                            USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS,
-                            GET_DESCRIPTOR,
-                            0x29 << 8, 0, buf, sizeof(HubDescriptor));
-        nb_port = buf[2];
-        hub_characteristics = buf[3];
-
-        USB_DBG("Hub has %d port", nb_port);
-
-        for (uint8_t j = 1; j <= nb_port; j++) {
-            setPortFeature(PORT_POWER_FEATURE, j);
-        }
-        wait_ms(buf[5]*2);
-
-        host->interruptRead(dev, int_in, buf, 1, false);
-        dev_connected = true;
-        return true;
-    }
-
-    return false;
-}
-
-void USBHostHub::disconnect() {
-    init();
-}
-
-/*virtual*/ void USBHostHub::setVidPid(uint16_t vid, uint16_t pid)
-{
-    // we don't check VID/PID for MSD driver
-}
-
-/*virtual*/ bool USBHostHub::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
-{
-    if ((hub_intf == -1) &&
-        (intf_class == HUB_CLASS) &&
-        (intf_subclass == 0) &&
-        (intf_protocol == 0)) {
-        hub_intf = intf_nb;
-        return true;
-    }
-    return false;
-}
-
-/*virtual*/ bool USBHostHub::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
-{
-    if (intf_nb == hub_intf) {
-        if ((type == INTERRUPT_ENDPOINT) && (dir == IN)) {
-            hub_device_found = true;
-            return true;
-        }
-    }
-    return false;
-}
-
-void USBHostHub::deviceConnected(USBDeviceConnected * dev) {
-    device_children[dev->getPort() - 1] = dev;
-}
-
-void USBHostHub::deviceDisconnected(USBDeviceConnected * dev) {
-    device_children[dev->getPort() - 1] = NULL;
-}
-
-void USBHostHub::hubDisconnected() {
-    for (uint8_t i = 0; i < MAX_HUB_PORT; i++) {
-        if (device_children[i] != NULL) {
-            host->freeDevice(device_children[i]);
-        }
-    }
-}
-
-void USBHostHub::rxHandler() {
-    uint32_t status;
-    if (int_in) {
-        if (int_in->getState() == USB_TYPE_IDLE) {
-            for (int port = 1; port <= nb_port; port++) {
-                status = getPortStatus(port);
-                USB_DBG("[hub handler hub: %d] status port %d [hub: %p]: 0x%X", dev->getHub(), port, dev, status);
-
-                // if connection status has changed
-                if (status & C_PORT_CONNECTION) {
-                    if (status & PORT_CONNECTION) {
-                        USB_DBG("[hub handler hub: %d - port: %d] new device connected", dev->getHub(), port);
-                        host->deviceConnected(dev->getHub() + 1, port, status & PORT_LOW_SPEED, this);
-                    } else {
-                        USB_DBG("[hub handler hub: %d - port: %d] device disconnected", dev->getHub(), port);
-                        host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
-                    }
-
-                    clearPortFeature(C_PORT_CONNECTION_FEATURE, port);
-                }
-
-                if (status & C_PORT_RESET) {
-                    clearPortFeature(C_PORT_RESET_FEATURE, port);
-                }
-
-                if (status & C_PORT_ENABLE) {
-                    clearPortFeature(C_PORT_ENABLE_FEATURE, port);
-                }
-
-                if ((status & PORT_OVER_CURRENT)) {
-                    USB_ERR("OVER CURRENT DETECTED\r\n");
-                    clearPortFeature(PORT_OVER_CURRENT, port);
-                    host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
-                }
-            }
-        }
-        host->interruptRead(dev, int_in, buf, 1, false);
-    }
-}
-
-void USBHostHub::portReset(uint8_t port) {
-    // reset port
-    uint32_t status;
-    USB_DBG("reset port %d on hub: %p [this: %p]", port, dev, this)
-    setPortFeature(PORT_RESET_FEATURE, port);
-#if defined(TARGET_RZ_A1H)
-    Thread::wait(50);   // Reset release waiting for Hi-Speed check.
-#endif
-    while(1) {
-        status = getPortStatus(port);
-        if (status & (PORT_ENABLE | PORT_RESET))
-            break;
-        if (status & PORT_OVER_CURRENT) {
-            USB_ERR("OVER CURRENT DETECTED\r\n");
-            clearPortFeature(PORT_OVER_CURRENT, port);
-            host->deviceDisconnected(dev->getHub() + 1, port, this, 0);
-            break;
-        }
-        Thread::wait(10);
-    }
-}
-
-void USBHostHub::setPortFeature(uint32_t feature, uint8_t port) {
-    host->controlWrite( dev,
-                        USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
-                        SET_FEATURE,
-                        feature,
-                        port,
-                        NULL,
-                        0);
-}
-
-void USBHostHub::clearPortFeature(uint32_t feature, uint8_t port) {
-    host->controlWrite( dev,
-                        USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
-                        CLEAR_FEATURE,
-                        feature,
-                        port,
-                        NULL,
-                        0);
-}
-
-uint32_t USBHostHub::getPortStatus(uint8_t port) {
-    uint32_t st;
-    host->controlRead(  dev,
-                        USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
-                        GET_STATUS,
-                        0,
-                        port,
-                        (uint8_t *)&st,
-                        4);
-    return st;
-}
-
-#endif