Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / vcp / usb_prop.c
blobc8558de3428948554db9fe62f4ba989d020c7aa3
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 ------------------------------------------------------------------*/
29 #include "usb_lib.h"
30 #include "usb_conf.h"
31 #include "usb_prop.h"
32 #include "usb_desc.h"
33 #include "usb_pwr.h"
34 #include "hw_config.h"
36 /* Private typedef -----------------------------------------------------------*/
37 /* Private define ------------------------------------------------------------*/
38 /* Private macro -------------------------------------------------------------*/
39 /* Private variables ---------------------------------------------------------*/
40 uint8_t Request = 0;
42 LINE_CODING linecoding = { 115200, /* baud rate*/
43 0x00, /* stop bits-1*/
44 0x00, /* parity - none*/
45 0x08 /* no. of bits 8*/
48 /* -------------------------------------------------------------------------- */
49 /* Structures initializations */
50 /* -------------------------------------------------------------------------- */
52 DEVICE Device_Table = {
53 EP_NUM, 1 };
55 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,
56 Virtual_Com_Port_GetConfigDescriptor, Virtual_Com_Port_GetStringDescriptor, 0, 0x40 /*MAX PACKET SIZE*/
59 USER_STANDARD_REQUESTS User_Standard_Requests = {
60 Virtual_Com_Port_GetConfiguration, Virtual_Com_Port_SetConfiguration,
61 Virtual_Com_Port_GetInterface,
62 Virtual_Com_Port_SetInterface,
63 Virtual_Com_Port_GetStatus,
64 Virtual_Com_Port_ClearFeature,
65 Virtual_Com_Port_SetEndPointFeature,
66 Virtual_Com_Port_SetDeviceFeature, Virtual_Com_Port_SetDeviceAddress };
68 ONE_DESCRIPTOR Device_Descriptor = { (uint8_t*)Virtual_Com_Port_DeviceDescriptor,
69 VIRTUAL_COM_PORT_SIZ_DEVICE_DESC };
71 ONE_DESCRIPTOR Config_Descriptor = { (uint8_t*)Virtual_Com_Port_ConfigDescriptor,
72 VIRTUAL_COM_PORT_SIZ_CONFIG_DESC };
74 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,
75 VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT }, { (uint8_t*)Virtual_Com_Port_StringSerial, VIRTUAL_COM_PORT_SIZ_STRING_SERIAL } };
77 /* Extern variables ----------------------------------------------------------*/
78 /* Private function prototypes -----------------------------------------------*/
79 /* Extern function prototypes ------------------------------------------------*/
80 /* Private functions ---------------------------------------------------------*/
81 /*******************************************************************************
82 * Function Name : Virtual_Com_Port_init.
83 * Description : Virtual COM Port Mouse init routine.
84 * Input : None.
85 * Output : None.
86 * Return : None.
87 *******************************************************************************/
88 void Virtual_Com_Port_init(void)
91 /* Update the serial number string descriptor with the data from the unique
92 ID*/
93 Get_SerialNum();
95 pInformation->Current_Configuration = 0;
97 /* Connect the device */
98 PowerOn();
100 /* Perform basic device initialization operations */
101 USB_SIL_Init();
103 bDeviceState = UNCONNECTED;
106 /*******************************************************************************
107 * Function Name : Virtual_Com_Port_Reset
108 * Description : Virtual_Com_Port Mouse reset routine
109 * Input : None.
110 * Output : None.
111 * Return : None.
112 *******************************************************************************/
113 void Virtual_Com_Port_Reset(void)
115 /* Set Virtual_Com_Port DEVICE as not configured */
116 pInformation->Current_Configuration = 0;
118 /* Current Feature initialization */
119 pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];
121 /* Set Virtual_Com_Port DEVICE with the default Interface*/
122 pInformation->Current_Interface = 0;
124 SetBTABLE(BTABLE_ADDRESS);
126 /* Initialize Endpoint 0 */
127 SetEPType(ENDP0, EP_CONTROL);
128 SetEPTxStatus(ENDP0, EP_TX_STALL);
129 SetEPRxAddr(ENDP0, ENDP0_RXADDR);
130 SetEPTxAddr(ENDP0, ENDP0_TXADDR);
131 Clear_Status_Out(ENDP0);
132 SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
133 SetEPRxValid(ENDP0);
135 /* Initialize Endpoint 1 */
136 SetEPType(ENDP1, EP_BULK);
137 SetEPTxAddr(ENDP1, ENDP1_TXADDR);
138 SetEPTxStatus(ENDP1, EP_TX_NAK);
139 SetEPRxStatus(ENDP1, EP_RX_DIS);
141 /* Initialize Endpoint 2 */
142 SetEPType(ENDP2, EP_INTERRUPT);
143 SetEPTxAddr(ENDP2, ENDP2_TXADDR);
144 SetEPRxStatus(ENDP2, EP_RX_DIS);
145 SetEPTxStatus(ENDP2, EP_TX_NAK);
147 /* Initialize Endpoint 3 */
148 SetEPType(ENDP3, EP_BULK);
149 SetEPRxAddr(ENDP3, ENDP3_RXADDR);
150 SetEPRxCount(ENDP3, VIRTUAL_COM_PORT_DATA_SIZE);
151 SetEPRxStatus(ENDP3, EP_RX_VALID);
152 SetEPTxStatus(ENDP3, EP_TX_DIS);
154 /* Set this device to response on default address */
155 SetDeviceAddress(0);
157 bDeviceState = ATTACHED;
160 /*******************************************************************************
161 * Function Name : Virtual_Com_Port_SetConfiguration.
162 * Description : Update the device state to configured.
163 * Input : None.
164 * Output : None.
165 * Return : None.
166 *******************************************************************************/
167 void Virtual_Com_Port_SetConfiguration(void)
169 DEVICE_INFO *pInfo = &Device_Info;
171 if (pInfo->Current_Configuration != 0) {
172 /* Device configured */
173 bDeviceState = CONFIGURED;
177 /*******************************************************************************
178 * Function Name : Virtual_Com_Port_SetConfiguration.
179 * Description : Update the device state to addressed.
180 * Input : None.
181 * Output : None.
182 * Return : None.
183 *******************************************************************************/
184 void Virtual_Com_Port_SetDeviceAddress(void)
186 bDeviceState = ADDRESSED;
189 /*******************************************************************************
190 * Function Name : Virtual_Com_Port_Status_In.
191 * Description : Virtual COM Port Status In Routine.
192 * Input : None.
193 * Output : None.
194 * Return : None.
195 *******************************************************************************/
196 void Virtual_Com_Port_Status_In(void)
198 if (Request == SET_LINE_CODING) {
199 Request = 0;
203 /*******************************************************************************
204 * Function Name : Virtual_Com_Port_Status_Out
205 * Description : Virtual COM Port Status OUT Routine.
206 * Input : None.
207 * Output : None.
208 * Return : None.
209 *******************************************************************************/
210 void Virtual_Com_Port_Status_Out(void)
214 /*******************************************************************************
215 * Function Name : Virtual_Com_Port_Data_Setup
216 * Description : handle the data class specific requests
217 * Input : Request Nb.
218 * Output : None.
219 * Return : USB_UNSUPPORT or USB_SUCCESS.
220 *******************************************************************************/
221 RESULT Virtual_Com_Port_Data_Setup(uint8_t RequestNo)
223 uint8_t *(*CopyRoutine)( uint16_t);
225 CopyRoutine = NULL;
227 if (RequestNo == GET_LINE_CODING) {
228 if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) {
229 CopyRoutine = Virtual_Com_Port_GetLineCoding;
231 } else if (RequestNo == SET_LINE_CODING) {
232 if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) {
233 CopyRoutine = Virtual_Com_Port_SetLineCoding;
235 Request = SET_LINE_CODING;
238 if (CopyRoutine == NULL) {
239 return USB_UNSUPPORT;
242 pInformation->Ctrl_Info.CopyData = CopyRoutine;
243 pInformation->Ctrl_Info.Usb_wOffset = 0;
244 (*CopyRoutine)(0);
245 return USB_SUCCESS;
248 /*******************************************************************************
249 * Function Name : Virtual_Com_Port_NoData_Setup.
250 * Description : handle the no data class specific requests.
251 * Input : Request Nb.
252 * Output : None.
253 * Return : USB_UNSUPPORT or USB_SUCCESS.
254 *******************************************************************************/
255 RESULT Virtual_Com_Port_NoData_Setup(uint8_t RequestNo)
258 if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) {
259 if (RequestNo == SET_COMM_FEATURE) {
260 return USB_SUCCESS;
261 } else if (RequestNo == SET_CONTROL_LINE_STATE) {
262 return USB_SUCCESS;
266 return USB_UNSUPPORT;
269 /*******************************************************************************
270 * Function Name : Virtual_Com_Port_GetDeviceDescriptor.
271 * Description : Gets the device descriptor.
272 * Input : Length.
273 * Output : None.
274 * Return : The address of the device descriptor.
275 *******************************************************************************/
276 uint8_t *Virtual_Com_Port_GetDeviceDescriptor(uint16_t Length)
278 return Standard_GetDescriptorData(Length, &Device_Descriptor);
281 /*******************************************************************************
282 * Function Name : Virtual_Com_Port_GetConfigDescriptor.
283 * Description : get the configuration descriptor.
284 * Input : Length.
285 * Output : None.
286 * Return : The address of the configuration descriptor.
287 *******************************************************************************/
288 uint8_t *Virtual_Com_Port_GetConfigDescriptor(uint16_t Length)
290 return Standard_GetDescriptorData(Length, &Config_Descriptor);
293 /*******************************************************************************
294 * Function Name : Virtual_Com_Port_GetStringDescriptor
295 * Description : Gets the string descriptors according to the needed index
296 * Input : Length.
297 * Output : None.
298 * Return : The address of the string descriptors.
299 *******************************************************************************/
300 uint8_t *Virtual_Com_Port_GetStringDescriptor(uint16_t Length)
302 uint8_t wValue0 = pInformation->USBwValue0;
303 if (wValue0 > 4) {
304 return NULL;
305 } else {
306 return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
310 /*******************************************************************************
311 * Function Name : Virtual_Com_Port_Get_Interface_Setting.
312 * Description : test the interface and the alternate setting according to the
313 * supported one.
314 * Input1 : uint8_t: Interface : interface number.
315 * Input2 : uint8_t: AlternateSetting : Alternate Setting number.
316 * Output : None.
317 * Return : The address of the string descriptors.
318 *******************************************************************************/
319 RESULT Virtual_Com_Port_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
321 if (AlternateSetting > 0) {
322 return USB_UNSUPPORT;
323 } else if (Interface > 1) {
324 return USB_UNSUPPORT;
326 return USB_SUCCESS;
329 /*******************************************************************************
330 * Function Name : Virtual_Com_Port_GetLineCoding.
331 * Description : send the linecoding structure to the PC host.
332 * Input : Length.
333 * Output : None.
334 * Return : Linecoding structure base address.
335 *******************************************************************************/
336 uint8_t *Virtual_Com_Port_GetLineCoding(uint16_t Length)
338 if (Length == 0) {
339 pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
340 return NULL;
342 return (uint8_t *)&linecoding;
345 /*******************************************************************************
346 * Function Name : Virtual_Com_Port_SetLineCoding.
347 * Description : Set the linecoding structure fields.
348 * Input : Length.
349 * Output : None.
350 * Return : Linecoding structure base address.
351 *******************************************************************************/
352 uint8_t *Virtual_Com_Port_SetLineCoding(uint16_t Length)
354 if (Length == 0) {
355 pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
356 return NULL;
358 return (uint8_t *)&linecoding;
361 /*******************************************************************************
362 * Function Name : Virtual_Com_Port_GetBaudRate.
363 * Description : Get the current baudrate
364 * Input : None.
365 * Output : None.
366 * Return : baudrate in bps
367 *******************************************************************************/
368 uint32_t Virtual_Com_Port_GetBaudRate(void)
370 return linecoding.bitrate;
373 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/