diff --git a/demos/device/keyboard/main.c b/demos/device/keyboard/main.c index 19f2da104..324c6a51c 100644 --- a/demos/device/keyboard/main.c +++ b/demos/device/keyboard/main.c @@ -2,17 +2,19 @@ #include #include -#include -#include #include "boards/board.h" #include "tusb.h" -// Variable to store CRP value in. Will be placed automatically -// by the linker when "Enable Code Read Protect" selected. -// See crp.h header for more information -__CRP const unsigned int CRP_WORD = CRP_NO_CRP ; +#if defined(__CODE_RED) + #include + #include + // Variable to store CRP value in. Will be placed automatically + // by the linker when "Enable Code Read Protect" selected. + // See crp.h header for more information + __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; +#endif -int main(void) +int main(void) { uint32_t current_tick = system_ticks; diff --git a/demos/device/keyboard/tusb_config.h b/demos/device/keyboard/tusb_config.h index d9cb23c4a..877b41712 100644 --- a/demos/device/keyboard/tusb_config.h +++ b/demos/device/keyboard/tusb_config.h @@ -67,6 +67,8 @@ /// Enable HID Mouse support //#define TUSB_CFG_DEVICE_HID_MOUSE +#define TUSB_CFG_DEBUG 3 + #ifdef __CODE_RED // make use of code red's support for ram region macros #if (MCU == MCU_LPC11UXX) || (MCU == MCU_LPC13UXX) #define TUSB_RAM_SECTION ".data.$RAM2" diff --git a/demos/host/.cproject b/demos/host/.cproject index e7525ec41..6d8f8efb2 100644 --- a/demos/host/.cproject +++ b/demos/host/.cproject @@ -5,6 +5,11 @@ + + + + + @@ -24,11 +29,12 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/host/.project b/demos/host/.project index d6830eea7..09e353e6e 100644 --- a/demos/host/.project +++ b/demos/host/.project @@ -86,6 +86,11 @@ 2 PARENT-1-PROJECT_LOC/bsp + + tinyusb + 2 + C:/Users/hathach/Dropbox/tinyusb/workspace/tinyusb/tinyusb + diff --git a/demos/host/main.c b/demos/host/main.c index ff10332f0..a96f9cbb9 100644 --- a/demos/host/main.c +++ b/demos/host/main.c @@ -1,3 +1,7 @@ +#include +#include +#include + #include "boards/board.h" #include "tusb.h" @@ -15,15 +19,18 @@ int main(void) uint32_t current_tick = system_ticks; board_init(); - tusb_init(0); + tusb_init(); while (1) { if (current_tick + 1000 < system_ticks) { current_tick += 1000; - board_leds(0x03, (current_tick/1000)%2); /* Toggle LED once per second */ - printf("hello world"); + board_leds(0x01, (current_tick/1000)%2); /* Toggle LED once per second */ + + printf("tinyusb: " __DATE__ "\t" __TIME__ "\n"); } } + + return 0; } diff --git a/demos/host/tusb_config.h b/demos/host/tusb_config.h new file mode 100644 index 000000000..ae2d29b70 --- /dev/null +++ b/demos/host/tusb_config.h @@ -0,0 +1,91 @@ +/* + * tusb_config.h + * + * Created on: Jan 11, 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_TUSB_CONFIG_H_ +#define _TUSB_TUSB_CONFIG_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#define TUSB_CFG_HOST + +/// Enable Device Support +//#define TUSB_CFG_DEVICE + +/// Enable CDC Support +//#define TUSB_CFG_DEVICE_CDC + +/// Enable HID Keyboard support +#define TUSB_CFG_DEVICE_HID_KEYBOARD + +/// Enable HID Mouse support +//#define TUSB_CFG_DEVICE_HID_MOUSE + +#define TUSB_CFG_DEBUG 3 + +#ifdef __CODE_RED // make use of code red's support for ram region macros + #if (MCU == MCU_LPC11UXX) || (MCU == MCU_LPC13UXX) + #define TUSB_RAM_SECTION ".data.$RAM2" + #elif (MCU == MCU_LPC43XX) + #define TUSB_RAM_SECTION ".data.$RAM3" + #endif + + #define TUSB_ATTR_RAM_SECTION __attribute__ ((section(TUSB_RAM_SECTION))) +#endif + + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_TUSB_CONFIG_H_ */ + +/** @} */ diff --git a/tests/project.yml b/tests/project.yml index 84661367e..ec4c6cb42 100644 --- a/tests/project.yml +++ b/tests/project.yml @@ -47,7 +47,7 @@ - _TEST_ - MCU=MCU_LPC43XX - CORE_M4 - - __CODE_RED + - __CODE_RED :test_preprocess: - *common_defines - _TEST_ diff --git a/tests/test/host/test_host_hid.c b/tests/test/host/test_hid_host.c similarity index 100% rename from tests/test/host/test_host_hid.c rename to tests/test/host/test_hid_host.c diff --git a/tests/test/host/test_host_hid_keyboard.c b/tests/test/host/test_hid_host_keyboard.c similarity index 85% rename from tests/test/host/test_host_hid_keyboard.c rename to tests/test/host/test_hid_host_keyboard.c index cf5a541d3..e02c18a84 100644 --- a/tests/test/host/test_host_hid_keyboard.c +++ b/tests/test/host/test_hid_host_keyboard.c @@ -35,6 +35,10 @@ * This file is part of the tiny usb stack. */ +#include "unity.h" +#include "hid.h" +#include "hid_host.h" + void setUp(void) { } @@ -43,7 +47,10 @@ void tearDown(void) { } -void test_() +void test_keyboard_get_invalid_parameter() { - TEST_IGNORE(); + tusb_interface_keyboard_handle_t handle; + tusb_keyboard_report_t report; + TEST_ASSERT_FALSE (tusb_host_keyboard_get(NULL, &report)); + TEST_ASSERT_FALSE (tusb_host_keyboard_get(&handle, NULL)); } 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 #include +#include +#include #include #include