Modified USBAudio to call a callback function when audio an packets is received.
Fork of USBDevice by
Revision 21:8133879e4fb4, committed 2014-03-27
- Comitter:
- bw
- Date:
- Thu Mar 27 21:26:37 2014 +0000
- Parent:
- 8:335f2506f422
- Commit message:
- Modified USBAudio to call a callback function when an audio packet is received.
Changed in this revision
USBAudio/USBAudio.cpp | Show annotated file Show diff for this revision Revisions of this file |
USBAudio/USBAudio.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 335f2506f422 -r 8133879e4fb4 USBAudio/USBAudio.cpp --- a/USBAudio/USBAudio.cpp Fri Mar 01 13:10:29 2013 +0000 +++ b/USBAudio/USBAudio.cpp Thu Mar 27 21:26:37 2014 +0000 @@ -141,6 +141,8 @@ // Called in ISR context on each start of frame +// A read callback services the audio packet in the "read" buffer. +// The "read" buffer is to be set once with a USBAudio::read(). void USBAudio::SOF(int frameNumber) { uint32_t size = 0; @@ -151,7 +153,7 @@ if (size) { available = true; readStart(EP3OUT, PACKET_SIZE_ISO_IN); - buf_stream_in = NULL; + readCallback.call(); } } }
diff -r 335f2506f422 -r 8133879e4fb4 USBAudio/USBAudio.h --- a/USBAudio/USBAudio.h Fri Mar 01 13:10:29 2013 +0000 +++ b/USBAudio/USBAudio.h Thu Mar 27 21:26:37 2014 +0000 @@ -145,6 +145,14 @@ updateVol.attach(tptr, mptr); } + /** Attach a callback to service incomming audio packets. + * + * @param function Function to attach + * + */ + void attachReadCallback(void(*fptr)(void)) { + readCallback.attach(fptr); + } protected: @@ -277,6 +285,9 @@ // callback to update volume FunctionPointer updateVol; + // callback to service incomming audio packet + FunctionPointer readCallback; + // boolean showing that the SOF handler has been called. Useful for readNB. volatile bool SOF_handler;