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:
Wed Mar 06 16:27:14 2013 +0000
Revision:
0:a554658735bf
Child:
2:5e8fdc541b98
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:a554658735bf 1 /* Copyright (c) 2010-2012 mbed.org, MIT License
mbed_official 0:a554658735bf 2 *
mbed_official 0:a554658735bf 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mbed_official 0:a554658735bf 4 * and associated documentation files (the "Software"), to deal in the Software without
mbed_official 0:a554658735bf 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mbed_official 0:a554658735bf 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mbed_official 0:a554658735bf 7 * Software is furnished to do so, subject to the following conditions:
mbed_official 0:a554658735bf 8 *
mbed_official 0:a554658735bf 9 * The above copyright notice and this permission notice shall be included in all copies or
mbed_official 0:a554658735bf 10 * substantial portions of the Software.
mbed_official 0:a554658735bf 11 *
mbed_official 0:a554658735bf 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mbed_official 0:a554658735bf 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mbed_official 0:a554658735bf 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mbed_official 0:a554658735bf 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 0:a554658735bf 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mbed_official 0:a554658735bf 17 */
mbed_official 0:a554658735bf 18
mbed_official 0:a554658735bf 19 #ifndef USBDEVICECONNECTED_H
mbed_official 0:a554658735bf 20 #define USBDEVICECONNECTED_H
mbed_official 0:a554658735bf 21
mbed_official 0:a554658735bf 22 #include "stdint.h"
mbed_official 0:a554658735bf 23 #include "USBEndpoint.h"
mbed_official 0:a554658735bf 24 #include "USBHostConf.h"
mbed_official 0:a554658735bf 25
mbed_official 0:a554658735bf 26 class USBHostHub;
mbed_official 0:a554658735bf 27
mbed_official 0:a554658735bf 28 typedef struct {
mbed_official 0:a554658735bf 29 bool in_use;
mbed_official 0:a554658735bf 30 uint8_t nb_endpoint;
mbed_official 0:a554658735bf 31 uint8_t intf_class;
mbed_official 0:a554658735bf 32 uint8_t intf_subclass;
mbed_official 0:a554658735bf 33 uint8_t intf_protocol;
mbed_official 0:a554658735bf 34 USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE];
mbed_official 0:a554658735bf 35 FunctionPointer detach;
mbed_official 0:a554658735bf 36 } INTERFACE;
mbed_official 0:a554658735bf 37
mbed_official 0:a554658735bf 38 class USBDeviceConnected
mbed_official 0:a554658735bf 39 {
mbed_official 0:a554658735bf 40 public:
mbed_official 0:a554658735bf 41
mbed_official 0:a554658735bf 42 /**
mbed_official 0:a554658735bf 43 * Constructor
mbed_official 0:a554658735bf 44 */
mbed_official 0:a554658735bf 45 USBDeviceConnected();
mbed_official 0:a554658735bf 46
mbed_official 0:a554658735bf 47 /**
mbed_official 0:a554658735bf 48 * Attach an USBEndpoint to this device
mbed_official 0:a554658735bf 49 *
mbed_official 0:a554658735bf 50 * @param ep pointeur on the USBEndpoint which will be attached
mbed_official 0:a554658735bf 51 * @returns true if successful, false otherwise
mbed_official 0:a554658735bf 52 */
mbed_official 0:a554658735bf 53 bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep);
mbed_official 0:a554658735bf 54
mbed_official 0:a554658735bf 55 /**
mbed_official 0:a554658735bf 56 * Retrieve an USBEndpoint by its TYPE and DIRECTION
mbed_official 0:a554658735bf 57 *
mbed_official 0:a554658735bf 58 * @param intf_nb the interface on which to lookup the USBEndpoint
mbed_official 0:a554658735bf 59 * @param type type of the USBEndpoint looked for
mbed_official 0:a554658735bf 60 * @param direction of the USBEndpoint looked for
mbed_official 0:a554658735bf 61 * @param index the index of the USBEndpoint whitin the interface
mbed_official 0:a554658735bf 62 * @returns pointer on the USBEndpoint if found, NULL otherwise
mbed_official 0:a554658735bf 63 */
mbed_official 0:a554658735bf 64 USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0);
mbed_official 0:a554658735bf 65
mbed_official 0:a554658735bf 66 /**
mbed_official 0:a554658735bf 67 * Retrieve an USBEndpoint by its index
mbed_official 0:a554658735bf 68 *
mbed_official 0:a554658735bf 69 * @param index index of the USBEndpoint
mbed_official 0:a554658735bf 70 * @returns pointer on the USBEndpoint if found, NULL otherwise
mbed_official 0:a554658735bf 71 */
mbed_official 0:a554658735bf 72 USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index);
mbed_official 0:a554658735bf 73
mbed_official 0:a554658735bf 74 /**
mbed_official 0:a554658735bf 75 * Add a new interface to this device
mbed_official 0:a554658735bf 76 *
mbed_official 0:a554658735bf 77 * @param intf_nb interface number
mbed_official 0:a554658735bf 78 * @param intf_class interface class
mbed_official 0:a554658735bf 79 * @param intf_subclass interface subclass
mbed_official 0:a554658735bf 80 * @param intf_ptotocol interface protocol
mbed_official 0:a554658735bf 81 * @returns true if successful, false otherwise
mbed_official 0:a554658735bf 82 */
mbed_official 0:a554658735bf 83 bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol);
mbed_official 0:a554658735bf 84
mbed_official 0:a554658735bf 85 /**
mbed_official 0:a554658735bf 86 * Get the number of interfaces attached to this USB device
mbed_official 0:a554658735bf 87 *
mbed_official 0:a554658735bf 88 * @returns number of interfaces
mbed_official 0:a554658735bf 89 */
mbed_official 0:a554658735bf 90 uint8_t getNbInterface() {
mbed_official 0:a554658735bf 91 return nb_interf;
mbed_official 0:a554658735bf 92 };
mbed_official 0:a554658735bf 93
mbed_official 0:a554658735bf 94 /**
mbed_official 0:a554658735bf 95 * Get a specific interface
mbed_official 0:a554658735bf 96 *
mbed_official 0:a554658735bf 97 * @param index index of the interface to be fetched
mbed_official 0:a554658735bf 98 * @returns interface
mbed_official 0:a554658735bf 99 */
mbed_official 0:a554658735bf 100 INTERFACE * getInterface(uint8_t index);
mbed_official 0:a554658735bf 101
mbed_official 0:a554658735bf 102 /**
mbed_official 0:a554658735bf 103 * Attach a member function to call when a the device has been disconnected
mbed_official 0:a554658735bf 104 *
mbed_official 0:a554658735bf 105 * @param tptr pointer to the object to call the member function on
mbed_official 0:a554658735bf 106 * @param mptr pointer to the member function to be called
mbed_official 0:a554658735bf 107 */
mbed_official 0:a554658735bf 108 template<typename T>
mbed_official 0:a554658735bf 109 inline void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) {
mbed_official 0:a554658735bf 110 if ((mptr != NULL) && (tptr != NULL)) {
mbed_official 0:a554658735bf 111 intf[intf_nb].detach.attach(tptr, mptr);
mbed_official 0:a554658735bf 112 }
mbed_official 0:a554658735bf 113 }
mbed_official 0:a554658735bf 114
mbed_official 0:a554658735bf 115 /**
mbed_official 0:a554658735bf 116 * Attach a callback called when the device has been disconnected
mbed_official 0:a554658735bf 117 *
mbed_official 0:a554658735bf 118 * @param fptr function pointer
mbed_official 0:a554658735bf 119 */
mbed_official 0:a554658735bf 120 inline void onDisconnect(uint8_t intf_nb, void (*fn)(void)) {
mbed_official 0:a554658735bf 121 if (fn != NULL) {
mbed_official 0:a554658735bf 122 intf[intf_nb].detach.attach(fn);
mbed_official 0:a554658735bf 123 }
mbed_official 0:a554658735bf 124 }
mbed_official 0:a554658735bf 125
mbed_official 0:a554658735bf 126 /**
mbed_official 0:a554658735bf 127 * Disconnect the device by calling a callback function registered by a driver
mbed_official 0:a554658735bf 128 */
mbed_official 0:a554658735bf 129 void disconnect();
mbed_official 0:a554658735bf 130
mbed_official 0:a554658735bf 131 // setters
mbed_official 0:a554658735bf 132 void init(uint8_t hub, uint8_t port, bool lowSpeed);
mbed_official 0:a554658735bf 133 inline void setAddress(uint8_t addr_) { addr = addr_; };
mbed_official 0:a554658735bf 134 inline void setVid(uint16_t vid_) { vid = vid_; };
mbed_official 0:a554658735bf 135 inline void setPid(uint16_t pid_) { pid = pid_; };
mbed_official 0:a554658735bf 136 inline void setClass(uint8_t device_class_) { device_class = device_class_; };
mbed_official 0:a554658735bf 137 inline void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; };
mbed_official 0:a554658735bf 138 inline void setProtocol(uint8_t pr) { proto = pr; };
mbed_official 0:a554658735bf 139 inline void setSizeControlEndpoint(uint32_t size) { sizeControlEndpoint = size; };
mbed_official 0:a554658735bf 140 inline void activeAddress(bool active) { activeAddr = active; };
mbed_official 0:a554658735bf 141 inline void setEnumerated() { enumerated = true; };
mbed_official 0:a554658735bf 142 inline void setHubParent(USBHostHub * hub) { hub_parent = hub; };
mbed_official 0:a554658735bf 143 inline void setName(const char * name_) { strcpy(name, name_); };
mbed_official 0:a554658735bf 144
mbed_official 0:a554658735bf 145 //getters
mbed_official 0:a554658735bf 146 inline uint8_t getPort() { return port; };
mbed_official 0:a554658735bf 147 inline uint8_t getHub() { return hub_nb; };
mbed_official 0:a554658735bf 148 inline uint8_t getAddress() { return addr; };
mbed_official 0:a554658735bf 149 inline uint16_t getVid() { return vid; };
mbed_official 0:a554658735bf 150 inline uint16_t getPid() { return pid; };
mbed_official 0:a554658735bf 151 inline uint8_t getClass() { return device_class; };
mbed_official 0:a554658735bf 152 inline uint8_t getSubClass() { return device_subclass; };
mbed_official 0:a554658735bf 153 inline uint8_t getProtocol() { return proto; };
mbed_official 0:a554658735bf 154 inline bool getSpeed() { return speed; };
mbed_official 0:a554658735bf 155 inline uint32_t getSizeControlEndpoint() { return sizeControlEndpoint; };
mbed_official 0:a554658735bf 156 inline bool isActiveAddress() { return activeAddr; };
mbed_official 0:a554658735bf 157 inline bool isEnumerated() { return enumerated; };
mbed_official 0:a554658735bf 158 inline USBHostHub * getHubParent() { return hub_parent; };
mbed_official 0:a554658735bf 159 inline const char * getName() { return name; };
mbed_official 0:a554658735bf 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 char name[10];
mbed_official 0:a554658735bf 183
mbed_official 0:a554658735bf 184 void init();
mbed_official 0:a554658735bf 185 };
mbed_official 0:a554658735bf 186
mbed_official 0:a554658735bf 187 #endif
mbed_official 0:a554658735bf 188