aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/usb/usb.c19
-rw-r--r--libmaple/usb/usb.h24
-rw-r--r--libmaple/usb/usb_cdcacm.c2
3 files changed, 22 insertions, 23 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 00ba4ef..667b11f 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -72,6 +72,7 @@ struct {
static usblib_dev usblib = {
.irq_mask = USB_ISR_MSK,
.state = USB_UNCONNECTED,
+ .clk_id = RCC_USB,
};
usblib_dev *USBLIB = &usblib;
@@ -79,11 +80,13 @@ usblib_dev *USBLIB = &usblib;
* Routines
*/
-void usb_init_usblib(void (**ep_int_in)(void), void (**ep_int_out)(void)) {
- rcc_clk_enable(RCC_USB);
+void usb_init_usblib(usblib_dev *dev,
+ void (**ep_int_in)(void),
+ void (**ep_int_out)(void)) {
+ rcc_clk_enable(dev->clk_id);
- USBLIB->ep_int_in = ep_int_in;
- USBLIB->ep_int_out = ep_int_out;
+ dev->ep_int_in = ep_int_in;
+ dev->ep_int_out = ep_int_out;
/* usb_lib/ declares both and then assumes that pFoo points to Foo
* (even though the names don't always match), which is stupid for
@@ -242,14 +245,6 @@ void __irq_usb_lp_can_rx0(void) {
#endif
}
-uint8 usbIsConfigured() {
- return USBLIB->state == USB_CONFIGURED;
-}
-
-uint8 usbIsConnected() {
- return USBLIB->state != USB_UNCONNECTED;
-}
-
/*
* Auxiliary routines
*/
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index 988c923..94579ea 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -32,6 +32,7 @@
#define _USB_H_
#include "libmaple_types.h"
+#include "rcc.h"
#ifdef __cplusplus
extern "C" {
@@ -51,28 +52,31 @@ typedef enum usb_dev_state {
USB_CONFIGURED
} usb_dev_state;
-/* Encapsulates global state formerly handled by usb_lib/
- * functionality */
+/* Encapsulates global state formerly handled by usb_lib/ */
typedef struct usblib_dev {
uint32 irq_mask;
void (**ep_int_in)(void);
void (**ep_int_out)(void);
usb_dev_state state;
+ rcc_clk_id clk_id;
} usblib_dev;
extern usblib_dev *USBLIB;
-/*
- * Convenience routines, etc.
- */
+void usb_init_usblib(usblib_dev *dev,
+ void (**ep_int_in)(void),
+ void (**ep_int_out)(void));
-void usb_init_usblib(void (**ep_int_in)(void), void (**ep_int_out)(void));
+static inline uint8 usb_is_connected(usblib_dev *dev) {
+ return dev->state != USB_UNCONNECTED;
+}
-uint8 usbIsConnected(void);
-uint8 usbIsConfigured(void);
+static inline uint8 usb_is_configured(usblib_dev *dev) {
+ return dev->state == USB_CONFIGURED;
+}
#ifdef __cplusplus
-} // extern "C"
+}
#endif
-#endif // _USB_H_
+#endif
diff --git a/libmaple/usb/usb_cdcacm.c b/libmaple/usb/usb_cdcacm.c
index fe06166..a86776b 100644
--- a/libmaple/usb/usb_cdcacm.c
+++ b/libmaple/usb/usb_cdcacm.c
@@ -398,7 +398,7 @@ void usb_cdcacm_enable(gpio_dev *disc_dev, uint8 disc_bit) {
gpio_write_bit(disc_dev, disc_bit, 0); // presents us to the host
/* initialize USB peripheral */
- usb_init_usblib(ep_int_in, ep_int_out);
+ usb_init_usblib(USBLIB, ep_int_in, ep_int_out);
}
void usb_cdcacm_disable(gpio_dev *disc_dev, uint8 disc_bit) {