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.
Dependents: DISCO-F429ZI_LCDTS_demo_richard
Fork of USBDEVICE by
Revision 3:d9c7334e2183, committed 2017-02-15
- Comitter:
- frq08711@LMECWL0871.LME.ST.COM
- Date:
- Wed Feb 15 09:48:15 2017 +0100
- Parent:
- 1:2a3ae13b45ef
- Child:
- 4:50ec00aa4515
- Child:
- 5:e541a0bc20c6
- Commit message:
- update 5.3.5
Changed in this revision
--- a/USBAudio/USBAudio.cpp Thu Dec 15 17:40:59 2016 +0100
+++ b/USBAudio/USBAudio.cpp Wed Feb 15 09:48:15 2017 +0100
@@ -85,7 +85,7 @@
SOF_handler = false;
writeIN = false;
if (interruptIN) {
- USBDevice::writeNB(EP3IN, buf_write, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
+ USBDevice::writeNB(EPISO_IN, buf_write, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
} else {
buf_stream_out = buf_write;
}
@@ -102,7 +102,7 @@
writeIN = false;
SOF_handler = false;
if (interruptIN) {
- USBDevice::writeNB(EP3IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
+ USBDevice::writeNB(EPISO_IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
} else {
buf_stream_out = buf;
}
@@ -113,6 +113,17 @@
return true;
}
+void USBAudio::writeSync(uint8_t *buf)
+{
+ USBDevice::writeNB(EPISO_IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
+}
+
+uint32_t USBAudio::readSync(uint8_t *buf)
+{
+ uint32_t size = 0;
+ USBDevice::readEP(EPISO_OUT, (uint8_t *)buf, &size, PACKET_SIZE_ISO_IN);
+ return size;
+}
float USBAudio::getVolume() {
return (mute) ? 0.0 : volume;
@@ -123,11 +134,15 @@
uint32_t size = 0;
interruptOUT = true;
if (buf_stream_in != NULL) {
- readEP(EP3OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN);
+ readEP(EPISO_OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN);
available = true;
buf_stream_in = NULL;
}
- readStart(EP3OUT, PACKET_SIZE_ISO_IN);
+ else {
+ if (rxDone)
+ rxDone.call();
+ }
+ readStart(EPISO_OUT, PACKET_SIZE_ISO_IN);
return false;
}
@@ -135,6 +150,8 @@
bool USBAudio::EPISO_IN_callback() {
interruptIN = true;
writeIN = true;
+ if (txDone)
+ txDone.call();
return true;
}
@@ -147,10 +164,10 @@
if (!interruptOUT) {
// read the isochronous endpoint
if (buf_stream_in != NULL) {
- if (USBDevice::readEP_NB(EP3OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN)) {
+ if (USBDevice::readEP_NB(EPISO_OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN)) {
if (size) {
available = true;
- readStart(EP3OUT, PACKET_SIZE_ISO_IN);
+ readStart(EPISO_OUT, PACKET_SIZE_ISO_IN);
buf_stream_in = NULL;
}
}
@@ -160,7 +177,7 @@
if (!interruptIN) {
// write if needed
if (buf_stream_out != NULL) {
- USBDevice::writeNB(EP3IN, (uint8_t *)buf_stream_out, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
+ USBDevice::writeNB(EPISO_IN, (uint8_t *)buf_stream_out, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
buf_stream_out = NULL;
}
}
@@ -177,11 +194,11 @@
}
// Configure isochronous endpoint
- realiseEndpoint(EP3OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS);
- realiseEndpoint(EP3IN, PACKET_SIZE_ISO_OUT, ISOCHRONOUS);
+ realiseEndpoint(EPISO_OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS);
+ realiseEndpoint(EPISO_IN, PACKET_SIZE_ISO_OUT, ISOCHRONOUS);
// activate readings on this endpoint
- readStart(EP3OUT, PACKET_SIZE_ISO_IN);
+ readStart(EPISO_OUT, PACKET_SIZE_ISO_IN);
return true;
}
--- a/USBAudio/USBAudio.h Thu Dec 15 17:40:59 2016 +0100
+++ b/USBAudio/USBAudio.h Wed Feb 15 09:48:15 2017 +0100
@@ -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
@@ -116,6 +124,12 @@
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)
*
* @param buf_read pointer on a buffer which will be filled with an audio packet
@@ -133,6 +147,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 +174,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:
@@ -277,6 +315,11 @@
// 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;
--- a/USBDevice/TARGET_STM/USBHAL_STM_TARGET.h Thu Dec 15 17:40:59 2016 +0100 +++ b/USBDevice/TARGET_STM/USBHAL_STM_TARGET.h Wed Feb 15 09:48:15 2017 +0100 @@ -15,14 +15,27 @@ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + #ifdef TARGET_STM32F303ZE #include "USBHAL_STM32F303ZE.h" #endif -#if defined(TARGET_STM32F429ZI) || defined(TARGET_STM32F446ZE) || defined(TARGET_STM32F207ZG) \ -|| defined(TARGET_STM32F767ZI) || defined (TARGET_STM32F746ZG) || defined(TARGET_STM32F411RE) \ -|| defined(TARGET_STM32F407VG) || defined(TARGET_STM32F401RE) + +#if defined(TARGET_STM32F207ZG) || \ + defined(TARGET_STM32F401RE) || \ + defined(TARGET_STM32F407VG) || \ + defined(TARGET_STM32F411RE) || \ + defined(TARGET_STM32F412ZG) || \ + defined(TARGET_STM32F429ZI) || \ + defined(TARGET_STM32F446ZE) || \ + defined(TARGET_STM32F746ZG) || \ + defined(TARGET_STM32F767ZI) #include "USBHAL_STM_144_64pins.h" #endif + #ifdef TARGET_STM32L476VG #include "USBHAL_STM32L476VG.h" #endif + +#ifdef TARGET_STM32F769NI +#include "USBHAL_STM32F769NI.h" +#endif
--- a/USBDevice/USBEndpoints.h Thu Dec 15 17:40:59 2016 +0100 +++ b/USBDevice/USBEndpoints.h Wed Feb 15 09:48:15 2017 +0100 @@ -53,6 +53,10 @@ #include "USBEndpoints_Maxim.h" #elif defined(TARGET_EFM32GG_STK3700) || defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32HG_STK3400) #include "USBEndpoints_EFM32.h" +#elif defined(TARGET_NUMAKER_PFM_NUC472) +#include "USBEndpoints_NUC472.h" +#elif defined(TARGET_NUMAKER_PFM_M453) +#include "USBEndpoints_M453.h" #else #error "Unknown target type" #endif
--- a/USBDevice/USBHAL.h Thu Dec 15 17:40:59 2016 +0100
+++ b/USBDevice/USBHAL.h Wed Feb 15 09:48:15 2017 +0100
@@ -68,6 +68,23 @@
virtual void suspendStateChanged(unsigned int suspended){};
virtual void SOF(int frameNumber){};
+#if defined(TARGET_NUMAKER_PFM_NUC472) || defined(TARGET_NUMAKER_PFM_M453)
+ // NUC472/M453 USB doesn't support configuration of the same EP number for IN/OUT simultaneously.
+ virtual bool EP1_OUT_callback(){return false;};
+ virtual bool EP2_IN_callback(){return false;};
+ virtual bool EP3_OUT_callback(){return false;};
+ virtual bool EP4_IN_callback(){return false;};
+ virtual bool EP5_OUT_callback(){return false;};
+ virtual bool EP6_IN_callback(){return false;};
+#if ! (defined(TARGET_NUMAKER_PFM_M453))
+ virtual bool EP7_OUT_callback(){return false;};
+ virtual bool EP8_IN_callback(){return false;};
+ virtual bool EP9_OUT_callback(){return false;};
+ virtual bool EP10_IN_callback(){return false;};
+ virtual bool EP11_OUT_callback(){return false;};
+ virtual bool EP12_IN_callback(){return false;};
+#endif
+#else
virtual bool EP1_OUT_callback(){return false;};
virtual bool EP1_IN_callback(){return false;};
virtual bool EP2_OUT_callback(){return false;};
@@ -102,6 +119,7 @@
virtual bool EP15_IN_callback(){return false;};
#endif
#endif
+#endif
private:
void usbisr(void);
@@ -110,10 +128,12 @@
#if defined(TARGET_LPC11UXX) || defined(TARGET_LPC11U6X) || defined(TARGET_LPC1347) || defined(TARGET_LPC1549)
bool (USBHAL::*epCallback[10 - 2])(void);
-#elif defined(TARGET_STM32F4) && !defined(USB_STM_HAL)
+#elif (defined(TARGET_STM32F4) && !defined(USB_STM_HAL)) || defined(TARGET_NUMAKER_PFM_M453)
bool (USBHAL::*epCallback[8 - 2])(void);
#elif defined(TARGET_STM32F4) || defined(TARGET_STM32F3) || defined (TARGET_STM32F2)|| defined(TARGET_STM32L4) || defined(TARGET_STM32F7)
PCD_HandleTypeDef hpcd;
+#elif defined(TARGET_NUMAKER_PFM_NUC472)
+ bool (USBHAL::*epCallback[14 - 2])(void);
#else
bool (USBHAL::*epCallback[32 - 2])(void);
#endif
--- a/USBDevice/USBHAL_STM32F4.cpp Thu Dec 15 17:40:59 2016 +0100
+++ b/USBDevice/USBHAL_STM32F4.cpp Wed Feb 15 09:48:15 2017 +0100
@@ -48,7 +48,7 @@
// Enable power and clocking
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
-#if defined(TARGET_STM32F407VG) || defined(TARGET_STM32F401RE) || defined(TARGET_STM32F411RE) || defined(TARGET_STM32F429ZI)
+#if defined(TARGET_STM32F407VG) || defined(TARGET_STM32F401RE) || defined(TARGET_STM32F411RE) || defined(TARGET_STM32F412ZG) || defined(TARGET_STM32F429ZI)
pin_function(PA_8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
pin_function(PA_9, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLDOWN, GPIO_AF10_OTG_FS));
pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS));
