USBDevice for STM support

Dependents:   Nucleo_Usb_JoyMouse Nucleo_usbmouse ELEC350_1-referral-2018-usb-hid USBJoystick_HelloWorld2_wip ... more

This library contains all mbed usb device library (mbed-os\features\unsupported\USBDevice).

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Wed Feb 15 09:48:15 2017 +0100
Revision:
3:d9c7334e2183
Parent:
1:2a3ae13b45ef
Child:
4:50ec00aa4515
update 5.3.5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 2 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 4 * and associated documentation files (the "Software"), to deal in the Software without
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 7 * Software is furnished to do so, subject to the following conditions:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 8 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 9 * The above copyright notice and this permission notice shall be included in all copies or
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 10 * substantial portions of the Software.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 11 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 17 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 18
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 19 #ifndef USBAudio_H
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 20 #define USBAudio_H
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 21
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 22 /* These headers are included for child class. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 23 #include "USBEndpoints.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 24 #include "USBDescriptor.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 25 #include "USBDevice_Types.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 26
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 27 #include "USBDevice.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 28 #include "Callback.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 29
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 30 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 31 * USBAudio example
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 32 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 33 * @code
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 34 * #include "mbed.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 35 * #include "USBAudio.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 36 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 37 * Serial pc(USBTX, USBRX);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 38 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 39 * // frequency: 48 kHz
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 40 * #define FREQ 48000
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 41 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 42 * // 1 channel: mono
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 43 * #define NB_CHA 1
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 44 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 45 * // length of an audio packet: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there is one channel, the length will be 48 * 2 * 1
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 46 * #define AUDIO_LENGTH_PACKET 48 * 2 * 1
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 47 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 48 * // USBAudio
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 49 * USBAudio audio(FREQ, NB_CHA);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 50 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 51 * int main() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 52 * int16_t buf[AUDIO_LENGTH_PACKET/2];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 53 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 54 * while (1) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 55 * // read an audio packet
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 56 * audio.read((uint8_t *)buf);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 57 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 58 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 59 * // print packet received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 60 * pc.printf("recv: ");
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 61 * for(int i = 0; i < AUDIO_LENGTH_PACKET/2; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 62 * pc.printf("%d ", buf[i]);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 63 * }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 64 * pc.printf("\r\n");
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 65 * }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 66 * }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 67 * @endcode
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 68 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 69 class USBAudio: public USBDevice {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 70 public:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 71
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 72 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 73 * Constructor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 74 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 75 * @param frequency_in frequency in Hz (default: 48000)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 76 * @param channel_nb_in channel number (1 or 2) (default: 1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 77 * @param frequency_out frequency in Hz (default: 8000)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 78 * @param channel_nb_out_in channel number (1 or 2) (default: 1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 79 * @param vendor_id Your vendor_id
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 80 * @param product_id Your product_id
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 81 * @param product_release Your preoduct_release
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 82 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 83 USBAudio(uint32_t frequency_in = 48000, uint8_t channel_nb_in = 1, uint32_t frequency_out = 8000, uint8_t channel_nb_out = 1, uint16_t vendor_id = 0x7bb8, uint16_t product_id = 0x1111, uint16_t product_release = 0x0100);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 84
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 85 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 86 * Get current volume between 0.0 and 1.0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 87 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 88 * @returns volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 89 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 90 float getVolume();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 91
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 92 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 93 * Read an audio packet. During a frame, only a single reading (you can't write and read an audio packet during the same frame)can be done using this method. Warning: Blocking
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 94 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 95 * @param buf pointer on a buffer which will be filled with an audio packet
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 96 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 97 * @returns true if successfull
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 98 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 99 bool read(uint8_t * buf);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 100
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 101 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 102 * Try to read an audio packet. During a frame, only a single reading (you can't write and read an audio packet during the same frame)can be done using this method. Warning: Non Blocking
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 103 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 104 * @param buf pointer on a buffer which will be filled if an audio packet is available
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 105 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 106 * @returns true if successfull
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 107 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 108 bool readNB(uint8_t * buf);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 109
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 110 /**
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 111 * read last received packet if some.
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 112 * @param buf pointer on a buffer which will be filled if an audio packet is available
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 113 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 114 * @returns the packet length
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 115 */
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 116 uint32_t readSync(uint8_t *buf);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 117
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 118 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 119 * Write an audio packet. During a frame, only a single writing (you can't write and read an audio packet during the same frame)can be done using this method.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 120 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 121 * @param buf pointer on the audio packet which will be sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 122 * @returns true if successful
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 123 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 124 bool write(uint8_t * buf);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 125
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 126 /**
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 127 * Write packet in endpoint fifo. assuming tx fifo is empty
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 128 * @param buf pointer on the audio packet which will be sent
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 129 */
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 130 void writeSync(uint8_t *buf);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 131
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 132 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 133 * Write and read an audio packet at the same time (on the same frame)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 134 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 135 * @param buf_read pointer on a buffer which will be filled with an audio packet
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 136 * @param buf_write pointer on the audio packet which will be sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 137 * @returns true if successful
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 138 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 139 bool readWrite(uint8_t * buf_read, uint8_t * buf_write);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 140
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 141
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 142 /** attach a handler to update the volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 143 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 144 * @param function Function to attach
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 145 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 146 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 147 void attach(void(*fptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 148 updateVol.attach(fptr);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 149 }
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 150 /** attach a handler to Tx Done
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 151 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 152 * @param function Function to attach
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 153 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 154 */
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 155 void attachTx(void(*fptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 156 txDone.attach(fptr);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 157 }
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 158 /** attach a handler to Rx Done
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 159 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 160 * @param function Function to attach
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 161 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 162 */
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 163 void attachRx(void(*fptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 164 rxDone.attach(fptr);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 165 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 166
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 167 /** Attach a nonstatic void/void member function to update the volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 168 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 169 * @param tptr Object pointer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 170 * @param mptr Member function pointer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 171 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 172 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 173 template<typename T>
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 174 void attach(T *tptr, void(T::*mptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 175 updateVol.attach(tptr, mptr);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 176 }
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 177 template<typename T>
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 178 void attachTx(T *tptr, void(T::*mptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 179 txDone.attach(tptr, mptr);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 180 }
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 181 template<typename T>
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 182 void attachRx(T *tptr, void(T::*mptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 183 rxDone.attach(tptr, mptr);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 184 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 185
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 186
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 187 protected:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 188
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 189 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 190 * Called by USBDevice layer. Set configuration of the device.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 191 * For instance, you can add all endpoints that you need on this function.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 192 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 193 * @param configuration Number of the configuration
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 194 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 195 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 196 virtual bool USBCallback_setConfiguration(uint8_t configuration);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 197
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 198 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 199 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 200 * This is used to handle extensions to standard requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 201 * and class specific requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 202 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 203 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 204 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 205 virtual bool USBCallback_request();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 206
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 207 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 208 * Get string product descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 209 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 210 * @returns pointer to the string product descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 211 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 212 virtual uint8_t * stringIproductDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 213
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 214 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 215 * Get string interface descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 216 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 217 * @returns pointer to the string interface descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 218 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 219 virtual uint8_t * stringIinterfaceDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 220
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 221 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 222 * Get configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 223 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 224 * @returns pointer to the configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 225 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 226 virtual uint8_t * configurationDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 227
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 228 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 229 * Called by USBDevice layer. Set interface/alternate of the device.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 230 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 231 * @param interface Number of the interface to be configured
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 232 * @param alternate Number of the alternate to be configured
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 233 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 234 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 235 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 236
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 237 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 238 * Called by USBDevice on Endpoint0 request completion
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 239 * if the 'notify' flag has been set to true. Warning: Called in ISR context
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 240 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 241 * In this case it is used to indicate that a HID report has
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 242 * been received from the host on endpoint 0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 243 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 244 * @param buf buffer received on endpoint 0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 245 * @param length length of this buffer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 246 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 247 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 248
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 249 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 250 * Callback called on each Start of Frame event
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 251 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 252 virtual void SOF(int frameNumber);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 253
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 254 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 255 * Callback called when a packet is received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 256 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 257 virtual bool EPISO_OUT_callback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 258
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 259 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 260 * Callback called when a packet has been sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 261 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 262 virtual bool EPISO_IN_callback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 263
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 264 private:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 265
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 266 // stream available ?
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 267 volatile bool available;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 268
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 269 // interrupt OUT has been received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 270 volatile bool interruptOUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 271
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 272 // interrupt IN has been received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 273 volatile bool interruptIN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 274
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 275 // audio packet has been written
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 276 volatile bool writeIN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 277
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 278 // FREQ
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 279 uint32_t FREQ_OUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 280 uint32_t FREQ_IN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 281
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 282 // size of the maximum packet for the isochronous endpoint
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 283 uint32_t PACKET_SIZE_ISO_IN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 284 uint32_t PACKET_SIZE_ISO_OUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 285
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 286 // mono, stereo,...
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 287 uint8_t channel_nb_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 288 uint8_t channel_nb_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 289
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 290 // channel config: master, left, right
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 291 uint8_t channel_config_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 292 uint8_t channel_config_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 293
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 294 // mute state
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 295 uint8_t mute;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 296
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 297 // Volume Current Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 298 uint16_t volCur;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 299
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 300 // Volume Minimum Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 301 uint16_t volMin;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 302
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 303 // Volume Maximum Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 304 uint16_t volMax;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 305
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 306 // Volume Resolution
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 307 uint16_t volRes;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 308
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 309 // Buffer containing one audio packet (to be read)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 310 volatile uint8_t * buf_stream_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 311
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 312 // Buffer containing one audio packet (to be written)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 313 volatile uint8_t * buf_stream_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 314
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 315 // callback to update volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 316 Callback<void()> updateVol;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 317
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 318 // callback transmit Done
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 319 Callback<void()> txDone;
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 320 // callback transmit Done
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 321 Callback<void()> rxDone;
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 322
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 323 // boolean showing that the SOF handler has been called. Useful for readNB.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 324 volatile bool SOF_handler;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 325
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 326 volatile float volume;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 327
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 328 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 329
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 330 #endif