mirror of https://github.com/ARMmbed/mbed-os.git
USBAudio: tx/rx iso call back.
parent
315d893e83
commit
3a6a5ab858
|
|
@ -113,6 +113,17 @@ bool USBAudio::write(uint8_t * buf) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void USBAudio::writeSync(uint8_t *buf)
|
||||
{
|
||||
USBDevice::writeNB(EP3IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
|
||||
}
|
||||
|
||||
uint32_t USBAudio::readSync(uint8_t *buf)
|
||||
{
|
||||
uint32_t size = 0;
|
||||
USBDevice::readEP(EP3OUT, (uint8_t *)buf, &size, PACKET_SIZE_ISO_IN);
|
||||
return size;
|
||||
}
|
||||
|
||||
float USBAudio::getVolume() {
|
||||
return (mute) ? 0.0 : volume;
|
||||
|
|
@ -127,6 +138,10 @@ bool USBAudio::EPISO_OUT_callback() {
|
|||
available = true;
|
||||
buf_stream_in = NULL;
|
||||
}
|
||||
else {
|
||||
if (rxDone)
|
||||
rxDone.call();
|
||||
}
|
||||
readStart(EP3OUT, PACKET_SIZE_ISO_IN);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -135,6 +150,8 @@ bool USBAudio::EPISO_OUT_callback() {
|
|||
bool USBAudio::EPISO_IN_callback() {
|
||||
interruptIN = true;
|
||||
writeIN = true;
|
||||
if (txDone)
|
||||
txDone.call();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,6 +107,14 @@ public:
|
|||
*/
|
||||
bool readNB(uint8_t * buf);
|
||||
|
||||
/**
|
||||
* read last received packet if some.
|
||||
* @param buf pointer on a buffer which will be filled if an audio packet is available
|
||||
*
|
||||
* @returns the packet length
|
||||
*/
|
||||
uint32_t readSync(uint8_t *buf);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
@ -115,6 +123,12 @@ public:
|
|||
*/
|
||||
bool write(uint8_t * buf);
|
||||
|
||||
/**
|
||||
* Write packet in endpoint fifo. assuming tx fifo is empty
|
||||
* @param buf pointer on the audio packet which will be sent
|
||||
*/
|
||||
void writeSync(uint8_t *buf);
|
||||
|
||||
/**
|
||||
* Write and read an audio packet at the same time (on the same frame)
|
||||
*
|
||||
|
|
@ -133,6 +147,22 @@ public:
|
|||
void attach(void(*fptr)(void)) {
|
||||
updateVol.attach(fptr);
|
||||
}
|
||||
/** attach a handler to Tx Done
|
||||
*
|
||||
* @param function Function to attach
|
||||
*
|
||||
*/
|
||||
void attachTx(void(*fptr)(void)) {
|
||||
txDone.attach(fptr);
|
||||
}
|
||||
/** attach a handler to Rx Done
|
||||
*
|
||||
* @param function Function to attach
|
||||
*
|
||||
*/
|
||||
void attachRx(void(*fptr)(void)) {
|
||||
rxDone.attach(fptr);
|
||||
}
|
||||
|
||||
/** Attach a nonstatic void/void member function to update the volume
|
||||
*
|
||||
|
|
@ -144,6 +174,14 @@ public:
|
|||
void attach(T *tptr, void(T::*mptr)(void)) {
|
||||
updateVol.attach(tptr, mptr);
|
||||
}
|
||||
template<typename T>
|
||||
void attachTx(T *tptr, void(T::*mptr)(void)) {
|
||||
txDone.attach(tptr, mptr);
|
||||
}
|
||||
template<typename T>
|
||||
void attachRx(T *tptr, void(T::*mptr)(void)) {
|
||||
rxDone.attach(tptr, mptr);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
|
@ -277,6 +315,11 @@ private:
|
|||
// callback to update volume
|
||||
Callback<void()> updateVol;
|
||||
|
||||
// callback transmit Done
|
||||
Callback<void()> txDone;
|
||||
// callback transmit Done
|
||||
Callback<void()> rxDone;
|
||||
|
||||
// boolean showing that the SOF handler has been called. Useful for readNB.
|
||||
volatile bool SOF_handler;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue