aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usb
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-08-10 15:45:30 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-10-18 13:30:18 -0400
commit00c5efa7b637ee6ef1878eb870eff140f2af94a8 (patch)
tree827e4de89378c9ec1565d55a985b546a9a670e74 /libmaple/usb
parentbbcbf65fd7d074268f4e25ae014965bceb995b79 (diff)
downloadlibrambutan-00c5efa7b637ee6ef1878eb870eff140f2af94a8.tar.gz
librambutan-00c5efa7b637ee6ef1878eb870eff140f2af94a8.zip
Remove usb_config.h.
Move its defines into usb_cdcacm.c and usb.[hc] as appropriate. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple/usb')
-rw-r--r--libmaple/usb/usb.c25
-rw-r--r--libmaple/usb/usb.h6
-rw-r--r--libmaple/usb/usb_cdcacm.c14
3 files changed, 28 insertions, 17 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 21a19db..0206bb8 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -38,7 +38,6 @@
#include "rcc.h"
#include "usb_reg_map.h"
-#include "usb_config.h"
#include "usb_lib_globals.h"
#include "usb_type.h"
@@ -109,7 +108,7 @@ void usbResumeInit(void) {
USB_BASE->CNTR = cntr;
/* Enable interrupt lines */
- USB_BASE->CNTR = ISR_MSK;
+ USB_BASE->CNTR = USB_ISR_MSK;
}
void usbResume(RESUME_STATE eResumeSetVal) {
@@ -161,41 +160,42 @@ void usbResume(RESUME_STATE eResumeSetVal) {
}
}
+#define SUSPEND_ENABLED 1
void __irq_usb_lp_can_rx0(void) {
wIstr = USB_BASE->ISTR;
- /* Use ISR_MSK to only include code for bits we care about. */
+ /* Use USB_ISR_MSK to only include code for bits we care about. */
-#if (ISR_MSK & USB_ISTR_RESET)
+#if (USB_ISR_MSK & USB_ISTR_RESET)
if (wIstr & USB_ISTR_RESET & wInterrupt_Mask) {
USB_BASE->ISTR = ~USB_ISTR_RESET;
pProperty->Reset();
}
#endif
-#if (ISR_MSK & USB_ISTR_PMAOVR)
+#if (USB_ISR_MSK & USB_ISTR_PMAOVR)
if (wIstr & ISTR_PMAOVR & wInterrupt_Mask) {
USB_BASE->ISTR = ~USB_ISTR_PMAOVR;
}
#endif
-#if (ISR_MSK & USB_ISTR_ERR)
+#if (USB_ISR_MSK & USB_ISTR_ERR)
if (wIstr & USB_ISTR_ERR & wInterrupt_Mask) {
USB_BASE->ISTR = ~USB_ISTR_ERR;
}
#endif
-#if (ISR_MSK & USB_ISTR_WKUP)
+#if (USB_ISR_MSK & USB_ISTR_WKUP)
if (wIstr & USB_ISTR_WKUP & wInterrupt_Mask) {
USB_BASE->ISTR = ~USB_ISTR_WKUP;
usbResume(RESUME_EXTERNAL);
}
#endif
-#if (ISR_MSK & USB_ISTR_SUSP)
+#if (USB_ISR_MSK & USB_ISTR_SUSP)
if (wIstr & USB_ISTR_SUSP & wInterrupt_Mask) {
/* check if SUSPEND is possible */
- if (F_SUSPEND_ENABLED) {
+ if (SUSPEND_ENABLED) {
usbSuspend();
} else {
/* if not possible then resume after xx ms */
@@ -206,14 +206,14 @@ void __irq_usb_lp_can_rx0(void) {
}
#endif
-#if (ISR_MSK & USB_ISTR_SOF)
+#if (USB_ISR_MSK & USB_ISTR_SOF)
if (wIstr & USB_ISTR_SOF & wInterrupt_Mask) {
USB_BASE->ISTR = ~USB_ISTR_SOF;
bIntPackSOF++;
}
#endif
-#if (ISR_MSK & USB_ISTR_ESOF)
+#if (USB_ISR_MSK & USB_ISTR_ESOF)
if (wIstr & USB_ISTR_ESOF & wInterrupt_Mask) {
USB_BASE->ISTR = ~USB_ISTR_ESOF;
/* resume handling timing is made with ESOFs */
@@ -225,13 +225,14 @@ void __irq_usb_lp_can_rx0(void) {
* Service the correct transfer interrupt.
*/
-#if (ISR_MSK & USB_ISTR_CTR)
+#if (USB_ISR_MSK & USB_ISTR_CTR)
if (wIstr & USB_ISTR_CTR & wInterrupt_Mask) {
dispatch_ctr_lp();
}
#endif
}
+#define RESET_DELAY 100000
void usbWaitReset(void) {
delay_us(RESET_DELAY);
nvic_sys_reset();
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index da6fa55..8ab40f0 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -34,6 +34,12 @@
extern "C" {
#endif
+#ifndef USB_ISR_MSK
+/* Handle CTRM, WKUPM, SUSPM, ERRM, SOFM, ESOFM, RESETM */
+#define USB_ISR_MSK 0xBF00
+#endif
+
+
/*
* Convenience routines, etc.
*/
diff --git a/libmaple/usb/usb_cdcacm.c b/libmaple/usb/usb_cdcacm.c
index 1a3b4e6..bf73c68 100644
--- a/libmaple/usb/usb_cdcacm.c
+++ b/libmaple/usb/usb_cdcacm.c
@@ -36,7 +36,6 @@
#include "nvic.h"
#include "usb.h"
-#include "usb_config.h"
#include "descriptors.h"
#include "usb_lib_globals.h"
#include "usb_reg_map.h"
@@ -136,6 +135,7 @@ const USB_Descriptor_Device usbVcomDescriptor_Device = {
.bNumConfigurations = 0x01,
};
+#define MAX_POWER (100 >> 1)
const USB_Descriptor_Config usbVcomDescriptor_Config = {
.Config_Header = {
.bLength = sizeof(USB_Descriptor_Config_Header),
@@ -146,7 +146,7 @@ const USB_Descriptor_Config usbVcomDescriptor_Config = {
.iConfiguration = 0x00,
.bmAttributes = (USB_CONFIG_ATTR_BUSPOWERED |
USB_CONFIG_ATTR_SELF_POWERED),
- .bMaxPower = USB_CONFIG_MAX_POWER,
+ .bMaxPower = MAX_POWER,
},
.CCI_Interface = {
@@ -402,13 +402,15 @@ void usbInit(void) {
usbPowerOn();
USB_BASE->ISTR = 0;
- wInterrupt_Mask = ISR_MSK;
+ wInterrupt_Mask = USB_ISR_MSK;
USB_BASE->CNTR = wInterrupt_Mask;
nvic_irq_enable(NVIC_USB_LP_CAN_RX0);
bDeviceState = UNCONNECTED;
}
+/* choose addresses to give endpoints the max 64 byte buffers */
+#define BTABLE_ADDRESS 0x00
void usbReset(void) {
pInformation->Current_Configuration = 0;
@@ -416,7 +418,7 @@ void usbReset(void) {
pInformation->Current_Feature = (USB_CONFIG_ATTR_BUSPOWERED |
USB_CONFIG_ATTR_SELF_POWERED);
- USB_BASE->BTABLE = USB_BTABLE_ADDRESS;
+ USB_BASE->BTABLE = BTABLE_ADDRESS;
/* setup control endpoint 0 */
usb_set_ep_type(USB_EP0, USB_EP_EP_TYPE_CONTROL);
@@ -595,10 +597,12 @@ void usbSetDeviceAddress(void) {
* Globals required by usb_lib/
*/
+#define NUM_ENDPTS 0x04
DEVICE Device_Table =
{NUM_ENDPTS,
1};
+#define MAX_PACKET_SIZE 0x40 /* 64B, maximum for USB FS Devices */
DEVICE_PROP Device_Property =
{usbInit,
usbReset,
@@ -611,7 +615,7 @@ DEVICE_PROP Device_Property =
usbGetConfigDescriptor,
usbGetStringDescriptor,
0,
- bMaxPacketSize};
+ MAX_PACKET_SIZE};
USER_STANDARD_REQUESTS User_Standard_Requests =
{NOP_Process,