Added backlight, reset, triangle and corner commands
[hackover2013-badge-firmware.git] / core / usbcdc / usbhw.c
index fdc88f1..88add23 100644 (file)
@@ -19,7 +19,7 @@
  *          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"
@@ -79,13 +79,12 @@ void USBIOClkConfig( void )
  *    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;
 }
@@ -98,8 +97,7 @@ void delay (uint32_t length )
  *    Return Value:    Endpoint Physical Address
  */
 
-uint32_t EPAdr (uint32_t EPNum) 
-{
+uint32_t EPAdr (uint32_t EPNum) {
   uint32_t val;
 
   val = (EPNum & 0x0F) << 1;
@@ -116,8 +114,8 @@ uint32_t EPAdr (uint32_t EPNum)
  *    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);
@@ -131,8 +129,8 @@ void WrCmd (uint32_t cmd)
  *    Return Value:    None
  */
 
-void WrCmdDat (uint32_t cmd, uint32_t val) 
-{
+void WrCmdDat (uint32_t cmd, uint32_t val) {
+
   WrCmd(cmd);
   WrCmd(val);
 }
@@ -145,8 +143,8 @@ void WrCmdDat (uint32_t cmd, uint32_t 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);
 }
@@ -158,8 +156,8 @@ void WrCmdEP (uint32_t EPNum, uint32_t 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);
@@ -173,8 +171,8 @@ uint32_t RdCmdDat (uint32_t cmd)
  *    Return Value:    None
  */
 
-void USB_Init (void) 
-{
+void USB_Init (void) {
+
   // Setup USB clock and pins
   USBIOClkConfig();  
 
@@ -203,8 +201,7 @@ void USB_Init (void)
  *    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));
 }
 
@@ -215,8 +212,8 @@ void USB_Connect (uint32_t con)
  *    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 
@@ -233,8 +230,7 @@ void USB_Reset (void)
  *    Return Value:    None
  */
 
-void USB_Suspend (void) 
-{
+void USB_Suspend (void) {
   /* Performed by Hardware */
 }
 
@@ -245,8 +241,7 @@ void USB_Suspend (void)
  *    Return Value:    None
  */
 
-void USB_Resume (void) 
-{
+void USB_Resume (void) {
   /* Performed by Hardware */
 }
 
@@ -257,10 +252,9 @@ void USB_Resume (void)
  *    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));
   }
 }
@@ -272,8 +266,7 @@ void USB_WakeUp (void)
  *    Return Value:    None
  */
 
-void USB_WakeUpCfg (uint32_t cfg) 
-{
+void USB_WakeUpCfg (uint32_t cfg) {
   cfg = cfg;  /* Not needed */
 }
 
@@ -284,8 +277,7 @@ void USB_WakeUpCfg (uint32_t cfg)
  *    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 */
 }
@@ -297,8 +289,8 @@ void USB_SetAddress (uint32_t adr)
  *    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;
 }
@@ -310,8 +302,7 @@ void USB_Configure (uint32_t cfg)
  *    Return Value:    None
  */
 
-void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) 
-{
+void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) {
   return;
 }
 
@@ -322,8 +313,7 @@ void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD)
  *    Return Value:    None
  */
 
-void USB_DirCtrlEP (uint32_t dir) 
-{
+void USB_DirCtrlEP (uint32_t dir) {
   dir = dir;  /* Not needed */
 }
 
@@ -336,8 +326,7 @@ void USB_DirCtrlEP (uint32_t dir)
  *    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));
 }
 
@@ -350,8 +339,7 @@ void USB_EnableEP (uint32_t EPNum)
  *    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));
 }
 
@@ -364,8 +352,7 @@ void USB_DisableEP (uint32_t EPNum)
  *    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));
 }
 
@@ -378,8 +365,7 @@ void USB_ResetEP (uint32_t EPNum)
  *    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));
 }
 
@@ -392,8 +378,7 @@ void USB_SetStallEP (uint32_t EPNum)
  *    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));
 }
 
@@ -406,8 +391,7 @@ void USB_ClrStallEP (uint32_t EPNum)
  *    Return Value:    None
  */
 
-void USB_ClearEPBuf (uint32_t EPNum) 
-{
+void USB_ClearEPBuf (uint32_t EPNum) {
   WrCmdEP(EPNum, CMD_CLR_BUF);
 }
 
@@ -421,30 +405,26 @@ void USB_ClearEPBuf (uint32_t EPNum)
  *    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);
   }
 
@@ -462,8 +442,7 @@ uint32_t USB_ReadEP (uint32_t EPNum, uint8_t *pData)
  *    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;
@@ -471,8 +450,7 @@ uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt)
   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;
   }
@@ -490,8 +468,7 @@ uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt)
  *    Return Value:    Frame Number
  */
 
-uint32_t USB_GetFrame (void) 
-{
+uint32_t USB_GetFrame (void) {
   uint32_t val;
 
   WrCmd(CMD_RD_FRAME);
@@ -515,8 +492,7 @@ void USB_IRQHandler (void)
   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 */
@@ -548,11 +524,10 @@ void USB_IRQHandler (void)
 
 #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
 
@@ -560,8 +535,7 @@ void USB_IRQHandler (void)
   /* 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);
@@ -602,5 +576,4 @@ void USB_IRQHandler (void)
 isr_end:
   return;
 }
-
 #endif
This page took 0.036326 seconds and 4 git commands to generate.