* V1.20 Added USB_ClearEPBuf
* V1.00 Initial Version
*----------------------------------------------------------------------------*/
-#include "projectconfig.h" /* LPC13xx definitions */
+#include "projectconfig.h"
#include "usb.h"
#include "usbcfg.h"
#include "usbreg.h"
* Return Value: None
*/
-void delay (uint32_t length )
-{
+void delay (uint32_t length ) {
uint32_t i;
for ( i = 0; i < length; i++ )
{
- __asm("nop");
+ __asm volatile("nop");
}
return;
}
* Return Value: Endpoint Physical Address
*/
-uint32_t EPAdr (uint32_t EPNum)
-{
+uint32_t EPAdr (uint32_t EPNum) {
uint32_t val;
val = (EPNum & 0x0F) << 1;
* Return Value: None
*/
-void WrCmd (uint32_t cmd)
-{
+void WrCmd (uint32_t cmd) {
+
USB_DEVINTCLR = CCEMTY_INT;
USB_CMDCODE = cmd;
while ((USB_DEVINTST & (CCEMTY_INT | DEV_STAT_INT)) == 0);
* Return Value: None
*/
-void WrCmdDat (uint32_t cmd, uint32_t val)
-{
+void WrCmdDat (uint32_t cmd, uint32_t val) {
+
WrCmd(cmd);
WrCmd(val);
}
* Return Value: None
*/
-void WrCmdEP (uint32_t EPNum, uint32_t cmd)
-{
+void WrCmdEP (uint32_t EPNum, uint32_t cmd){
+
WrCmd(CMD_SEL_EP(EPAdr(EPNum)));
WrCmd(cmd);
}
* Return Value: Data Value
*/
-uint32_t RdCmdDat (uint32_t cmd)
-{
+uint32_t RdCmdDat (uint32_t cmd) {
+
USB_DEVINTCLR = CCEMTY_INT | CDFULL_INT;
USB_CMDCODE = cmd;
while ((USB_DEVINTST & (CDFULL_INT | DEV_STAT_INT)) == 0);
* Return Value: None
*/
-void USB_Init (void)
-{
+void USB_Init (void) {
+
// Setup USB clock and pins
USBIOClkConfig();
* Return Value: None
*/
-void USB_Connect (uint32_t con)
-{
+void USB_Connect (uint32_t con) {
WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(con ? DEV_CON : 0));
}
* Return Value: None
*/
-void USB_Reset (void)
-{
+void USB_Reset (void) {
+
USB_DEVINTCLR = 0x000FFFFF;
/* Enable all eight(8) EPs, note: EP won't be ready until it's
configured/enabled when device sending SetEPStatus command
* Return Value: None
*/
-void USB_Suspend (void)
-{
+void USB_Suspend (void) {
/* Performed by Hardware */
}
* Return Value: None
*/
-void USB_Resume (void)
-{
+void USB_Resume (void) {
/* Performed by Hardware */
}
* Return Value: None
*/
-void USB_WakeUp (void)
-{
- if (USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP)
- {
+void USB_WakeUp (void) {
+
+ if (USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP) {
WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON));
}
}
* Return Value: None
*/
-void USB_WakeUpCfg (uint32_t cfg)
-{
+void USB_WakeUpCfg (uint32_t cfg) {
cfg = cfg; /* Not needed */
}
* Return Value: None
*/
-void USB_SetAddress (uint32_t adr)
-{
+void USB_SetAddress (uint32_t adr) {
WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Don't wait for next */
WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Setup Status Phase */
}
* Return Value: None
*/
-void USB_Configure (uint32_t cfg)
-{
+void USB_Configure (uint32_t cfg) {
+
WrCmdDat(CMD_CFG_DEV, DAT_WR_BYTE(cfg ? CONF_DVICE : 0));
return;
}
* Return Value: None
*/
-void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD)
-{
+void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) {
return;
}
* Return Value: None
*/
-void USB_DirCtrlEP (uint32_t dir)
-{
+void USB_DirCtrlEP (uint32_t dir) {
dir = dir; /* Not needed */
}
* Return Value: None
*/
-void USB_EnableEP (uint32_t EPNum)
-{
+void USB_EnableEP (uint32_t EPNum) {
WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0));
}
* Return Value: None
*/
-void USB_DisableEP (uint32_t EPNum)
-{
+void USB_DisableEP (uint32_t EPNum) {
WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(EP_STAT_DA));
}
* Return Value: None
*/
-void USB_ResetEP (uint32_t EPNum)
-{
+void USB_ResetEP (uint32_t EPNum) {
WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0));
}
* Return Value: None
*/
-void USB_SetStallEP (uint32_t EPNum)
-{
+void USB_SetStallEP (uint32_t EPNum) {
WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(EP_STAT_ST));
}
* Return Value: None
*/
-void USB_ClrStallEP (uint32_t EPNum)
-{
+void USB_ClrStallEP (uint32_t EPNum) {
WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0));
}
* Return Value: None
*/
-void USB_ClearEPBuf (uint32_t EPNum)
-{
+void USB_ClearEPBuf (uint32_t EPNum) {
WrCmdEP(EPNum, CMD_CLR_BUF);
}
* Return Value: Number of bytes read
*/
-uint32_t USB_ReadEP (uint32_t EPNum, uint8_t *pData)
-{
+uint32_t USB_ReadEP (uint32_t EPNum, uint8_t *pData) {
uint32_t cnt, n;
USB_CTRL = ((EPNum & 0x0F) << 2) | CTRL_RD_EN;
/* 3 clock cycles to fetch the packet length from RAM. */
delay( 5 );
- do
- {
+ do {
cnt = USB_RXPLEN;
} while ((cnt & PKT_DV) == 0);
cnt &= PKT_LNGTH_MASK;
- for (n = 0; n < (cnt + 3) / 4; n++)
- {
+ for (n = 0; n < (cnt + 3) / 4; n++) {
*((uint32_t __attribute__((packed)) *)pData) = USB_RXDATA;
pData += 4;
}
USB_CTRL = 0;
- if ((EPNum & 0x80) != 0x04)
- { /* Non-Isochronous Endpoint */
+ if ((EPNum & 0x80) != 0x04) { /* Non-Isochronous Endpoint */
WrCmdEP(EPNum, CMD_CLR_BUF);
}
* Return Value: Number of bytes written
*/
-uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt)
-{
+uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt) {
uint32_t n;
USB_CTRL = ((EPNum & 0x0F) << 2) | CTRL_WR_EN;
delay( 5 );
USB_TXPLEN = cnt;
- for (n = 0; n < (cnt + 3) / 4; n++)
- {
+ for (n = 0; n < (cnt + 3) / 4; n++) {
USB_TXDATA = *((uint32_t __attribute__((packed)) *)pData);
pData += 4;
}
* Return Value: Frame Number
*/
-uint32_t USB_GetFrame (void)
-{
+uint32_t USB_GetFrame (void) {
uint32_t val;
WrCmd(CMD_RD_FRAME);
USB_DEVINTCLR = disr;
/* Device Status Interrupt (Reset, Connect change, Suspend/Resume) */
- if (disr & DEV_STAT_INT)
- {
+ if (disr & DEV_STAT_INT) {
WrCmd(CMD_GET_DEV_STAT);
val = RdCmdDat(DAT_GET_DEV_STAT); /* Device Status */
if (val & DEV_RST) { /* Reset */
#if USB_SOF_EVENT
/* Start of Frame Interrupt */
- if (disr & FRAME_INT)
- {
+ if (disr & FRAME_INT) {
USB_DEVINTCLR = FRAME_INT;
USB_SOF_Event();
- // SOFIRQCount++;
+ SOFIRQCount++;
}
#endif
/* NO error interrupt anymore, below code can be used
as example to get error status from command engine. */
/* Error Interrupt */
- if (disr & ERR_INT)
- {
+ if (disr & ERR_INT) {
WrCmd(CMD_RD_ERR_STAT);
val = RdCmdDat(DAT_RD_ERR_STAT);
USB_Error_Event(val);
isr_end:
return;
}
-
#endif