Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBDevice by
Diff: USBAudio/USBAudio.h
- Revision:
- 70:2c525a50f1b6
- Parent:
- 47:a0cd9646ecd1
diff -r c5e178adb138 -r 2c525a50f1b6 USBAudio/USBAudio.h
--- a/USBAudio/USBAudio.h Fri Nov 11 17:59:00 2016 +0000
+++ b/USBAudio/USBAudio.h Thu Jul 20 10:14:36 2017 +0100
@@ -25,7 +25,7 @@
#include "USBDevice_Types.h"
#include "USBDevice.h"
-
+#include "Callback.h"
/**
* USBAudio example
@@ -108,6 +108,14 @@
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.
*
* @param buf pointer on the audio packet which will be sent
@@ -115,6 +123,19 @@
*/
bool write(uint8_t * buf);
+ /** Audio Jitter value*/
+ enum AudioSampleCorrectType {
+ RemoveOneSample = -1,
+ NoCorrection = 0,
+ AddOneSample = 1
+ };
+ /**
+ * Write packet in endpoint fifo. assuming tx fifo is empty
+ * @param buf pointer on the audio packet which will be sent
+ * @param jitter_nb : AudioSampleCorrecttype
+ **/
+ void writeSync(uint8_t *buf, AudioSampleCorrectType jitter_nb = NoCorrection );
+
/**
* Write and read an audio packet at the same time (on the same frame)
*
@@ -133,6 +154,22 @@
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 +181,14 @@
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:
@@ -275,7 +320,12 @@
volatile uint8_t * buf_stream_out;
// callback to update volume
- FunctionPointer updateVol;
+ 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;
