From 8cd811e2a9760afc1702ae0a872e999517bfcb40 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 29 Nov 2012 10:41:33 +0700 Subject: [PATCH] start to work with doxygen fix mem_size/mem_base usage with device rom driver --- tinyusb/class/hid.c | 2 +- tinyusb/common/arch/arch.h | 25 ++++++++++------- tinyusb/common/arch/arch_lpc134x.h | 19 +++++++------ tinyusb/common/arch/arch_lpc43xx.h | 21 ++++++++------ tinyusb/common/arch/arm_mx.h | 20 +++++++------ tinyusb/common/common.h | 21 ++++++++------ tinyusb/common/compiler/compiler.h | 22 +++++++++------ tinyusb/common/compiler/compiler_gcc.h | 19 ++++++++----- tinyusb/common/errors.c | 5 ++++ tinyusb/common/errors.h | 18 ++++++++++++ tinyusb/common/fifo.h | 39 ++++++++++++++++++++------ tinyusb/device/dcd.c | 21 +++++++++----- tinyusb/tusb.h | 14 +++++++++ tinyusb/tusb_cfg.h | 31 ++++++++++---------- 14 files changed, 188 insertions(+), 89 deletions(-) diff --git a/tinyusb/class/hid.c b/tinyusb/class/hid.c index 21871d284..50cf2ac25 100644 --- a/tinyusb/class/hid.c +++ b/tinyusb/class/hid.c @@ -210,7 +210,7 @@ ErrorCode_t usb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *con ASSERT_STATUS( USBD_API->hid->init(hUsb, &hid_param) ); /* update memory variables */ - *mem_base = hid_param.mem_base; + *mem_base += (*mem_size - hid_param.mem_size); *mem_size = hid_param.mem_size; return LPC_OK; diff --git a/tinyusb/common/arch/arch.h b/tinyusb/common/arch/arch.h index 8580d4208..d641ceefb 100644 --- a/tinyusb/common/arch/arch.h +++ b/tinyusb/common/arch/arch.h @@ -35,19 +35,28 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief Architecture Header + * + * \note TBD + */ + +/** \ingroup Group_Common + * \defgroup Group_Arch Architecture + * \brief Group_Arch brief + * + * @{ + */ + #ifndef _TUSB_ARCH_H_ #define _TUSB_ARCH_H_ -#ifdef __cplusplus - extern "C" { -#endif - #define ARCH_LPC134X 1 #define ARCH_LPC43XX 2 #define ARCH ARCH_LPC134X -#define ENDIAN_LITTLE -#define ALIGNMENT (4) +#define ENDIAN_LITTLE ///< MCU Endian +#define ALIGNMENT (4) ///< MCU Alignment #if ARCH == ARCH_LPC134X #include "arch_lpc134x.h" @@ -55,8 +64,4 @@ #endif -#ifdef __cplusplus - } -#endif - #endif /* _TUSB_ARCH_H_ */ diff --git a/tinyusb/common/arch/arch_lpc134x.h b/tinyusb/common/arch/arch_lpc134x.h index 988c562e3..0ac5d971b 100644 --- a/tinyusb/common/arch/arch_lpc134x.h +++ b/tinyusb/common/arch/arch_lpc134x.h @@ -35,13 +35,20 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief LPC13Uxx Header + * + * \note TBD + */ + +/** \ingroup Group_Arch + * + * @{ + */ + #ifndef _TUSB_ARCH_LPC134_X_H_ #define _TUSB_ARCH_LPC134_X_H_ -#ifdef __cplusplus - extern "C" { -#endif - #include "arm_mx.h" #include "LPC13Uxx.h" @@ -49,8 +56,4 @@ #define DEVICE_ROMDRIVER -#ifdef __cplusplus - } -#endif - #endif /* _TUSB_ARCH_LPC134_X_H_ */ diff --git a/tinyusb/common/arch/arch_lpc43xx.h b/tinyusb/common/arch/arch_lpc43xx.h index f04dc4f74..05c177cc0 100644 --- a/tinyusb/common/arch/arch_lpc43xx.h +++ b/tinyusb/common/arch/arch_lpc43xx.h @@ -35,20 +35,25 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief LPC43xx Header + * + * \note TBD + */ + +/** \ingroup Group_Arch + * + * @{ + */ + #ifndef _TUSB_ARCH_LPC43XX_H_ #define _TUSB_ARCH_LPC43XX_H_ -#ifdef __cplusplus - extern "C" { -#endif - #define ARM_M4 //#define ARM_M0 #include "arm_mx.h" -#ifdef __cplusplus - } -#endif - #endif /* _TUSB_ARCH_LPC43XX_H_ */ + +/// @} diff --git a/tinyusb/common/arch/arm_mx.h b/tinyusb/common/arch/arm_mx.h index 760eea9c9..ea4ac5f36 100644 --- a/tinyusb/common/arch/arm_mx.h +++ b/tinyusb/common/arch/arm_mx.h @@ -35,18 +35,22 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief ARM Cortex Mx Header + * + * \note TBD + */ + +/** \ingroup Group_Arch + * + * @{ + */ + #ifndef _TUSB_ARM_MX_H_ #define _TUSB_ARM_MX_H_ -#ifdef __cplusplus - extern "C" { -#endif - #define ENDIAN_LITTLE #define ALIGNMENT (4) -#ifdef __cplusplus - } -#endif - #endif /* _TUSB_ARM_MX_H_ */ +/// @} diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h index 1405b7605..768d9ae1c 100644 --- a/tinyusb/common/common.h +++ b/tinyusb/common/common.h @@ -35,13 +35,22 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief Common Header File + * + * \note TBD + */ + +/** \ingroup Group_TinyUSB + * \defgroup Group_Common Common Files + * \brief Group_Common brief + * + * @{ + */ + #ifndef _TUSB_COMMON_H_ #define _TUSB_COMMON_H_ -#ifdef __cplusplus - extern "C" { -#endif - #include #include #include @@ -78,8 +87,4 @@ #define ASSERT_STATUS(sts) ASSERT_STATUS_MESSAGE(sts, NULL) -#ifdef __cplusplus - } -#endif - #endif /* _TUSB_COMMON_H_ */ diff --git a/tinyusb/common/compiler/compiler.h b/tinyusb/common/compiler/compiler.h index 6621b4160..4aae60f22 100644 --- a/tinyusb/common/compiler/compiler.h +++ b/tinyusb/common/compiler/compiler.h @@ -35,19 +35,25 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief Compiler Header + * + * \note TBD + */ + +/** \ingroup Group_Common + * \defgroup Group_Compiler Compiler + * \brief Group_Compiler brief + * + * @{ + */ + #ifndef _TUSB_COMPILER_H_ #define _TUSB_COMPILER_H_ -#ifdef __cplusplus - extern "C" { -#endif - #if defined(__GNUC__) #include "compiler_gcc.h" #endif -#ifdef __cplusplus - } -#endif - #endif /* _TUSB_COMPILER_H_ */ +/// @} diff --git a/tinyusb/common/compiler/compiler_gcc.h b/tinyusb/common/compiler/compiler_gcc.h index 38ef5f20f..d3047a544 100644 --- a/tinyusb/common/compiler/compiler_gcc.h +++ b/tinyusb/common/compiler/compiler_gcc.h @@ -35,9 +35,16 @@ * This file is part of the tiny usb stack. */ -#ifdef __cplusplus - extern "C" { -#endif +/** \file + * \brief GCC Header + * + * \note TBD + */ + +/** \ingroup Group_Compiler + * + * @{ + */ #ifndef _TUSB_COMPILER_GCC_H_ #define _TUSB_COMPILER_GCC_H_ @@ -56,8 +63,6 @@ #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) #define ATTR_ALWAYS_INLINE __attribute__ ((always_inline)) -#ifdef __cplusplus - } -#endif - #endif /* _TUSB_COMPILER_GCC_H_ */ + +/// @} diff --git a/tinyusb/common/errors.c b/tinyusb/common/errors.c index 90753786b..c0878ef67 100644 --- a/tinyusb/common/errors.c +++ b/tinyusb/common/errors.c @@ -35,3 +35,8 @@ * This file is part of the tiny usb stack. */ +char const* const TUSB_ErrorStr[] = { +# define ERROR_ENUM(x) #x, +# include "errors_def" +# undef ERROR_ENUM +}; diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index e4a75f0e8..20a797792 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -35,13 +35,31 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief Error Header + * + * \note TBD + */ + +/** \ingroup Group_Common + * + * @{ + */ + #ifndef _TUSB_ERRORS_H_ #define _TUSB_ERRORS_H_ +enum TUSB_ERROR { +# define ERROR_ENUM(x) x, +# include "errors_def" +# undef ERROR_ENUM +}; + #ifdef __cplusplus extern "C" { #endif +extern char const* const TUSB_ErrorStr[]; #ifdef __cplusplus } diff --git a/tinyusb/common/fifo.h b/tinyusb/common/fifo.h index 1019c8bde..4a0bfc340 100644 --- a/tinyusb/common/fifo.h +++ b/tinyusb/common/fifo.h @@ -35,23 +35,40 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief Error Header + * + * \note TBD + */ + +/** \ingroup Group_Common + * + * @{ + */ + #ifndef _TUSB_FIFO_H_ #define _TUSB_FIFO_H_ #include "common/common.h" -/* ToDo: Describe each field in fifo_t */ -typedef struct _fifo_t +/** + * \brief Simple FIFO + */ +typedef struct { - uint8_t* buf; - uint16_t size; - volatile uint16_t len; - volatile uint16_t wr_ptr; - volatile uint16_t rd_ptr; - bool overwritable; - IRQn_Type irq; + uint8_t* buf; ///< buffer pointer + uint16_t size; ///< buffer size + volatile uint16_t len; ///< bytes in fifo + volatile uint16_t wr_ptr; ///< write pointer + volatile uint16_t rd_ptr; ///< read pointer + bool overwritable; ///< allow overwrite data when full + IRQn_Type irq; ///< interrupt used to lock fifo } fifo_t; +#ifdef __cplusplus + extern "C" { +#endif + void fifo_init(fifo_t* f, uint8_t* buffer, uint16_t size, bool overwritable, IRQn_Type irq); bool fifo_write(fifo_t* f, uint8_t data); bool fifo_read(fifo_t* f, uint8_t *data); @@ -73,4 +90,8 @@ static inline uint16_t fifo_getLength(fifo_t* f) return f->len; } +#ifdef __cplusplus + } +#endif + #endif /* _TUSB_FIFO_H_ */ diff --git a/tinyusb/device/dcd.c b/tinyusb/device/dcd.c index 11f920b13..2802c0299 100644 --- a/tinyusb/device/dcd.c +++ b/tinyusb/device/dcd.c @@ -39,9 +39,10 @@ // TODO refractor later #include "descriptors.h" +#include #define USB_ROM_SIZE (1024*2) -uint8_t usb_RomDriver_buffer[USB_ROM_SIZE]ALIGNED(2048) /*__BSS(RAM2)*/; +uint8_t usb_RomDriver_buffer[USB_ROM_SIZE] ATTR_ALIGNED(2048) __BSS(RAM2); USBD_HANDLE_T g_hUsb; volatile static bool isConfigured = false; @@ -83,12 +84,15 @@ ErrorCode_t USB_Reset_Event (USBD_HANDLE_T hUsb) void dcd_init() { /* ROM DRIVER INIT */ + uint32_t membase = (uint32_t) usb_RomDriver_buffer; + uint32_t memsize = USB_ROM_SIZE; + USBD_API_INIT_PARAM_T usb_param = { .usb_reg_base = LPC_USB_BASE, .max_num_ep = USB_MAX_EP_NUM, - .mem_base = (uint32_t) usb_RomDriver_buffer, - .mem_size = USB_ROM_SIZE, //USBD_API->hw->GetMemSize() + .mem_base = membase, + .mem_size = memsize, .USB_Configure_Event = USB_Configure_Event, .USB_Reset_Event = USB_Reset_Event @@ -106,22 +110,25 @@ void dcd_init() /* Start USB hardware initialisation */ ASSERT_STATUS(USBD_API->hw->Init(&g_hUsb, &DeviceDes, &usb_param)); - /* Initialise the class driver(s) */ + membase += (memsize - usb_param.mem_size); + memsize = usb_param.mem_size; + + /* Initialise the class driver(s) */ #ifdef CFG_USB_CDC ASSERT_STATUS( usb_cdc_init(g_hUsb, &USB_FsConfigDescriptor.CDC_CCI_Interface, - &USB_FsConfigDescriptor.CDC_DCI_Interface, &usb_param.mem_base, &usb_param.mem_size) ); + &USB_FsConfigDescriptor.CDC_DCI_Interface, &membase, &memsize) ); #endif #ifdef CFG_CLASS_HID_KEYBOARD ASSERT_STATUS( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_KeyboardInterface , HID_KeyboardReportDescriptor, USB_FsConfigDescriptor.HID_KeyboardHID.DescriptorList[0].wDescriptorLength, - &usb_param.mem_base , &usb_param.mem_size) ); + &membase , &memsize) ); #endif #ifdef CFG_USB_HID_MOUSE ASSERT_STATUS( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_MouseInterface , HID_MouseReportDescriptor, USB_FsConfigDescriptor.HID_MouseHID.DescriptorList[0].wDescriptorLength, - &usb_param.mem_base , &usb_param.mem_size) ); + &membase , &memsize) ); #endif /* Enable the USB interrupt */ diff --git a/tinyusb/tusb.h b/tinyusb/tusb.h index a793e0da0..6e44c0a97 100644 --- a/tinyusb/tusb.h +++ b/tinyusb/tusb.h @@ -35,6 +35,18 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief Tiny USB header + * + * \note Tiny USB header Note + */ + +/** \defgroup Group_TinyUSB Tiny USB + * \brief Group_TinyUSB brief + * + * @{ + */ + #ifndef _TUSB_H_ #define _TUSB_H_ @@ -58,3 +70,5 @@ #endif #endif /* _TUSB_H_ */ + +/** @} */ diff --git a/tinyusb/tusb_cfg.h b/tinyusb/tusb_cfg.h index 7331d904f..478577ebf 100644 --- a/tinyusb/tusb_cfg.h +++ b/tinyusb/tusb_cfg.h @@ -35,23 +35,26 @@ * This file is part of the tiny usb stack. */ +/** \file + * \brief Configure File + * + * \note TBD + */ + +/** \ingroup Group_TinyUSB + * + * @{ + */ + #ifndef _TUSB_CFG_H_ #define _TUSB_CFG_H_ -#ifdef __cplusplus - extern "C" { -#endif - -#include "common/common.h" - -#define CFG_TUSB_HOST -#define CFG_TUSB_DEVICE - -#define CFG_CLASS_HID_KEYBOARD +#define CFG_TUSB_HOST ///< Enable Host Support +#define CFG_TUSB_DEVICE ///< Enable Device Support +#define CFG_CLASS_HID_KEYBOARD ///< Enable HID Keyboard support #define CLASS_HID (defined CFG_CLASS_HID_KEYBOARD) - // TODO APP #define USB_MAX_IF_NUM 8 #define USB_MAX_EP_NUM 5 @@ -75,8 +78,6 @@ #define CDC_NOTIFICATION_EP_MAXPACKETSIZE 8 #define CDC_DATA_EP_MAXPACKET_SIZE 16 -#ifdef __cplusplus - } -#endif - #endif /* _TUSB_CFG_H_ */ + +/** @} */