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/USBEndpoint.h@4:b320d68e98e7, 2013-03-12 (annotated)
- Committer:
- samux
- Date:
- Tue Mar 12 17:23:37 2013 +0000
- Revision:
- 4:b320d68e98e7
- Parent:
- 0:a554658735bf
- 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 USBENDPOINT_H |
| mbed_official | 0:a554658735bf | 20 | #define USBENDPOINT_H |
| mbed_official | 0:a554658735bf | 21 | |
| mbed_official | 0:a554658735bf | 22 | #include "FunctionPointer.h" |
| mbed_official | 0:a554658735bf | 23 | #include "USBHostTypes.h" |
| mbed_official | 0:a554658735bf | 24 | |
| mbed_official | 0:a554658735bf | 25 | class USBDeviceConnected; |
| mbed_official | 0:a554658735bf | 26 | |
| mbed_official | 0:a554658735bf | 27 | class USBEndpoint |
| mbed_official | 0:a554658735bf | 28 | { |
| mbed_official | 0:a554658735bf | 29 | public: |
| mbed_official | 0:a554658735bf | 30 | /** |
| mbed_official | 0:a554658735bf | 31 | * Constructor |
| mbed_official | 0:a554658735bf | 32 | */ |
| mbed_official | 0:a554658735bf | 33 | USBEndpoint() { |
| mbed_official | 0:a554658735bf | 34 | state = USB_TYPE_FREE; |
| mbed_official | 0:a554658735bf | 35 | nextEp = NULL; |
| mbed_official | 0:a554658735bf | 36 | }; |
| mbed_official | 0:a554658735bf | 37 | |
| mbed_official | 0:a554658735bf | 38 | /** |
| mbed_official | 0:a554658735bf | 39 | * Initialize an endpoint |
| mbed_official | 0:a554658735bf | 40 | * |
| mbed_official | 0:a554658735bf | 41 | * @param hced hced associated to the endpoint |
| mbed_official | 0:a554658735bf | 42 | * @param type endpoint type |
| mbed_official | 0:a554658735bf | 43 | * @param dir endpoint direction |
| mbed_official | 0:a554658735bf | 44 | * @param size endpoint size |
| mbed_official | 0:a554658735bf | 45 | * @param ep_number endpoint number |
| mbed_official | 0:a554658735bf | 46 | * @param td_list array of two allocated transfer descriptors |
| mbed_official | 0:a554658735bf | 47 | */ |
| mbed_official | 0:a554658735bf | 48 | void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); |
| mbed_official | 0:a554658735bf | 49 | |
| mbed_official | 0:a554658735bf | 50 | /** |
| mbed_official | 0:a554658735bf | 51 | * Set next token. Warining: only useful for the control endpoint |
| mbed_official | 0:a554658735bf | 52 | * |
| mbed_official | 0:a554658735bf | 53 | * @param token IN, OUT or SETUP token |
| mbed_official | 0:a554658735bf | 54 | */ |
| mbed_official | 0:a554658735bf | 55 | void setNextToken(uint32_t token); |
| mbed_official | 0:a554658735bf | 56 | |
| mbed_official | 0:a554658735bf | 57 | /** |
| mbed_official | 0:a554658735bf | 58 | * Queue an endpoint |
| mbed_official | 0:a554658735bf | 59 | * |
| mbed_official | 0:a554658735bf | 60 | * endpoint endpoint which will be queued in the linked list |
| mbed_official | 0:a554658735bf | 61 | */ |
| mbed_official | 0:a554658735bf | 62 | void queueEndpoint(USBEndpoint * endpoint); |
| mbed_official | 0:a554658735bf | 63 | |
| mbed_official | 0:a554658735bf | 64 | |
| mbed_official | 0:a554658735bf | 65 | /** |
| mbed_official | 0:a554658735bf | 66 | * Queue a transfer on the endpoint |
| mbed_official | 0:a554658735bf | 67 | */ |
| mbed_official | 0:a554658735bf | 68 | void queueTransfer(); |
| mbed_official | 0:a554658735bf | 69 | |
| mbed_official | 0:a554658735bf | 70 | /** |
| mbed_official | 0:a554658735bf | 71 | * Unqueue a transfer from the endpoint |
| mbed_official | 0:a554658735bf | 72 | * |
| mbed_official | 0:a554658735bf | 73 | * @param td hctd which will be unqueued |
| mbed_official | 0:a554658735bf | 74 | */ |
| mbed_official | 0:a554658735bf | 75 | void unqueueTransfer(volatile HCTD * td); |
| mbed_official | 0:a554658735bf | 76 | |
| mbed_official | 0:a554658735bf | 77 | /** |
| mbed_official | 0:a554658735bf | 78 | * Attach a member function to call when a transfer is finished |
| mbed_official | 0:a554658735bf | 79 | * |
| mbed_official | 0:a554658735bf | 80 | * @param tptr pointer to the object to call the member function on |
| mbed_official | 0:a554658735bf | 81 | * @param mptr pointer to the member function to be called |
| mbed_official | 0:a554658735bf | 82 | */ |
| mbed_official | 0:a554658735bf | 83 | template<typename T> |
| mbed_official | 0:a554658735bf | 84 | inline void attach(T* tptr, void (T::*mptr)(void)) { |
| mbed_official | 0:a554658735bf | 85 | if((mptr != NULL) && (tptr != NULL)) { |
| mbed_official | 0:a554658735bf | 86 | rx.attach(tptr, mptr); |
| mbed_official | 0:a554658735bf | 87 | } |
| mbed_official | 0:a554658735bf | 88 | } |
| mbed_official | 0:a554658735bf | 89 | |
| mbed_official | 0:a554658735bf | 90 | /** |
| mbed_official | 0:a554658735bf | 91 | * Attach a callback called when a transfer is finished |
| mbed_official | 0:a554658735bf | 92 | * |
| mbed_official | 0:a554658735bf | 93 | * @param fptr function pointer |
| mbed_official | 0:a554658735bf | 94 | */ |
| mbed_official | 0:a554658735bf | 95 | inline void attach(void (*fn)(void)) { |
| mbed_official | 0:a554658735bf | 96 | if(fn != NULL) { |
| mbed_official | 0:a554658735bf | 97 | rx.attach(fn); |
| mbed_official | 0:a554658735bf | 98 | } |
| mbed_official | 0:a554658735bf | 99 | } |
| mbed_official | 0:a554658735bf | 100 | |
| mbed_official | 0:a554658735bf | 101 | /** |
| mbed_official | 0:a554658735bf | 102 | * Call the handler associted to the end of a transfer |
| mbed_official | 0:a554658735bf | 103 | */ |
| mbed_official | 0:a554658735bf | 104 | inline void call() { |
| mbed_official | 0:a554658735bf | 105 | rx.call(); |
| mbed_official | 0:a554658735bf | 106 | }; |
| mbed_official | 0:a554658735bf | 107 | |
| mbed_official | 0:a554658735bf | 108 | |
| mbed_official | 0:a554658735bf | 109 | // setters |
| mbed_official | 0:a554658735bf | 110 | inline void setState(USB_TYPE st) { state = st; } |
| mbed_official | 0:a554658735bf | 111 | void setState(uint8_t st); |
| mbed_official | 0:a554658735bf | 112 | void setDeviceAddress(uint8_t addr); |
| mbed_official | 0:a554658735bf | 113 | inline void setLengthTransferred(int len) { transferred = len; }; |
| mbed_official | 0:a554658735bf | 114 | void setSpeed(uint8_t speed); |
| mbed_official | 0:a554658735bf | 115 | void setSize(uint32_t size); |
| mbed_official | 0:a554658735bf | 116 | inline void setDir(ENDPOINT_DIRECTION d) { dir = d; } |
| samux | 4:b320d68e98e7 | 117 | inline void setIntfNb(uint8_t intf_nb_) { intf_nb = intf_nb_; }; |
| mbed_official | 0:a554658735bf | 118 | |
| mbed_official | 0:a554658735bf | 119 | // getters |
| mbed_official | 0:a554658735bf | 120 | const char * getStateString(); |
| mbed_official | 0:a554658735bf | 121 | inline USB_TYPE getState() { return state; } |
| mbed_official | 0:a554658735bf | 122 | inline ENDPOINT_TYPE getType() { return type; }; |
| mbed_official | 0:a554658735bf | 123 | inline uint8_t getDeviceAddress() { return hced->control & 0x7f; }; |
| mbed_official | 0:a554658735bf | 124 | inline int getLengthTransferred() { return transferred; } |
| mbed_official | 0:a554658735bf | 125 | inline uint8_t * getBufStart() { return buf_start; } |
| mbed_official | 0:a554658735bf | 126 | inline uint8_t getAddress(){ return address; }; |
| mbed_official | 0:a554658735bf | 127 | inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; }; |
| mbed_official | 0:a554658735bf | 128 | inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); }; |
| mbed_official | 0:a554658735bf | 129 | inline volatile HCTD** getTDList() { return td_list; }; |
| mbed_official | 0:a554658735bf | 130 | inline volatile HCED * getHCED() { return hced; }; |
| mbed_official | 0:a554658735bf | 131 | inline ENDPOINT_DIRECTION getDir() { return dir; } |
| mbed_official | 0:a554658735bf | 132 | inline volatile HCTD * getProcessedTD() { return td_current; }; |
| mbed_official | 0:a554658735bf | 133 | inline volatile HCTD* getNextTD() { return td_current; }; |
| mbed_official | 0:a554658735bf | 134 | inline bool isSetup() { return setup; } |
| mbed_official | 0:a554658735bf | 135 | inline USBEndpoint * nextEndpoint() { return (USBEndpoint*)nextEp; }; |
| samux | 4:b320d68e98e7 | 136 | inline uint8_t getIntfNb() { return intf_nb; }; |
| mbed_official | 0:a554658735bf | 137 | |
| mbed_official | 0:a554658735bf | 138 | USBDeviceConnected * dev; |
| mbed_official | 0:a554658735bf | 139 | |
| mbed_official | 0:a554658735bf | 140 | private: |
| mbed_official | 0:a554658735bf | 141 | ENDPOINT_TYPE type; |
| mbed_official | 0:a554658735bf | 142 | volatile USB_TYPE state; |
| mbed_official | 0:a554658735bf | 143 | ENDPOINT_DIRECTION dir; |
| mbed_official | 0:a554658735bf | 144 | bool setup; |
| mbed_official | 0:a554658735bf | 145 | |
| mbed_official | 0:a554658735bf | 146 | uint8_t address; |
| mbed_official | 0:a554658735bf | 147 | |
| mbed_official | 0:a554658735bf | 148 | int transfer_len; |
| mbed_official | 0:a554658735bf | 149 | int transferred; |
| mbed_official | 0:a554658735bf | 150 | uint8_t * buf_start; |
| mbed_official | 0:a554658735bf | 151 | |
| mbed_official | 0:a554658735bf | 152 | FunctionPointer rx; |
| mbed_official | 0:a554658735bf | 153 | |
| mbed_official | 0:a554658735bf | 154 | USBEndpoint* nextEp; |
| mbed_official | 0:a554658735bf | 155 | |
| mbed_official | 0:a554658735bf | 156 | // USBEndpoint descriptor |
| mbed_official | 0:a554658735bf | 157 | volatile HCED * hced; |
| mbed_official | 0:a554658735bf | 158 | |
| mbed_official | 0:a554658735bf | 159 | volatile HCTD * td_list[2]; |
| mbed_official | 0:a554658735bf | 160 | volatile HCTD * td_current; |
| mbed_official | 0:a554658735bf | 161 | volatile HCTD * td_next; |
| samux | 4:b320d68e98e7 | 162 | |
| samux | 4:b320d68e98e7 | 163 | uint8_t intf_nb; |
| mbed_official | 0:a554658735bf | 164 | |
| mbed_official | 0:a554658735bf | 165 | }; |
| mbed_official | 0:a554658735bf | 166 | |
| mbed_official | 0:a554658735bf | 167 | #endif |
