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:
Thu Dec 15 17:40:59 2016 +0100
Revision:
1:2a3ae13b45ef
Child:
3:d9c7334e2183
copy of git hub directory unsupported/USBDevice

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 1:2a3ae13b45ef 111 * 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 112 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 113 * @param buf pointer on the audio packet which will be sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 114 * @returns true if successful
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 115 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 116 bool write(uint8_t * buf);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 117
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 118 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 119 * Write and read an audio packet at the same time (on the same frame)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 120 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 121 * @param buf_read pointer on a buffer which will be filled with an audio packet
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 122 * @param buf_write pointer on the audio packet which will be sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 123 * @returns true if successful
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 124 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 125 bool readWrite(uint8_t * buf_read, uint8_t * buf_write);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 126
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 127
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 128 /** attach a handler to update the volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 129 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 130 * @param function Function to attach
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 131 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 132 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 133 void attach(void(*fptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 134 updateVol.attach(fptr);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 135 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 136
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 137 /** Attach a nonstatic void/void member function to update the volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 138 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 139 * @param tptr Object pointer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 140 * @param mptr Member function pointer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 141 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 142 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 143 template<typename T>
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 144 void attach(T *tptr, void(T::*mptr)(void)) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 145 updateVol.attach(tptr, mptr);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 146 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 147
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 148
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 149 protected:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 150
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 151 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 152 * Called by USBDevice layer. Set configuration of the device.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 153 * For instance, you can add all endpoints that you need on this function.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 154 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 155 * @param configuration Number of the configuration
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 156 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 157 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 158 virtual bool USBCallback_setConfiguration(uint8_t configuration);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 159
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 160 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 161 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 162 * This is used to handle extensions to standard requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 163 * and class specific requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 164 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 165 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 166 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 167 virtual bool USBCallback_request();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 168
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 169 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 170 * Get string product descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 171 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 172 * @returns pointer to the string product descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 173 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 174 virtual uint8_t * stringIproductDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 175
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 176 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 177 * Get string interface descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 178 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 179 * @returns pointer to the string interface descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 180 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 181 virtual uint8_t * stringIinterfaceDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 182
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 183 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 184 * Get configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 185 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 186 * @returns pointer to the configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 187 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 188 virtual uint8_t * configurationDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 189
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 190 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 191 * Called by USBDevice layer. Set interface/alternate of the device.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 192 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 193 * @param interface Number of the interface to be configured
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 194 * @param alternate Number of the alternate to be configured
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 195 * @returns true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 196 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 197 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 198
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 199 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 200 * Called by USBDevice on Endpoint0 request completion
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 201 * if the 'notify' flag has been set to true. Warning: Called in ISR context
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 202 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 203 * In this case it is used to indicate that a HID report has
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 204 * been received from the host on endpoint 0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 205 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 206 * @param buf buffer received on endpoint 0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 207 * @param length length of this buffer
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 208 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 209 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 210
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 211 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 212 * Callback called on each Start of Frame event
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 213 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 214 virtual void SOF(int frameNumber);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 215
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 216 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 217 * Callback called when a packet is received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 218 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 219 virtual bool EPISO_OUT_callback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 220
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 221 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 222 * Callback called when a packet has been sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 223 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 224 virtual bool EPISO_IN_callback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 225
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 226 private:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 227
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 228 // stream available ?
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 229 volatile bool available;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 230
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 231 // interrupt OUT has been received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 232 volatile bool interruptOUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 233
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 234 // interrupt IN has been received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 235 volatile bool interruptIN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 236
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 237 // audio packet has been written
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 238 volatile bool writeIN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 239
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 240 // FREQ
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 241 uint32_t FREQ_OUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 242 uint32_t FREQ_IN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 243
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 244 // size of the maximum packet for the isochronous endpoint
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 245 uint32_t PACKET_SIZE_ISO_IN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 246 uint32_t PACKET_SIZE_ISO_OUT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 247
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 248 // mono, stereo,...
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 249 uint8_t channel_nb_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 250 uint8_t channel_nb_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 251
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 252 // channel config: master, left, right
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 253 uint8_t channel_config_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 254 uint8_t channel_config_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 255
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 256 // mute state
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 257 uint8_t mute;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 258
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 259 // Volume Current Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 260 uint16_t volCur;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 261
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 262 // Volume Minimum Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 263 uint16_t volMin;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 264
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 265 // Volume Maximum Value
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 266 uint16_t volMax;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 267
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 268 // Volume Resolution
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 269 uint16_t volRes;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 270
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 271 // Buffer containing one audio packet (to be read)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 272 volatile uint8_t * buf_stream_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 273
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 274 // Buffer containing one audio packet (to be written)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 275 volatile uint8_t * buf_stream_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 276
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 277 // callback to update volume
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 278 Callback<void()> updateVol;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 279
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 280 // boolean showing that the SOF handler has been called. Useful for readNB.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 281 volatile bool SOF_handler;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 282
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 283 volatile float volume;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 284
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 285 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 286
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 287 #endif