aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usb/usb.c
diff options
context:
space:
mode:
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;
}