[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / vcp / usb_prop.c
blob381414f676802263e789d3785cff9c171e1f34db
1 /**
2 ******************************************************************************
3 * @file usb_prop.c
4 * @author MCD Application Team
5 * @version V4.0.0
6 * @date 21-January-2013
7 * @brief All processing related to Virtual Com Port Demo
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
17 * http://www.st.com/software_license_agreement_liberty_v2
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 ******************************************************************************
28 /* Includes ------------------------------------------------------------------*/
30 #include "platform.h"
32 #include "usb_lib.h"
33 #include "usb_conf.h"
34 #include "usb_prop.h"
35 #include "usb_desc.h"
36 #include "usb_pwr.h"
37 #include "hw_config.h"
39 /* Private typedef -----------------------------------------------------------*/
40 /* Private define ------------------------------------------------------------*/
41 /* Private macro -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 uint8_t Request = 0;
45 LINE_CODING linecoding = { 115200, /* baud rate*/
46 0x00, /* stop bits-1*/
47 0x00, /* parity - none*/
48 0x08 /* no. of bits 8*/
51 /* -------------------------------------------------------------------------- */
52 /* Structures initializations */
53 /* -------------------------------------------------------------------------- */
55 DEVICE Device_Table = {
56 EP_NUM, 1 };
58 DEVICE_PROP Device_Property = { Virtual_Com_Port_init, Virtual_Com_Port_Reset, Virtual_Com_Port_Status_In, Virtual_Com_Port_Status_Out, Virtual_Com_Port_Data_Setup, Virtual_Com_Port_NoData_Setup, Virtual_Com_Port_Get_Interface_Setting, Virtual_Com_Port_GetDeviceDescriptor,
59 Virtual_Com_Port_GetConfigDescriptor, Virtual_Com_Port_GetStringDescriptor, 0, 0x40 /*MAX PACKET SIZE*/
62 USER_STANDARD_REQUESTS User_Standard_Requests = {
63 Virtual_Com_Port_GetConfiguration, Virtual_Com_Port_SetConfiguration,
64 Virtual_Com_Port_GetInterface,
65 Virtual_Com_Port_SetInterface,
66 Virtual_Com_Port_GetStatus,
67 Virtual_Com_Port_ClearFeature,
68 Virtual_Com_Port_SetEndPointFeature,
69 Virtual_Com_Port_SetDeviceFeature, Virtual_Com_Port_SetDeviceAddress };
71 ONE_DESCRIPTOR Device_Descriptor = { (uint8_t*)Virtual_Com_Port_DeviceDescriptor,
72 VIRTUAL_COM_PORT_SIZ_DEVICE_DESC };
74 ONE_DESCRIPTOR Config_Descriptor = { (uint8_t*)Virtual_Com_Port_ConfigDescriptor,
75 VIRTUAL_COM_PORT_SIZ_CONFIG_DESC };
77 ONE_DESCRIPTOR String_Descriptor[4] = { { (uint8_t*)Virtual_Com_Port_StringLangID, VIRTUAL_COM_PORT_SIZ_STRING_LANGID }, { (uint8_t*)Virtual_Com_Port_StringVendor, VIRTUAL_COM_PORT_SIZ_STRING_VENDOR }, { (uint8_t*)Virtual_Com_Port_StringProduct,
78 VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT }, { (uint8_t*)Virtual_Com_Port_StringSerial, VIRTUAL_COM_PORT_SIZ_STRING_SERIAL } };
80 /* Extern variables ----------------------------------------------------------*/
81 /* Private function prototypes -----------------------------------------------*/
82 /* Extern function prototypes ------------------------------------------------*/
83 /* Private functions ---------------------------------------------------------*/
84 /*******************************************************************************
85 * Function Name : Virtual_Com_Port_init.
86 * Description : Virtual COM Port Mouse init routine.
87 * Input : None.
88 * Output : None.
89 * Return : None.
90 *******************************************************************************/
91 void Virtual_Com_Port_init(void)
93 /* Update the serial number string descriptor with the data from the unique
94 ID*/
95 Get_SerialNum();
97 pInformation->Current_Configuration = 0;
99 /* Connect the device */
100 PowerOn();
102 /* Perform basic device initialization operations */
103 USB_SIL_Init();
105 bDeviceState = UNCONNECTED;
108 /*******************************************************************************
109 * Function Name : Virtual_Com_Port_Reset
110 * Description : Virtual_Com_Port Mouse reset routine
111 * Input : None.
112 * Output : None.
113 * Return : None.
114 *******************************************************************************/
115 void Virtual_Com_Port_Reset(void)
117 /* Set Virtual_Com_Port DEVICE as not configured */
118 pInformation->Current_Configuration = 0;
120 /* Current Feature initialization */
121 pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];
123 /* Set Virtual_Com_Port DEVICE with the default Interface*/
124 pInformation->Current_Interface = 0;
126 SetBTABLE(BTABLE_ADDRESS);
128 /* Initialize Endpoint 0 */
129 SetEPType(ENDP0, EP_CONTROL);
130 SetEPTxStatus(ENDP0, EP_TX_STALL);
131 SetEPRxAddr(ENDP0, ENDP0_RXADDR);
132 SetEPTxAddr(ENDP0, ENDP0_TXADDR);
133 Clear_Status_Out(ENDP0);
134 SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
135 SetEPRxValid(ENDP0);
137 /* Initialize Endpoint 1 */
138 SetEPType(ENDP1, EP_BULK);
139 SetEPTxAddr(ENDP1, ENDP1_TXADDR);
140 SetEPTxStatus(ENDP1, EP_TX_NAK);
141 SetEPRxStatus(ENDP1, EP_RX_DIS);
143 /* Initialize Endpoint 2 */
144 SetEPType(ENDP2, EP_INTERRUPT);
145 SetEPTxAddr(ENDP2, ENDP2_TXADDR);
146 SetEPRxStatus(ENDP2, EP_RX_DIS);
147 SetEPTxStatus(ENDP2, EP_TX_NAK);
149 /* Initialize Endpoint 3 */
150 SetEPType(ENDP3, EP_BULK);
151 SetEPRxAddr(ENDP3, ENDP3_RXADDR);
152 SetEPRxCount(ENDP3, VIRTUAL_COM_PORT_DATA_SIZE);
153 SetEPRxStatus(ENDP3, EP_RX_VALID);
154 SetEPTxStatus(ENDP3, EP_TX_DIS);
156 /* Set this device to response on default address */
157 SetDeviceAddress(0);
159 bDeviceState = ATTACHED;
162 /*******************************************************************************
163 * Function Name : Virtual_Com_Port_SetConfiguration.
164 * Description : Update the device state to configured.
165 * Input : None.
166 * Output : None.
167 * Return : None.
168 *******************************************************************************/
169 void Virtual_Com_Port_SetConfiguration(void)
171 DEVICE_INFO *pInfo = &Device_Info;
173 if (pInfo->Current_Configuration != 0) {
174 /* Device configured */
175 bDeviceState = CONFIGURED;
179 /*******************************************************************************
180 * Function Name : Virtual_Com_Port_SetConfiguration.
181 * Description : Update the device state to addressed.
182 * Input : None.
183 * Output : None.
184 * Return : None.
185 *******************************************************************************/
186 void Virtual_Com_Port_SetDeviceAddress(void)
188 bDeviceState = ADDRESSED;
191 /*******************************************************************************
192 * Function Name : Virtual_Com_Port_Status_In.
193 * Description : Virtual COM Port Status In Routine.
194 * Input : None.
195 * Output : None.
196 * Return : None.
197 *******************************************************************************/
198 void Virtual_Com_Port_Status_In(void)
200 if (Request == SET_LINE_CODING) {
201 Request = 0;
205 /*******************************************************************************
206 * Function Name : Virtual_Com_Port_Status_Out
207 * Description : Virtual COM Port Status OUT Routine.
208 * Input : None.
209 * Output : None.
210 * Return : None.
211 *******************************************************************************/
212 void Virtual_Com_Port_Status_Out(void)
216 /*******************************************************************************
217 * Function Name : Virtual_Com_Port_Data_Setup
218 * Description : handle the data class specific requests
219 * Input : Request Nb.
220 * Output : None.
221 * Return : USB_UNSUPPORT or USB_SUCCESS.
222 *******************************************************************************/
223 RESULT Virtual_Com_Port_Data_Setup(uint8_t RequestNo)
225 uint8_t *(*CopyRoutine)( uint16_t);
227 CopyRoutine = NULL;
229 if (RequestNo == GET_LINE_CODING) {
230 if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) {
231 CopyRoutine = Virtual_Com_Port_GetLineCoding;
233 } else if (RequestNo == SET_LINE_CODING) {
234 if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) {
235 CopyRoutine = Virtual_Com_Port_SetLineCoding;
237 Request = SET_LINE_CODING;
240 if (CopyRoutine == NULL) {
241 return USB_UNSUPPORT;
244 pInformation->Ctrl_Info.CopyData = CopyRoutine;
245 pInformation->Ctrl_Info.Usb_wOffset = 0;
246 (*CopyRoutine)(0);
247 return USB_SUCCESS;
250 /*******************************************************************************
251 * Function Name : Virtual_Com_Port_NoData_Setup.
252 * Description : handle the no data class specific requests.
253 * Input : Request Nb.
254 * Output : None.
255 * Return : USB_UNSUPPORT or USB_SUCCESS.
256 *******************************************************************************/
257 RESULT Virtual_Com_Port_NoData_Setup(uint8_t RequestNo)
260 if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) {
261 if (RequestNo == SET_COMM_FEATURE) {
262 return USB_SUCCESS;
263 } else if (RequestNo == SET_CONTROL_LINE_STATE) {
264 return USB_SUCCESS;
268 return USB_UNSUPPORT;
271 /*******************************************************************************
272 * Function Name : Virtual_Com_Port_GetDeviceDescriptor.
273 * Description : Gets the device descriptor.
274 * Input : Length.
275 * Output : None.
276 * Return : The address of the device descriptor.
277 *******************************************************************************/
278 uint8_t *Virtual_Com_Port_GetDeviceDescriptor(uint16_t Length)
280 return Standard_GetDescriptorData(Length, &Device_Descriptor);
283 /*******************************************************************************
284 * Function Name : Virtual_Com_Port_GetConfigDescriptor.
285 * Description : get the configuration descriptor.
286 * Input : Length.
287 * Output : None.
288 * Return : The address of the configuration descriptor.
289 *******************************************************************************/
290 uint8_t *Virtual_Com_Port_GetConfigDescriptor(uint16_t Length)
292 return Standard_GetDescriptorData(Length, &Config_Descriptor);
295 /*******************************************************************************
296 * Function Name : Virtual_Com_Port_GetStringDescriptor
297 * Description : Gets the string descriptors according to the needed index
298 * Input : Length.
299 * Output : None.
300 * Return : The address of the string descriptors.
301 *******************************************************************************/
302 uint8_t *Virtual_Com_Port_GetStringDescriptor(uint16_t Length)
304 uint8_t wValue0 = pInformation->USBwValue0;
305 if (wValue0 > 4) {
306 return NULL;
307 } else {
308 return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
312 /*******************************************************************************
313 * Function Name : Virtual_Com_Port_Get_Interface_Setting.
314 * Description : test the interface and the alternate setting according to the
315 * supported one.
316 * Input1 : uint8_t: Interface : interface number.
317 * Input2 : uint8_t: AlternateSetting : Alternate Setting number.
318 * Output : None.
319 * Return : The address of the string descriptors.
320 *******************************************************************************/
321 RESULT Virtual_Com_Port_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
323 if (AlternateSetting > 0) {
324 return USB_UNSUPPORT;
325 } else if (Interface > 1) {
326 return USB_UNSUPPORT;
328 return USB_SUCCESS;
331 /*******************************************************************************
332 * Function Name : Virtual_Com_Port_GetLineCoding.
333 * Description : send the linecoding structure to the PC host.
334 * Input : Length.
335 * Output : None.
336 * Return : Linecoding structure base address.
337 *******************************************************************************/
338 uint8_t *Virtual_Com_Port_GetLineCoding(uint16_t Length)
340 if (Length == 0) {
341 pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
342 return NULL;
344 return (uint8_t *)&linecoding;
347 /*******************************************************************************
348 * Function Name : Virtual_Com_Port_SetLineCoding.
349 * Description : Set the linecoding structure fields.
350 * Input : Length.
351 * Output : None.
352 * Return : Linecoding structure base address.
353 *******************************************************************************/
354 uint8_t *Virtual_Com_Port_SetLineCoding(uint16_t Length)
356 if (Length == 0) {
357 pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
358 return NULL;
360 return (uint8_t *)&linecoding;
363 /*******************************************************************************
364 * Function Name : Virtual_Com_Port_GetBaudRate.
365 * Description : Get the current baudrate
366 * Input : None.
367 * Output : None.
368 * Return : baudrate in bps
369 *******************************************************************************/
370 uint32_t Virtual_Com_Port_GetBaudRate(void)
372 return linecoding.bitrate;
375 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/