diff options
| author | hathach <[email protected]> | 2012-11-29 15:35:59 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2012-11-29 15:35:59 +0700 |
| commit | 360b28b44fa2ad7973f06c7f048a66a68e6cb90f (patch) | |
| tree | a80ef4f6ba6282faa2fd13cc18689667f47626e9 /tinyusb | |
| parent | 382cd30be2e3069a490977e1a492783188a02da0 (diff) | |
add more doxygen docs
start to use TUSB_Error_t
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/class/hid.c | 35 | ||||
| -rw-r--r-- | tinyusb/class/hid.h | 8 | ||||
| -rw-r--r-- | tinyusb/common/arch/arch.h | 2 | ||||
| -rw-r--r-- | tinyusb/common/common.h | 24 | ||||
| -rw-r--r-- | tinyusb/common/errors.c | 1 | ||||
| -rw-r--r-- | tinyusb/common/errors.h | 14 | ||||
| -rw-r--r-- | tinyusb/common/errors_def | 39 | ||||
| -rw-r--r-- | tinyusb/common/fifo.h | 6 | ||||
| -rw-r--r-- | tinyusb/device/dcd.c | 20 | ||||
| -rw-r--r-- | tinyusb/device/dcd.h | 9 | ||||
| -rw-r--r-- | tinyusb/host/hcd.c | 45 | ||||
| -rw-r--r-- | tinyusb/host/hcd.h | 4 | ||||
| -rw-r--r-- | tinyusb/tusb.c | 13 | ||||
| -rw-r--r-- | tinyusb/tusb.h | 5 | ||||
| -rw-r--r-- | tinyusb/tusb_cfg.h | 16 |
15 files changed, 185 insertions, 56 deletions
diff --git a/tinyusb/class/hid.c b/tinyusb/class/hid.c index 50cf2ac25..84a5799e0 100644 --- a/tinyusb/class/hid.c +++ b/tinyusb/class/hid.c @@ -180,7 +180,7 @@ ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event) @brief Initialises USB HID using the ROM based drivers */ /**************************************************************************/ -ErrorCode_t usb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *const pIntfDesc, uint8_t const * const pHIDReportDesc, uint32_t ReportDescLength, uint32_t* mem_base, uint32_t* mem_size) +TUSB_Error_t usb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *const pIntfDesc, uint8_t const * const pHIDReportDesc, uint32_t ReportDescLength, uint32_t* mem_base, uint32_t* mem_size) { USB_HID_REPORT_T reports_data = { @@ -207,7 +207,7 @@ ErrorCode_t usb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *con ASSERT( (pIntfDesc != NULL) && (pIntfDesc->bInterfaceClass == USB_DEVICE_CLASS_HUMAN_INTERFACE), ERR_FAILED); - ASSERT_STATUS( USBD_API->hid->init(hUsb, &hid_param) ); + ASSERT( LPC_OK == USBD_API->hid->init(hUsb, &hid_param), tERROR_FAILED ); /* update memory variables */ *mem_base += (*mem_size - hid_param.mem_size); @@ -221,7 +221,7 @@ ErrorCode_t usb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *con */ /**************************************************************************/ -ErrorCode_t usb_hid_configured(USBD_HANDLE_T hUsb) +TUSB_Error_t usb_hid_configured(USBD_HANDLE_T hUsb) { #ifdef CFG_CLASS_HID_KEYBOARD USBD_API->hw->WriteEP(hUsb , HID_KEYBOARD_EP_IN , (uint8_t* ) &hid_keyboard_report , sizeof(USB_HID_KeyboardReport_t) ); // initial packet for IN endpoint , will not work if omitted @@ -231,7 +231,7 @@ ErrorCode_t usb_hid_configured(USBD_HANDLE_T hUsb) USBD_API->hw->WriteEP(hUsb , HID_MOUSE_EP_IN , (uint8_t* ) &hid_mouse_report , sizeof(USB_HID_MouseReport_t) ); // initial packet for IN endpoint, will not work if omitted #endif - return LPC_OK; + return tERROR_NONE; } #ifdef CFG_CLASS_HID_KEYBOARD @@ -271,13 +271,19 @@ ErrorCode_t usb_hid_configured(USBD_HANDLE_T hUsb) @endcode */ /**************************************************************************/ -ErrorCode_t usb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint8_t numkey) +TUSB_Error_t usb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint8_t numkey) { - uint32_t start_time = systickGetSecondsActive(); - while (bKeyChanged) // TODO blocking while previous key has yet sent - can use fifo to improve this +// uint32_t start_time = systickGetSecondsActive(); +// while (bKeyChanged) // TODO blocking while previous key has yet sent - can use fifo to improve this +// { +// ASSERT_MESSAGE(systickGetSecondsActive() - start_time < 5, ERR_FAILED, "HID Keyboard Timeout"); +// } + + if (bKeyChanged) { - ASSERT_MESSAGE(systickGetSecondsActive() - start_time < 5, ERR_FAILED, "HID Keyboard Timeout"); + return tERROR_FAILED; } + ASSERT(keycodes && numkey && numkey <=6, ERR_FAILED); hid_keyboard_report.Modifier = modifier; @@ -316,12 +322,17 @@ ErrorCode_t usb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint @endcode */ /**************************************************************************/ -ErrorCode_t usb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y) +TUSB_Error_t usb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y) { - uint32_t start_time = systickGetSecondsActive(); - while (bMouseChanged) // TODO Block while previous key hasn't been sent - can use fifo to improve this +// uint32_t start_time = systickGetSecondsActive(); +// while (bMouseChanged) // TODO Block while previous key hasn't been sent - can use fifo to improve this +// { +// ASSERT_MESSAGE(systickGetSecondsActive() - start_time < 5, ERR_FAILED, "HID Mouse Timeout"); +// } + + if (bMouseChanged) { - ASSERT_MESSAGE(systickGetSecondsActive() - start_time < 5, ERR_FAILED, "HID Mouse Timeout"); + return tERROR_FAILED; } hid_mouse_report.Button = buttons; diff --git a/tinyusb/class/hid.h b/tinyusb/class/hid.h index 8ba5eea77..aabf5df8a 100644 --- a/tinyusb/class/hid.h +++ b/tinyusb/class/hid.h @@ -46,11 +46,11 @@ #include "common/common.h" #include "device/dcd.h" -ErrorCode_t usb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *const pIntfDesc, uint8_t const * const pHIDReportDesc, uint32_t ReportDescLength, uint32_t* mem_base, uint32_t* mem_size); -ErrorCode_t usb_hid_configured(USBD_HANDLE_T hUsb); +TUSB_Error_t usb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *const pIntfDesc, uint8_t const * const pHIDReportDesc, uint32_t ReportDescLength, uint32_t* mem_base, uint32_t* mem_size) ATTR_NON_NULL; +TUSB_Error_t usb_hid_configured(USBD_HANDLE_T hUsb); -ErrorCode_t usb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint8_t numkey); -ErrorCode_t usb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y); +TUSB_Error_t usb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint8_t numkey) ATTR_NON_NULL; +TUSB_Error_t usb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y); /** \brief Standard HID Boot Protocol Mouse Report. * diff --git a/tinyusb/common/arch/arch.h b/tinyusb/common/arch/arch.h index d641ceefb..79a948330 100644 --- a/tinyusb/common/arch/arch.h +++ b/tinyusb/common/arch/arch.h @@ -65,3 +65,5 @@ #endif #endif /* _TUSB_ARCH_H_ */ + +/** @{ */ diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h index 768d9ae1c..480edde9c 100644 --- a/tinyusb/common/common.h +++ b/tinyusb/common/common.h @@ -41,7 +41,7 @@ * \note TBD */ -/** \ingroup Group_TinyUSB +/** * \defgroup Group_Common Common Files * \brief Group_Common brief * @@ -54,37 +54,41 @@ #include <stddef.h> #include <stdbool.h> #include <string.h> +#include <stdio.h> +#include "tusb_cfg.h" #include "arch/arch.h" #include "compiler/compiler.h" #include "errors.h" //#if ( defined CFG_PRINTF_UART || defined CFG_PRINTF_USBCDC || defined CFG_PRINTF_DEBUG ) -#if 1 // TODO refractor ASSERT - #define PRINTF_LOCATION(mess) printf("Assert: %s at line %d: %s\n", __func__, __LINE__, mess) +#if CFG_TUSB_DEBUG_LEVEL + #define PRINTF(...) printf(__VA_ARGS__) #else - #define PRINTF_LOCATION(mess) + #define PRINTF(...) #endif #define ASSERT_MESSAGE(condition, value, message) \ do{\ if (!(condition)) {\ - PRINTF_LOCATION(message);\ + PRINTF("Assert at %s line %d: %s\n", __func__, __LINE__, message); \ return (value);\ }\ }while(0) #define ASSERT(condition, value) ASSERT_MESSAGE(condition, value, NULL) -#define ASSERT_STATUS_MESSAGE(sts, message) \ +#define ASSERT_ERROR_MESSAGE(sts, message) \ do{\ - ErrorCode_t status = (sts);\ - if (LPC_OK != status) {\ - PRINTF_LOCATION(message);\ + TUSB_Error_t status = (TUSB_Error_t)(sts);\ + if (tERROR_NONE != status) {\ + PRINTF("Assert at %s line %d: %s %s\n", __func__, __LINE__, TUSB_ErrorStr[status], message); \ return status;\ }\ }while(0) -#define ASSERT_STATUS(sts) ASSERT_STATUS_MESSAGE(sts, NULL) +#define ASSERT_ERROR(sts) ASSERT_ERROR_MESSAGE(sts, NULL) #endif /* _TUSB_COMMON_H_ */ + +/** @{ */ diff --git a/tinyusb/common/errors.c b/tinyusb/common/errors.c index c0878ef67..26db61241 100644 --- a/tinyusb/common/errors.c +++ b/tinyusb/common/errors.c @@ -39,4 +39,5 @@ char const* const TUSB_ErrorStr[] = { # define ERROR_ENUM(x) #x, # include "errors_def" # undef ERROR_ENUM + 0 }; diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index 20a797792..0d36b56fc 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -42,23 +42,29 @@ */ /** \ingroup Group_Common - * + * \defgroup Group_Error tinyUSB Error Codes * @{ */ #ifndef _TUSB_ERRORS_H_ #define _TUSB_ERRORS_H_ -enum TUSB_ERROR { +/** \enum TUSB_Error + * \brief Error Code returned + */ + +typedef enum { # define ERROR_ENUM(x) x, # include "errors_def" # undef ERROR_ENUM -}; + ERROR_COUNT +}TUSB_Error_t; #ifdef __cplusplus extern "C" { #endif +/// Enum to String for debugging purposes. Only available if \ref CFG_TUSB_DEBUG_LEVEL > 0 extern char const* const TUSB_ErrorStr[]; #ifdef __cplusplus @@ -66,3 +72,5 @@ extern char const* const TUSB_ErrorStr[]; #endif #endif /* _TUSB_ERRORS_H_ */ + + /** @{ */ diff --git a/tinyusb/common/errors_def b/tinyusb/common/errors_def new file mode 100644 index 000000000..927c72d7d --- /dev/null +++ b/tinyusb/common/errors_def @@ -0,0 +1,39 @@ +/* + * errors_def + * + * Created on: Nov 27, 2012 + * Author: hathach ([email protected]) + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach ([email protected]) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +ERROR_ENUM(tERROR_NONE) +ERROR_ENUM(tERROR_FAILED) diff --git a/tinyusb/common/fifo.h b/tinyusb/common/fifo.h index 4a0bfc340..3ee9da7e6 100644 --- a/tinyusb/common/fifo.h +++ b/tinyusb/common/fifo.h @@ -51,10 +51,10 @@ #include "common/common.h" -/** - * \brief Simple FIFO +/** \struct fifo_t + * \brief Simple Circular FIFO */ -typedef struct +typedef struct _fifo_t { uint8_t* buf; ///< buffer pointer uint16_t size; ///< buffer size diff --git a/tinyusb/device/dcd.c b/tinyusb/device/dcd.c index 2802c0299..84109af2c 100644 --- a/tinyusb/device/dcd.c +++ b/tinyusb/device/dcd.c @@ -57,7 +57,7 @@ ErrorCode_t USB_Configure_Event (USBD_HANDLE_T hUsb) if (pCtrl->config_value) { #if defined(CLASS_HID) - ASSERT_STATUS( usb_hid_configured(hUsb) ); + ASSERT( tERROR_NONE == usb_hid_configured(hUsb), ERR_FAILED ); #endif #ifdef CFG_USB_CDC @@ -81,7 +81,7 @@ ErrorCode_t USB_Reset_Event (USBD_HANDLE_T hUsb) return LPC_OK; } -void dcd_init() +TUSB_Error_t dcd_init() { /* ROM DRIVER INIT */ uint32_t membase = (uint32_t) usb_RomDriver_buffer; @@ -107,26 +107,26 @@ void dcd_init() .device_qualifier = NULL }; - /* Start USB hardware initialisation */ - ASSERT_STATUS(USBD_API->hw->Init(&g_hUsb, &DeviceDes, &usb_param)); + /* USB hardware core initialization */ + ASSERT(LPC_OK == USBD_API->hw->Init(&g_hUsb, &DeviceDes, &usb_param), tERROR_FAILED); 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, + #ifdef CFG_CLASS_CDC + ASSERT_ERROR( usb_cdc_init(g_hUsb, &USB_FsConfigDescriptor.CDC_CCI_Interface, &USB_FsConfigDescriptor.CDC_DCI_Interface, &membase, &memsize) ); #endif #ifdef CFG_CLASS_HID_KEYBOARD - ASSERT_STATUS( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_KeyboardInterface , + ASSERT_ERROR( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_KeyboardInterface , HID_KeyboardReportDescriptor, USB_FsConfigDescriptor.HID_KeyboardHID.DescriptorList[0].wDescriptorLength, &membase , &memsize) ); #endif - #ifdef CFG_USB_HID_MOUSE - ASSERT_STATUS( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_MouseInterface , + #ifdef CFG_CLASS_HID_MOUSE + ASSERT_ERROR( usb_hid_init(g_hUsb , &USB_FsConfigDescriptor.HID_MouseInterface , HID_MouseReportDescriptor, USB_FsConfigDescriptor.HID_MouseHID.DescriptorList[0].wDescriptorLength, &membase , &memsize) ); #endif @@ -136,6 +136,8 @@ void dcd_init() /* Perform USB soft connect */ USBD_API->hw->Connect(g_hUsb, 1); + + return tERROR_NONE; } /**************************************************************************/ diff --git a/tinyusb/device/dcd.h b/tinyusb/device/dcd.h index 836669e7e..0e6c0bd99 100644 --- a/tinyusb/device/dcd.h +++ b/tinyusb/device/dcd.h @@ -38,11 +38,7 @@ #ifndef _TUSB_DCD_H_ #define _TUSB_DCD_H_ -#ifdef __cplusplus - extern "C" { -#endif -#include "tusb_cfg.h" #include "common/common.h" #ifdef DEVICE_ROMDRIVER @@ -51,6 +47,11 @@ #define USBD_API ((*(ROM **)(0x1FFF1FF8))->pUSBD) // TODO HAL #endif +#ifdef __cplusplus + extern "C" { +#endif + +TUSB_Error_t dcd_init() ATTR_WARN_UNUSED_RESULT; #ifdef __cplusplus } diff --git a/tinyusb/host/hcd.c b/tinyusb/host/hcd.c new file mode 100644 index 000000000..77175d573 --- /dev/null +++ b/tinyusb/host/hcd.c @@ -0,0 +1,45 @@ +/* + * hcd.c + * + * Created on: Nov 29, 2012 + * Author: hathach ([email protected]) + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach ([email protected]) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +#include "hcd.h" + +TUSB_Error_t hcd_init() +{ + + + return tERROR_NONE; +} diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h index a9932af08..64bf28205 100644 --- a/tinyusb/host/hcd.h +++ b/tinyusb/host/hcd.h @@ -38,10 +38,14 @@ #ifndef _TUSB_HCD_H_ #define _TUSB_HCD_H_ +#include "common/common.h" + #ifdef __cplusplus extern "C" { #endif +TUSB_Error_t hcd_init() ATTR_WARN_UNUSED_RESULT; + #ifdef __cplusplus } #endif diff --git a/tinyusb/tusb.c b/tinyusb/tusb.c index c503876cb..f4acc7ab6 100644 --- a/tinyusb/tusb.c +++ b/tinyusb/tusb.c @@ -37,11 +37,7 @@ #include "tusb.h" -#ifdef CFG_TUSB_DEVICE - #include "device/dcd.h" -#endif - -ErrorCode_t tusb_init(void) +TUSB_Error_t tusb_init(void) { /* HARDWARE INIT */ @@ -55,8 +51,13 @@ ErrorCode_t tusb_init(void) LPC_IOCON->PIO0_6 &= ~0x07; LPC_IOCON->PIO0_6 |= (0x01<<0); /* Secondary function SoftConn */ +#ifdef CFG_TUSB_HOST + ASSERT_ERROR( hcd_init() ); +#endif + #ifdef CFG_TUSB_DEVICE - dcd_init(); + ASSERT_ERROR( dcd_init() ); #endif + return LPC_OK; } diff --git a/tinyusb/tusb.h b/tinyusb/tusb.h index 6e44c0a97..fd02fadb7 100644 --- a/tinyusb/tusb.h +++ b/tinyusb/tusb.h @@ -55,7 +55,10 @@ #endif #include "common/common.h" -#include "tusb_cfg.h" + +#ifdef CFG_TUSB_HOST + #include "host/hcd.h" +#endif #ifdef CFG_TUSB_DEVICE #include "device/dcd.h" diff --git a/tinyusb/tusb_cfg.h b/tinyusb/tusb_cfg.h index 478577ebf..bc55b580a 100644 --- a/tinyusb/tusb_cfg.h +++ b/tinyusb/tusb_cfg.h @@ -42,16 +42,24 @@ */ /** \ingroup Group_TinyUSB - * + * \defgroup Group_TinyUSB_Configure Configuration tusb_cfg.h * @{ */ #ifndef _TUSB_CFG_H_ #define _TUSB_CFG_H_ -#define CFG_TUSB_HOST ///< Enable Host Support -#define CFG_TUSB_DEVICE ///< Enable Device Support -#define CFG_CLASS_HID_KEYBOARD ///< Enable HID Keyboard support +/// 0: no debug infor 3: most debug infor provided +#define CFG_TUSB_DEBUG_LEVEL 3 + +/// Enable Host Support +#define CFG_TUSB_HOST + +/// Enable Device Support +#define CFG_TUSB_DEVICE + +/// Enable HID Keyboard support +#define CFG_CLASS_HID_KEYBOARD #define CLASS_HID (defined CFG_CLASS_HID_KEYBOARD) |
