aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmaple/usb/usb.c10
-rw-r--r--libmaple/usb/usb.h5
-rw-r--r--libmaple/usb/usb_config.h42
-rw-r--r--wirish/boards.cpp2
-rw-r--r--wirish/boards/maple.h5
-rw-r--r--wirish/boards/maple_RET6.h3
-rw-r--r--wirish/boards/maple_mini.h3
-rw-r--r--wirish/boards/maple_native.h3
-rw-r--r--wirish/boards/olimex_stm32_h103.h4
-rw-r--r--wirish/usb_serial.cpp4
10 files changed, 39 insertions, 42 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 651b36e..9b70b6b 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -99,22 +99,22 @@ struct {
volatile uint8 bESOFcnt;
} ResumeS;
-void setupUSB (void) {
- gpio_set_mode(USB_DISC_DEV, USB_DISC_PIN, GPIO_OUTPUT_PP);
+void setupUSB (gpio_dev *disc_dev, uint8 disc_bit) {
+ gpio_set_mode(disc_dev, disc_bit, GPIO_OUTPUT_PP);
/* setup the apb1 clock for USB */
pRCC->APB1ENR |= 0x00800000;
/* initialize the usb application */
- gpio_write_bit(USB_DISC_DEV, USB_DISC_PIN, 0); // presents us to the host
+ gpio_write_bit(disc_dev, disc_bit, 0); // presents us to the host
USB_Init(); // low level init routine provided by the ST library
}
-void disableUSB (void) {
+void disableUSB (gpio_dev *disc_dev, uint8 disc_bit) {
// These are just guesses about how to do this
// TODO: real disable function
usbDsbISR();
- gpio_write_bit(USB_DISC_DEV, USB_DISC_PIN, 1);
+ gpio_write_bit(disc_dev, disc_bit, 1);
}
void usbSuspend(void) {
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index c724c54..0df3c8d 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -29,6 +29,7 @@
#include "usb_lib.h"
#include "libmaple.h"
+#include "gpio.h"
#ifdef __cplusplus
extern "C" {
@@ -56,8 +57,8 @@ typedef enum {
extern volatile uint32 bDeviceState;
-void setupUSB(void);
-void disableUSB(void);
+void setupUSB(gpio_dev*, uint8);
+void disableUSB(gpio_dev*, uint8);
void usbSuspend(void);
void usbResumeInit(void);
void usbResume(RESUME_STATE);
diff --git a/libmaple/usb/usb_config.h b/libmaple/usb/usb_config.h
index 62a6a71..6eb88a5 100644
--- a/libmaple/usb/usb_config.h
+++ b/libmaple/usb/usb_config.h
@@ -25,42 +25,20 @@
*****************************************************************************/
#define VCOM_ID_VENDOR 0x1EAF
+#define VCOM_ID_PRODUCT 0x0004
#define RESET_DELAY (100000)
#define USB_CONFIG_MAX_POWER (100 >> 1)
-#if defined(BOARD_maple) || defined(BOARD_maple_RET6)
+#if !(defined(BOARD_maple) || defined(BOARD_maple_RET6) || \
+ defined(BOARD_maple_mini) || defined(BOARD_maple_native))
- /* USB Identifier numbers */
- #define VCOM_ID_PRODUCT 0x0004
- #define USB_DISC_DEV GPIOC
- #define USB_DISC_PIN 12
-
-#elif defined(BOARD_maple_mini)
-
- #define VCOM_ID_PRODUCT 0x0004
- #define USB_DISC_DEV GPIOB
- #define USB_DISC_PIN 9
-
-#elif defined(BOARD_maple_native)
-
- #define VCOM_ID_PRODUCT 0x0004
- #define USB_DISC_DEV GPIOB
- #define USB_DISC_PIN 8
-
-#elif defined(BOARD_olimex_stm32_h103)
-
- #define VCOM_ID_PRODUCT 0x0004
- #define USB_DISC_DEV GPIOC
- #define USB_DISC_PIN 11
-
-#else
-
-#error ("Sorry! the USB stack relies on LeafLabs board-specific " \
- "configuration right now. If you want, you can pretend you're one " \
- "of our boards; i.e., #define BOARD_maple, BOARD_maple_mini, or " \
- "BOARD_maple_native according to what matches your MCU best. " \
- "You should also take a look at libmaple/usb/descriptors.c; we make " \
- "some assumptions there that you probably won't like.")
+#warning ("Warning! The USB stack relies on LeafLabs board-specific " \
+ "configuration right now. If you want, you can pretend " \
+ "you're one of our boards; i.e., #define BOARD_maple, " \
+ "BOARD_maple_mini, etc. according to what matches your MCU " \
+ "best. You should also take a look at " \
+ "libmaple/usb/descriptors.c; " \
+ "we make some assumptions there that you probably won't like.")
#endif
diff --git a/wirish/boards.cpp b/wirish/boards.cpp
index 5cdc4d1..1b921ac 100644
--- a/wirish/boards.cpp
+++ b/wirish/boards.cpp
@@ -58,7 +58,7 @@ void init(void) {
afio_init();
setupADC();
setupTimers();
- setupUSB();
+ setupUSB(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
boardInit();
}
diff --git a/wirish/boards/maple.h b/wirish/boards/maple.h
index e26de99..a986884 100644
--- a/wirish/boards/maple.h
+++ b/wirish/boards/maple.h
@@ -84,4 +84,9 @@
#define BOARD_JTDO_PIN 42
#define BOARD_NJTRST_PIN 43
+/* USB configuration. BOARD_USB_DISC_DEV is the GPIO port containing
+ * the USB_DISC pin, and BOARD_USB_DISC_BIT is that pin's bit. */
+#define BOARD_USB_DISC_DEV GPIOC
+#define BOARD_USB_DISC_BIT 12
+
#endif
diff --git a/wirish/boards/maple_RET6.h b/wirish/boards/maple_RET6.h
index 352d565..9e7ce9d 100644
--- a/wirish/boards/maple_RET6.h
+++ b/wirish/boards/maple_RET6.h
@@ -85,4 +85,7 @@
#define BOARD_JTDO_PIN 42
#define BOARD_NJTRST_PIN 43
+#define BOARD_USB_DISC_DEV GPIOC
+#define BOARD_USB_DISC_BIT 12
+
#endif
diff --git a/wirish/boards/maple_mini.h b/wirish/boards/maple_mini.h
index 7bf7016..40f507b 100644
--- a/wirish/boards/maple_mini.h
+++ b/wirish/boards/maple_mini.h
@@ -70,4 +70,7 @@
#define BOARD_JTDO_PIN 19
#define BOARD_NJTRST_PIN 18
+#define BOARD_USB_DISC_DEV GPIOB
+#define BOARD_USB_DISC_BIT 9
+
#endif
diff --git a/wirish/boards/maple_native.h b/wirish/boards/maple_native.h
index f575bfb..7c09014 100644
--- a/wirish/boards/maple_native.h
+++ b/wirish/boards/maple_native.h
@@ -77,4 +77,7 @@
#define BOARD_JTDO_PIN 104
#define BOARD_NJTRST_PIN 105
+#define BOARD_USB_DISC_DEV GPIOB
+#define BOARD_USB_DISC_BIT 8
+
#endif
diff --git a/wirish/boards/olimex_stm32_h103.h b/wirish/boards/olimex_stm32_h103.h
index e2d5236..d2b5fcc 100644
--- a/wirish/boards/olimex_stm32_h103.h
+++ b/wirish/boards/olimex_stm32_h103.h
@@ -85,4 +85,8 @@
#define BOARD_JTDO_PIN 44
#define BOARD_NJTRST_PIN 45
+/* USB configuration */
+#define BOARD_USB_DISC_DEV GPIOC
+#define BOARD_USB_DISC_BIT 11
+
#endif
diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp
index 0a2be43..927f7fc 100644
--- a/wirish/usb_serial.cpp
+++ b/wirish/usb_serial.cpp
@@ -39,11 +39,11 @@ USBSerial::USBSerial(void) {
}
void USBSerial::begin(void) {
- setupUSB();
+ setupUSB(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
}
void USBSerial::end(void) {
- disableUSB();
+ disableUSB(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
}
void USBSerial::write(uint8 ch) {