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:
Tue Mar 28 11:00:57 2017 +0200
Branch:
master
Revision:
4:50ec00aa4515
Parent:
3:d9c7334e2183
update for 5.4.2

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 4:50ec00aa4515 126 /** Audio Jitter value*/
frq08711@LMECWL0871.LME.ST.COM 4:50ec00aa4515 127 enum AudioSampleCorrectType {
frq08711@LMECWL0871.LME.ST.COM 4:50ec00aa4515 128 RemoveOneSample = -1,
frq08711@LMECWL0871.LME.ST.COM 4:50ec00aa4515 129 NoCorrection = 0,
frq08711@LMECWL0871.LME.ST.COM 4:50ec00aa4515 130 AddOneSample = 1
frq08711@LMECWL0871.LME.ST.COM 4:50ec00aa4515 131 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 132 /**
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 133 * Write packet in endpoint fifo. assuming tx fifo is empty
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 134 * @param buf pointer on the audio packet which will be sent
frq08711@LMECWL0871.LME.ST.COM 4:50ec00aa4515 135 * @param jitter_nb : AudioSampleCorrecttype
frq08711@LMECWL0871.LME.ST.COM 4:50ec00aa4515 136 **/
frq08711@LMECWL0871.LME.ST.COM 4:50ec00aa4515 137 void writeSync(uint8_t *buf, AudioSampleCorrectType jitter_nb = NoCorrection );
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 138
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 139 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 140 * Write and read an audio packet at the same time (on the same frame)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 141 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 142 * @param buf_read pointer on a buffer which will be filled with an audio packet
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 143 * @param buf_write pointer on the audio packet which will be sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 144 * @returns true if successful
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 145 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 146 bool readWrite(uint8_t * buf_read, uint8_t * buf_write);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 147
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 148
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 149 /** attach a handler to update the volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 150 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 151 * @param function Function to attach
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 152 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 153 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 154 void attach(void(*fptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 155 updateVol.attach(fptr);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 156 }
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 157 /** attach a handler to Tx Done
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 158 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 159 * @param function Function to attach
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 160 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 161 */
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 162 void attachTx(void(*fptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 163 txDone.attach(fptr);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 164 }
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 165 /** attach a handler to Rx Done
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 166 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 167 * @param function Function to attach
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 168 *
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 169 */
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 170 void attachRx(void(*fptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 171 rxDone.attach(fptr);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 172 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 173
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 174 /** Attach a nonstatic void/void member function to update the volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 175 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 176 * @param tptr Object pointer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 177 * @param mptr Member function pointer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 178 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 179 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 180 template<typename T>
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 181 void attach(T *tptr, void(T::*mptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 182 updateVol.attach(tptr, mptr);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 183 }
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 184 template<typename T>
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 185 void attachTx(T *tptr, void(T::*mptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 186 txDone.attach(tptr, mptr);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 187 }
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 188 template<typename T>
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 189 void attachRx(T *tptr, void(T::*mptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 190 rxDone.attach(tptr, mptr);
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 191 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 192
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 193
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 194 protected:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 195
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 196 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 197 * Called by USBDevice layer. Set configuration of the device.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 198 * For instance, you can add all endpoints that you need on this function.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 199 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 200 * @param configuration Number of the configuration
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 201 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 202 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 203 virtual bool USBCallback_setConfiguration(uint8_t configuration);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 204
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 205 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 206 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 207 * This is used to handle extensions to standard requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 208 * and class specific requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 209 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 210 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 211 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 212 virtual bool USBCallback_request();
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 product descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 216 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 217 * @returns pointer to the string product descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 218 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 219 virtual uint8_t * stringIproductDesc();
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 string interface descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 223 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 224 * @returns pointer to the string interface descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 225 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 226 virtual uint8_t * stringIinterfaceDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 227
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 228 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 229 * Get configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 230 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 231 * @returns pointer to the configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 232 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 233 virtual uint8_t * configurationDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 234
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 235 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 236 * Called by USBDevice layer. Set interface/alternate of the device.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 237 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 238 * @param interface Number of the interface to be configured
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 239 * @param alternate Number of the alternate to be configured
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 240 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 241 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 242 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 243
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 244 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 245 * Called by USBDevice on Endpoint0 request completion
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 246 * if the 'notify' flag has been set to true. Warning: Called in ISR context
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 247 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 248 * In this case it is used to indicate that a HID report has
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 249 * been received from the host on endpoint 0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 250 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 251 * @param buf buffer received on endpoint 0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 252 * @param length length of this buffer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 253 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 254 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 255
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 256 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 257 * Callback called on each Start of Frame event
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 258 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 259 virtual void SOF(int frameNumber);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 260
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 261 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 262 * Callback called when a packet is received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 263 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 264 virtual bool EPISO_OUT_callback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 265
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 266 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 267 * Callback called when a packet has been sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 268 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 269 virtual bool EPISO_IN_callback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 270
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 271 private:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 272
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 273 // stream available ?
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 274 volatile bool available;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 275
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 276 // interrupt OUT has been received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 277 volatile bool interruptOUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 278
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 279 // interrupt IN has been received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 280 volatile bool interruptIN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 281
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 282 // audio packet has been written
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 283 volatile bool writeIN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 284
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 285 // FREQ
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 286 uint32_t FREQ_OUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 287 uint32_t FREQ_IN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 288
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 289 // size of the maximum packet for the isochronous endpoint
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 290 uint32_t PACKET_SIZE_ISO_IN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 291 uint32_t PACKET_SIZE_ISO_OUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 292
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 293 // mono, stereo,...
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 294 uint8_t channel_nb_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 295 uint8_t channel_nb_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 296
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 297 // channel config: master, left, right
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 298 uint8_t channel_config_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 299 uint8_t channel_config_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 300
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 301 // mute state
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 302 uint8_t mute;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 303
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 304 // Volume Current Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 305 uint16_t volCur;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 306
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 307 // Volume Minimum Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 308 uint16_t volMin;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 309
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 310 // Volume Maximum Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 311 uint16_t volMax;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 312
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 313 // Volume Resolution
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 314 uint16_t volRes;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 315
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 316 // Buffer containing one audio packet (to be read)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 317 volatile uint8_t * buf_stream_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 318
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 319 // Buffer containing one audio packet (to be written)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 320 volatile uint8_t * buf_stream_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 321
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 322 // callback to update volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 323 Callback<void()> updateVol;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 324
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 325 // callback transmit Done
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 326 Callback<void()> txDone;
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 327 // callback transmit Done
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 328 Callback<void()> rxDone;
frq08711@LMECWL0871.LME.ST.COM 3:d9c7334e2183 329
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 330 // boolean showing that the SOF handler has been called. Useful for readNB.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 331 volatile bool SOF_handler;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 332
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 333 volatile float volume;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 334
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 335 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 336
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 337 #endif