1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

usb cdc: make HID/CDC configurable in hwsettings

This commit is contained in:
Stacey Sheldon 2011-09-14 17:04:15 -04:00
parent e6ead85857
commit eebdda6276
19 changed files with 86 additions and 76 deletions

View File

@ -198,8 +198,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) {
}
uint8_t processRX() {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB_HID) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB_HID, mReceive_Buffer, 63, 0) == 63) {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
}

View File

@ -113,7 +113,7 @@ void processComand(uint8_t *xReceive_Buffer) {
#ifdef DEBUG_SSP
char str[63]= {0};
sprintf(str,"Received COMMAND:%d|",Command);
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
PIOS_COM_SendString(PIOS_COM_TELEM_USB,str);
#endif
EchoReqFlag = (Command >> 7);
EchoAnsFlag = (Command >> 6) & 0x01;
@ -324,11 +324,11 @@ void processComand(uint8_t *xReceive_Buffer) {
case Download_Req:
#ifdef DEBUG_SSP
sprintf(str,"COMMAND:DOWNLOAD_REQ 1 Status=%d|",DeviceState);
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
PIOS_COM_SendString(PIOS_COM_TELEM_USB,str);
#endif
if (DeviceState == DFUidle) {
#ifdef DEBUG_SSP
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,"COMMAND:DOWNLOAD_REQ 1|");
PIOS_COM_SendString(PIOS_COM_TELEM_USB,"COMMAND:DOWNLOAD_REQ 1|");
#endif
downType = Data0;
downPacketTotal = Count;
@ -442,7 +442,7 @@ uint32_t CalcFirmCRC() {
}
void sendData(uint8_t * buf, uint16_t size) {
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB_HID, buf, size);
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
if (DeviceState == downloading)
PIOS_DELAY_WaitmS(20);//this is an hack, we should check wtf is wrong with hid
}

View File

@ -68,7 +68,7 @@ const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
#endif /* PIOS_INCLUDE_USB_COM */
uint32_t pios_com_telem_usb_hid_id;
uint32_t pios_com_telem_usb_id;
/**
* PIOS_Board_Init()
@ -103,7 +103,7 @@ void PIOS_Board_Init(void) {
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_hid_id, &pios_usb_hid_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
pios_com_telem_usb_rx_buffer, sizeof(pios_com_telem_usb_rx_buffer),
pios_com_telem_usb_tx_buffer, sizeof(pios_com_telem_usb_tx_buffer))) {
PIOS_Assert(0);

View File

@ -249,8 +249,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) {
uint8_t processRX() {
if (ProgPort == Usb) {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB_HID) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB_HID, mReceive_Buffer, 63, 0) == 63) {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
}

View File

@ -121,7 +121,7 @@ void processComand(uint8_t *xReceive_Buffer) {
#ifdef DEBUG_SSP
char str[63]= {0};
sprintf(str,"Received COMMAND:%d|",Command);
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
PIOS_COM_SendString(PIOS_COM_TELEM_USB,str);
#endif
EchoReqFlag = (Command >> 7);
EchoAnsFlag = (Command >> 6) & 0x01;
@ -389,11 +389,11 @@ void processComand(uint8_t *xReceive_Buffer) {
case Download_Req:
#ifdef DEBUG_SSP
sprintf(str,"COMMAND:DOWNLOAD_REQ 1 Status=%d|",DeviceState);
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
PIOS_COM_SendString(PIOS_COM_TELEM_USB,str);
#endif
if (DeviceState == DFUidle) {
#ifdef DEBUG_SSP
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,"COMMAND:DOWNLOAD_REQ 1|");
PIOS_COM_SendString(PIOS_COM_TELEM_USB,"COMMAND:DOWNLOAD_REQ 1|");
#endif
downType = Data0;
downPacketTotal = Count;
@ -551,7 +551,7 @@ uint32_t CalcFirmCRC() {
void sendData(uint8_t * buf, uint16_t size) {
if (ProgPort == Usb) {
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB_HID, buf, size);
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
if (DeviceState == downloading)
PIOS_DELAY_WaitmS(10);

View File

@ -226,8 +226,7 @@ const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
#endif /* PIOS_INCLUDE_USB_COM */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_hid_id;
uint32_t pios_com_telem_usb_cdc_id;
uint32_t pios_com_telem_usb_id;
#include "pios_opahrs.h"
@ -275,7 +274,7 @@ void PIOS_Board_Init(void) {
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_hid_id, &pios_usb_hid_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
pios_com_telem_usb_rx_buffer, sizeof(pios_com_telem_usb_rx_buffer),
pios_com_telem_usb_tx_buffer, sizeof(pios_com_telem_usb_tx_buffer))) {
PIOS_Assert(0);

View File

@ -204,8 +204,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) {
}
uint8_t processRX() {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB_HID) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB_HID, mReceive_Buffer, 63, 0) == 63) {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
}

View File

@ -141,7 +141,7 @@ void processComand(uint8_t *xReceive_Buffer) {
#ifdef DEBUG_SSP
char str[63]= {0};
sprintf(str,"Received COMMAND:%d|",Command);
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
PIOS_COM_SendString(PIOS_COM_TELEM_USB,str);
#endif
EchoReqFlag = (Command >> 7);
EchoAnsFlag = (Command >> 6) & 0x01;
@ -322,7 +322,7 @@ void processComand(uint8_t *xReceive_Buffer) {
Buffer[15] = devicesTable[Data0 - 1].devID;
}
sendData(Buffer + 1, 63);
//PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB_HID, Buffer + 1, 63);//FIX+1
//PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, Buffer + 1, 63);//FIX+1
break;
case JumpFW:
FLASH_Lock();
@ -356,11 +356,11 @@ void processComand(uint8_t *xReceive_Buffer) {
case Download_Req:
#ifdef DEBUG_SSP
sprintf(str,"COMMAND:DOWNLOAD_REQ 1 Status=%d|",DeviceState);
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
PIOS_COM_SendString(PIOS_COM_TELEM_USB,str);
#endif
if (DeviceState == DFUidle) {
#ifdef DEBUG_SSP
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,"COMMAND:DOWNLOAD_REQ 1|");
PIOS_COM_SendString(PIOS_COM_TELEM_USB,"COMMAND:DOWNLOAD_REQ 1|");
#endif
downType = Data0;
downPacketTotal = Count;
@ -474,7 +474,7 @@ uint32_t CalcFirmCRC() {
}
void sendData(uint8_t * buf, uint16_t size) {
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB_HID, buf, size);
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
if (DeviceState == downloading)
PIOS_DELAY_WaitmS(10);
}

View File

@ -68,7 +68,7 @@ const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
#endif /* PIOS_INCLUDE_USB_COM */
uint32_t pios_com_telem_usb_hid_id;
uint32_t pios_com_telem_usb_id;
/**
* PIOS_Board_Init()
@ -103,7 +103,7 @@ void PIOS_Board_Init(void) {
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_hid_id, &pios_usb_hid_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
pios_com_telem_usb_rx_buffer, sizeof(pios_com_telem_usb_rx_buffer),
pios_com_telem_usb_tx_buffer, sizeof(pios_com_telem_usb_tx_buffer))) {
PIOS_Assert(0);

View File

@ -1101,8 +1101,7 @@ const struct pios_usb_com_cfg pios_usb_com_cdc_cfg = {
#endif /* PIOS_INCLUDE_USB_COM */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_hid_id;
uint32_t pios_com_telem_usb_cdc_id;
uint32_t pios_com_telem_usb_id;
uint32_t pios_com_gps_id;
/**
@ -1436,34 +1435,53 @@ void PIOS_Board_Init(void) {
#if defined(PIOS_INCLUDE_USB_HID)
uint32_t pios_usb_id;
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
#if defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_usb_hid_id, &pios_usb_hid_com_driver, pios_usb_com_id,
rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
PIOS_Assert(0);
}
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_cdc_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer2 = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
uint8_t * tx_buffer2 = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
PIOS_Assert(rx_buffer2);
PIOS_Assert(tx_buffer2);
if (PIOS_COM_Init(&pios_com_telem_usb_cdc_id, &pios_usb_cdc_com_driver, pios_usb_com_id,
rx_buffer2, PIOS_COM_TELEM_USB_RX_BUF_LEN,
tx_buffer2, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
PIOS_Assert(0);
}
/* Configure the usb telemetry protocol */
uint8_t hwsettings_usb_telemetry_channel;
HwSettingsUSB_TelemetryChannelGet(&hwsettings_usb_telemetry_channel);
switch (hwsettings_usb_telemetry_channel) {
case HWSETTINGS_USB_TELEMETRYCHANNEL_HID:
#if defined(PIOS_INCLUDE_COM)
{
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
PIOS_Assert(0);
}
}
#endif /* PIOS_INCLUDE_COM */
break;
case HWSETTINGS_USB_TELEMETRYCHANNEL_CDC:
#if defined(PIOS_INCLUDE_COM)
{
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_cdc_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_cdc_com_driver, pios_usb_com_id,
rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
PIOS_Assert(0);
}
}
#endif /* PIOS_INCLUDE_COM */
break;
default:
PIOS_Assert(0);
}
#endif /* PIOS_INCLUDE_USB_HID */
PIOS_IAP_Init();

View File

@ -311,7 +311,7 @@ static void telemetryRxTask(void *parameters)
#if defined(PIOS_INCLUDE_USB_HID)
// Determine input port (USB takes priority over telemetry port)
if (PIOS_USB_HID_CheckAvailable(0)) {
inputPort = PIOS_COM_TELEM_USB_CDC;
inputPort = PIOS_COM_TELEM_USB;
} else
#endif /* PIOS_INCLUDE_USB_HID */
{
@ -348,7 +348,7 @@ static int32_t transmitData(uint8_t * data, int32_t length)
// Determine input port (USB takes priority over telemetry port)
#if defined(PIOS_INCLUDE_USB_HID)
if (PIOS_USB_HID_CheckAvailable(0)) {
outputPort = PIOS_COM_TELEM_USB_CDC;
outputPort = PIOS_COM_TELEM_USB;
} else
#endif /* PIOS_INCLUDE_USB_HID */
{

View File

@ -1069,8 +1069,7 @@ const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
#endif /* PIOS_INCLUDE_USB_COM */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_hid_id;
uint32_t pios_com_telem_usb_cdc_id;
uint32_t pios_com_telem_usb_id;
uint32_t pios_com_gps_id;
uint32_t pios_com_aux_id;
uint32_t pios_com_dsm_id;
@ -1299,7 +1298,7 @@ void PIOS_Board_Init(void) {
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_usb_hid_id, &pios_usb_hid_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
PIOS_Assert(0);

View File

@ -141,11 +141,8 @@ extern uint32_t pios_com_gps_id;
#define PIOS_COM_GPS (pios_com_gps_id)
#endif /* PIOS_INCLUDE_GPS */
extern uint32_t pios_com_telem_usb_hid_id;
#define PIOS_COM_TELEM_USB_HID (pios_com_telem_usb_hid_id)
extern uint32_t pios_com_telem_usb_cdc_id;
#define PIOS_COM_TELEM_USB_CDC (pios_com_telem_usb_cdc_id)
extern uint32_t pios_com_telem_usb_id;
#define PIOS_COM_TELEM_USB (pios_com_telem_usb_id)
//-------------------------
// ADC

View File

@ -156,8 +156,8 @@ extern uint32_t pios_com_serial_id;
//#define PIOS_COM_DEBUG PIOS_COM_SERIAL // uncomment this to send debug info out the serial port
#if defined(PIOS_INCLUDE_USB_HID)
extern uint32_t pios_com_telem_usb_hid_id;
#define PIOS_COM_TELEM_USB_HID (pios_com_telem_usb_hid_id)
extern uint32_t pios_com_telem_usb_id;
#define PIOS_COM_TELEM_USB (pios_com_telem_usb_id)
#endif
#if defined(PIOS_COM_DEBUG)

View File

@ -152,11 +152,8 @@ extern uint32_t pios_com_telem_rf_id;
extern uint32_t pios_com_gps_id;
#define PIOS_COM_GPS (pios_com_gps_id)
extern uint32_t pios_com_telem_usb_hid_id;
#define PIOS_COM_TELEM_USB_HID (pios_com_telem_usb_hid_id)
extern uint32_t pios_com_telem_usb_cdc_id;
#define PIOS_COM_TELEM_USB_CDC (pios_com_telem_usb_cdc_id)
extern uint32_t pios_com_telem_usb_id;
#define PIOS_COM_TELEM_USB (pios_com_telem_usb_id)
#ifdef PIOS_ENABLE_AUX_UART
extern uint32_t pios_com_aux_id;

View File

@ -777,7 +777,7 @@ void apiconfig_process(void)
if (PIOS_USB_HID_CheckAvailable(0))
{ // USB comms is up, use the USB comm-port instead of the USART comm-port
apiconfig_usb_comms = true;
apiconfig_comm_port = PIOS_COM_TELEM_USB_HID;
apiconfig_comm_port = PIOS_COM_TELEM_USB;
}
#endif

View File

@ -339,8 +339,7 @@ const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
#endif /* PIOS_INCLUDE_USB_COM */
uint32_t pios_com_serial_id;
uint32_t pios_com_telem_usb_hid_id;
uint32_t pios_com_telem_usb_cdc_id;
uint32_t pios_com_telem_usb_id;
/**
* PIOS_Board_Init()
@ -378,7 +377,7 @@ void PIOS_Board_Init(void) {
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_hid_id, &pios_usb_hid_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
pios_com_telem_usb_rx_buffer, sizeof(pios_com_telem_usb_rx_buffer),
pios_com_telem_usb_tx_buffer, sizeof(pios_com_telem_usb_tx_buffer))) {
PIOS_Assert(0);

View File

@ -74,7 +74,7 @@ void trans_process(void)
if (PIOS_USB_HID_CheckAvailable(0))
{ // USB comms is up, use the USB comm-port instead of the USART comm-port
usb_comms = true;
comm_port = PIOS_COM_TELEM_USB_HID;
comm_port = PIOS_COM_TELEM_USB;
}
#endif

View File

@ -11,6 +11,7 @@
<field name="TelemetrySpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
<field name="GPSSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
<field name="USB_TelemetryChannel" units="function" type="enum" elements="1" options="HID,CDC" defaultvalue="HID"/>
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS" options="Disabled,Enabled" defaultvalue="Disabled"/>
<field name="DSMxBind" units="" type="uint8" elements="1" defaultvalue="0"/>