From 844665608fbeeab270e3d1a4bd797afd24302a10 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 16 Nov 2011 13:26:34 -0500 Subject: Make USB its own submodule. Add libmaple/usb/rules.mk, which compiles the USB FS device firmware submodule. Move the logic for compiling the USB stack from libmaple/rules.mk into libmaple/usb/rules.mk. Move libmaple/usb/usb_cdacm.h to libmaple/include/libmaple/. Its API is sufficiently general that we'll be able to port it over to USB OTG (either FS or HS) eventually, and that lets us include it from Wirish using the new style for libmaple headers. Fix the includes for public libmaple headers within libmaple/usb. Signed-off-by: Marti Bolivar --- Makefile | 1 + libmaple/include/libmaple/usb_cdcacm.h | 59 ++++++++++++++++++++++++++++++++++ libmaple/rules.mk | 14 +------- libmaple/usb/rules.mk | 36 +++++++++++++++++++++ libmaple/usb/usb.c | 8 +++-- libmaple/usb/usb_cdcacm.c | 10 +++--- libmaple/usb/usb_cdcacm.h | 59 ---------------------------------- libmaple/usb/usb_descriptors.h | 2 +- libmaple/usb/usb_lib_globals.h | 1 + libmaple/usb/usb_reg_map.h | 4 +-- wirish/boards.cpp | 2 +- wirish/usb_serial.cpp | 2 +- 12 files changed, 114 insertions(+), 84 deletions(-) create mode 100644 libmaple/include/libmaple/usb_cdcacm.h create mode 100644 libmaple/usb/rules.mk delete mode 100644 libmaple/usb/usb_cdcacm.h diff --git a/Makefile b/Makefile index c6a1e07..c2a60dd 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,7 @@ ifeq ($(LIBMAPLE_MODULES),) else LIBMAPLE_MODULES += $(SRCROOT)/libmaple endif +LIBMAPLE_MODULES += $(SRCROOT)/libmaple/usb # USB FS device LIBMAPLE_MODULES += $(LIBMAPLE_MODULE_FAMILY) # family submodule in libmaple LIBMAPLE_MODULES += $(SRCROOT)/wirish # Official libraries: diff --git a/libmaple/include/libmaple/usb_cdcacm.h b/libmaple/include/libmaple/usb_cdcacm.h new file mode 100644 index 0000000..2dbcbea --- /dev/null +++ b/libmaple/include/libmaple/usb_cdcacm.h @@ -0,0 +1,59 @@ +/****************************************************************************** + * The MIT License + * + * Copyright (c) 2011 LeafLabs LLC. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + *****************************************************************************/ + +/** + * @file usb_cdcacm.h + * @brief USB CDC ACM (virtual serial terminal) support + */ + +#ifndef _LIBMAPLE_USB_CDCACM_H_ +#define _LIBMAPLE_USB_CDCACM_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void usb_cdcacm_enable(gpio_dev*, uint8); +void usb_cdcacm_disable(gpio_dev*, uint8); + +void usb_cdcacm_putc(char ch); +uint32 usb_cdcacm_tx(const uint8* buf, uint32 len); +uint32 usb_cdcacm_rx(uint8* buf, uint32 len); + +uint32 usb_cdcacm_data_available(void); /* in RX buffer */ +uint16 usb_cdcacm_get_pending(void); + +uint8 usb_cdcacm_get_dtr(void); +uint8 usb_cdcacm_get_rts(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libmaple/rules.mk b/libmaple/rules.mk index a6b330a..3dcf0ce 100644 --- a/libmaple/rules.mk +++ b/libmaple/rules.mk @@ -3,13 +3,8 @@ sp := $(sp).x dirstack_$(sp) := $(d) d := $(dir) BUILDDIRS += $(BUILD_PATH)/$(d) -BUILDDIRS += $(BUILD_PATH)/$(d)/usb -BUILDDIRS += $(BUILD_PATH)/$(d)/usb/usb_lib LIBMAPLE_INCLUDES := -I$(LIBMAPLE_PATH)/include -# FIXME: move public USB headers to include/libmaple/usb/ or something. -LIBMAPLE_INCLUDES += -I$(LIBMAPLE_PATH)/usb \ - -I$(LIBMAPLE_PATH)/usb/usb_lib # Local flags CFLAGS_$(d) = -I$(d) $(LIBMAPLE_INCLUDES) -Wall # -Werror @@ -33,14 +28,7 @@ cSRCS_$(d) := adc.c \ systick.c \ timer.c \ usart.c \ - util.c \ - usb/usb.c \ - usb/usb_reg_map.c \ - usb/usb_cdcacm.c \ - usb/usb_lib/usb_core.c \ - usb/usb_lib/usb_init.c \ - usb/usb_lib/usb_mem.c \ - usb/usb_lib/usb_regs.c + util.c sSRCS_$(d) := exc.S diff --git a/libmaple/usb/rules.mk b/libmaple/usb/rules.mk new file mode 100644 index 0000000..9ef8d70 --- /dev/null +++ b/libmaple/usb/rules.mk @@ -0,0 +1,36 @@ +# Standard things +sp := $(sp).x +dirstack_$(sp) := $(d) +d := $(dir) +BUILDDIRS += $(BUILD_PATH)/$(d) +BUILDDIRS += $(BUILD_PATH)/$(d)/usb_lib + +# Local flags +CFLAGS_$(d) = -I$(d) -I$(d)/usb_lib $(LIBMAPLE_INCLUDES) -Wall + +# Local rules and targets +sSRCS_$(d) := +cSRCS_$(d) := usb.c \ + usb_reg_map.c \ + usb_cdcacm.c \ + usb_lib/usb_core.c \ + usb_lib/usb_init.c \ + usb_lib/usb_mem.c \ + usb_lib/usb_regs.c + +sFILES_$(d) := $(sSRCS_$(d):%=$(d)/%) +cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%) + +OBJS_$(d) := $(sFILES_$(d):%.S=$(BUILD_PATH)/%.o) \ + $(cFILES_$(d):%.c=$(BUILD_PATH)/%.o) +DEPS_$(d) := $(OBJS_$(d):%.o=%.d) + +$(OBJS_$(d)): TGT_CFLAGS := $(CFLAGS_$(d)) +$(OBJS_$(d)): TGT_ASFLAGS := + +TGT_BIN += $(OBJS_$(d)) + +# Standard things +-include $(DEPS_$(d)) +d := $(dirstack_$(sp)) +sp := $(basename $(sp)) diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c index 667b11f..6f23848 100644 --- a/libmaple/usb/usb.c +++ b/libmaple/usb/usb.c @@ -29,14 +29,16 @@ * @brief USB support. */ -#include "usb.h" +#include -#include "libmaple.h" -#include "rcc.h" +#include +#include +/* Private headers */ #include "usb_reg_map.h" #include "usb_lib_globals.h" +/* usb_lib headers */ #include "usb_type.h" #include "usb_core.h" diff --git a/libmaple/usb/usb_cdcacm.c b/libmaple/usb/usb_cdcacm.c index dc7b79e..07d2bc8 100644 --- a/libmaple/usb/usb_cdcacm.c +++ b/libmaple/usb/usb_cdcacm.c @@ -31,16 +31,18 @@ * routines. */ -#include "usb_cdcacm.h" +#include -#include "nvic.h" -#include "delay.h" +#include +#include +#include -#include "usb.h" +/* Private headers */ #include "usb_descriptors.h" #include "usb_lib_globals.h" #include "usb_reg_map.h" +/* usb_lib headers */ #include "usb_type.h" #include "usb_core.h" #include "usb_def.h" diff --git a/libmaple/usb/usb_cdcacm.h b/libmaple/usb/usb_cdcacm.h deleted file mode 100644 index ec672a3..0000000 --- a/libmaple/usb/usb_cdcacm.h +++ /dev/null @@ -1,59 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file usb_cdcacm.h - * @brief USB CDC ACM (virtual serial terminal) support - */ - -#ifndef _USB_CDCACM_H_ -#define _USB_CDCACM_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void usb_cdcacm_enable(gpio_dev*, uint8); -void usb_cdcacm_disable(gpio_dev*, uint8); - -void usb_cdcacm_putc(char ch); -uint32 usb_cdcacm_tx(const uint8* buf, uint32 len); -uint32 usb_cdcacm_rx(uint8* buf, uint32 len); - -uint32 usb_cdcacm_data_available(void); /* in RX buffer */ -uint16 usb_cdcacm_get_pending(void); - -uint8 usb_cdcacm_get_dtr(void); -uint8 usb_cdcacm_get_rts(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libmaple/usb/usb_descriptors.h b/libmaple/usb/usb_descriptors.h index 405588a..9bcb2b6 100644 --- a/libmaple/usb/usb_descriptors.h +++ b/libmaple/usb/usb_descriptors.h @@ -27,7 +27,7 @@ #ifndef _USB_DESCRIPTORS_H_ #define _USB_DESCRIPTORS_H_ -#include "libmaple.h" +#include #define USB_DESCRIPTOR_TYPE_DEVICE 0x01 #define USB_DESCRIPTOR_TYPE_CONFIGURATION 0x02 diff --git a/libmaple/usb/usb_lib_globals.h b/libmaple/usb/usb_lib_globals.h index a494817..1cd2754 100644 --- a/libmaple/usb/usb_lib_globals.h +++ b/libmaple/usb/usb_lib_globals.h @@ -27,6 +27,7 @@ #ifndef _USB_LIB_GLOBALS_H_ #define _USB_LIB_GLOBALS_H_ +/* usb_lib headers */ #include "usb_type.h" #include "usb_core.h" diff --git a/libmaple/usb/usb_reg_map.h b/libmaple/usb/usb_reg_map.h index 5bf5d96..ce80842 100644 --- a/libmaple/usb/usb_reg_map.h +++ b/libmaple/usb/usb_reg_map.h @@ -24,8 +24,8 @@ * SOFTWARE. *****************************************************************************/ -#include "libmaple_types.h" -#include "util.h" +#include +#include #ifndef _USB_REG_MAP_H_ #define _USB_REG_MAP_H_ diff --git a/wirish/boards.cpp b/wirish/boards.cpp index dbdcf1c..1f97119 100644 --- a/wirish/boards.cpp +++ b/wirish/boards.cpp @@ -41,7 +41,7 @@ #include #include #include -#include "usb_cdcacm.h" +#include static void setupFlash(void); static void setupClocks(void); diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp index 1fd6e65..388c739 100644 --- a/wirish/usb_serial.cpp +++ b/wirish/usb_serial.cpp @@ -32,7 +32,7 @@ #include -#include "usb_cdcacm.h" +#include #include #include -- cgit v1.2.3