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
USBHost/USBDeviceConnected.h@4:b320d68e98e7, 2013-03-12 (annotated)
- Committer:
- samux
- Date:
- Tue Mar 12 17:23:37 2013 +0000
- Revision:
- 4:b320d68e98e7
- Parent:
- 2:5e8fdc541b98
- Child:
- 8:93da8ea2708b
bug fixes - support composite device
Who changed what in which revision?
| User | Revision | Line number | New 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" |
| samux | 4:b320d68e98e7 | 25 | #include "rtos.h" |
| mbed_official | 0:a554658735bf | 26 | |
| mbed_official | 0:a554658735bf | 27 | class USBHostHub; |
| mbed_official | 0:a554658735bf | 28 | |
| mbed_official | 0:a554658735bf | 29 | typedef struct { |
| mbed_official | 0:a554658735bf | 30 | bool in_use; |
| mbed_official | 0:a554658735bf | 31 | uint8_t nb_endpoint; |
| mbed_official | 0:a554658735bf | 32 | uint8_t intf_class; |
| mbed_official | 0:a554658735bf | 33 | uint8_t intf_subclass; |
| mbed_official | 0:a554658735bf | 34 | uint8_t intf_protocol; |
| mbed_official | 0:a554658735bf | 35 | USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; |
| mbed_official | 0:a554658735bf | 36 | FunctionPointer detach; |
| samux | 4:b320d68e98e7 | 37 | char name[10]; |
| mbed_official | 0:a554658735bf | 38 | } INTERFACE; |
| mbed_official | 0:a554658735bf | 39 | |
| mbed_official | 0:a554658735bf | 40 | class USBDeviceConnected |
| mbed_official | 0:a554658735bf | 41 | { |
| mbed_official | 0:a554658735bf | 42 | public: |
| mbed_official | 0:a554658735bf | 43 | |
| mbed_official | 0:a554658735bf | 44 | /** |
| mbed_official | 0:a554658735bf | 45 | * Constructor |
| mbed_official | 0:a554658735bf | 46 | */ |
| mbed_official | 0:a554658735bf | 47 | USBDeviceConnected(); |
| mbed_official | 0:a554658735bf | 48 | |
| mbed_official | 0:a554658735bf | 49 | /** |
| mbed_official | 0:a554658735bf | 50 | * Attach an USBEndpoint to this device |
| mbed_official | 0:a554658735bf | 51 | * |
| mbed_official | 0:a554658735bf | 52 | * @param ep pointeur on the USBEndpoint which will be attached |
| mbed_official | 0:a554658735bf | 53 | * @returns true if successful, false otherwise |
| mbed_official | 0:a554658735bf | 54 | */ |
| mbed_official | 0:a554658735bf | 55 | bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); |
| mbed_official | 0:a554658735bf | 56 | |
| mbed_official | 0:a554658735bf | 57 | /** |
| mbed_official | 0:a554658735bf | 58 | * Retrieve an USBEndpoint by its TYPE and DIRECTION |
| mbed_official | 0:a554658735bf | 59 | * |
| mbed_official | 0:a554658735bf | 60 | * @param intf_nb the interface on which to lookup the USBEndpoint |
| mbed_official | 0:a554658735bf | 61 | * @param type type of the USBEndpoint looked for |
| samux | 2:5e8fdc541b98 | 62 | * @param dir direction of the USBEndpoint looked for |
| mbed_official | 0:a554658735bf | 63 | * @param index the index of the USBEndpoint whitin the interface |
| mbed_official | 0:a554658735bf | 64 | * @returns pointer on the USBEndpoint if found, NULL otherwise |
| mbed_official | 0:a554658735bf | 65 | */ |
| mbed_official | 0:a554658735bf | 66 | USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); |
| mbed_official | 0:a554658735bf | 67 | |
| mbed_official | 0:a554658735bf | 68 | /** |
| mbed_official | 0:a554658735bf | 69 | * Retrieve an USBEndpoint by its index |
| mbed_official | 0:a554658735bf | 70 | * |
| mbed_official | 0:a554658735bf | 71 | * @param index index of the USBEndpoint |
| mbed_official | 0:a554658735bf | 72 | * @returns pointer on the USBEndpoint if found, NULL otherwise |
| mbed_official | 0:a554658735bf | 73 | */ |
| mbed_official | 0:a554658735bf | 74 | USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); |
| mbed_official | 0:a554658735bf | 75 | |
| mbed_official | 0:a554658735bf | 76 | /** |
| mbed_official | 0:a554658735bf | 77 | * Add a new interface to this device |
| mbed_official | 0:a554658735bf | 78 | * |
| mbed_official | 0:a554658735bf | 79 | * @param intf_nb interface number |
| mbed_official | 0:a554658735bf | 80 | * @param intf_class interface class |
| mbed_official | 0:a554658735bf | 81 | * @param intf_subclass interface subclass |
| samux | 2:5e8fdc541b98 | 82 | * @param intf_protocol interface protocol |
| mbed_official | 0:a554658735bf | 83 | * @returns true if successful, false otherwise |
| mbed_official | 0:a554658735bf | 84 | */ |
| mbed_official | 0:a554658735bf | 85 | bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); |
| mbed_official | 0:a554658735bf | 86 | |
| mbed_official | 0:a554658735bf | 87 | /** |
| mbed_official | 0:a554658735bf | 88 | * Get the number of interfaces attached to this USB device |
| mbed_official | 0:a554658735bf | 89 | * |
| mbed_official | 0:a554658735bf | 90 | * @returns number of interfaces |
| mbed_official | 0:a554658735bf | 91 | */ |
| mbed_official | 0:a554658735bf | 92 | uint8_t getNbInterface() { |
| mbed_official | 0:a554658735bf | 93 | return nb_interf; |
| mbed_official | 0:a554658735bf | 94 | }; |
| mbed_official | 0:a554658735bf | 95 | |
| mbed_official | 0:a554658735bf | 96 | /** |
| mbed_official | 0:a554658735bf | 97 | * Get a specific interface |
| mbed_official | 0:a554658735bf | 98 | * |
| mbed_official | 0:a554658735bf | 99 | * @param index index of the interface to be fetched |
| mbed_official | 0:a554658735bf | 100 | * @returns interface |
| mbed_official | 0:a554658735bf | 101 | */ |
| mbed_official | 0:a554658735bf | 102 | INTERFACE * getInterface(uint8_t index); |
| mbed_official | 0:a554658735bf | 103 | |
| mbed_official | 0:a554658735bf | 104 | /** |
| mbed_official | 0:a554658735bf | 105 | * Attach a member function to call when a the device has been disconnected |
| mbed_official | 0:a554658735bf | 106 | * |
| samux | 2:5e8fdc541b98 | 107 | * @param intf_nb interface number |
| mbed_official | 0:a554658735bf | 108 | * @param tptr pointer to the object to call the member function on |
| mbed_official | 0:a554658735bf | 109 | * @param mptr pointer to the member function to be called |
| mbed_official | 0:a554658735bf | 110 | */ |
| mbed_official | 0:a554658735bf | 111 | template<typename T> |
| mbed_official | 0:a554658735bf | 112 | inline void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) { |
| mbed_official | 0:a554658735bf | 113 | if ((mptr != NULL) && (tptr != NULL)) { |
| mbed_official | 0:a554658735bf | 114 | intf[intf_nb].detach.attach(tptr, mptr); |
| mbed_official | 0:a554658735bf | 115 | } |
| mbed_official | 0:a554658735bf | 116 | } |
| mbed_official | 0:a554658735bf | 117 | |
| mbed_official | 0:a554658735bf | 118 | /** |
| mbed_official | 0:a554658735bf | 119 | * Attach a callback called when the device has been disconnected |
| mbed_official | 0:a554658735bf | 120 | * |
| samux | 2:5e8fdc541b98 | 121 | * @param intf_nb interface number |
| samux | 2:5e8fdc541b98 | 122 | * @param fn function pointer |
| mbed_official | 0:a554658735bf | 123 | */ |
| mbed_official | 0:a554658735bf | 124 | inline void onDisconnect(uint8_t intf_nb, void (*fn)(void)) { |
| mbed_official | 0:a554658735bf | 125 | if (fn != NULL) { |
| mbed_official | 0:a554658735bf | 126 | intf[intf_nb].detach.attach(fn); |
| mbed_official | 0:a554658735bf | 127 | } |
| mbed_official | 0:a554658735bf | 128 | } |
| mbed_official | 0:a554658735bf | 129 | |
| mbed_official | 0:a554658735bf | 130 | /** |
| mbed_official | 0:a554658735bf | 131 | * Disconnect the device by calling a callback function registered by a driver |
| mbed_official | 0:a554658735bf | 132 | */ |
| mbed_official | 0:a554658735bf | 133 | void disconnect(); |
| mbed_official | 0:a554658735bf | 134 | |
| mbed_official | 0:a554658735bf | 135 | // setters |
| mbed_official | 0:a554658735bf | 136 | void init(uint8_t hub, uint8_t port, bool lowSpeed); |
| mbed_official | 0:a554658735bf | 137 | inline void setAddress(uint8_t addr_) { addr = addr_; }; |
| mbed_official | 0:a554658735bf | 138 | inline void setVid(uint16_t vid_) { vid = vid_; }; |
| mbed_official | 0:a554658735bf | 139 | inline void setPid(uint16_t pid_) { pid = pid_; }; |
| mbed_official | 0:a554658735bf | 140 | inline void setClass(uint8_t device_class_) { device_class = device_class_; }; |
| mbed_official | 0:a554658735bf | 141 | inline void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; }; |
| mbed_official | 0:a554658735bf | 142 | inline void setProtocol(uint8_t pr) { proto = pr; }; |
| mbed_official | 0:a554658735bf | 143 | inline void setSizeControlEndpoint(uint32_t size) { sizeControlEndpoint = size; }; |
| mbed_official | 0:a554658735bf | 144 | inline void activeAddress(bool active) { activeAddr = active; }; |
| mbed_official | 0:a554658735bf | 145 | inline void setEnumerated() { enumerated = true; }; |
| samux | 4:b320d68e98e7 | 146 | inline void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; }; |
| mbed_official | 0:a554658735bf | 147 | inline void setHubParent(USBHostHub * hub) { hub_parent = hub; }; |
| samux | 4:b320d68e98e7 | 148 | inline void setName(const char * name_, uint8_t intf_nb) { strcpy(intf[intf_nb].name, name_); }; |
| mbed_official | 0:a554658735bf | 149 | |
| mbed_official | 0:a554658735bf | 150 | //getters |
| mbed_official | 0:a554658735bf | 151 | inline uint8_t getPort() { return port; }; |
| mbed_official | 0:a554658735bf | 152 | inline uint8_t getHub() { return hub_nb; }; |
| mbed_official | 0:a554658735bf | 153 | inline uint8_t getAddress() { return addr; }; |
| mbed_official | 0:a554658735bf | 154 | inline uint16_t getVid() { return vid; }; |
| mbed_official | 0:a554658735bf | 155 | inline uint16_t getPid() { return pid; }; |
| mbed_official | 0:a554658735bf | 156 | inline uint8_t getClass() { return device_class; }; |
| mbed_official | 0:a554658735bf | 157 | inline uint8_t getSubClass() { return device_subclass; }; |
| mbed_official | 0:a554658735bf | 158 | inline uint8_t getProtocol() { return proto; }; |
| mbed_official | 0:a554658735bf | 159 | inline bool getSpeed() { return speed; }; |
| mbed_official | 0:a554658735bf | 160 | inline uint32_t getSizeControlEndpoint() { return sizeControlEndpoint; }; |
| mbed_official | 0:a554658735bf | 161 | inline bool isActiveAddress() { return activeAddr; }; |
| mbed_official | 0:a554658735bf | 162 | inline bool isEnumerated() { return enumerated; }; |
| mbed_official | 0:a554658735bf | 163 | inline USBHostHub * getHubParent() { return hub_parent; }; |
| samux | 4:b320d68e98e7 | 164 | inline uint8_t getNbIntf() { return nb_interf; }; |
| samux | 4:b320d68e98e7 | 165 | inline const char * getName(uint8_t intf_nb) { return intf[intf_nb].name; }; |
| mbed_official | 0:a554658735bf | 166 | |
| mbed_official | 0:a554658735bf | 167 | // in case this device is a hub |
| mbed_official | 0:a554658735bf | 168 | USBHostHub * hub; |
| mbed_official | 0:a554658735bf | 169 | |
| mbed_official | 0:a554658735bf | 170 | private: |
| mbed_official | 0:a554658735bf | 171 | USBHostHub * hub_parent; |
| mbed_official | 0:a554658735bf | 172 | |
| mbed_official | 0:a554658735bf | 173 | INTERFACE intf[MAX_INTF]; |
| mbed_official | 0:a554658735bf | 174 | uint32_t sizeControlEndpoint; |
| mbed_official | 0:a554658735bf | 175 | uint8_t hub_nb; |
| mbed_official | 0:a554658735bf | 176 | uint8_t port; |
| mbed_official | 0:a554658735bf | 177 | uint16_t vid; |
| mbed_official | 0:a554658735bf | 178 | uint16_t pid; |
| mbed_official | 0:a554658735bf | 179 | uint8_t addr; |
| mbed_official | 0:a554658735bf | 180 | uint8_t device_class; |
| mbed_official | 0:a554658735bf | 181 | uint8_t device_subclass; |
| mbed_official | 0:a554658735bf | 182 | uint8_t proto; |
| mbed_official | 0:a554658735bf | 183 | bool speed; |
| mbed_official | 0:a554658735bf | 184 | volatile bool activeAddr; |
| mbed_official | 0:a554658735bf | 185 | volatile bool enumerated; |
| mbed_official | 0:a554658735bf | 186 | uint8_t nb_interf; |
| mbed_official | 0:a554658735bf | 187 | |
| mbed_official | 0:a554658735bf | 188 | void init(); |
| mbed_official | 0:a554658735bf | 189 | }; |
| mbed_official | 0:a554658735bf | 190 | |
| mbed_official | 0:a554658735bf | 191 | #endif |
