Use USB VCP as a normal serial driver as well
This commit is contained in:
@@ -135,7 +135,7 @@ AuxSerialState auxSerialState = {
|
||||
};
|
||||
|
||||
// TODO: grab context to get buffer
|
||||
static bool auxSerialOnSend(uint8_t* data)
|
||||
static uint8_t auxSerialOnSend(uint8_t* data)
|
||||
{
|
||||
return auxSerialTxFifo.pop(*data);
|
||||
}
|
||||
@@ -153,14 +153,15 @@ static void* auxSerialInit(const etx_serial_init* params)
|
||||
}
|
||||
|
||||
const etx_serial_driver_t AuxSerialDriver = {
|
||||
.init = auxSerialInit,
|
||||
.deinit = aux_serial_deinit,
|
||||
.sendByte = aux_serial_putc,
|
||||
.sendBuffer = aux_serial_send_buffer,
|
||||
.waitForTxCompleted = aux_wait_tx_completed,
|
||||
.getByte = aux_get_byte,
|
||||
.setReceiveCb = nullptr,
|
||||
.setOnErrorCb = nullptr,
|
||||
.init = auxSerialInit,
|
||||
.deinit = aux_serial_deinit,
|
||||
.sendByte = aux_serial_putc,
|
||||
.sendBuffer = aux_serial_send_buffer,
|
||||
.waitForTxCompleted = aux_wait_tx_completed,
|
||||
.getByte = aux_get_byte,
|
||||
.getBaudrate = nullptr,
|
||||
.setReceiveCb = nullptr,
|
||||
.setBaudrateCb = nullptr,
|
||||
};
|
||||
|
||||
extern "C" void AUX_SERIAL_USART_IRQHandler(void)
|
||||
@@ -206,7 +207,7 @@ AuxSerialState aux2SerialState = {
|
||||
.usart = &aux2USART,
|
||||
};
|
||||
|
||||
static bool aux2SerialOnSend(uint8_t* data)
|
||||
static uint8_t aux2SerialOnSend(uint8_t* data)
|
||||
{
|
||||
return aux2SerialTxFifo.pop(*data);
|
||||
}
|
||||
@@ -229,14 +230,15 @@ extern "C" void AUX2_SERIAL_USART_IRQHandler(void)
|
||||
}
|
||||
|
||||
const etx_serial_driver_t Aux2SerialDriver = {
|
||||
.init = aux2SerialInit,
|
||||
.deinit = aux_serial_deinit,
|
||||
.sendByte = aux_serial_putc,
|
||||
.sendBuffer = aux_serial_send_buffer,
|
||||
.waitForTxCompleted = aux_wait_tx_completed,
|
||||
.getByte = aux_get_byte,
|
||||
.setReceiveCb = nullptr,
|
||||
.setOnErrorCb = nullptr,
|
||||
.init = aux2SerialInit,
|
||||
.deinit = aux_serial_deinit,
|
||||
.sendByte = aux_serial_putc,
|
||||
.sendBuffer = aux_serial_send_buffer,
|
||||
.waitForTxCompleted = aux_wait_tx_completed,
|
||||
.getByte = aux_get_byte,
|
||||
.getBaudrate = nullptr,
|
||||
.setReceiveCb = nullptr,
|
||||
.setBaudrateCb = nullptr,
|
||||
};
|
||||
|
||||
#endif // AUX2_SERIAL
|
||||
|
||||
@@ -24,12 +24,10 @@
|
||||
#include "hal/serial_driver.h"
|
||||
|
||||
#if defined(AUX_SERIAL)
|
||||
|
||||
extern const etx_serial_driver_t AuxSerialDriver;
|
||||
#endif
|
||||
|
||||
#if defined(AUX2_SERIAL)
|
||||
|
||||
extern const etx_serial_driver_t Aux2SerialDriver;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -80,26 +80,8 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usb_driver.h"
|
||||
|
||||
#if !defined(SIMU)
|
||||
#include "usbd_cdc_core.h"
|
||||
#include "usbd_msc_core.h"
|
||||
#include "usbd_hid_core.h"
|
||||
#include "usbd_usr.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usbd_conf.h"
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SIMU)
|
||||
#include "../simu/simpgmspace.h"
|
||||
#endif
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "definitions.h"
|
||||
|
||||
void getCPUUniqueID(char * s);
|
||||
EXTERN_C(void getCPUUniqueID(char * s));
|
||||
|
||||
#define LEN_CPU_UID (3*8+2)
|
||||
|
||||
@@ -29,4 +30,4 @@ void getCPUUniqueID(char * s);
|
||||
extern const uint32_t cpu_uid[3];
|
||||
#else
|
||||
extern const uint32_t * cpu_uid;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -139,6 +139,10 @@ const etx_serial_driver_t ExtmoduleSerialDriver = {
|
||||
.sendByte = extmoduleSendByte,
|
||||
.sendBuffer = extmoduleSendBuffer,
|
||||
.waitForTxCompleted = extmoduleWaitForTxCompleted,
|
||||
.getByte = nullptr,
|
||||
.getBaudrate = nullptr,
|
||||
.setReceiveCb = nullptr,
|
||||
.setBaudrateCb = nullptr,
|
||||
};
|
||||
|
||||
extern "C" void EXTMODULE_USART_IRQHandler(void)
|
||||
|
||||
@@ -31,7 +31,7 @@ ModuleFifo intmoduleFifo;
|
||||
static uint8_t * intmoduleTxBufferData;
|
||||
static volatile uint8_t intmoduleTxBufferRemaining;
|
||||
|
||||
bool intmoduleTxBufferSend(uint8_t* data)
|
||||
uint8_t intmoduleTxBufferSend(uint8_t* data)
|
||||
{
|
||||
if (intmoduleTxBufferRemaining) {
|
||||
*data = *(intmoduleTxBufferData++);
|
||||
@@ -158,4 +158,8 @@ const etx_serial_driver_t IntmoduleSerialDriver = {
|
||||
.sendByte = intmoduleSendByte,
|
||||
.sendBuffer = intmoduleSendBuffer,
|
||||
.waitForTxCompleted = intmoduleWaitForTxCompleted,
|
||||
.getByte = nullptr,
|
||||
.getBaudrate = nullptr,
|
||||
.setReceiveCb = nullptr,
|
||||
.setBaudrateCb = nullptr,
|
||||
};
|
||||
|
||||
@@ -19,18 +19,24 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "usb_dcd_int.h"
|
||||
#include "usb_bsp.h"
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "opentx.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "usb_driver.h"
|
||||
|
||||
extern "C" {
|
||||
#include "usb_conf.h"
|
||||
#include "usb_dcd_int.h"
|
||||
#include "usb_bsp.h"
|
||||
|
||||
#include "usbd_cdc_core.h"
|
||||
#include "usbd_msc_core.h"
|
||||
#include "usbd_hid_core.h"
|
||||
#include "usbd_usr.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_conf.h"
|
||||
}
|
||||
|
||||
static bool usbDriverStarted = false;
|
||||
#if defined(BOOT)
|
||||
static usbMode selectedUsbMode = USB_MASS_STORAGE_MODE;
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/serial_port.h"
|
||||
#include "definitions.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -47,14 +50,9 @@ void usbStart();
|
||||
void usbStop();
|
||||
bool usbStarted();
|
||||
|
||||
int getSelectedUsbMode();
|
||||
EXTERN_C(int getSelectedUsbMode());
|
||||
void setSelectedUsbMode(int mode);
|
||||
|
||||
uint32_t usbSerialFreeSpace();
|
||||
void usbSerialPutc(void*, uint8_t c);
|
||||
EXTERN_C(uint32_t usbSerialFreeSpace());
|
||||
|
||||
uint32_t usbSerialBaudRate(void);
|
||||
|
||||
void usbSerialSetReceiveDataCb(void (*cb)(uint8_t* buf, uint32_t len));
|
||||
void usbSerialSetCtrlLineStateCb(void (*cb)(uint16_t ctrlLineState));
|
||||
void usbSerialSetBaudRateCb(void (*cb)(uint32_t baud));
|
||||
extern const etx_serial_port_t UsbSerialPort;
|
||||
|
||||
@@ -25,11 +25,13 @@
|
||||
|
||||
// include STM32 headers and generic board defs
|
||||
#include "board_common.h"
|
||||
#include "usb_driver.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_conf.h"
|
||||
#include "usbd_cdc_core.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
@@ -76,9 +78,13 @@ extern "C" const CDC_IF_Prop_TypeDef VCP_fops =
|
||||
|
||||
} // extern "C"
|
||||
|
||||
static void (*receiveDataCb)(uint8_t* buf, uint32_t len);
|
||||
static void (*ctrlLineStateCb)(uint16_t ctrlLineState);
|
||||
static void (*baudRateCb)(uint32_t baud);
|
||||
static void (*receiveDataCb)(uint8_t*, uint32_t) = nullptr;
|
||||
// static void* receiveDataCbCtx;
|
||||
|
||||
//static void (*ctrlLineStateCb)(uint16_t ctrlLineState);
|
||||
|
||||
static void (*baudRateCb)(uint32_t) = nullptr;
|
||||
// static void* baudRateCbCtx;
|
||||
|
||||
bool cdcConnected = false;
|
||||
|
||||
@@ -92,8 +98,8 @@ bool cdcConnected = false;
|
||||
static uint16_t VCP_Init(void)
|
||||
{
|
||||
cdcConnected = true;
|
||||
ctrlLineStateCb = NULL;
|
||||
baudRateCb = NULL;
|
||||
// receiveDataCb = nullptr;
|
||||
// baudRateCb = nullptr;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
@@ -107,6 +113,9 @@ static uint16_t VCP_Init(void)
|
||||
static uint16_t VCP_DeInit(void)
|
||||
{
|
||||
cdcConnected = false;
|
||||
receiveDataCb = nullptr;
|
||||
baudRateCb = nullptr;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -157,8 +166,10 @@ static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||
case SET_LINE_CODING:
|
||||
if (plc && (Len == sizeof (*plc))) {
|
||||
// If a callback is provided, tell the upper driver of changes in baud rate
|
||||
if (baudRateCb) {
|
||||
baudRateCb(plc->bitrate);
|
||||
auto _cb = baudRateCb;
|
||||
// auto _ctx = baudRateCbCtx;
|
||||
if (_cb) {
|
||||
_cb(/*_ctx,*/ plc->bitrate);
|
||||
}
|
||||
// Copy into structure to save for later
|
||||
ust_cpy(&g_lc, plc);
|
||||
@@ -173,11 +184,11 @@ static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||
|
||||
case SET_CONTROL_LINE_STATE:
|
||||
// If a callback is provided, tell the upper driver of changes in DTR/RTS state
|
||||
if (plc && (Len == sizeof (uint16_t))) {
|
||||
if (ctrlLineStateCb) {
|
||||
ctrlLineStateCb(*((uint16_t *)Buf));
|
||||
}
|
||||
}
|
||||
// if (plc && (Len == sizeof (uint16_t))) {
|
||||
// if (ctrlLineStateCb) {
|
||||
// ctrlLineStateCb(*((uint16_t *)Buf));
|
||||
// }
|
||||
// }
|
||||
break;
|
||||
|
||||
case SEND_BREAK:
|
||||
@@ -255,28 +266,51 @@ void usbSerialPutc(void*, uint8_t c)
|
||||
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
|
||||
{
|
||||
auto _rxCb = receiveDataCb;
|
||||
if (_rxCb) _rxCb(Buf, Len);
|
||||
// auto _ctx = receiveDataCbCtx;
|
||||
|
||||
if (_rxCb) _rxCb(/*_ctx,*/ Buf, Len);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
uint32_t usbSerialBaudRate(void)
|
||||
uint32_t usbSerialBaudRate(void*)
|
||||
{
|
||||
return g_lc.bitrate;
|
||||
}
|
||||
|
||||
void usbSerialSetReceiveDataCb(void (*cb)(uint8_t* buf, uint32_t len))
|
||||
void usbSerialSetReceiveDataCb(void*, void (*cb)(uint8_t*, uint32_t))
|
||||
{
|
||||
// receiveDataCb = nullptr;
|
||||
// receiveDataCbCtx = cb_ctx;
|
||||
receiveDataCb = cb;
|
||||
}
|
||||
|
||||
void usbSerialSetBaudRateCb(void (*cb)(uint32_t baud))
|
||||
void usbSerialSetBaudRateCb(void*, void (*cb)(uint32_t))
|
||||
{
|
||||
// baudRateCb = nullptr;
|
||||
// baudRateCbCtx = cb_ctx;
|
||||
baudRateCb = cb;
|
||||
}
|
||||
|
||||
void usbSerialSetCtrlLineStateCb(void (*cb)(uint16_t ctrlLineState))
|
||||
{
|
||||
ctrlLineStateCb = cb;
|
||||
}
|
||||
// void usbSerialSetCtrlLineStateCb(void (*cb)(uint16_t ctrlLineState))
|
||||
// {
|
||||
// ctrlLineStateCb = cb;
|
||||
// }
|
||||
|
||||
static const etx_serial_driver_t usbSerialDriver = {
|
||||
nullptr,
|
||||
nullptr,
|
||||
usbSerialPutc,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
usbSerialBaudRate,
|
||||
usbSerialSetReceiveDataCb,
|
||||
usbSerialSetBaudRateCb,
|
||||
};
|
||||
|
||||
const etx_serial_port_t UsbSerialPort = {
|
||||
&usbSerialDriver,
|
||||
nullptr,
|
||||
};
|
||||
|
||||
// /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Reference in New Issue
Block a user