fome-fw/firmware/hw_layer/serial_over_usb/usbconsole.c

69 lines
1.5 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file usbconsole.c
* @brief USB-over-serial configuration
*
* @date Oct 14, 2013
2018-01-20 17:55:31 -08:00
* @author Andrey Belomutskiy, (c) 2012-2018
2015-07-10 06:01:56 -07:00
*/
2018-09-16 19:39:46 -07:00
#include "global.h"
2015-07-10 06:01:56 -07:00
2019-04-12 17:52:51 -07:00
#if EFI_USB_SERIAL
2015-07-10 06:01:56 -07:00
#include "usbconsole.h"
#include "usbcfg.h"
#include "efifeatures.h"
static bool isUsbSerialInitialized = false;
2015-07-10 06:01:56 -07:00
void usb_serial_start(void) {
/*
* Initializes a serial-over-USB CDC driver.
*/
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
/*
* Activates the USB driver and then the USB bus pull-up on D+.
* Note, a delay is inserted in order to not have to disconnect the cable
* after a reset.
*/
2019-03-15 06:13:54 -07:00
// See also https://github.com/rusefi/rusefi/issues/705
#ifndef EFI_SKIP_USB_DISCONNECT
2015-07-10 06:01:56 -07:00
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1500);
2019-03-15 06:13:54 -07:00
#endif/* EFI_SKIP_USB_DISCONNECT */
2015-07-10 06:01:56 -07:00
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
2017-05-23 15:06:09 -07:00
#if HAL_USE_SERIAL
2019-01-25 18:04:33 -08:00
/**
* todo: start taking USB pins from configuration?
* at the moment USB pinout is hard-coded in board.h file
*
* PA10/PA11/PA12
* #define GPIOA_OTG_FS_ID 10
* #define GPIOA_OTG_FS_DM 11
* #define GPIOA_OTG_FS_DP 12
*/
2015-07-10 06:01:56 -07:00
/*
* Activates the serial driver 2 using the driver default configuration.
*/
sdStart(&SD2, NULL);
2017-05-23 15:06:09 -07:00
#endif
isUsbSerialInitialized = true;
2015-07-10 06:01:56 -07:00
}
bool is_usb_serial_ready(void) {
return isUsbSerialInitialized && SDU1.config->usbp->state == USB_ACTIVE;
2015-07-10 06:01:56 -07:00
}
#else
bool is_usb_serial_ready(void) {
return false;
}
2017-04-01 21:20:47 -07:00
#endif /* EFI_USB_SERIAL */