able to build lpc11u with IAR

clean ending warming with IAR
This commit is contained in:
hathach
2014-03-12 14:43:58 +07:00
parent b6e4c0d348
commit 0f0d9d127b
24 changed files with 5925 additions and 6282 deletions

View File

@@ -1,222 +1,222 @@
/**************************************************************************/
/*!
@file hid_device.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
#ifndef _TUSB_HID_DEVICE_H_
#define _TUSB_HID_DEVICE_H_
#include "common/common.h"
#include "device/usbd.h"
#include "hid.h"
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------+
// KEYBOARD APPLICATION API
//--------------------------------------------------------------------+
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
* @{ */
/** \defgroup Keyboard_Device Device
* @{ */
/** \brief Check if the interface is currently busy or not
* \param[in] coreid USB Controller ID
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_keyboard_send.
*/
bool tusbd_hid_keyboard_is_busy(uint8_t coreid);
/** \brief Submit USB transfer
* \param[in] coreid USB Controller ID
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \returns \ref tusb_error_t type to indicate success or error condition.
* \retval TUSB_ERROR_NONE on success
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
* The result of usb transfer will be reported by the interface's callback function
*/
tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const *p_report);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK API
//--------------------------------------------------------------------+
void tusbd_hid_keyboard_mounted_cb(uint8_t coreid);
void tusbd_hid_keyboard_unmounted_cb(uint8_t coreid);
/** \brief Callback function that is invoked when an transferring event occurred
* after invoking \ref tusbd_hid_keyboard_send
* \param[in] coreid USB Controller ID
* \param[in] event an value from \ref tusb_event_t
* \note event can be one of following
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
*/
void tusbd_hid_keyboard_cb(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
* via control endpoint.
* \param[in] coreid USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[out] pp_report pointer to buffer that application need to update, value must be accessible by USB controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \param[in] requested_length number of bytes that host requested
* \retval non-zero Actual number of bytes in the response's buffer.
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
* sending STALL in the data phase.
* \note After this callback, the request is silently executed by the tinyusb stack, thus
* the completion of this control request will not be reported to application.
* For Keyboard, USB host often uses this to turn on/off the LED for CAPLOCKS, NUMLOCK (\ref hid_keyboard_led_bm_t)
*/
uint16_t tusbd_hid_keyboard_get_report_cb(uint8_t coreid, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
* via control endpoint.
* \param[in] coreid USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[in] p_report_data buffer containing the report's data
* \param[in] length number of bytes in the \a p_report_data
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
* Application are free to handle data at its own will.
*/
void tusbd_hid_keyboard_set_report_cb(uint8_t coreid, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length);
/** @} */
/** @} */
//--------------------------------------------------------------------+
// MOUSE APPLICATION API
//--------------------------------------------------------------------+
/** \addtogroup ClassDriver_HID_Mouse Mouse
* @{ */
/** \defgroup Mouse_Device Device
* @{ */
/** \brief Check if the interface is currently busy or not
* \param[in] coreid USB Controller ID
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_mouse_send.
*/
bool tusbd_hid_mouse_is_busy(uint8_t coreid);
/** \brief Perform transfer queuing
* \param[in] coreid USB Controller ID
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \returns \ref tusb_error_t type to indicate success or error condition.
* \retval TUSB_ERROR_NONE on success
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
* The result of usb transfer will be reported by the interface's callback function
*/
tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_report);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK API
//--------------------------------------------------------------------+
void tusbd_hid_mouse_mounted_cb(uint8_t coreid);
void tusbd_hid_mouse_unmounted_cb(uint8_t coreid);
/** \brief Callback function that is invoked when an transferring event occurred
* after invoking \ref tusbd_hid_mouse_send
* \param[in] coreid USB Controller ID
* \param[in] event an value from \ref tusb_event_t
* \note event can be one of following
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
*/
void tusbd_hid_mouse_cb(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
* via control endpoint.
* \param[in] coreid USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[out] pp_report pointer to buffer that application need to update, value must be accessible by USB controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \param[in] requested_length number of bytes that host requested
* \retval non-zero Actual number of bytes in the response's buffer.
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
* sending STALL in the data phase.
* \note After this callback, the request is silently executed by the tinyusb stack, thus
* the completion of this control request will not be reported to application
*/
uint16_t tusbd_hid_mouse_get_report_cb(uint8_t coreid, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
* via control endpoint.
* \param[in] coreid USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[in] p_report_data buffer containing the report's data
* \param[in] length number of bytes in the \a p_report_data
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
* Application are free to handle data at its own will.
*/
void tusbd_hid_mouse_set_report_cb(uint8_t coreid, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length);
/** @} */
/** @} */
//--------------------------------------------------------------------+
// USBD-CLASS DRIVER API
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_
void hidd_init(void);
tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
tusb_error_t hidd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * p_request);
tusb_error_t hidd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
void hidd_close(uint8_t coreid);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_HID_DEVICE_H_ */
/**************************************************************************/
/*!
@file hid_device.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
#ifndef _TUSB_HID_DEVICE_H_
#define _TUSB_HID_DEVICE_H_
#include "common/common.h"
#include "device/usbd.h"
#include "hid.h"
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------+
// KEYBOARD APPLICATION API
//--------------------------------------------------------------------+
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
* @{ */
/** \defgroup Keyboard_Device Device
* @{ */
/** \brief Check if the interface is currently busy or not
* \param[in] coreid USB Controller ID
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_keyboard_send.
*/
bool tusbd_hid_keyboard_is_busy(uint8_t coreid);
/** \brief Submit USB transfer
* \param[in] coreid USB Controller ID
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \returns \ref tusb_error_t type to indicate success or error condition.
* \retval TUSB_ERROR_NONE on success
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
* The result of usb transfer will be reported by the interface's callback function
*/
tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const *p_report);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK API
//--------------------------------------------------------------------+
void tusbd_hid_keyboard_mounted_cb(uint8_t coreid);
void tusbd_hid_keyboard_unmounted_cb(uint8_t coreid);
/** \brief Callback function that is invoked when an transferring event occurred
* after invoking \ref tusbd_hid_keyboard_send
* \param[in] coreid USB Controller ID
* \param[in] event an value from \ref tusb_event_t
* \note event can be one of following
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
*/
void tusbd_hid_keyboard_cb(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
* via control endpoint.
* \param[in] coreid USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[out] pp_report pointer to buffer that application need to update, value must be accessible by USB controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \param[in] requested_length number of bytes that host requested
* \retval non-zero Actual number of bytes in the response's buffer.
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
* sending STALL in the data phase.
* \note After this callback, the request is silently executed by the tinyusb stack, thus
* the completion of this control request will not be reported to application.
* For Keyboard, USB host often uses this to turn on/off the LED for CAPLOCKS, NUMLOCK (\ref hid_keyboard_led_bm_t)
*/
uint16_t tusbd_hid_keyboard_get_report_cb(uint8_t coreid, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
* via control endpoint.
* \param[in] coreid USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[in] p_report_data buffer containing the report's data
* \param[in] length number of bytes in the \a p_report_data
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
* Application are free to handle data at its own will.
*/
void tusbd_hid_keyboard_set_report_cb(uint8_t coreid, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length);
/** @} */
/** @} */
//--------------------------------------------------------------------+
// MOUSE APPLICATION API
//--------------------------------------------------------------------+
/** \addtogroup ClassDriver_HID_Mouse Mouse
* @{ */
/** \defgroup Mouse_Device Device
* @{ */
/** \brief Check if the interface is currently busy or not
* \param[in] coreid USB Controller ID
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_mouse_send.
*/
bool tusbd_hid_mouse_is_busy(uint8_t coreid);
/** \brief Perform transfer queuing
* \param[in] coreid USB Controller ID
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \returns \ref tusb_error_t type to indicate success or error condition.
* \retval TUSB_ERROR_NONE on success
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
* The result of usb transfer will be reported by the interface's callback function
*/
tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_report);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK API
//--------------------------------------------------------------------+
void tusbd_hid_mouse_mounted_cb(uint8_t coreid);
void tusbd_hid_mouse_unmounted_cb(uint8_t coreid);
/** \brief Callback function that is invoked when an transferring event occurred
* after invoking \ref tusbd_hid_mouse_send
* \param[in] coreid USB Controller ID
* \param[in] event an value from \ref tusb_event_t
* \note event can be one of following
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
*/
void tusbd_hid_mouse_cb(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
* via control endpoint.
* \param[in] coreid USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[out] pp_report pointer to buffer that application need to update, value must be accessible by USB controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \param[in] requested_length number of bytes that host requested
* \retval non-zero Actual number of bytes in the response's buffer.
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
* sending STALL in the data phase.
* \note After this callback, the request is silently executed by the tinyusb stack, thus
* the completion of this control request will not be reported to application
*/
uint16_t tusbd_hid_mouse_get_report_cb(uint8_t coreid, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
* via control endpoint.
* \param[in] coreid USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[in] p_report_data buffer containing the report's data
* \param[in] length number of bytes in the \a p_report_data
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
* Application are free to handle data at its own will.
*/
void tusbd_hid_mouse_set_report_cb(uint8_t coreid, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length);
/** @} */
/** @} */
//--------------------------------------------------------------------+
// USBD-CLASS DRIVER API
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_
void hidd_init(void);
tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
tusb_error_t hidd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * p_request);
tusb_error_t hidd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
void hidd_close(uint8_t coreid);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_HID_DEVICE_H_ */

View File

@@ -1,134 +1,134 @@
/**************************************************************************/
/*!
@file binary.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_BINARY_H_
#define _TUSB_BINARY_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "primitive_types.h"
#include "compiler/compiler.h"
//------------- Bit manipulation -------------//
#define BIT_(n) (1U << (n)) ///< n-th Bit
#define BIT_SET_(x, n) ( (x) | BIT_(n) ) ///< set n-th bit of x to 1
#define BIT_CLR_(x, n) ( (x) & (~BIT_(n)) ) ///< clear n-th bit of x
#define BIT_TEST_(x, n) ( ((x) & BIT_(n)) ? true : false ) ///< check if n-th bit of x is 1
static inline uint32_t bit_set(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_set(uint32_t value, uint8_t n)
{
return value | BIT_(n);
}
static inline uint32_t bit_clear(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_clear(uint32_t value, uint8_t n)
{
return value & (~BIT_(n));
}
static inline bool bit_test(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline bool bit_test(uint32_t value, uint8_t n)
{
return (value & BIT_(n)) ? true : false;
}
///< create a mask with n-bit lsb set to 1
static inline uint32_t bit_mask(uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_mask(uint8_t n)
{
return (n < 32) ? ( BIT_(n) - 1 ) : UINT32_MAX;
}
static inline uint32_t bit_mask_range(uint8_t start, uint32_t end) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_mask_range(uint8_t start, uint32_t end)
{
return bit_mask(end+1) & ~ bit_mask(start);
}
static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, uint32_t pattern) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, uint32_t pattern)
{
return ( value & ~bit_mask_range(start, end) ) | (pattern << start);
}
//------------- Binary Constant -------------//
#if defined(__GNUC__) && !defined(__CC_ARM)
#define BIN8(x) ((uint8_t) (0b##x))
#define BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
#define BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
#else
// internal macro of B8, B16, B32
#define _B8__(x) (((x&0x0000000FUL)?1:0) \
+((x&0x000000F0UL)?2:0) \
+((x&0x00000F00UL)?4:0) \
+((x&0x0000F000UL)?8:0) \
+((x&0x000F0000UL)?16:0) \
+((x&0x00F00000UL)?32:0) \
+((x&0x0F000000UL)?64:0) \
+((x&0xF0000000UL)?128:0))
#define BIN8(d) ((uint8_t) _B8__(0x##d##UL))
#define BIN16(dmsb,dlsb) (((uint16_t)BIN8(dmsb)<<8) + BIN8(dlsb))
#define BIN32(dmsb,db2,db3,dlsb) \
(((uint32_t)BIN8(dmsb)<<24) \
+ ((uint32_t)BIN8(db2)<<16) \
+ ((uint32_t)BIN8(db3)<<8) \
+ BIN8(dlsb))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_BINARY_H_ */
/** @} */
/**************************************************************************/
/*!
@file binary.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_BINARY_H_
#define _TUSB_BINARY_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "primitive_types.h"
#include "compiler/compiler.h"
//------------- Bit manipulation -------------//
#define BIT_(n) (1U << (n)) ///< n-th Bit
#define BIT_SET_(x, n) ( (x) | BIT_(n) ) ///< set n-th bit of x to 1
#define BIT_CLR_(x, n) ( (x) & (~BIT_(n)) ) ///< clear n-th bit of x
#define BIT_TEST_(x, n) ( ((x) & BIT_(n)) ? true : false ) ///< check if n-th bit of x is 1
static inline uint32_t bit_set(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_set(uint32_t value, uint8_t n)
{
return value | BIT_(n);
}
static inline uint32_t bit_clear(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_clear(uint32_t value, uint8_t n)
{
return value & (~BIT_(n));
}
static inline bool bit_test(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline bool bit_test(uint32_t value, uint8_t n)
{
return (value & BIT_(n)) ? true : false;
}
///< create a mask with n-bit lsb set to 1
static inline uint32_t bit_mask(uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_mask(uint8_t n)
{
return (n < 32) ? ( BIT_(n) - 1 ) : UINT32_MAX;
}
static inline uint32_t bit_mask_range(uint8_t start, uint32_t end) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_mask_range(uint8_t start, uint32_t end)
{
return bit_mask(end+1) & ~ bit_mask(start);
}
static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, uint32_t pattern) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, uint32_t pattern)
{
return ( value & ~bit_mask_range(start, end) ) | (pattern << start);
}
//------------- Binary Constant -------------//
#if defined(__GNUC__) && !defined(__CC_ARM)
#define BIN8(x) ((uint8_t) (0b##x))
#define BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
#define BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
#else
// internal macro of B8, B16, B32
#define _B8__(x) (((x&0x0000000FUL)?1:0) \
+((x&0x000000F0UL)?2:0) \
+((x&0x00000F00UL)?4:0) \
+((x&0x0000F000UL)?8:0) \
+((x&0x000F0000UL)?16:0) \
+((x&0x00F00000UL)?32:0) \
+((x&0x0F000000UL)?64:0) \
+((x&0xF0000000UL)?128:0))
#define BIN8(d) ((uint8_t) _B8__(0x##d##UL))
#define BIN16(dmsb,dlsb) (((uint16_t)BIN8(dmsb)<<8) + BIN8(dlsb))
#define BIN32(dmsb,db2,db3,dlsb) \
(((uint32_t)BIN8(dmsb)<<24) \
+ ((uint32_t)BIN8(db2)<<16) \
+ ((uint32_t)BIN8(db3)<<8) \
+ BIN8(dlsb))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_BINARY_H_ */
/** @} */

View File

@@ -1,193 +1,193 @@
/**************************************************************************/
/*!
@file std_descriptors.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \brief Types & Declaration by USB Specs. All documents sources mentioned here (eg section 3.5) is referring to USB 2.0 Specs unless state otherwise
*/
/** \addtogroup group_usb_definitions USB Definitions
* @{
* \defgroup Group_StdDescriptor Standard Descriptors
* @{
*/
#ifndef _TUSB_STD_DESCRIPTORS_H_
#define _TUSB_STD_DESCRIPTORS_H_
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------+
// STANDARD DESCRIPTORS
//--------------------------------------------------------------------+
/// USB Standard Device Descriptor (section 9.6.1, table 9-8)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< DEVICE Descriptor Type.
uint16_t bcdUSB ; ///< BUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
uint8_t bDeviceClass ; ///< Class code (assigned by the USB-IF). \li If this field is reset to zero, each interface within a configuration specifies its own class information and the various interfaces operate independently. \li If this field is set to a value between 1 and FEH, the device supports different class specifications on different interfaces and the interfaces may not operate independently. This value identifies the class definition used for the aggregate interfaces. \li If this field is set to FFH, the device class is vendor-specific.
uint8_t bDeviceSubClass ; ///< Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass field. \li If the bDeviceClass field is reset to zero, this field must also be reset to zero. \li If the bDeviceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
uint8_t bDeviceProtocol ; ///< Protocol code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass and the bDeviceSubClass fields. If a device supports class-specific protocols on a device basis as opposed to an interface basis, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use class-specific protocols on a device basis. However, it may use classspecific protocols on an interface basis. \li If this field is set to FFH, the device uses a vendor-specific protocol on a device basis.
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid). For HS devices is fixed to 64.
uint16_t idVendor ; ///< Vendor ID (assigned by the USB-IF).
uint16_t idProduct ; ///< Product ID (assigned by the manufacturer).
uint16_t bcdDevice ; ///< Device release number in binary-coded decimal.
uint8_t iManufacturer ; ///< Index of string descriptor describing manufacturer.
uint8_t iProduct ; ///< Index of string descriptor describing product.
uint8_t iSerialNumber ; ///< Index of string descriptor describing the device's serial number.
uint8_t bNumConfigurations ; ///< Number of possible configurations.
} tusb_descriptor_device_t;
/// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
uint16_t wTotalLength ; ///< Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
uint8_t bNumInterfaces ; ///< Number of interfaces supported by this configuration
uint8_t bConfigurationValue ; ///< Value to use as an argument to the SetConfiguration() request to select this configuration.
uint8_t iConfiguration ; ///< Index of string descriptor describing this configuration
uint8_t bmAttributes ; ///< Configuration characteristics \n D7: Reserved (set to one)\n D6: Self-powered \n D5: Remote Wakeup \n D4...0: Reserved (reset to zero) \n D7 is reserved and must be set to one for historical reasons. \n A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see USB 2.0 spec Section 9.4.5). \n If a device configuration supports remote wakeup, D5 is set to one.
uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
} tusb_descriptor_configuration_t;
/// USB Standard Interface Descriptor (section 9.6.1 table 9-12)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< INTERFACE Descriptor Type
uint8_t bInterfaceNumber ; ///< Number of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration.
uint8_t bAlternateSetting ; ///< Value used to select this alternate setting for the interface identified in the prior field
uint8_t bNumEndpoints ; ///< Number of endpoints used by this interface (excluding endpoint zero). If this value is zero, this interface only uses the Default Control Pipe.
uint8_t bInterfaceClass ; ///< Class code (assigned by the USB-IF). \li A value of zero is reserved for future standardization. \li If this field is set to FFH, the interface class is vendor-specific. \li All other values are reserved for assignment by the USB-IF.
uint8_t bInterfaceSubClass ; ///< Subclass code (assigned by the USB-IF). \n These codes are qualified by the value of the bInterfaceClass field. \li If the bInterfaceClass field is reset to zero, this field must also be reset to zero. \li If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
uint8_t bInterfaceProtocol ; ///< Protocol code (assigned by the USB). \n These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use a class-specific protocol on this interface. \li If this field is set to FFH, the device uses a vendor-specific protocol for this interface.
uint8_t iInterface ; ///< Index of string descriptor describing this interface
} tusb_descriptor_interface_t;
/// USB Standard Endpoint Descriptor (section 9.6.1 table 9-13)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type
uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
ATTR_PACKED_STRUCT(struct) {
uint8_t xfer : 2;
uint8_t sync : 2;
uint8_t usage : 2;
uint8_t : 2;
} bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
ATTR_PACKED_STRUCT(struct) {
uint16_t size : 11; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
uint16_t hs_period_mult : 2;
uint16_t : 0;
}wMaxPacketSize;
uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
} tusb_descriptor_endpoint_t;
/// USB Other Speed Configuration Descriptor (section 9.6.1 table 9-11)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint16_t wTotalLength ; ///< Total length of data returned
uint8_t bNumInterfaces ; ///< Number of interfaces supported by this speed configuration
uint8_t bConfigurationValue ; ///< Value to use to select configuration
uint8_t IConfiguration ; ///< Index of string descriptor
uint8_t bmAttributes ; ///< Same as Configuration descriptor
uint8_t bMaxPower ; ///< Same as Configuration descriptor
} tusb_descriptor_other_speed_t;
/// USB Device Qualifier Descriptor (section 9.6.1 table 9-9)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Device Qualifier Type
uint16_t bcdUSB ; ///< USB specification version number (e.g., 0200H for V2.00)
uint8_t bDeviceClass ; ///< Class Code
uint8_t bDeviceSubClass ; ///< SubClass Code
uint8_t bDeviceProtocol ; ///< Protocol Code
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for other speed
uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
uint8_t bReserved ; ///< Reserved for future use, must be zero
} tusb_descriptor_device_qualifier_t;
/// USB Interface Association Descriptor (IAD ECN)
typedef ATTR_PACKED_STRUCT(struct)
{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint8_t bFirstInterface ; ///< Index of the first associated interface.
uint8_t bInterfaceCount ; ///< Total number of associated interfaces.
uint8_t bFunctionClass ; ///< Interface class ID.
uint8_t bFunctionSubClass ; ///< Interface subclass ID.
uint8_t bFunctionProtocol ; ///< Interface protocol ID.
uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
} tusb_descriptor_interface_association_t;
/// USB Header Descriptor
typedef ATTR_PACKED_STRUCT(struct)
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
} tusb_descriptor_header_t;
typedef ATTR_PACKED_STRUCT(struct)
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
uint16_t unicode_string[];
} tusb_descriptor_string_t;
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_STD_DESCRIPTORS_H_ */
/** @} */
/** @} */
/**************************************************************************/
/*!
@file std_descriptors.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \brief Types & Declaration by USB Specs. All documents sources mentioned here (eg section 3.5) is referring to USB 2.0 Specs unless state otherwise
*/
/** \addtogroup group_usb_definitions USB Definitions
* @{
* \defgroup Group_StdDescriptor Standard Descriptors
* @{
*/
#ifndef _TUSB_STD_DESCRIPTORS_H_
#define _TUSB_STD_DESCRIPTORS_H_
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------+
// STANDARD DESCRIPTORS
//--------------------------------------------------------------------+
/// USB Standard Device Descriptor (section 9.6.1, table 9-8)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< DEVICE Descriptor Type.
uint16_t bcdUSB ; ///< BUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
uint8_t bDeviceClass ; ///< Class code (assigned by the USB-IF). \li If this field is reset to zero, each interface within a configuration specifies its own class information and the various interfaces operate independently. \li If this field is set to a value between 1 and FEH, the device supports different class specifications on different interfaces and the interfaces may not operate independently. This value identifies the class definition used for the aggregate interfaces. \li If this field is set to FFH, the device class is vendor-specific.
uint8_t bDeviceSubClass ; ///< Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass field. \li If the bDeviceClass field is reset to zero, this field must also be reset to zero. \li If the bDeviceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
uint8_t bDeviceProtocol ; ///< Protocol code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass and the bDeviceSubClass fields. If a device supports class-specific protocols on a device basis as opposed to an interface basis, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use class-specific protocols on a device basis. However, it may use classspecific protocols on an interface basis. \li If this field is set to FFH, the device uses a vendor-specific protocol on a device basis.
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid). For HS devices is fixed to 64.
uint16_t idVendor ; ///< Vendor ID (assigned by the USB-IF).
uint16_t idProduct ; ///< Product ID (assigned by the manufacturer).
uint16_t bcdDevice ; ///< Device release number in binary-coded decimal.
uint8_t iManufacturer ; ///< Index of string descriptor describing manufacturer.
uint8_t iProduct ; ///< Index of string descriptor describing product.
uint8_t iSerialNumber ; ///< Index of string descriptor describing the device's serial number.
uint8_t bNumConfigurations ; ///< Number of possible configurations.
} tusb_descriptor_device_t;
/// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
uint16_t wTotalLength ; ///< Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
uint8_t bNumInterfaces ; ///< Number of interfaces supported by this configuration
uint8_t bConfigurationValue ; ///< Value to use as an argument to the SetConfiguration() request to select this configuration.
uint8_t iConfiguration ; ///< Index of string descriptor describing this configuration
uint8_t bmAttributes ; ///< Configuration characteristics \n D7: Reserved (set to one)\n D6: Self-powered \n D5: Remote Wakeup \n D4...0: Reserved (reset to zero) \n D7 is reserved and must be set to one for historical reasons. \n A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see USB 2.0 spec Section 9.4.5). \n If a device configuration supports remote wakeup, D5 is set to one.
uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
} tusb_descriptor_configuration_t;
/// USB Standard Interface Descriptor (section 9.6.1 table 9-12)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< INTERFACE Descriptor Type
uint8_t bInterfaceNumber ; ///< Number of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration.
uint8_t bAlternateSetting ; ///< Value used to select this alternate setting for the interface identified in the prior field
uint8_t bNumEndpoints ; ///< Number of endpoints used by this interface (excluding endpoint zero). If this value is zero, this interface only uses the Default Control Pipe.
uint8_t bInterfaceClass ; ///< Class code (assigned by the USB-IF). \li A value of zero is reserved for future standardization. \li If this field is set to FFH, the interface class is vendor-specific. \li All other values are reserved for assignment by the USB-IF.
uint8_t bInterfaceSubClass ; ///< Subclass code (assigned by the USB-IF). \n These codes are qualified by the value of the bInterfaceClass field. \li If the bInterfaceClass field is reset to zero, this field must also be reset to zero. \li If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
uint8_t bInterfaceProtocol ; ///< Protocol code (assigned by the USB). \n These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use a class-specific protocol on this interface. \li If this field is set to FFH, the device uses a vendor-specific protocol for this interface.
uint8_t iInterface ; ///< Index of string descriptor describing this interface
} tusb_descriptor_interface_t;
/// USB Standard Endpoint Descriptor (section 9.6.1 table 9-13)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type
uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
ATTR_PACKED_STRUCT(struct) {
uint8_t xfer : 2;
uint8_t sync : 2;
uint8_t usage : 2;
uint8_t : 2;
} bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
ATTR_PACKED_STRUCT(struct) {
uint16_t size : 11; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
uint16_t hs_period_mult : 2;
uint16_t : 0;
}wMaxPacketSize;
uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
} tusb_descriptor_endpoint_t;
/// USB Other Speed Configuration Descriptor (section 9.6.1 table 9-11)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint16_t wTotalLength ; ///< Total length of data returned
uint8_t bNumInterfaces ; ///< Number of interfaces supported by this speed configuration
uint8_t bConfigurationValue ; ///< Value to use to select configuration
uint8_t IConfiguration ; ///< Index of string descriptor
uint8_t bmAttributes ; ///< Same as Configuration descriptor
uint8_t bMaxPower ; ///< Same as Configuration descriptor
} tusb_descriptor_other_speed_t;
/// USB Device Qualifier Descriptor (section 9.6.1 table 9-9)
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Device Qualifier Type
uint16_t bcdUSB ; ///< USB specification version number (e.g., 0200H for V2.00)
uint8_t bDeviceClass ; ///< Class Code
uint8_t bDeviceSubClass ; ///< SubClass Code
uint8_t bDeviceProtocol ; ///< Protocol Code
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for other speed
uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
uint8_t bReserved ; ///< Reserved for future use, must be zero
} tusb_descriptor_device_qualifier_t;
/// USB Interface Association Descriptor (IAD ECN)
typedef ATTR_PACKED_STRUCT(struct)
{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint8_t bFirstInterface ; ///< Index of the first associated interface.
uint8_t bInterfaceCount ; ///< Total number of associated interfaces.
uint8_t bFunctionClass ; ///< Interface class ID.
uint8_t bFunctionSubClass ; ///< Interface subclass ID.
uint8_t bFunctionProtocol ; ///< Interface protocol ID.
uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
} tusb_descriptor_interface_association_t;
/// USB Header Descriptor
typedef ATTR_PACKED_STRUCT(struct)
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
} tusb_descriptor_header_t;
typedef ATTR_PACKED_STRUCT(struct)
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
uint16_t unicode_string[];
} tusb_descriptor_string_t;
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_STD_DESCRIPTORS_H_ */
/** @} */
/** @} */

View File

@@ -1,84 +1,84 @@
/**************************************************************************/
/*!
@file std_request.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_STD_REQUEST_H_
#define _TUSB_STD_REQUEST_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef ATTR_PACKED_STRUCT(struct){
union {
ATTR_PACKED_STRUCT(struct) {
uint8_t recipient : 5; /**< Recipient type tusb_std_request_recipient_t. */
uint8_t type : 2; /**< Request type tusb_control_request_type_t. */
uint8_t direction : 1; /**< Direction type. tusb_direction_t */
} bmRequestType_bit;
uint8_t bmRequestType;
};
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} tusb_control_request_t;
STATIC_ASSERT( sizeof(tusb_control_request_t) == 8, "mostly compiler option issue");
// TODO move to somewhere suitable
static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t recipient) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t recipient)
{
return ((uint8_t) (direction << 7)) | ((uint8_t) (type << 5)) | (recipient);
}
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_STD_REQUEST_H_ */
/** @} */
/**************************************************************************/
/*!
@file std_request.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_STD_REQUEST_H_
#define _TUSB_STD_REQUEST_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef ATTR_PACKED_STRUCT(struct){
union {
ATTR_PACKED_STRUCT(struct) {
uint8_t recipient : 5; /**< Recipient type tusb_std_request_recipient_t. */
uint8_t type : 2; /**< Request type tusb_control_request_type_t. */
uint8_t direction : 1; /**< Direction type. tusb_direction_t */
} bmRequestType_bit;
uint8_t bmRequestType;
};
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} tusb_control_request_t;
STATIC_ASSERT( sizeof(tusb_control_request_t) == 8, "mostly compiler option issue");
// TODO move to somewhere suitable
static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t recipient) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t recipient)
{
return ((uint8_t) (direction << 7)) | ((uint8_t) (type << 5)) | (recipient);
}
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_STD_REQUEST_H_ */
/** @} */

View File

@@ -1,85 +1,85 @@
/**************************************************************************/
/*!
@file timeout_timer.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \file
* \brief TBD
*
* \note TBD
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_TIMEOUT_TTIMER_H_
#define _TUSB_TIMEOUT_TTIMER_H_
#include "compiler/compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
uint32_t start;
uint32_t interval;
}timeout_timer_t;
static inline void timeout_set(timeout_timer_t* tt, uint32_t msec) ATTR_ALWAYS_INLINE;
static inline void timeout_set(timeout_timer_t* tt, uint32_t msec)
{
tt->interval = osal_tick_from_msec(msec);
tt->start = osal_tick_get();
}
static inline bool timeout_expired(timeout_timer_t* tt) ATTR_ALWAYS_INLINE;
static inline bool timeout_expired(timeout_timer_t* tt)
{
return ( osal_tick_get() - tt->start ) >= tt->interval;
}
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_TIMEOUT_TTIMER_H_ */
/** @} */
/**************************************************************************/
/*!
@file timeout_timer.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \file
* \brief TBD
*
* \note TBD
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_TIMEOUT_TTIMER_H_
#define _TUSB_TIMEOUT_TTIMER_H_
#include "compiler/compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
uint32_t start;
uint32_t interval;
}timeout_timer_t;
static inline void timeout_set(timeout_timer_t* tt, uint32_t msec) ATTR_ALWAYS_INLINE;
static inline void timeout_set(timeout_timer_t* tt, uint32_t msec)
{
tt->interval = osal_tick_from_msec(msec);
tt->start = osal_tick_get();
}
static inline bool timeout_expired(timeout_timer_t* tt) ATTR_ALWAYS_INLINE;
static inline bool timeout_expired(timeout_timer_t* tt)
{
return ( osal_tick_get() - tt->start ) >= tt->interval;
}
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_TIMEOUT_TTIMER_H_ */
/** @} */

View File

@@ -1,237 +1,237 @@
/**************************************************************************/
/*!
@file tusb_types.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup group_usb_definitions
* \defgroup USBDef_Type USB Types
* @{
*/
#ifndef _TUSB_TUSB_TYPES_H_
#define _TUSB_TUSB_TYPES_H_
#ifdef __cplusplus
extern "C" {
#endif
/// defined base on EHCI specs value for Endpoint Speed
typedef enum {
TUSB_SPEED_FULL = 0,
TUSB_SPEED_LOW ,
TUSB_SPEED_HIGH
}tusb_speed_t;
/// defined base on USB Specs Endpoint's bmAttributes
typedef enum {
TUSB_XFER_CONTROL = 0 ,
TUSB_XFER_ISOCHRONOUS ,
TUSB_XFER_BULK ,
TUSB_XFER_INTERRUPT
}tusb_xfer_type_t;
typedef enum {
TUSB_DIR_HOST_TO_DEV = 0,
TUSB_DIR_DEV_TO_HOST = 1,
TUSB_DIR_DEV_TO_HOST_MASK = 0x80
}tusb_direction_t;
/// USB Descriptor Types (section 9.4 table 9-5)
typedef enum {
TUSB_DESC_TYPE_DEVICE = 0x01 ,
TUSB_DESC_TYPE_CONFIGURATION = 0x02 ,
TUSB_DESC_TYPE_STRING = 0x03 ,
TUSB_DESC_TYPE_INTERFACE = 0x04 ,
TUSB_DESC_TYPE_ENDPOINT = 0x05 ,
TUSB_DESC_TYPE_DEVICE_QUALIFIER = 0x06 ,
TUSB_DESC_TYPE_OTHER_SPEED_CONFIGURATION = 0x07 ,
TUSB_DESC_TYPE_INTERFACE_POWER = 0x08 ,
TUSB_DESC_TYPE_OTG = 0x09 ,
TUSB_DESC_TYPE_DEBUG = 0x0A ,
TUSB_DESC_TYPE_INTERFACE_ASSOCIATION = 0x0B ,
TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC = 0x24
}tusb_std_descriptor_type_t;
typedef enum {
TUSB_REQUEST_GET_STATUS =0 , ///< 0
TUSB_REQUEST_CLEAR_FEATURE , ///< 1
TUSB_REQUEST_RESERVED , ///< 2
TUSB_REQUEST_SET_FEATURE , ///< 3
TUSB_REQUEST_RESERVED2 , ///< 4
TUSB_REQUEST_SET_ADDRESS , ///< 5
TUSB_REQUEST_GET_DESCRIPTOR , ///< 6
TUSB_REQUEST_SET_DESCRIPTOR , ///< 7
TUSB_REQUEST_GET_CONFIGURATION , ///< 8
TUSB_REQUEST_SET_CONFIGURATION , ///< 9
TUSB_REQUEST_GET_INTERFACE , ///< 10
TUSB_REQUEST_SET_INTERFACE , ///< 11
TUSB_REQUEST_SYNCH_FRAME ///< 12
}tusb_std_request_code_t;
typedef enum {
TUSB_REQUEST_TYPE_STANDARD = 0,
TUSB_REQUEST_TYPE_CLASS,
TUSB_REQUEST_TYPE_VENDOR
} tusb_control_request_type_t;
typedef enum {
TUSB_REQUEST_RECIPIENT_DEVICE =0,
TUSB_REQUEST_RECIPIENT_INTERFACE,
TUSB_REQUEST_RECIPIENT_ENDPOINT,
TUSB_REQUEST_RECIPIENT_OTHER
} tusb_std_request_recipient_t;
typedef enum {
TUSB_CLASS_UNSPECIFIED = 0 , ///< 0
TUSB_CLASS_AUDIO = 1 , ///< 1
TUSB_CLASS_CDC = 2 , ///< 2
TUSB_CLASS_HID = 3 , ///< 3
TUSB_CLASS_RESERVED_4 = 4 , ///< 4
TUSB_CLASS_PHYSICAL = 5 , ///< 5
TUSB_CLASS_IMAGE = 6 , ///< 6
TUSB_CLASS_PRINTER = 7 , ///< 7
TUSB_CLASS_MSC = 8 , ///< 8
TUSB_CLASS_HUB = 9 , ///< 9
TUSB_CLASS_CDC_DATA = 10 , ///< 10
TUSB_CLASS_SMART_CARD = 11 , ///< 11
TUSB_CLASS_RESERVED_12 = 12 , ///< 12
TUSB_CLASS_CONTENT_SECURITY = 13 , ///< 13
TUSB_CLASS_VIDEO = 14 , ///< 14
TUSB_CLASS_PERSONAL_HEALTHCARE = 15 , ///< 15
TUSB_CLASS_AUDIO_VIDEO = 16 , ///< 16
TUSB_CLASS_MAPPED_INDEX_START = 17 , // TODO compact & minimize this number
TUSB_CLASS_MAPPED_INDEX_END = TUSB_CLASS_MAPPED_INDEX_START + 5,
TUSB_CLASS_DIAGNOSTIC = 0xDC ,
TUSB_CLASS_WIRELESS_CONTROLLER = 0xE0 ,
TUSB_CLASS_MISC = 0xEF ,
TUSB_CLASS_APPLICATION_SPECIFIC = 0xFE ,
TUSB_CLASS_VENDOR_SPECIFIC = 0xFF
}tusb_std_class_code_t;
typedef enum {
MISC_SUBCLASS_COMMON = 2
}misc_subclass_type_t;
typedef enum {
MISC_PROTOCOL_IAD = 1
}misc_protocol_type_t;
typedef enum tusb_std_class_flag_{
TUSB_CLASS_FLAG_AUDIO = BIT_(TUSB_CLASS_AUDIO) , ///< 1
TUSB_CLASS_FLAG_CDC = BIT_(TUSB_CLASS_CDC) , ///< 2
TUSB_CLASS_FLAG_HID = BIT_(TUSB_CLASS_HID) , ///< 3
TUSB_CLASS_FLAG_PHYSICAL = BIT_(TUSB_CLASS_PHYSICAL) , ///< 5
TUSB_CLASS_FLAG_IMAGE = BIT_(TUSB_CLASS_IMAGE) , ///< 6
TUSB_CLASS_FLAG_PRINTER = BIT_(TUSB_CLASS_PRINTER) , ///< 7
TUSB_CLASS_FLAG_MSC = BIT_(TUSB_CLASS_MSC) , ///< 8
TUSB_CLASS_FLAG_HUB = BIT_(TUSB_CLASS_HUB) , ///< 9
TUSB_CLASS_FLAG_CDC_DATA = BIT_(TUSB_CLASS_CDC_DATA) , ///< 10
TUSB_CLASS_FLAG_SMART_CARD = BIT_(TUSB_CLASS_SMART_CARD) , ///< 11
TUSB_CLASS_FLAG_CONTENT_SECURITY = BIT_(TUSB_CLASS_CONTENT_SECURITY) , ///< 13
TUSB_CLASS_FLAG_VIDEO = BIT_(TUSB_CLASS_VIDEO) , ///< 14
TUSB_CLASS_FLAG_PERSONAL_HEALTHCARE = BIT_(TUSB_CLASS_PERSONAL_HEALTHCARE) , ///< 15
TUSB_CLASS_FLAG_AUDIO_VIDEO = BIT_(TUSB_CLASS_AUDIO_VIDEO) , ///< 16
TUSB_CLASS_FLAG_DIAGNOSTIC = BIT_(27) ,
TUSB_CLASS_FLAG_WIRELESS_CONTROLLER = BIT_(28) ,
TUSB_CLASS_FLAG_MISC = BIT_(29) ,
TUSB_CLASS_FLAG_APPLICATION_SPECIFIC = BIT_(30) ,
TUSB_CLASS_FLAG_VENDOR_SPECIFIC = BIT_(31)
} tusb_std_class_flag_t;
enum {
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5),
TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6),
TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7)
};
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
/// Device State
typedef enum tusb_device_state_{
TUSB_DEVICE_STATE_UNPLUG = 0 ,
TUSB_DEVICE_STATE_ADDRESSED ,
TUSB_DEVICE_STATE_CONFIGURED ,
TUSB_DEVICE_STATE_SUSPENDED ,
TUSB_DEVICE_STATE_REMOVING ,
TUSB_DEVICE_STATE_SAFE_REMOVE ,
TUSB_DEVICE_STATE_INVALID_PARAMETER
}tusb_device_state_t;
typedef enum {
TUSB_EVENT_NONE = 0,
TUSB_EVENT_XFER_COMPLETE,
TUSB_EVENT_XFER_ERROR,
TUSB_EVENT_XFER_STALLED,
TUSB_EVENT_BUS_RESET, // TODO refractor
TUSB_EVENT_SETUP_RECEIVED,
}tusb_event_t;
enum {
DESCRIPTOR_OFFSET_LENGTH = 0,
DESCRIPTOR_OFFSET_TYPE = 1
};
enum {
INTERFACE_INVALID_NUMBER = 0xff
};
static inline uint8_t std_class_code_to_index(uint8_t std_class_code) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint8_t std_class_code_to_index(uint8_t std_class_code)
{
return (std_class_code <= TUSB_CLASS_AUDIO_VIDEO ) ? std_class_code :
(std_class_code == TUSB_CLASS_DIAGNOSTIC ) ? TUSB_CLASS_MAPPED_INDEX_START :
(std_class_code == TUSB_CLASS_WIRELESS_CONTROLLER ) ? TUSB_CLASS_MAPPED_INDEX_START + 1 :
(std_class_code == TUSB_CLASS_MISC ) ? TUSB_CLASS_MAPPED_INDEX_START + 2 :
(std_class_code == TUSB_CLASS_APPLICATION_SPECIFIC ) ? TUSB_CLASS_MAPPED_INDEX_START + 3 :
(std_class_code == TUSB_CLASS_VENDOR_SPECIFIC ) ? TUSB_CLASS_MAPPED_INDEX_START + 4 : 0;
}
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_TUSB_TYPES_H_ */
/** @} */
/**************************************************************************/
/*!
@file tusb_types.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup group_usb_definitions
* \defgroup USBDef_Type USB Types
* @{
*/
#ifndef _TUSB_TUSB_TYPES_H_
#define _TUSB_TUSB_TYPES_H_
#ifdef __cplusplus
extern "C" {
#endif
/// defined base on EHCI specs value for Endpoint Speed
typedef enum {
TUSB_SPEED_FULL = 0,
TUSB_SPEED_LOW ,
TUSB_SPEED_HIGH
}tusb_speed_t;
/// defined base on USB Specs Endpoint's bmAttributes
typedef enum {
TUSB_XFER_CONTROL = 0 ,
TUSB_XFER_ISOCHRONOUS ,
TUSB_XFER_BULK ,
TUSB_XFER_INTERRUPT
}tusb_xfer_type_t;
typedef enum {
TUSB_DIR_HOST_TO_DEV = 0,
TUSB_DIR_DEV_TO_HOST = 1,
TUSB_DIR_DEV_TO_HOST_MASK = 0x80
}tusb_direction_t;
/// USB Descriptor Types (section 9.4 table 9-5)
typedef enum {
TUSB_DESC_TYPE_DEVICE = 0x01 ,
TUSB_DESC_TYPE_CONFIGURATION = 0x02 ,
TUSB_DESC_TYPE_STRING = 0x03 ,
TUSB_DESC_TYPE_INTERFACE = 0x04 ,
TUSB_DESC_TYPE_ENDPOINT = 0x05 ,
TUSB_DESC_TYPE_DEVICE_QUALIFIER = 0x06 ,
TUSB_DESC_TYPE_OTHER_SPEED_CONFIGURATION = 0x07 ,
TUSB_DESC_TYPE_INTERFACE_POWER = 0x08 ,
TUSB_DESC_TYPE_OTG = 0x09 ,
TUSB_DESC_TYPE_DEBUG = 0x0A ,
TUSB_DESC_TYPE_INTERFACE_ASSOCIATION = 0x0B ,
TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC = 0x24
}tusb_std_descriptor_type_t;
typedef enum {
TUSB_REQUEST_GET_STATUS =0 , ///< 0
TUSB_REQUEST_CLEAR_FEATURE , ///< 1
TUSB_REQUEST_RESERVED , ///< 2
TUSB_REQUEST_SET_FEATURE , ///< 3
TUSB_REQUEST_RESERVED2 , ///< 4
TUSB_REQUEST_SET_ADDRESS , ///< 5
TUSB_REQUEST_GET_DESCRIPTOR , ///< 6
TUSB_REQUEST_SET_DESCRIPTOR , ///< 7
TUSB_REQUEST_GET_CONFIGURATION , ///< 8
TUSB_REQUEST_SET_CONFIGURATION , ///< 9
TUSB_REQUEST_GET_INTERFACE , ///< 10
TUSB_REQUEST_SET_INTERFACE , ///< 11
TUSB_REQUEST_SYNCH_FRAME ///< 12
}tusb_std_request_code_t;
typedef enum {
TUSB_REQUEST_TYPE_STANDARD = 0,
TUSB_REQUEST_TYPE_CLASS,
TUSB_REQUEST_TYPE_VENDOR
} tusb_control_request_type_t;
typedef enum {
TUSB_REQUEST_RECIPIENT_DEVICE =0,
TUSB_REQUEST_RECIPIENT_INTERFACE,
TUSB_REQUEST_RECIPIENT_ENDPOINT,
TUSB_REQUEST_RECIPIENT_OTHER
} tusb_std_request_recipient_t;
typedef enum {
TUSB_CLASS_UNSPECIFIED = 0 , ///< 0
TUSB_CLASS_AUDIO = 1 , ///< 1
TUSB_CLASS_CDC = 2 , ///< 2
TUSB_CLASS_HID = 3 , ///< 3
TUSB_CLASS_RESERVED_4 = 4 , ///< 4
TUSB_CLASS_PHYSICAL = 5 , ///< 5
TUSB_CLASS_IMAGE = 6 , ///< 6
TUSB_CLASS_PRINTER = 7 , ///< 7
TUSB_CLASS_MSC = 8 , ///< 8
TUSB_CLASS_HUB = 9 , ///< 9
TUSB_CLASS_CDC_DATA = 10 , ///< 10
TUSB_CLASS_SMART_CARD = 11 , ///< 11
TUSB_CLASS_RESERVED_12 = 12 , ///< 12
TUSB_CLASS_CONTENT_SECURITY = 13 , ///< 13
TUSB_CLASS_VIDEO = 14 , ///< 14
TUSB_CLASS_PERSONAL_HEALTHCARE = 15 , ///< 15
TUSB_CLASS_AUDIO_VIDEO = 16 , ///< 16
TUSB_CLASS_MAPPED_INDEX_START = 17 , // TODO compact & minimize this number
TUSB_CLASS_MAPPED_INDEX_END = TUSB_CLASS_MAPPED_INDEX_START + 5,
TUSB_CLASS_DIAGNOSTIC = 0xDC ,
TUSB_CLASS_WIRELESS_CONTROLLER = 0xE0 ,
TUSB_CLASS_MISC = 0xEF ,
TUSB_CLASS_APPLICATION_SPECIFIC = 0xFE ,
TUSB_CLASS_VENDOR_SPECIFIC = 0xFF
}tusb_std_class_code_t;
typedef enum {
MISC_SUBCLASS_COMMON = 2
}misc_subclass_type_t;
typedef enum {
MISC_PROTOCOL_IAD = 1
}misc_protocol_type_t;
typedef enum tusb_std_class_flag_{
TUSB_CLASS_FLAG_AUDIO = BIT_(TUSB_CLASS_AUDIO) , ///< 1
TUSB_CLASS_FLAG_CDC = BIT_(TUSB_CLASS_CDC) , ///< 2
TUSB_CLASS_FLAG_HID = BIT_(TUSB_CLASS_HID) , ///< 3
TUSB_CLASS_FLAG_PHYSICAL = BIT_(TUSB_CLASS_PHYSICAL) , ///< 5
TUSB_CLASS_FLAG_IMAGE = BIT_(TUSB_CLASS_IMAGE) , ///< 6
TUSB_CLASS_FLAG_PRINTER = BIT_(TUSB_CLASS_PRINTER) , ///< 7
TUSB_CLASS_FLAG_MSC = BIT_(TUSB_CLASS_MSC) , ///< 8
TUSB_CLASS_FLAG_HUB = BIT_(TUSB_CLASS_HUB) , ///< 9
TUSB_CLASS_FLAG_CDC_DATA = BIT_(TUSB_CLASS_CDC_DATA) , ///< 10
TUSB_CLASS_FLAG_SMART_CARD = BIT_(TUSB_CLASS_SMART_CARD) , ///< 11
TUSB_CLASS_FLAG_CONTENT_SECURITY = BIT_(TUSB_CLASS_CONTENT_SECURITY) , ///< 13
TUSB_CLASS_FLAG_VIDEO = BIT_(TUSB_CLASS_VIDEO) , ///< 14
TUSB_CLASS_FLAG_PERSONAL_HEALTHCARE = BIT_(TUSB_CLASS_PERSONAL_HEALTHCARE) , ///< 15
TUSB_CLASS_FLAG_AUDIO_VIDEO = BIT_(TUSB_CLASS_AUDIO_VIDEO) , ///< 16
TUSB_CLASS_FLAG_DIAGNOSTIC = BIT_(27) ,
TUSB_CLASS_FLAG_WIRELESS_CONTROLLER = BIT_(28) ,
TUSB_CLASS_FLAG_MISC = BIT_(29) ,
TUSB_CLASS_FLAG_APPLICATION_SPECIFIC = BIT_(30) ,
TUSB_CLASS_FLAG_VENDOR_SPECIFIC = BIT_(31)
} tusb_std_class_flag_t;
enum {
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5),
TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6),
TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7)
};
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
/// Device State
typedef enum tusb_device_state_{
TUSB_DEVICE_STATE_UNPLUG = 0 ,
TUSB_DEVICE_STATE_ADDRESSED ,
TUSB_DEVICE_STATE_CONFIGURED ,
TUSB_DEVICE_STATE_SUSPENDED ,
TUSB_DEVICE_STATE_REMOVING ,
TUSB_DEVICE_STATE_SAFE_REMOVE ,
TUSB_DEVICE_STATE_INVALID_PARAMETER
}tusb_device_state_t;
typedef enum {
TUSB_EVENT_NONE = 0,
TUSB_EVENT_XFER_COMPLETE,
TUSB_EVENT_XFER_ERROR,
TUSB_EVENT_XFER_STALLED,
TUSB_EVENT_BUS_RESET, // TODO refractor
TUSB_EVENT_SETUP_RECEIVED,
}tusb_event_t;
enum {
DESCRIPTOR_OFFSET_LENGTH = 0,
DESCRIPTOR_OFFSET_TYPE = 1
};
enum {
INTERFACE_INVALID_NUMBER = 0xff
};
static inline uint8_t std_class_code_to_index(uint8_t std_class_code) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint8_t std_class_code_to_index(uint8_t std_class_code)
{
return (std_class_code <= TUSB_CLASS_AUDIO_VIDEO ) ? std_class_code :
(std_class_code == TUSB_CLASS_DIAGNOSTIC ) ? TUSB_CLASS_MAPPED_INDEX_START :
(std_class_code == TUSB_CLASS_WIRELESS_CONTROLLER ) ? TUSB_CLASS_MAPPED_INDEX_START + 1 :
(std_class_code == TUSB_CLASS_MISC ) ? TUSB_CLASS_MAPPED_INDEX_START + 2 :
(std_class_code == TUSB_CLASS_APPLICATION_SPECIFIC ) ? TUSB_CLASS_MAPPED_INDEX_START + 3 :
(std_class_code == TUSB_CLASS_VENDOR_SPECIFIC ) ? TUSB_CLASS_MAPPED_INDEX_START + 4 : 0;
}
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_TUSB_TYPES_H_ */
/** @} */

View File

@@ -1,106 +1,106 @@
/**************************************************************************/
/*!
@file usbd.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_USBD_H_
#define _TUSB_USBD_H_
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
#include "common/common.h"
#include "osal/osal.h"
#include "dcd.h"
#ifdef __cplusplus
extern "C" {
#endif
// LPC11uxx and LPC13uxx requires each buffer has to be 64-byte alignment
#if TUSB_CFG_MCU == MCU_LPC11UXX || TUSB_CFG_MCU == MCU_LPC13UXX
#define ATTR_USB_MIN_ALIGNMENT ATTR_ALIGNED(64)
#else
#define ATTR_USB_MIN_ALIGNMENT
#endif
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
typedef struct {
void (* const init) (void);
tusb_error_t (* const open)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*);
tusb_error_t (* const control_request_subtask) (uint8_t, tusb_control_request_t const *);
tusb_error_t (* const xfer_cb) (endpoint_handle_t, tusb_event_t, uint32_t);
void (* const close) (uint8_t);
} usbd_class_driver_t;
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
bool tusbd_is_configured(uint8_t coreid) ATTR_WARN_UNUSED_RESULT;
//void tusbd_device_suspended_cb(uint8_t coreid);
//--------------------------------------------------------------------+
// CLASS-USBD & INTERNAL API
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_
extern osal_semaphore_handle_t usbd_control_xfer_sem_hdl;
tusb_error_t usbd_init(void);
OSAL_TASK_FUNCTION (usbd_task) (void* p_task_para);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_USBD_H_ */
/** @} */
/**************************************************************************/
/*!
@file usbd.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_USBD_H_
#define _TUSB_USBD_H_
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
#include "common/common.h"
#include "osal/osal.h"
#include "dcd.h"
#ifdef __cplusplus
extern "C" {
#endif
// LPC11uxx and LPC13uxx requires each buffer has to be 64-byte alignment
#if TUSB_CFG_MCU == MCU_LPC11UXX || TUSB_CFG_MCU == MCU_LPC13UXX
#define ATTR_USB_MIN_ALIGNMENT ATTR_ALIGNED(64)
#else
#define ATTR_USB_MIN_ALIGNMENT
#endif
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
typedef struct {
void (* const init) (void);
tusb_error_t (* const open)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*);
tusb_error_t (* const control_request_subtask) (uint8_t, tusb_control_request_t const *);
tusb_error_t (* const xfer_cb) (endpoint_handle_t, tusb_event_t, uint32_t);
void (* const close) (uint8_t);
} usbd_class_driver_t;
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
bool tusbd_is_configured(uint8_t coreid) ATTR_WARN_UNUSED_RESULT;
//void tusbd_device_suspended_cb(uint8_t coreid);
//--------------------------------------------------------------------+
// CLASS-USBD & INTERNAL API
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_
extern osal_semaphore_handle_t usbd_control_xfer_sem_hdl;
tusb_error_t usbd_init(void);
OSAL_TASK_FUNCTION (usbd_task) (void* p_task_para);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_USBD_H_ */
/** @} */

View File

@@ -1,89 +1,89 @@
/**************************************************************************/
/*!
@file usbd_dcd.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_USBD_DCD_H_
#define _TUSB_USBD_DCD_H_
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
#include "common/common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
USBD_INTERFACE_NUM_MAX = 16 // USB specs specify up to 16 endpoints per device
};
typedef enum {
USBD_BUS_EVENT_RESET = 1,
USBD_BUS_EVENT_UNPLUGGED,
USBD_BUS_EVENT_SUSPENDED,
USBD_BUS_EVENT_RESUME
}usbd_bus_event_type_t;
typedef struct {
volatile uint8_t state;
uint8_t interface2class[USBD_INTERFACE_NUM_MAX]; // determine interface number belongs to which class
}usbd_device_info_t;
extern usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER];
//--------------------------------------------------------------------+
// callback from DCD ISR
//--------------------------------------------------------------------+
void usbd_dcd_bus_event_isr(uint8_t coreid, usbd_bus_event_type_t bus_event);
void usbd_setup_received_isr(uint8_t coreid, tusb_control_request_t * p_request);
void usbd_xfer_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_USBD_DCD_H_ */
/** @} */
/**************************************************************************/
/*!
@file usbd_dcd.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_USBD_DCD_H_
#define _TUSB_USBD_DCD_H_
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
#include "common/common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
USBD_INTERFACE_NUM_MAX = 16 // USB specs specify up to 16 endpoints per device
};
typedef enum {
USBD_BUS_EVENT_RESET = 1,
USBD_BUS_EVENT_UNPLUGGED,
USBD_BUS_EVENT_SUSPENDED,
USBD_BUS_EVENT_RESUME
}usbd_bus_event_type_t;
typedef struct {
volatile uint8_t state;
uint8_t interface2class[USBD_INTERFACE_NUM_MAX]; // determine interface number belongs to which class
}usbd_device_info_t;
extern usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER];
//--------------------------------------------------------------------+
// callback from DCD ISR
//--------------------------------------------------------------------+
void usbd_dcd_bus_event_isr(uint8_t coreid, usbd_bus_event_type_t bus_event);
void usbd_setup_received_isr(uint8_t coreid, tusb_control_request_t * p_request);
void usbd_xfer_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes);
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_USBD_DCD_H_ */
/** @} */

View File

@@ -1,73 +1,73 @@
/**************************************************************************/
/*!
@file hal_lpc11uxx.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_HAL_LPC11UXX_H_
#define _TUSB_HAL_LPC11UXX_H_
#include "LPC11Uxx.h"
#ifdef __cplusplus
extern "C" {
#endif
static inline void hal_interrupt_enable(uint8_t coreid)
{
(void) coreid; // discard compiler's warning
NVIC_EnableIRQ(USB_IRQn);
}
static inline void hal_interrupt_disable(uint8_t coreid)
{
(void) coreid; // discard compiler's warning
NVIC_DisableIRQ(USB_IRQn);
}
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_HAL_LPC11UXX_H_ */
/** @} */
/**************************************************************************/
/*!
@file hal_lpc11uxx.h
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org)
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. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_HAL_LPC11UXX_H_
#define _TUSB_HAL_LPC11UXX_H_
#include "LPC11Uxx.h"
#ifdef __cplusplus
extern "C" {
#endif
static inline void hal_interrupt_enable(uint8_t coreid)
{
(void) coreid; // discard compiler's warning
NVIC_EnableIRQ(USB_IRQn);
}
static inline void hal_interrupt_disable(uint8_t coreid)
{
(void) coreid; // discard compiler's warning
NVIC_DisableIRQ(USB_IRQn);
}
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_HAL_LPC11UXX_H_ */
/** @} */