diff options
| author | hathach <[email protected]> | 2013-01-18 14:39:42 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-01-18 14:39:42 +0700 |
| commit | d8c8b9e38ad94ab84c24f22c2ecb79ce4d78b7ba (patch) | |
| tree | 1090e26f45a534e5113f28d82f8381eef274e358 /tinyusb | |
| parent | 7976e2fd55d33a0bf8a74a729eb246a8842d58ee (diff) | |
add ASSERT POINTER support
add hid host and separate hid host & device
update host project setting with EA4357 board
add para checking test for hid host
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/class/hid.c | 10 | ||||
| -rw-r--r-- | tinyusb/class/hid.h | 56 | ||||
| -rw-r--r-- | tinyusb/class/hid_device.h | 105 | ||||
| -rw-r--r-- | tinyusb/class/hid_host.c | 51 | ||||
| -rw-r--r-- | tinyusb/class/hid_host.h | 70 | ||||
| -rw-r--r-- | tinyusb/common/assertion.h | 10 | ||||
| -rw-r--r-- | tinyusb/common/common.h | 3 |
7 files changed, 251 insertions, 54 deletions
diff --git a/tinyusb/class/hid.c b/tinyusb/class/hid.c index ec2df6156..dceb4d7db 100644 --- a/tinyusb/class/hid.c +++ b/tinyusb/class/hid.c @@ -40,7 +40,7 @@ #if defined DEVICE_CLASS_HID && defined TUSB_CFG_DEVICE #ifdef TUSB_CFG_DEVICE_HID_KEYBOARD -USB_HID_KeyboardReport_t hid_keyboard_report; +tusb_keyboard_report_t hid_keyboard_report; static volatile bool bKeyChanged = false; #endif @@ -67,7 +67,7 @@ ErrorCode_t HID_GetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t #ifdef TUSB_CFG_DEVICE_HID_KEYBOARD case HID_PROTOCOL_KEYBOARD: *pBuffer = (uint8_t*) &hid_keyboard_report; - *plength = sizeof(USB_HID_KeyboardReport_t); + *plength = sizeof(tusb_keyboard_report_t); if (!bKeyChanged) { @@ -131,9 +131,9 @@ ErrorCode_t HID_EpIn_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event) case HID_PROTOCOL_KEYBOARD: if (!bKeyChanged) { - memset(&hid_keyboard_report, 0, sizeof(USB_HID_KeyboardReport_t)); + memset(&hid_keyboard_report, 0, sizeof(tusb_keyboard_report_t)); } - USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_keyboard_report, sizeof(USB_HID_KeyboardReport_t)); + USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_keyboard_report, sizeof(tusb_keyboard_report_t)); bKeyChanged = false; break; #endif @@ -223,7 +223,7 @@ TUSB_Error_t tusb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *c TUSB_Error_t tusb_hid_configured(USBD_HANDLE_T hUsb) { #ifdef TUSB_CFG_DEVICE_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 + USBD_API->hw->WriteEP(hUsb , HID_KEYBOARD_EP_IN , (uint8_t* ) &hid_keyboard_report , sizeof(tusb_keyboard_report_t) ); // initial packet for IN endpoint , will not work if omitted #endif #ifdef TUSB_CFG_DEVICE_HID_MOUSE diff --git a/tinyusb/class/hid.h b/tinyusb/class/hid.h index 4779e9e81..0add02bfc 100644 --- a/tinyusb/class/hid.h +++ b/tinyusb/class/hid.h @@ -58,14 +58,6 @@ // TODO refractor #include "common/common.h" -#ifdef TUSB_CFG_DEVICE -#include "device/dcd.h" -#endif - -#ifdef TUSB_CFG_HOST -#include "device/hcd.h" -#endif - /** \struct USB_HID_MouseReport_t * \brief Standard HID Boot Protocol Mouse Report. * @@ -78,7 +70,7 @@ typedef ATTR_PREPACKED struct int8_t Y; /**< Current delta Y movement on the mouse. */ } ATTR_PACKED USB_HID_MouseReport_t; -/** \struct USB_HID_KeyboardReport_t +/** \struct tusb_keyboard_report_t * \brief Standard HID Boot Protocol Keyboard Report. * * Type define for a standard Boot Protocol Keyboard report @@ -88,7 +80,7 @@ typedef ATTR_PREPACKED struct uint8_t Modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of HID_KEYBOARD_MODIFER_* masks). */ uint8_t Reserved; /**< Reserved for OEM use, always set to 0. */ uint8_t KeyCode[6]; /**< Key codes of the currently pressed keys. */ -} ATTR_PACKED USB_HID_KeyboardReport_t; +} ATTR_PACKED tusb_keyboard_report_t; /** \enum USB_HID_MOUSE_BUTTON_CODE * \brief Button codes for HID mouse @@ -158,48 +150,18 @@ enum USB_HID_LOCAL_CODE HID_Local_Turkish_F }; -#ifdef DEVICE_ROMDRIVER -/** \brief Initialize HID driver - * - * \param[in] para1 - * \param[out] para2 - * \return Error Code of the \ref TUSB_ERROR enum - * \note - */ -TUSB_Error_t tusb_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); - -/** \brief Notify HID class that usb is configured - * - * \param[in] para1 - * \param[out] para2 - * \return Error Code of the \ref TUSB_ERROR enum - * \note - */ -TUSB_Error_t tusb_hid_configured(USBD_HANDLE_T hUsb); - -/** \brief Used by Application to send Keycode to Host - * - * \param[in] para1 - * \param[out] para2 - * \return Error Code of the \ref TUSB_ERROR enum - * \note - */ -TUSB_Error_t tusb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint8_t numkey); - -/** \brief - * - * \param[in] para1 - * \param[out] para2 - * \return Error Code of the \ref TUSB_ERROR enum - * \note - */ -TUSB_Error_t tusb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y); +#ifdef TUSB_CFG_DEVICE + #include "device/dcd.h" + #include "hid_device.h" #endif - #ifdef TUSB_CFG_HOST + #include "host/hcd.h" + #include "hid_host.h" #endif + + #ifdef __cplusplus } #endif diff --git a/tinyusb/class/hid_device.h b/tinyusb/class/hid_device.h new file mode 100644 index 000000000..31c3a489f --- /dev/null +++ b/tinyusb/class/hid_device.h @@ -0,0 +1,105 @@ +/* + * hid_device.h + * + * Created on: Jan 18, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * 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. + */ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_HID_DEVICE_H_ +#define _TUSB_HID_DEVICE_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "hid.h" + +#ifdef DEVICE_ROMDRIVER +/** \brief Initialize HID driver + * + * \param[in] para1 + * \param[out] para2 + * \return Error Code of the \ref TUSB_ERROR enum + * \note + */ +TUSB_Error_t tusb_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); + +/** \brief Notify HID class that usb is configured + * + * \param[in] para1 + * \param[out] para2 + * \return Error Code of the \ref TUSB_ERROR enum + * \note + */ +TUSB_Error_t tusb_hid_configured(USBD_HANDLE_T hUsb); + +/** \brief Used by Application to send Keycode to Host + * + * \param[in] para1 + * \param[out] para2 + * \return Error Code of the \ref TUSB_ERROR enum + * \note + */ +TUSB_Error_t tusb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint8_t numkey); + +/** \brief + * + * \param[in] para1 + * \param[out] para2 + * \return Error Code of the \ref TUSB_ERROR enum + * \note + */ +TUSB_Error_t tusb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y); + +#endif /* ROM DRIVRER */ + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_HID_DEVICE_H_ */ + +/** @} */ diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c new file mode 100644 index 000000000..17b1aca0e --- /dev/null +++ b/tinyusb/class/hid_host.c @@ -0,0 +1,51 @@ +/* + * hid_host.c + * + * Created on: Dec 20, 2012 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * 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 "hid.h" + +#if defined DEVICE_CLASS_HID && defined TUSB_CFG_HOST + +bool tusb_host_keyboard_get(tusb_interface_keyboard_handle_t const * const handle, tusb_keyboard_report_t * const report) +{ + ASSSERT_PTR(handle, false); + ASSSERT_PTR(report, false); + + return true; +} + +#endif + diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h new file mode 100644 index 000000000..856edff7c --- /dev/null +++ b/tinyusb/class/hid_host.h @@ -0,0 +1,70 @@ +/* + * hid_host.h + * + * Created on: Jan 18, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * 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. + */ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_HID_HOST_H_ +#define _TUSB_HID_HOST_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "hid.h" + +typedef uint32_t tusb_interface_keyboard_handle_t; + +bool tusb_host_keyboard_get(tusb_interface_keyboard_handle_t const * const handle, tusb_keyboard_report_t *report); + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_HID_HOST_H_ */ + +/** @} */ diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index a1aa968e9..cf99622d8 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -98,7 +98,7 @@ extern "C" // Logical Assert //--------------------------------------------------------------------+ #define ASSERT(...) ASSERT_TRUE(__VA_ARGS__) -#define ASSERT_TRUE(condition , error) ASSERT_DEFINE( ,(condition), error, "%s", "evaluated to false") +#define ASSERT_TRUE(condition , error) ASSERT_DEFINE( , (condition), error, "%s", "evaluated to false") #define ASSERT_FALSE(condition , error) ASSERT_DEFINE( ,!(condition), error, "%s", "evaluated to true") //--------------------------------------------------------------------+ @@ -129,6 +129,14 @@ extern "C" #define ASSERT_HEX_EQUAL(...) ASSERT_XXX_EQUAL("0x%x", __VA_ARGS__) #define ASSERT_HEX_WITHIN(...) ASSERT_XXX_WITHIN("0x%x", __VA_ARGS__) +//--------------------------------------------------------------------+ +// Pointer Assert +//--------------------------------------------------------------------+ +#define ASSSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__) +#define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL") +#define ASSSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is NULL") + + #ifdef __cplusplus } #endif diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h index a17fb62dc..1aae86fe8 100644 --- a/tinyusb/common/common.h +++ b/tinyusb/common/common.h @@ -56,8 +56,9 @@ extern "C" { #endif -#include <stddef.h> #include <stdbool.h> +#include <stdint.h> +#include <stddef.h> #include <string.h> #include <stdio.h> |
