1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 17:55:28 +03:00

Early initialize USBD to avoid USB detection issues; USB defines cleanup

This commit is contained in:
Konstantin Sharlaimov (DigitalEntity) 2018-02-06 00:55:04 +10:00
parent 5afb5b8e36
commit dbbe3219be
47 changed files with 18 additions and 131 deletions

View file

@ -20,6 +20,8 @@
#include "platform.h"
#ifdef USE_VCP
#include "build/build_config.h"
#include "common/utils.h"
@ -182,10 +184,8 @@ static const struct serialPortVTable usbVTable[] = {
}
};
serialPort_t *usbVcpOpen(void)
void usbVcpInitHardware(void)
{
vcpPort_t *s;
#if defined(STM32F4)
usbGenerateDisconnectPulse();
@ -214,6 +214,11 @@ serialPort_t *usbVcpOpen(void)
USB_Interrupts_Config();
USB_Init();
#endif
}
serialPort_t *usbVcpOpen(void)
{
vcpPort_t *s;
s = &vcpPort;
s->port.vTable = usbVTable;
@ -227,3 +232,5 @@ uint32_t usbVcpGetBaudRate(serialPort_t *instance)
return CDC_BaudRate();
}
#endif

View file

@ -27,6 +27,7 @@ typedef struct {
bool buffering;
} vcpPort_t;
void usbVcpInitHardware(void);
serialPort_t *usbVcpOpen(void);
struct serialPort_s;
uint32_t usbVcpGetBaudRate(struct serialPort_s *instance);

View file

@ -1,55 +0,0 @@
/*
* 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"
#include "drivers/io.h"
#include "drivers/time.h"
static IO_t usbDetectPin = IO_NONE;
void usbCableDetectDeinit(void)
{
#ifdef USB_DETECT_PIN
IOInit(usbDetectPin, OWNER_FREE, RESOURCE_NONE);
IOConfigGPIO(usbDetectPin, IOCFG_IN_FLOATING);
usbDetectPin = IO_NONE;
#endif
}
void usbCableDetectInit(void)
{
#ifdef USB_DETECT_PIN
usbDetectPin = IOGetByTag(IO_TAG(USB_DETECT_PIN));
IOInit(usbDetectPin, OWNER_USB, RESOURCE_INPUT);
IOConfigGPIO(usbDetectPin, IOCFG_OUT_PP);
#endif
}
bool usbCableIsInserted(void)
{
bool result = false;
#ifdef USB_DETECT_PIN
result = IORead(usbDetectPin) != 0;
#endif
return result;
}

View file

@ -1,22 +0,0 @@
/*
* 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/>.
*/
#pragma once
void usbCableDetectDeinit(void);
void usbCableDetectInit(void);
bool usbCableIsInserted(void);

View file

@ -20,7 +20,7 @@
#include "platform.h"
#ifdef USB_IO
#ifdef USE_VCP
#include "drivers/io.h"
#include "drivers/time.h"

View file

@ -65,6 +65,7 @@
#include "drivers/serial.h"
#include "drivers/serial_softserial.h"
#include "drivers/serial_uart.h"
#include "drivers/serial_usb_vcp.h"
#include "drivers/sound_beeper.h"
#include "drivers/system.h"
#include "drivers/time.h"
@ -241,6 +242,11 @@ void init(void)
}
#endif
#ifdef USE_VCP
// Early initialize USB hardware
usbVcpInitHardware();
#endif
delay(500);
timerInit(); // timer must be initialized before any channel is allocated

View file

@ -78,7 +78,6 @@
#define USE_FLASHFS
#define USE_FLASH_M25P16
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PC5
#define VBUS_SENSING_ENABLED

View file

@ -98,7 +98,6 @@
//#define USE_FLASHFS
//#define USE_FLASH_M25P16
#define USB_IO
#define USE_VCP
#define USE_UART1

View file

@ -106,7 +106,6 @@
//#define USE_FLASHFS
//#define USE_FLASH_M25P16
#define USB_IO
#define USE_VCP
#define USE_UART1

View file

@ -64,7 +64,6 @@
#define USE_PITOT_MS4525
#define PITOT_I2C_BUS BUS_I2C2
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PA8

View file

@ -70,7 +70,6 @@
#define USABLE_TIMER_CHANNEL_COUNT 16
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PA8

View file

@ -58,7 +58,6 @@
#define USABLE_TIMER_CHANNEL_COUNT 16
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PA8

View file

@ -73,7 +73,6 @@
#define SDCARD_DMA_CLK RCC_AHB1Periph_DMA1
#define SDCARD_DMA_CHANNEL DMA_Channel_0
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_ENABLED
#define VBUS_SENSING_PIN PC5

View file

@ -49,7 +49,6 @@
//#define REMAP_TIM16_DMA // XXX
//#define REMAP_TIM17_DMA // XXX
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -67,7 +67,6 @@
#define USE_FLASHFS
#define USE_FLASH_M25P16
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PC5
#define VBUS_SENSING_ENABLED

View file

@ -86,7 +86,6 @@
#define USE_FLASHFS
#define USE_FLASH_M25P16
#define USB_IO
#define USE_VCP
//#define VBUS_SENSING_PIN PA8
//#define VBUS_SENSING_ENABLED

View file

@ -65,7 +65,6 @@
#define USE_MAG_HMC5883
#define USE_MAG_QMC5883
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART3

View file

@ -56,7 +56,6 @@
#define USE_MAG_QMC5883
#define MAG_AK8975_ALIGN CW90_DEG_FLIP
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -64,8 +64,6 @@
#define MAX7456_SPI_BUS BUS_SPI3
#define MAX7456_CS_PIN PA15
#define USB_IO
#define USE_VCP
#define USE_UART1

View file

@ -77,7 +77,6 @@
#define USE_FLASHFS
#define USE_FLASH_M25P16
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PA9

View file

@ -75,8 +75,6 @@
#define USE_MAG_HMC5883
#define USE_MAG_QMC5883
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -70,8 +70,6 @@
#define USABLE_TIMER_CHANNEL_COUNT 17
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PA9

View file

@ -55,8 +55,6 @@
#define USE_MAG_MAG3110
#define USE_MAG_QMC5883
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -57,7 +57,6 @@
#define MAX7456_CS_PIN PA4
#define MAX7456_SPI_BUS BUS_SPI1
#define USB_IO
#define USE_VCP
// #define VBUS_SENSING_PIN PA9

View file

@ -111,7 +111,6 @@
#define USE_FLASH_M25P16
// *************** UART *****************************
#define USB_IO
#define USE_VCP
// provide for Telemetry module

View file

@ -58,7 +58,6 @@
#define SDCARD_SPI_INSTANCE SPI2
#define SDCARD_SPI_CS_PIN SPI2_NSS_PIN
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PC5

View file

@ -109,8 +109,6 @@
#define SDCARD_DMA_CHANNEL_TX_COMPLETE_FLAG DMA1_FLAG_TC5
#endif
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -90,7 +90,6 @@
#define RX_MISO_PIN PB14
#define RX_SPI_INSTANCE SPI2
#define RX_IRQ_PIN PB3
#define USB_IO
#define USE_VCP
#define USE_UART1

View file

@ -88,7 +88,6 @@
#define CURRENT_METER_ADC_CHANNEL ADC_CHN_2
#define RSSI_ADC_CHANNEL ADC_CHN_3
#define USB_IO
#define USE_VCP
#define USE_UART1

View file

@ -60,8 +60,6 @@
#define USE_ACC_MPU9250
#define ACC_MPU9250_ALIGN CW270_DEG
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -94,7 +94,6 @@
#define MAX7456_CS_PIN PB10
// *************** UART *****************************
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PB12
#define VBUS_SENSING_ENABLED

View file

@ -97,7 +97,6 @@
#define MAX7456_CS_PIN PB10
// *************** UART *****************************
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PB12
#define VBUS_SENSING_ENABLED

View file

@ -53,7 +53,6 @@
//#define USE_MAG
//#define USE_MAG_HMC5883
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -69,7 +69,6 @@
#define USE_RANGEFINDER_HCSR04_I2C
#define RANGEFINDER_I2C_BUS BUS_I2C1
#define USB_IO
#define USB_CABLE_DETECTION
#define USB_DETECT_PIN PB5

View file

@ -115,7 +115,6 @@
#define RANGEFINDER_I2C_BUS BUS_I2C2
#define USE_RANGEFINDER_HCSR04_I2C
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PC5
#define VBUS_SENSING_ENABLED

View file

@ -79,7 +79,6 @@
#define USABLE_TIMER_CHANNEL_COUNT 5
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PC4

View file

@ -44,7 +44,6 @@
#define MPU6000_CS_PIN PB12
#define MPU6000_SPI_BUS BUS_SPI2
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -94,7 +94,6 @@
#define ENSURE_MPU_DATA_READY_IS_LOW
#define EXTI_CALLBACK_HANDLER_COUNT 1 // MPU data ready
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PA9
#define VBUS_SENSING_ENABLED

View file

@ -49,8 +49,6 @@
#define USE_MAG_HMC5883 // External
#define USE_MAG_QMC5883 // External
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -82,7 +82,6 @@
#define USE_FLASHFS
#define USE_FLASH_M25P16
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PC5
#define VBUS_SENSING_ENABLED

View file

@ -54,7 +54,6 @@
#define USE_MAG_QMC5883
#define MAG_AK8975_ALIGN CW180_DEG_FLIP
#define USB_IO
#define USE_VCP
#define USE_UART1 // Conn 1 - TX (PB6) RX PB7 (AF7)
#define USE_UART2 // Input - RX (PA3)

View file

@ -72,7 +72,6 @@
#define USE_FLASH_M25P16
#define USE_FLASH_TOOLS
#define USB_IO
#define USE_VCP
#define VBUS_SENSING_PIN PA8

View file

@ -59,8 +59,6 @@
#define USE_MAG_MPU9250
#define MAG_MPU9250_ALIGN CW270_DEG_FLIP
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -64,7 +64,6 @@
#define RANGEFINDER_HCSR04_ECHO_PIN PB1
#define RANGEFINDER_HCSR04_TRIGGER_PIN PB0
#define USB_IO
#define USB_CABLE_DETECTION
#define USB_DETECT_PIN PB5

View file

@ -63,7 +63,6 @@
#define USE_MAG_HMC5883
#define USE_MAG_QMC5883
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -64,8 +64,6 @@
#define USE_MAG_MPU9250
#define USE_MAG_HMC5883
#define USB_IO
#define USE_VCP
#define USE_UART1
#define USE_UART2

View file

@ -83,7 +83,6 @@
#define MAX7456_CS_PIN PA14
// Serial Ports
#define USB_IO
#define USE_VCP
#define USE_UART1