rusefi-1/firmware/hw_layer/serial_over_usb/usbconsole.c

65 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
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
2018-09-16 19:39:46 -07:00
#include "global.h"
#include "os_access.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"
static bool isUsbSerialInitialized = false;
/**
* start USB serial using hard-coded communications pins (see comments inside the code)
*/
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
efiSetPadMode("USB ID", EFI_USB_SERIAL_ID, PAL_MODE_ALTERNATE(EFI_USB_AF));
2019-06-05 19:04:31 -07:00
efiSetPadMode("USB DM", EFI_USB_SERIAL_DM, PAL_MODE_ALTERNATE(EFI_USB_AF));
efiSetPadMode("USB DP", EFI_USB_SERIAL_DP, PAL_MODE_ALTERNATE(EFI_USB_AF));
2015-07-10 06:01:56 -07:00
/*
* Activates the serial driver using the driver default configuration.
2015-07-10 06:01:56 -07:00
*/
2019-07-27 17:18:20 -07:00
sdStart(&USB_SERIAL_DRIVER, NULL);
2019-06-05 19:04:31 -07:00
#endif /* HAL_USE_SERIAL */
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 */