common: Add NXP's USB serial code.
[gps-watch.git] / src / common / usb_device_ch9.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  * 
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  *  that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  *   of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  *   list of conditions and the following disclaimer in the documentation and/or
16  *   other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  *   contributors may be used to endorse or promote products derived from this
20  *   software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #ifndef __USB_DEVICE_CH9_H__
36 #define __USB_DEVICE_CH9_H__
37
38 /*******************************************************************************
39 * Definitions
40 ******************************************************************************/
41 /*!
42  * @addtogroup usb_device_ch9
43  * @{
44  */
45
46 /*******************************************************************************
47  * Definitions
48  ******************************************************************************/
49
50 /*! @brief Defines USB device status size when the host request to get device status */
51 #define USB_DEVICE_STATUS_SIZE (0x02U)
52
53 /*! @brief Defines USB device interface status size when the host request to get interface status */
54 #define USB_INTERFACE_STATUS_SIZE (0x02U)
55
56 /*! @brief Defines USB device endpoint status size when the host request to get endpoint status */
57 #define USB_ENDPOINT_STATUS_SIZE (0x02U)
58
59 /*! @brief Defines USB device configuration size when the host request to get current configuration */
60 #define USB_CONFIGURE_SIZE (0X01U)
61
62 /*! @brief Defines USB device interface alternate setting size when the host request to get interface alternate setting
63  */
64 #define USB_INTERFACE_SIZE (0X01U)
65
66 /*! @brief Defines USB device status mask */
67 #define USB_GET_STATUS_DEVICE_MASK (0x03U)
68
69 /*! @brief Defines USB device interface status mask */
70 #define USB_GET_STATUS_INTERFACE_MASK (0x03U)
71
72 /*! @brief Defines USB device endpoint status mask */
73 #define USB_GET_STATUS_ENDPOINT_MASK (0x03U)
74
75 /*! @brief Control read and write sequence */
76 typedef enum _usb_device_control_read_write_sequence
77 {
78     kUSB_DeviceControlPipeSetupStage = 0U, /*!< Setup stage */
79     kUSB_DeviceControlPipeDataStage,       /*!< Data stage */
80     kUSB_DeviceControlPipeStatusStage,     /*!< status stage */
81 } usb_device_control_read_write_sequence_t;
82
83 /*******************************************************************************
84 * API
85 ******************************************************************************/
86 #if defined(__cplusplus)
87 extern "C" {
88 #endif
89
90 /*******************************************************************************
91  * API
92  ******************************************************************************/
93
94 /*!
95  * @brief Initialize the control pipes.
96  *
97  * The function is used to initialize the control pipes. This function should be called when event
98  * kUSB_DeviceEventBusReset is received.
99  *
100  * @param handle      The device handle.
101  *
102  * @return A USB error code or kStatus_USB_Success.
103  */
104 extern usb_status_t USB_DeviceControlPipeInit(usb_device_handle handle);
105
106 #if defined(__cplusplus)
107 }
108 #endif
109
110 /*! @}*/
111
112 #endif /* __USB_DEVICE_CH9_H__ */