aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/usb/usb.c40
-rw-r--r--libmaple/usb/usb.h19
-rw-r--r--libmaple/usb/usb_cdcacm.c11
3 files changed, 31 insertions, 39 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;
}
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index 077128f..988c923 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -66,27 +66,8 @@ extern usblib_dev *USBLIB;
* Convenience routines, etc.
*/
-typedef enum {
- RESUME_EXTERNAL,
- RESUME_INTERNAL,
- RESUME_LATER,
- RESUME_WAIT,
- RESUME_START,
- RESUME_ON,
- RESUME_OFF,
- RESUME_ESOF
-} RESUME_STATE;
-
void usb_init_usblib(void (**ep_int_in)(void), void (**ep_int_out)(void));
-void usbSuspend(void);
-void usbResumeInit(void);
-void usbResume(RESUME_STATE);
-
-/* overloaded ISR routine, this is the main usb ISR */
-void __irq_usb_lp_can_rx0(void);
-void usbWaitReset(void);
-
uint8 usbIsConnected(void);
uint8 usbIsConfigured(void);
diff --git a/libmaple/usb/usb_cdcacm.c b/libmaple/usb/usb_cdcacm.c
index d2f6eba..fe06166 100644
--- a/libmaple/usb/usb_cdcacm.c
+++ b/libmaple/usb/usb_cdcacm.c
@@ -34,6 +34,7 @@
#include "usb_cdcacm.h"
#include "nvic.h"
+#include "delay.h"
#include "usb.h"
#include "descriptors.h"
@@ -81,6 +82,8 @@ static uint8* usbGetStringDescriptor(uint16 length);
static void usbSetConfiguration(void);
static void usbSetDeviceAddress(void);
+static void wait_reset(void);
+
/*
* VCOM config
*/
@@ -510,7 +513,7 @@ static void vcomDataRxCb(void) {
reset_state = DTR_LOW;
if (newBytes >= 4) {
- unsigned int target = (unsigned int)usbWaitReset | 0x1;
+ unsigned int target = (unsigned int)wait_reset | 0x1;
usb_copy_from_pma(chkBuf, 4, VCOM_RX_ADDR);
@@ -751,3 +754,9 @@ static void usbSetConfiguration(void) {
static void usbSetDeviceAddress(void) {
USBLIB->state = USB_ADDRESSED;
}
+
+#define RESET_DELAY 100000
+static void wait_reset(void) {
+ delay_us(RESET_DELAY);
+ nvic_sys_reset();
+}