Skip to content

Commit 3a6a5ab

Browse files
committed
USBAudio: tx/rx iso call back.
1 parent 315d893 commit 3a6a5ab

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

features/unsupported/USBDevice/USBAudio/USBAudio.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ bool USBAudio::write(uint8_t * buf) {
113113
return true;
114114
}
115115

116+
void USBAudio::writeSync(uint8_t *buf)
117+
{
118+
USBDevice::writeNB(EP3IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
119+
}
120+
121+
uint32_t USBAudio::readSync(uint8_t *buf)
122+
{
123+
uint32_t size = 0;
124+
USBDevice::readEP(EP3OUT, (uint8_t *)buf, &size, PACKET_SIZE_ISO_IN);
125+
return size;
126+
}
116127

117128
float USBAudio::getVolume() {
118129
return (mute) ? 0.0 : volume;
@@ -127,6 +138,10 @@ bool USBAudio::EPISO_OUT_callback() {
127138
available = true;
128139
buf_stream_in = NULL;
129140
}
141+
else {
142+
if (rxDone)
143+
rxDone.call();
144+
}
130145
readStart(EP3OUT, PACKET_SIZE_ISO_IN);
131146
return false;
132147
}
@@ -135,6 +150,8 @@ bool USBAudio::EPISO_OUT_callback() {
135150
bool USBAudio::EPISO_IN_callback() {
136151
interruptIN = true;
137152
writeIN = true;
153+
if (txDone)
154+
txDone.call();
138155
return true;
139156
}
140157

features/unsupported/USBDevice/USBAudio/USBAudio.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ class USBAudio: public USBDevice {
107107
*/
108108
bool readNB(uint8_t * buf);
109109

110+
/**
111+
* read last received packet if some.
112+
* @param buf pointer on a buffer which will be filled if an audio packet is available
113+
*
114+
* @returns the packet length
115+
*/
116+
uint32_t readSync(uint8_t *buf);
117+
110118
/**
111119
* 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.
112120
*
@@ -115,6 +123,12 @@ class USBAudio: public USBDevice {
115123
*/
116124
bool write(uint8_t * buf);
117125

126+
/**
127+
* Write packet in endpoint fifo. assuming tx fifo is empty
128+
* @param buf pointer on the audio packet which will be sent
129+
*/
130+
void writeSync(uint8_t *buf);
131+
118132
/**
119133
* Write and read an audio packet at the same time (on the same frame)
120134
*
@@ -133,6 +147,22 @@ class USBAudio: public USBDevice {
133147
void attach(void(*fptr)(void)) {
134148
updateVol.attach(fptr);
135149
}
150+
/** attach a handler to Tx Done
151+
*
152+
* @param function Function to attach
153+
*
154+
*/
155+
void attachTx(void(*fptr)(void)) {
156+
txDone.attach(fptr);
157+
}
158+
/** attach a handler to Rx Done
159+
*
160+
* @param function Function to attach
161+
*
162+
*/
163+
void attachRx(void(*fptr)(void)) {
164+
rxDone.attach(fptr);
165+
}
136166

137167
/** Attach a nonstatic void/void member function to update the volume
138168
*
@@ -144,6 +174,14 @@ class USBAudio: public USBDevice {
144174
void attach(T *tptr, void(T::*mptr)(void)) {
145175
updateVol.attach(tptr, mptr);
146176
}
177+
template<typename T>
178+
void attachTx(T *tptr, void(T::*mptr)(void)) {
179+
txDone.attach(tptr, mptr);
180+
}
181+
template<typename T>
182+
void attachRx(T *tptr, void(T::*mptr)(void)) {
183+
rxDone.attach(tptr, mptr);
184+
}
147185

148186

149187
protected:
@@ -277,6 +315,11 @@ class USBAudio: public USBDevice {
277315
// callback to update volume
278316
Callback<void()> updateVol;
279317

318+
// callback transmit Done
319+
Callback<void()> txDone;
320+
// callback transmit Done
321+
Callback<void()> rxDone;
322+
280323
// boolean showing that the SOF handler has been called. Useful for readNB.
281324
volatile bool SOF_handler;
282325

0 commit comments

Comments
 (0)