aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usb/usb.c
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-10-21 17:50:39 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-10-21 18:13:05 -0400
commit1e51e683e3321256c07c146bdd0e3d246be31c34 (patch)
tree6b4194f6fa74b5b7c9f5b6ace56e3454f7ee2aab /libmaple/usb/usb.c
parent298494be23f188b8dba8b8322898e1de50963147 (diff)
downloadlibrambutan-1e51e683e3321256c07c146bdd0e3d246be31c34.tar.gz
librambutan-1e51e683e3321256c07c146bdd0e3d246be31c34.zip
USB: API cleanups.
Remove usbSuspend(), usbResumeInit(), usbResume(), the USB low-priority IRQ, and usbWaitReset() from usb.h. Also remove RESUME_STATE since it was only there for usbResume(). These functions don't need to be seen by anybody except for usb.c and usb_cdcacm.c, so move them there (altering their names to fit with libmaple style guidelines) and mark them static. Clean up includes in usb.c while we're there. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple/usb/usb.c')
-rw-r--r--libmaple/usb/usb.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index ec189d6..00ba4ef 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -32,9 +32,6 @@
#include "usb.h"
#include "libmaple.h"
-#include "gpio.h"
-#include "delay.h"
-#include "nvic.h"
#include "rcc.h"
#include "usb_reg_map.h"
@@ -56,6 +53,17 @@ uint16 SaveRState; /* caches RX status for later use */
* Other state
*/
+typedef enum {
+ RESUME_EXTERNAL,
+ RESUME_INTERNAL,
+ RESUME_LATER,
+ RESUME_WAIT,
+ RESUME_START,
+ RESUME_ON,
+ RESUME_OFF,
+ RESUME_ESOF
+} RESUME_STATE;
+
struct {
volatile RESUME_STATE eState;
volatile uint8 bESOFcnt;
@@ -89,11 +97,11 @@ void usb_init_usblib(void (**ep_int_in)(void), void (**ep_int_out)(void)) {
pProperty->Init();
}
-void usbSuspend(void) {
+static void usb_suspend(void) {
uint16 cntr;
/* TODO decide if read/modify/write is really what we want
- * (e.g. usbResumeInit() reconfigures CNTR). */
+ * (e.g. usb_resume_init() reconfigures CNTR). */
cntr = USB_BASE->CNTR;
cntr |= USB_CNTR_FSUSP;
USB_BASE->CNTR = cntr;
@@ -103,7 +111,7 @@ void usbSuspend(void) {
USBLIB->state = USB_SUSPENDED;
}
-void usbResumeInit(void) {
+static void usb_resume_init(void) {
uint16 cntr;
cntr = USB_BASE->CNTR;
@@ -114,7 +122,7 @@ void usbResumeInit(void) {
USB_BASE->CNTR = USB_ISR_MSK;
}
-void usbResume(RESUME_STATE eResumeSetVal) {
+static void usb_resume(RESUME_STATE eResumeSetVal) {
uint16 cntr;
if (eResumeSetVal != RESUME_ESOF)
@@ -123,11 +131,11 @@ void usbResume(RESUME_STATE eResumeSetVal) {
switch (ResumeS.eState)
{
case RESUME_EXTERNAL:
- usbResumeInit();
+ usb_resume_init();
ResumeS.eState = RESUME_OFF;
break;
case RESUME_INTERNAL:
- usbResumeInit();
+ usb_resume_init();
ResumeS.eState = RESUME_START;
break;
case RESUME_LATER:
@@ -191,7 +199,7 @@ void __irq_usb_lp_can_rx0(void) {
#if (USB_ISR_MSK & USB_ISTR_WKUP)
if (istr & USB_ISTR_WKUP & USBLIB->irq_mask) {
USB_BASE->ISTR = ~USB_ISTR_WKUP;
- usbResume(RESUME_EXTERNAL);
+ usb_resume(RESUME_EXTERNAL);
}
#endif
@@ -199,10 +207,10 @@ void __irq_usb_lp_can_rx0(void) {
if (istr & USB_ISTR_SUSP & USBLIB->irq_mask) {
/* check if SUSPEND is possible */
if (SUSPEND_ENABLED) {
- usbSuspend();
+ usb_suspend();
} else {
/* if not possible then resume after xx ms */
- usbResume(RESUME_LATER);
+ usb_resume(RESUME_LATER);
}
/* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
USB_BASE->ISTR = ~USB_ISTR_SUSP;
@@ -219,7 +227,7 @@ void __irq_usb_lp_can_rx0(void) {
if (istr & USB_ISTR_ESOF & USBLIB->irq_mask) {
USB_BASE->ISTR = ~USB_ISTR_ESOF;
/* resume handling timing is made with ESOFs */
- usbResume(RESUME_ESOF); /* request without change of the machine state */
+ usb_resume(RESUME_ESOF); /* request without change of the machine state */
}
#endif
@@ -234,12 +242,6 @@ void __irq_usb_lp_can_rx0(void) {
#endif
}
-#define RESET_DELAY 100000
-void usbWaitReset(void) {
- delay_us(RESET_DELAY);
- nvic_sys_reset();
-}
-
uint8 usbIsConfigured() {
return USBLIB->state == USB_CONFIGURED;
}