Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / drivers / usb_io.c
blobb2f4157eeb930120ef689a29b12cb2ea512b94f6
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
23 #ifdef USE_VCP
25 #include "drivers/io.h"
26 #include "drivers/time.h"
27 #include "usb_io.h"
29 #ifdef USB_DETECT_PIN
30 static IO_t usbDetectPin = IO_NONE;
31 #endif
33 void usbCableDetectDeinit(void)
35 #ifdef USB_DETECT_PIN
36 IOInit(usbDetectPin, OWNER_FREE, RESOURCE_NONE, 0);
37 IOConfigGPIO(usbDetectPin, IOCFG_IN_FLOATING);
38 usbDetectPin = IO_NONE;
39 #endif
42 void usbCableDetectInit(void)
44 #ifdef USB_DETECT_PIN
45 usbDetectPin = IOGetByTag(IO_TAG(USB_DETECT_PIN));
47 IOInit(usbDetectPin, OWNER_USB, RESOURCE_INPUT, 0);
48 IOConfigGPIO(usbDetectPin, IOCFG_OUT_PP);
49 #endif
52 bool usbCableIsInserted(void)
54 bool result = false;
56 #ifdef USB_DETECT_PIN
57 result = IORead(usbDetectPin) != 0;
58 #endif
60 return result;
63 void usbGenerateDisconnectPulse(void)
65 /* Pull down PA12 to create USB disconnect pulse */
66 IO_t usbPin = IOGetByTag(IO_TAG(PA12));
67 IOConfigGPIO(usbPin, IOCFG_OUT_OD);
69 IOLo(usbPin);
71 delay(200);
73 IOHi(usbPin);
76 #endif