common: Remove unused function USB_VcomReadBlocking().
[gps-watch.git] / src / common / virtual_com.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 #ifndef _USB_CDC_VCOM_H_
35 #define _USB_CDC_VCOM_H_ 1
36
37 #include "usb_device_descriptor.h"
38 #include "fsl_common.h"
39
40 /*******************************************************************************
41 * Definitions
42 ******************************************************************************/
43 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
44 #define CONTROLLER_ID kUSB_ControllerEhci0
45 #define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
46 #endif /* USB_DEVICE_CONFIG_EHCI */
47
48 #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
49 #define CONTROLLER_ID kUSB_ControllerKhci0
50 #define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
51 #endif /* USB_DEVICE_CONFIG_KHCI */
52
53 #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
54 #define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0
55 #define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
56 #endif /* USB_DEVICE_CONFIG_LPCIP3511FS */
57
58 #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
59 #define CONTROLLER_ID kUSB_ControllerLpcIp3511Hs0
60 #define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
61 #endif /* USB_DEVICE_CONFIG_LPCIP3511HS */
62
63 #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
64 #define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0
65 #define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
66
67 #endif
68
69 #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
70 #define CONTROLLER_ID kUSB_ControllerLpcIp3511Hs0
71 #define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
72 #endif
73
74 #define USB_DEVICE_INTERRUPT_PRIORITY (3U)
75
76 /* Currently configured line coding */
77 #define LINE_CODING_SIZE (0x07)
78 #define LINE_CODING_DTERATE (115200)
79 #define LINE_CODING_CHARFORMAT (0x00)
80 #define LINE_CODING_PARITYTYPE (0x00)
81 #define LINE_CODING_DATABITS (0x08)
82
83 /* Communications feature */
84 #define COMM_FEATURE_DATA_SIZE (0x02)
85 #define STATUS_ABSTRACT_STATE (0x0000)
86 #define COUNTRY_SETTING (0x0000)
87
88 /* Notification of serial state */
89 #define NOTIF_PACKET_SIZE (0x08)
90 #define UART_BITMAP_SIZE (0x02)
91 #define NOTIF_REQUEST_TYPE (0xA1)
92
93 /* Define the types for application */
94 typedef struct _usb_cdc_vcom_struct
95 {
96     usb_device_handle deviceHandle; /* USB device handle. */
97     volatile uint8_t attach; /* A flag to indicate whether a usb device is attached. 1: attached, 0: not attached */
98     uint8_t speed;           /* Speed of USB device. USB_SPEED_FULL/USB_SPEED_LOW/USB_SPEED_HIGH.                 */
99     volatile uint8_t
100         startTransactions; /* A flag to indicate whether a CDC device is ready to transmit and receive data.    */
101     uint8_t currentConfiguration; /* Current configuration value. */
102     uint8_t currentInterfaceAlternateSetting
103         [USB_CDC_VCOM_INTERFACE_COUNT]; /* Current alternate setting value for each interface. */
104 } usb_cdc_vcom_struct_t;
105
106 /* Define the infomation relates to abstract control model */
107 typedef struct _usb_cdc_acm_info
108 {
109     uint8_t serialStateBuf[NOTIF_PACKET_SIZE + UART_BITMAP_SIZE]; /* Serial state buffer of the CDC device to notify the
110                                                                      serial state to host. */
111     bool dtePresent;          /* A flag to indicate whether DTE is present.         */
112     uint16_t breakDuration;   /* Length of time in milliseconds of the break signal */
113     uint8_t dteStatus;        /* Status of data terminal equipment                  */
114     uint8_t currentInterface; /* Current interface index.                           */
115     uint16_t uartState;       /* UART state of the CDC device.                      */
116 } usb_cdc_acm_info_t;
117
118 /*******************************************************************************
119  * Prototypes
120  ******************************************************************************/
121 /*!
122  * @brief Application initialization function.
123  *
124  * This function initializes the application.
125  *
126  * @return pointer to USB device handle.
127  */
128 usb_device_handle USB_VcomInit(void);
129
130 /*!
131  * @brief Application initialization function.
132  *
133  * This function initializes the application.
134  *
135  * @return pointer to USB device handle.
136  */
137 void USB_VcomDeinit(usb_device_handle deviceHandle);
138
139 /*!
140  * @brief USB send data to host using a blocking method.
141  *
142  * This function sends data to host by usb cdc protocol
143  * @param baseAddr pointer to USB device handle.
144  * @param buf pointer to the data.
145  * @param count size of the transfer.
146  *
147  * @return None.
148  */
149 void USB_VcomWriteBlocking(usb_device_handle baseAddr, const uint8_t *buf, size_t count);
150
151 #endif /* _USB_CDC_VCOM_H_ */