1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00
betaflight/src/main/drivers/usb_io.c

80 lines
1.7 KiB
C

/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#ifdef USE_VCP
#include "drivers/io.h"
#include "drivers/time.h"
#include "usb_io.h"
#include "sdcard.h"
#ifdef USE_USB_DETECT
static IO_t usbDetectPin = IO_NONE;
#endif
void usbCableDetectDeinit(void)
{
#ifdef USE_USB_DETECT
IOInit(usbDetectPin, OWNER_FREE, 0);
IOConfigGPIO(usbDetectPin, IOCFG_IN_FLOATING);
usbDetectPin = IO_NONE;
#endif
}
void usbCableDetectInit(void)
{
#ifdef USE_USB_DETECT
#ifndef USB_DETECT_PIN
#define USB_DETECT_PIN NONE
#endif
usbDetectPin = IOGetByTag(IO_TAG(USB_DETECT_PIN));
IOInit(usbDetectPin, OWNER_USB_DETECT, 0);
IOConfigGPIO(usbDetectPin, IOCFG_OUT_PP);
#endif
}
bool usbCableIsInserted(void)
{
bool result = false;
#ifdef USE_USB_DETECT
result = IORead(usbDetectPin) != 0;
#endif
return result;
}
void usbGenerateDisconnectPulse(void)
{
/* Pull down PA12 to create USB disconnect pulse */
IO_t usbPin = IOGetByTag(IO_TAG(PA12));
IOConfigGPIO(usbPin, IOCFG_OUT_OD);
IOLo(usbPin);
delay(200);
IOHi(usbPin);
}
#endif