SDG+USBHost(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

Committer:
mbed_official
Date:
Tue Jun 03 11:30:38 2014 +0100
Revision:
24:868cbfe611a7
Parent:
8:93da8ea2708b
Synchronized with git revision bcacbb9fbf3432829227430830cca4315b57c1b9

Full URL: https://github.com/mbedmicro/mbed/commit/bcacbb9fbf3432829227430830cca4315b57c1b9/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 8:93da8ea2708b 1 /* mbed USBHost Library
samux 8:93da8ea2708b 2 * Copyright (c) 2006-2013 ARM Limited
samux 8:93da8ea2708b 3 *
samux 8:93da8ea2708b 4 * Licensed under the Apache License, Version 2.0 (the "License");
samux 8:93da8ea2708b 5 * you may not use this file except in compliance with the License.
samux 8:93da8ea2708b 6 * You may obtain a copy of the License at
samux 8:93da8ea2708b 7 *
samux 8:93da8ea2708b 8 * http://www.apache.org/licenses/LICENSE-2.0
samux 8:93da8ea2708b 9 *
samux 8:93da8ea2708b 10 * Unless required by applicable law or agreed to in writing, software
samux 8:93da8ea2708b 11 * distributed under the License is distributed on an "AS IS" BASIS,
samux 8:93da8ea2708b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
samux 8:93da8ea2708b 13 * See the License for the specific language governing permissions and
samux 8:93da8ea2708b 14 * limitations under the License.
samux 8:93da8ea2708b 15 */
mbed_official 0:a554658735bf 16
mbed_official 0:a554658735bf 17 #ifndef USBDEVICECONNECTED_H
mbed_official 0:a554658735bf 18 #define USBDEVICECONNECTED_H
mbed_official 0:a554658735bf 19
mbed_official 0:a554658735bf 20 #include "stdint.h"
mbed_official 0:a554658735bf 21 #include "USBEndpoint.h"
mbed_official 0:a554658735bf 22 #include "USBHostConf.h"
samux 4:b320d68e98e7 23 #include "rtos.h"
mbed_official 0:a554658735bf 24
mbed_official 0:a554658735bf 25 class USBHostHub;
mbed_official 0:a554658735bf 26
mbed_official 0:a554658735bf 27 typedef struct {
mbed_official 0:a554658735bf 28 bool in_use;
mbed_official 0:a554658735bf 29 uint8_t nb_endpoint;
mbed_official 0:a554658735bf 30 uint8_t intf_class;
mbed_official 0:a554658735bf 31 uint8_t intf_subclass;
mbed_official 0:a554658735bf 32 uint8_t intf_protocol;
mbed_official 0:a554658735bf 33 USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE];
mbed_official 0:a554658735bf 34 FunctionPointer detach;
samux 4:b320d68e98e7 35 char name[10];
mbed_official 24:868cbfe611a7 36 } INTERFACE;
mbed_official 0:a554658735bf 37
samux 8:93da8ea2708b 38 /**
samux 8:93da8ea2708b 39 * USBDeviceConnected class
samux 8:93da8ea2708b 40 */
mbed_official 0:a554658735bf 41 class USBDeviceConnected
mbed_official 0:a554658735bf 42 {
mbed_official 0:a554658735bf 43 public:
mbed_official 0:a554658735bf 44
mbed_official 0:a554658735bf 45 /**
mbed_official 0:a554658735bf 46 * Constructor
mbed_official 0:a554658735bf 47 */
mbed_official 0:a554658735bf 48 USBDeviceConnected();
mbed_official 0:a554658735bf 49
mbed_official 0:a554658735bf 50 /**
mbed_official 0:a554658735bf 51 * Attach an USBEndpoint to this device
mbed_official 0:a554658735bf 52 *
samux 8:93da8ea2708b 53 * @param intf_nb interface number
mbed_official 0:a554658735bf 54 * @param ep pointeur on the USBEndpoint which will be attached
mbed_official 0:a554658735bf 55 * @returns true if successful, false otherwise
mbed_official 0:a554658735bf 56 */
mbed_official 0:a554658735bf 57 bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep);
mbed_official 0:a554658735bf 58
mbed_official 0:a554658735bf 59 /**
mbed_official 0:a554658735bf 60 * Retrieve an USBEndpoint by its TYPE and DIRECTION
mbed_official 0:a554658735bf 61 *
mbed_official 0:a554658735bf 62 * @param intf_nb the interface on which to lookup the USBEndpoint
mbed_official 0:a554658735bf 63 * @param type type of the USBEndpoint looked for
samux 2:5e8fdc541b98 64 * @param dir direction of the USBEndpoint looked for
mbed_official 0:a554658735bf 65 * @param index the index of the USBEndpoint whitin the interface
mbed_official 0:a554658735bf 66 * @returns pointer on the USBEndpoint if found, NULL otherwise
mbed_official 0:a554658735bf 67 */
mbed_official 0:a554658735bf 68 USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0);
mbed_official 0:a554658735bf 69
mbed_official 0:a554658735bf 70 /**
mbed_official 0:a554658735bf 71 * Retrieve an USBEndpoint by its index
mbed_official 0:a554658735bf 72 *
samux 8:93da8ea2708b 73 * @param intf_nb interface number
mbed_official 0:a554658735bf 74 * @param index index of the USBEndpoint
mbed_official 0:a554658735bf 75 * @returns pointer on the USBEndpoint if found, NULL otherwise
mbed_official 0:a554658735bf 76 */
mbed_official 0:a554658735bf 77 USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index);
mbed_official 0:a554658735bf 78
mbed_official 0:a554658735bf 79 /**
mbed_official 0:a554658735bf 80 * Add a new interface to this device
mbed_official 0:a554658735bf 81 *
mbed_official 0:a554658735bf 82 * @param intf_nb interface number
mbed_official 0:a554658735bf 83 * @param intf_class interface class
mbed_official 0:a554658735bf 84 * @param intf_subclass interface subclass
samux 2:5e8fdc541b98 85 * @param intf_protocol interface protocol
mbed_official 0:a554658735bf 86 * @returns true if successful, false otherwise
mbed_official 0:a554658735bf 87 */
mbed_official 0:a554658735bf 88 bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol);
mbed_official 0:a554658735bf 89
mbed_official 0:a554658735bf 90 /**
mbed_official 0:a554658735bf 91 * Get a specific interface
mbed_official 0:a554658735bf 92 *
mbed_official 0:a554658735bf 93 * @param index index of the interface to be fetched
mbed_official 0:a554658735bf 94 * @returns interface
mbed_official 0:a554658735bf 95 */
mbed_official 0:a554658735bf 96 INTERFACE * getInterface(uint8_t index);
mbed_official 0:a554658735bf 97
mbed_official 0:a554658735bf 98 /**
mbed_official 0:a554658735bf 99 * Attach a member function to call when a the device has been disconnected
mbed_official 0:a554658735bf 100 *
samux 2:5e8fdc541b98 101 * @param intf_nb interface number
mbed_official 0:a554658735bf 102 * @param tptr pointer to the object to call the member function on
mbed_official 0:a554658735bf 103 * @param mptr pointer to the member function to be called
mbed_official 0:a554658735bf 104 */
mbed_official 0:a554658735bf 105 template<typename T>
mbed_official 0:a554658735bf 106 inline void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) {
mbed_official 0:a554658735bf 107 if ((mptr != NULL) && (tptr != NULL)) {
mbed_official 0:a554658735bf 108 intf[intf_nb].detach.attach(tptr, mptr);
mbed_official 0:a554658735bf 109 }
mbed_official 0:a554658735bf 110 }
mbed_official 0:a554658735bf 111
mbed_official 0:a554658735bf 112 /**
mbed_official 0:a554658735bf 113 * Attach a callback called when the device has been disconnected
mbed_official 0:a554658735bf 114 *
samux 2:5e8fdc541b98 115 * @param intf_nb interface number
samux 2:5e8fdc541b98 116 * @param fn function pointer
mbed_official 0:a554658735bf 117 */
mbed_official 0:a554658735bf 118 inline void onDisconnect(uint8_t intf_nb, void (*fn)(void)) {
mbed_official 0:a554658735bf 119 if (fn != NULL) {
mbed_official 0:a554658735bf 120 intf[intf_nb].detach.attach(fn);
mbed_official 0:a554658735bf 121 }
mbed_official 0:a554658735bf 122 }
mbed_official 0:a554658735bf 123
mbed_official 0:a554658735bf 124 /**
mbed_official 0:a554658735bf 125 * Disconnect the device by calling a callback function registered by a driver
mbed_official 0:a554658735bf 126 */
mbed_official 0:a554658735bf 127 void disconnect();
mbed_official 0:a554658735bf 128
mbed_official 0:a554658735bf 129 // setters
mbed_official 0:a554658735bf 130 void init(uint8_t hub, uint8_t port, bool lowSpeed);
mbed_official 0:a554658735bf 131 inline void setAddress(uint8_t addr_) { addr = addr_; };
mbed_official 0:a554658735bf 132 inline void setVid(uint16_t vid_) { vid = vid_; };
mbed_official 0:a554658735bf 133 inline void setPid(uint16_t pid_) { pid = pid_; };
mbed_official 0:a554658735bf 134 inline void setClass(uint8_t device_class_) { device_class = device_class_; };
mbed_official 0:a554658735bf 135 inline void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; };
mbed_official 0:a554658735bf 136 inline void setProtocol(uint8_t pr) { proto = pr; };
mbed_official 0:a554658735bf 137 inline void setSizeControlEndpoint(uint32_t size) { sizeControlEndpoint = size; };
mbed_official 0:a554658735bf 138 inline void activeAddress(bool active) { activeAddr = active; };
mbed_official 0:a554658735bf 139 inline void setEnumerated() { enumerated = true; };
samux 4:b320d68e98e7 140 inline void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; };
mbed_official 0:a554658735bf 141 inline void setHubParent(USBHostHub * hub) { hub_parent = hub; };
samux 4:b320d68e98e7 142 inline void setName(const char * name_, uint8_t intf_nb) { strcpy(intf[intf_nb].name, name_); };
mbed_official 0:a554658735bf 143
mbed_official 0:a554658735bf 144 //getters
mbed_official 0:a554658735bf 145 inline uint8_t getPort() { return port; };
mbed_official 0:a554658735bf 146 inline uint8_t getHub() { return hub_nb; };
mbed_official 0:a554658735bf 147 inline uint8_t getAddress() { return addr; };
mbed_official 0:a554658735bf 148 inline uint16_t getVid() { return vid; };
mbed_official 0:a554658735bf 149 inline uint16_t getPid() { return pid; };
mbed_official 0:a554658735bf 150 inline uint8_t getClass() { return device_class; };
mbed_official 0:a554658735bf 151 inline uint8_t getSubClass() { return device_subclass; };
mbed_official 0:a554658735bf 152 inline uint8_t getProtocol() { return proto; };
mbed_official 0:a554658735bf 153 inline bool getSpeed() { return speed; };
mbed_official 0:a554658735bf 154 inline uint32_t getSizeControlEndpoint() { return sizeControlEndpoint; };
mbed_official 0:a554658735bf 155 inline bool isActiveAddress() { return activeAddr; };
mbed_official 0:a554658735bf 156 inline bool isEnumerated() { return enumerated; };
mbed_official 0:a554658735bf 157 inline USBHostHub * getHubParent() { return hub_parent; };
samux 4:b320d68e98e7 158 inline uint8_t getNbIntf() { return nb_interf; };
samux 4:b320d68e98e7 159 inline const char * getName(uint8_t intf_nb) { return intf[intf_nb].name; };
mbed_official 24:868cbfe611a7 160
mbed_official 0:a554658735bf 161 // in case this device is a hub
mbed_official 0:a554658735bf 162 USBHostHub * hub;
mbed_official 0:a554658735bf 163
mbed_official 0:a554658735bf 164 private:
mbed_official 0:a554658735bf 165 USBHostHub * hub_parent;
mbed_official 0:a554658735bf 166
mbed_official 0:a554658735bf 167 INTERFACE intf[MAX_INTF];
mbed_official 0:a554658735bf 168 uint32_t sizeControlEndpoint;
mbed_official 0:a554658735bf 169 uint8_t hub_nb;
mbed_official 0:a554658735bf 170 uint8_t port;
mbed_official 0:a554658735bf 171 uint16_t vid;
mbed_official 0:a554658735bf 172 uint16_t pid;
mbed_official 0:a554658735bf 173 uint8_t addr;
mbed_official 0:a554658735bf 174 uint8_t device_class;
mbed_official 0:a554658735bf 175 uint8_t device_subclass;
mbed_official 0:a554658735bf 176 uint8_t proto;
mbed_official 0:a554658735bf 177 bool speed;
mbed_official 0:a554658735bf 178 volatile bool activeAddr;
mbed_official 0:a554658735bf 179 volatile bool enumerated;
mbed_official 0:a554658735bf 180 uint8_t nb_interf;
mbed_official 0:a554658735bf 181
mbed_official 0:a554658735bf 182 void init();
mbed_official 0:a554658735bf 183 };
mbed_official 0:a554658735bf 184
mbed_official 0:a554658735bf 185 #endif