mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
usb cdc: USB composite device with HID + VCP
This commit is contained in:
parent
458d3467ab
commit
c0259dc616
@ -111,6 +111,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_board_info.c
|
||||
|
@ -39,6 +39,7 @@
|
||||
#define PIOS_INCLUDE_LED
|
||||
#define PIOS_INCLUDE_SYS
|
||||
#define PIOS_INCLUDE_USB_HID
|
||||
#define PIOS_INCLUDE_USB_COM
|
||||
#define PIOS_INCLUDE_COM
|
||||
#define PIOS_INCLUDE_GPIO
|
||||
#define PIOS_NO_GPS
|
||||
|
@ -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) >= 63) {
|
||||
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
|
||||
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB_HID) >= 63) {
|
||||
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB_HID, mReceive_Buffer, 63, 0) == 63) {
|
||||
processComand(mReceive_Buffer);
|
||||
}
|
||||
}
|
||||
|
@ -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,str);
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,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,str);
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
|
||||
#endif
|
||||
if (DeviceState == DFUidle) {
|
||||
#ifdef DEBUG_SSP
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB,"COMMAND:DOWNLOAD_REQ 1|");
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,"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, buf, size);
|
||||
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB_HID, buf, size);
|
||||
if (DeviceState == downloading)
|
||||
PIOS_DELAY_WaitmS(20);//this is an hack, we should check wtf is wrong with hid
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ static uint8_t pios_com_telem_usb_tx_buffer[PIOS_COM_TELEM_USB_TX_BUF_LEN];
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
#include "pios_usb_hid_priv.h"
|
||||
|
||||
static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
static const struct pios_usb_cfg pios_usb_main_cfg = {
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
|
||||
@ -56,9 +56,19 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
||||
extern const struct pios_com_driver pios_usb_com_driver;
|
||||
#if defined(PIOS_INCLUDE_USB_COM)
|
||||
#include <pios_usb_com_priv.h>
|
||||
|
||||
uint32_t pios_com_telem_usb_id;
|
||||
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
|
||||
.type = PIOS_USB_COM_HID,
|
||||
.data_if = 0,
|
||||
.data_rx_ep = 1,
|
||||
.data_tx_ep = 1,
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM */
|
||||
|
||||
uint32_t pios_com_telem_usb_hid_id;
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
@ -84,12 +94,16 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_GPIO_Init();
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
uint32_t pios_usb_hid_id;
|
||||
if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg)) {
|
||||
uint32_t pios_usb_id;
|
||||
if (PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
#if defined(PIOS_INCLUDE_COM)
|
||||
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_com_driver, pios_usb_hid_id,
|
||||
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);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_telem_usb_hid_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);
|
||||
|
@ -114,6 +114,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_board_info.c
|
||||
|
@ -40,6 +40,7 @@
|
||||
#define PIOS_INCLUDE_SYS
|
||||
#define PIOS_INCLUDE_USART
|
||||
#define PIOS_INCLUDE_USB_HID
|
||||
#define PIOS_INCLUDE_USB_COM
|
||||
#define PIOS_INCLUDE_OPAHRS
|
||||
#define PIOS_INCLUDE_COM
|
||||
#define PIOS_INCLUDE_GPIO
|
||||
|
@ -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) >= 63) {
|
||||
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
|
||||
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB_HID) >= 63) {
|
||||
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB_HID, mReceive_Buffer, 63, 0) == 63) {
|
||||
processComand(mReceive_Buffer);
|
||||
}
|
||||
}
|
||||
|
@ -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,str);
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,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,str);
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
|
||||
#endif
|
||||
if (DeviceState == DFUidle) {
|
||||
#ifdef DEBUG_SSP
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB,"COMMAND:DOWNLOAD_REQ 1|");
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,"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, buf, size);
|
||||
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB_HID, buf, size);
|
||||
if (DeviceState == downloading)
|
||||
PIOS_DELAY_WaitmS(10);
|
||||
|
||||
|
@ -201,7 +201,7 @@ static uint8_t pios_com_telem_rf_tx_buffer[PIOS_COM_TELEM_RF_TX_BUF_LEN];
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
#include "pios_usb_hid_priv.h"
|
||||
|
||||
static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
static const struct pios_usb_cfg pios_usb_main_cfg = {
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
|
||||
@ -213,10 +213,21 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
||||
extern const struct pios_com_driver pios_usb_com_driver;
|
||||
#if defined(PIOS_INCLUDE_USB_COM)
|
||||
#include <pios_usb_com_priv.h>
|
||||
|
||||
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
|
||||
.type = PIOS_USB_COM_HID,
|
||||
.data_if = 0,
|
||||
.data_rx_ep = 1,
|
||||
.data_tx_ep = 1,
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM */
|
||||
|
||||
uint32_t pios_com_telem_rf_id;
|
||||
uint32_t pios_com_telem_usb_id;
|
||||
uint32_t pios_com_telem_usb_hid_id;
|
||||
uint32_t pios_com_telem_usb_cdc_id;
|
||||
|
||||
#include "pios_opahrs.h"
|
||||
|
||||
@ -257,10 +268,14 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_GPIO_Init();
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
uint32_t pios_usb_hid_id;
|
||||
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
|
||||
uint32_t pios_usb_id;
|
||||
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
|
||||
#if defined(PIOS_INCLUDE_COM)
|
||||
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_com_driver, pios_usb_hid_id,
|
||||
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);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_telem_usb_hid_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);
|
||||
|
@ -110,6 +110,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_board_info.c
|
||||
|
@ -38,6 +38,7 @@
|
||||
#define PIOS_INCLUDE_LED
|
||||
#define PIOS_INCLUDE_SYS
|
||||
#define PIOS_INCLUDE_USB_HID
|
||||
#define PIOS_INCLUDE_USB_COM
|
||||
#define PIOS_INCLUDE_COM
|
||||
#define PIOS_INCLUDE_GPIO
|
||||
//#define DEBUG_SSP
|
||||
|
@ -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) >= 63) {
|
||||
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
|
||||
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB_HID) >= 63) {
|
||||
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB_HID, mReceive_Buffer, 63, 0) == 63) {
|
||||
processComand(mReceive_Buffer);
|
||||
}
|
||||
}
|
||||
|
@ -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,str);
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,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, Buffer + 1, 63);//FIX+1
|
||||
//PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB_HID, 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,str);
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,str);
|
||||
#endif
|
||||
if (DeviceState == DFUidle) {
|
||||
#ifdef DEBUG_SSP
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB,"COMMAND:DOWNLOAD_REQ 1|");
|
||||
PIOS_COM_SendString(PIOS_COM_TELEM_USB_HID,"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, buf, size);
|
||||
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB_HID, buf, size);
|
||||
if (DeviceState == downloading)
|
||||
PIOS_DELAY_WaitmS(10);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ static uint8_t pios_com_telem_usb_tx_buffer[PIOS_COM_TELEM_USB_TX_BUF_LEN];
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
#include "pios_usb_hid_priv.h"
|
||||
|
||||
static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
static const struct pios_usb_cfg pios_usb_main_cfg = {
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
|
||||
@ -56,9 +56,19 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
||||
extern const struct pios_com_driver pios_usb_com_driver;
|
||||
#if defined(PIOS_INCLUDE_USB_COM)
|
||||
#include <pios_usb_com_priv.h>
|
||||
|
||||
uint32_t pios_com_telem_usb_id;
|
||||
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
|
||||
.type = PIOS_USB_COM_HID,
|
||||
.data_if = 0,
|
||||
.data_rx_ep = 1,
|
||||
.data_tx_ep = 1,
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM */
|
||||
|
||||
uint32_t pios_com_telem_usb_hid_id;
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
@ -84,10 +94,16 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_GPIO_Init();
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
uint32_t pios_usb_hid_id;
|
||||
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
|
||||
uint32_t pios_usb_id;
|
||||
if (PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
#if defined(PIOS_INCLUDE_COM)
|
||||
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_com_driver, pios_usb_hid_id,
|
||||
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);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_telem_usb_hid_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);
|
||||
|
@ -203,11 +203,12 @@ SRC += $(PIOSSTM32F10X)/pios_wdg.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_tim.c
|
||||
|
||||
|
||||
# PIOS USB related files (seperated to make code maintenance more easy)
|
||||
# PIOS USB related files (separated to make code maintenance more easy)
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_crc.c
|
||||
|
@ -62,6 +62,8 @@
|
||||
#define PIOS_INCLUDE_SYS
|
||||
#define PIOS_INCLUDE_USART
|
||||
#define PIOS_INCLUDE_USB_HID
|
||||
#define PIOS_INCLUDE_USB_COM
|
||||
#define PIOS_INCLUDE_USB_COM_CDC
|
||||
#define PIOS_INCLUDE_COM
|
||||
#define PIOS_INCLUDE_SETTINGS
|
||||
#define PIOS_INCLUDE_FREERTOS
|
||||
|
@ -55,7 +55,7 @@
|
||||
#endif
|
||||
|
||||
/* Internal defines which are used by PIOS USB HID (don't touch) */
|
||||
#define PIOS_USB_EP_NUM 2
|
||||
#define PIOS_USB_EP_NUM 5
|
||||
|
||||
/* Buffer table base address */
|
||||
#define PIOS_USB_BTABLE_ADDRESS 0x000
|
||||
|
@ -33,7 +33,7 @@
|
||||
#define PIOS_HID_OFF_HID_DESC 0x12
|
||||
|
||||
#define PIOS_HID_SIZ_DEVICE_DESC 18
|
||||
#define PIOS_HID_SIZ_CONFIG_DESC 41
|
||||
#define PIOS_HID_SIZ_CONFIG_DESC 107
|
||||
#define PIOS_HID_SIZ_REPORT_DESC 36
|
||||
#define PIOS_HID_SIZ_STRING_LANGID 4
|
||||
#define PIOS_HID_SIZ_STRING_VENDOR 28
|
||||
|
@ -1067,7 +1067,7 @@ uint32_t pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE];
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
#include "pios_usb_hid_priv.h"
|
||||
|
||||
static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
static const struct pios_usb_cfg pios_usb_main_cfg = {
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
|
||||
@ -1079,10 +1079,30 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
||||
extern const struct pios_com_driver pios_usb_com_driver;
|
||||
#if defined(PIOS_INCLUDE_USB_COM)
|
||||
#include <pios_usb_com_priv.h>
|
||||
|
||||
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
|
||||
.type = PIOS_USB_COM_HID,
|
||||
.data_if = 0,
|
||||
.data_rx_ep = 1,
|
||||
.data_tx_ep = 1,
|
||||
};
|
||||
|
||||
const struct pios_usb_com_cfg pios_usb_com_cdc_cfg = {
|
||||
.type = PIOS_USB_COM_CDC,
|
||||
.ctrl_if = 1,
|
||||
.ctrl_tx_ep = 2,
|
||||
|
||||
.data_if = 2,
|
||||
.data_rx_ep = 3,
|
||||
.data_tx_ep = 3,
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_USB_COM */
|
||||
|
||||
uint32_t pios_com_telem_rf_id;
|
||||
uint32_t pios_com_telem_usb_id;
|
||||
uint32_t pios_com_telem_usb_hid_id;
|
||||
uint32_t pios_com_telem_usb_cdc_id;
|
||||
uint32_t pios_com_gps_id;
|
||||
|
||||
/**
|
||||
@ -1414,18 +1434,35 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_GPIO_Init();
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
uint32_t pios_usb_hid_id;
|
||||
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
|
||||
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_id, &pios_usb_com_driver, pios_usb_hid_id,
|
||||
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);
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_COM */
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
||||
|
@ -27,9 +27,9 @@ const uint8_t PIOS_HID_DeviceDescriptor[PIOS_HID_SIZ_DEVICE_DESC] =
|
||||
USB_DEVICE_DESCRIPTOR_TYPE, // bDescriptorType
|
||||
0x00, // bcdUSB
|
||||
0x02,
|
||||
0x00, // bDeviceClass
|
||||
0x00, // bDeviceSubClass
|
||||
0x00, // bDeviceProtocol
|
||||
0xEF, // bDeviceClass (Misc)
|
||||
0x02, // bDeviceSubClass (common)
|
||||
0x01, // bDeviceProtocol (IAD)
|
||||
0x40, // bMaxPacketSize40
|
||||
(uint8_t)((PIOS_USB_VENDOR_ID) & 0xff), // idVendor
|
||||
(uint8_t)((PIOS_USB_VENDOR_ID) >> 8),
|
||||
@ -51,17 +51,27 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
|
||||
{
|
||||
0x09, // bLength: Configuation Descriptor size
|
||||
USB_CONFIGURATION_DESCRIPTOR_TYPE, // bDescriptorType: Configuration
|
||||
PIOS_HID_SIZ_CONFIG_DESC,
|
||||
// wTotalLength: Bytes returned
|
||||
PIOS_HID_SIZ_CONFIG_DESC, // wTotalLength: Bytes returned
|
||||
0x00,
|
||||
0x01, // bNumInterfaces: 1 interface
|
||||
0x03, // bNumInterfaces: 3 interfaces
|
||||
0x01, // bConfigurationValue: Configuration value
|
||||
0x00, // iConfiguration: Index of string descriptor describing the configuration
|
||||
0xC0, // bmAttributes: Bus powered
|
||||
0x7D, // MaxPower 250 mA - needed to power the RF transmitter
|
||||
|
||||
// *************** Interface Association Descriptor *****************
|
||||
// 9
|
||||
0x08, /* bLength */
|
||||
0x0B, /* bDescriptorType (IAD) */
|
||||
0x01, /* bFirstInterface */
|
||||
0x02, /* bInterfaceCount */
|
||||
0x02, /* bFunctionClass (Communication Class) */
|
||||
0x02, /* bFunctionSubClass (Abstract Control Model) */
|
||||
0x00, /* bFunctionProtocol (V.25ter, Common AT commands) */
|
||||
0x00, /* iInterface */
|
||||
|
||||
// ************** Descriptor of Custom HID interface ****************
|
||||
// 09
|
||||
// 17
|
||||
0x09, // bLength: Interface Descriptor size
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType: Interface descriptor type
|
||||
0x00, // bInterfaceNumber: Number of Interface
|
||||
@ -73,19 +83,19 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
|
||||
0, // iInterface: Index of string descriptor
|
||||
|
||||
// ******************** Descriptor of Custom HID HID ********************
|
||||
// 18
|
||||
// 26
|
||||
0x09, // bLength: HID Descriptor size
|
||||
HID_DESCRIPTOR_TYPE, // bDescriptorType: HID
|
||||
0x10, // bcdHID: HID Class Spec release number
|
||||
0x01,
|
||||
0x00, // bCountryCode: Hardware target country
|
||||
0x01, // bNumDescriptors: Number of HID class descriptors to follow
|
||||
0x02, // bNumDescriptors: Number of HID class descriptors to follow
|
||||
0x22, // bDescriptorType
|
||||
PIOS_HID_SIZ_REPORT_DESC, // wItemLength: Total length of Report descriptor
|
||||
0x00,
|
||||
|
||||
// ******************** Descriptor of Custom HID endpoints ******************
|
||||
// 27
|
||||
// 35
|
||||
0x07, // bLength: Endpoint Descriptor size
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType:
|
||||
|
||||
@ -94,18 +104,102 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
|
||||
0x40, // wMaxPacketSize: 2 Bytes max
|
||||
0x00,
|
||||
0x04, // bInterval: Polling Interval in ms
|
||||
// 34
|
||||
|
||||
|
||||
// 42
|
||||
0x07, // bLength: Endpoint Descriptor size
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType:
|
||||
// Endpoint descriptor type
|
||||
0x01, // bEndpointAddress:
|
||||
// Endpoint Address (OUT)
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType: (Endpoint descriptor type)
|
||||
0x01, // bEndpointAddress: Endpoint Address (OUT)
|
||||
0x03, // bmAttributes: Interrupt endpoint
|
||||
0x40, // wMaxPacketSize: 2 Bytes max
|
||||
0x00,
|
||||
0x04, // bInterval: Polling Interval in ms
|
||||
// 41
|
||||
|
||||
// ************** Descriptor of CDC Control interface ****************
|
||||
// 49
|
||||
0x09, /* bLength */
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
0x01, /* bInterfaceNumber */
|
||||
0x00, /* bAlternateSetting */
|
||||
0x01, /* bNumEndpoints */
|
||||
0x02, /* bInterfaceClass (Communication Class) */
|
||||
0x02, /* bInterfaceSubClass (Abstract Control Model) */
|
||||
0x01, /* bFunctionProtocol (V.25ter, Common AT commands) */
|
||||
0x00, /* iInterface */
|
||||
|
||||
// ************** Header Functional Descriptor ****************
|
||||
// 58
|
||||
0x05, /* bLength */
|
||||
0x24, /* bDescriptorType (Class Specific Interface) */
|
||||
0x00, /* bDescriptorSubtype (CDC Header Functional) */
|
||||
0x10, /* bcdCDC (CDC spec release number, 1.10 */
|
||||
0x01,
|
||||
|
||||
// ************** Call Management Functional Descriptor ****************
|
||||
// 63
|
||||
0x05, /* bLength */
|
||||
0x24, /* bDescriptorType (Class Specific Interface) */
|
||||
0x01, /* bDescriptorSubtype (CDC Call Management) */
|
||||
0x00, /* bmCapabilities (No call handling) */
|
||||
0x02, /* bDataInterface (Interface number of Data Class Interface) */
|
||||
|
||||
// ************** Abstract Control Management Functional Descriptor ****************
|
||||
// 68
|
||||
0x04, /* bLength */
|
||||
0x24, /* bDescriptorType (Class Specific Interface) */
|
||||
0x02, /* bDescriptorSubtype (CDC Abstract Control Management) */
|
||||
0x00, /* bmCapabilities */
|
||||
|
||||
// ************** Union Functional Descriptor ****************
|
||||
// 72
|
||||
0x05, /* bLength */
|
||||
0x24, /* bDescriptorType (Class Specific Interface) */
|
||||
0x06, /* bDescriptorSubtype (CDC Union) */
|
||||
0x01, /* bMasterInterface (Interface number of master interface in the union) */
|
||||
0x02, /* bSlaveInterface (Interface number of slave interface in the union) */
|
||||
|
||||
// ************** Endpoint2 Functional Descriptor ****************
|
||||
// 77
|
||||
0x07, /* bLength */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType (Endpoint)
|
||||
0x82, /* bEndpointAddress*/
|
||||
0x03, /* bmAttributes (Interrupt Endpoint) */
|
||||
0x40, /* wMaxPacketSize (bytes) */
|
||||
0x00,
|
||||
0x04, /* bInterval (ms) */
|
||||
|
||||
// ************** Descriptor of CDC Data interface ****************
|
||||
// 84
|
||||
0x09, /* bLength */
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
0x02, /* bInterfaceNumber */
|
||||
0x00, /* bAlternateSetting */
|
||||
0x02, /* bNumEndpoints */
|
||||
0x0A, /* bInterfaceClass (Data Interface Class) */
|
||||
0x00, /* bInterfaceSubClass */
|
||||
0x00, /* bFunctionProtocol (No class specific protocol) */
|
||||
0x00, /* iInterface */
|
||||
|
||||
// ************** Endpoint3 Functional Descriptor ****************
|
||||
// 93
|
||||
0x07, /* bLength */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType (Endpoint)
|
||||
0x83, /* bEndpointAddress*/
|
||||
0x02, /* bmAttributes (Bulk) */
|
||||
0x40, /* wMaxPacketSize (bytes) */
|
||||
0x00,
|
||||
0x00, /* bInterval (ms) */
|
||||
|
||||
// ************** Endpoint3 Functional Descriptor ****************
|
||||
// 100
|
||||
0x07, /* bLength */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType (Endpoint)
|
||||
0x03, /* bEndpointAddress*/
|
||||
0x02, /* bmAttributes (Bulk) */
|
||||
0x40, /* wMaxPacketSize (bytes) */
|
||||
0x00,
|
||||
0x00 /* bInterval (ms) */
|
||||
|
||||
// 107
|
||||
};
|
||||
|
||||
// *************************************************
|
||||
@ -115,7 +209,7 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
|
||||
0x06, 0x9c, 0xff, // USAGE_PAGE (Vendor Page: 0xFF00)
|
||||
0x09, 0x01, // USAGE (Demo Kit)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
// 6
|
||||
// 7
|
||||
|
||||
// Data 1
|
||||
0x85, 0x01, // REPORT_ID (1)
|
||||
@ -123,9 +217,9 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0xff, // LOGICAL_MAXIMUM (255)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, PIOS_USB_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
|
||||
0x95, PIOS_USB_COM_DATA_LENGTH+1, // REPORT_COUNT (1)
|
||||
0x81, 0x83, // INPUT (Const,Var,Array)
|
||||
// 20
|
||||
// 21
|
||||
|
||||
// Data 1
|
||||
0x85, 0x02, // REPORT_ID (2)
|
||||
@ -133,9 +227,9 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0xff, // LOGICAL_MAXIMUM (255)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, PIOS_USB_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
|
||||
0x95, PIOS_USB_COM_DATA_LENGTH+1, // REPORT_COUNT (1)
|
||||
0x91, 0x82, // OUTPUT (Data,Var,Abs,Vol)
|
||||
// 34
|
||||
// 35
|
||||
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
|
@ -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;
|
||||
inputPort = PIOS_COM_TELEM_USB_HID;
|
||||
} 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;
|
||||
outputPort = PIOS_COM_TELEM_USB_HID;
|
||||
} else
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
{
|
||||
|
@ -186,6 +186,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_crc.c
|
||||
|
@ -56,6 +56,7 @@
|
||||
#define PIOS_INCLUDE_SYS
|
||||
#define PIOS_INCLUDE_USART
|
||||
#define PIOS_INCLUDE_USB_HID
|
||||
#define PIOS_INCLUDE_USB_COM
|
||||
#define PIOS_INCLUDE_BMP085
|
||||
//#define PIOS_INCLUDE_HCSR04
|
||||
#define PIOS_INCLUDE_OPAHRS
|
||||
|
@ -1044,7 +1044,7 @@ uint32_t pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE];
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
#include "pios_usb_hid_priv.h"
|
||||
|
||||
static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
static const struct pios_usb_cfg pios_usb_main_cfg = {
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
|
||||
@ -1056,10 +1056,21 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
||||
extern const struct pios_com_driver pios_usb_com_driver;
|
||||
#if defined(PIOS_INCLUDE_USB_COM)
|
||||
#include <pios_usb_com_priv.h>
|
||||
|
||||
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
|
||||
.type = PIOS_USB_COM_HID,
|
||||
.data_if = 0,
|
||||
.data_rx_ep = 1,
|
||||
.data_tx_ep = 1,
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM */
|
||||
|
||||
uint32_t pios_com_telem_rf_id;
|
||||
uint32_t pios_com_telem_usb_id;
|
||||
uint32_t pios_com_telem_usb_hid_id;
|
||||
uint32_t pios_com_telem_usb_cdc_id;
|
||||
uint32_t pios_com_gps_id;
|
||||
uint32_t pios_com_aux_id;
|
||||
uint32_t pios_com_dsm_id;
|
||||
@ -1277,14 +1288,18 @@ void PIOS_Board_Init(void) {
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
uint32_t pios_usb_hid_id;
|
||||
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
|
||||
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_id, &pios_usb_com_driver, pios_usb_hid_id,
|
||||
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);
|
||||
|
@ -141,8 +141,11 @@ 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_id;
|
||||
#define PIOS_COM_TELEM_USB (pios_com_telem_usb_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)
|
||||
|
||||
//-------------------------
|
||||
// ADC
|
||||
@ -266,8 +269,9 @@ extern uint32_t pios_com_telem_usb_id;
|
||||
// USB
|
||||
//-------------------------
|
||||
#define PIOS_USB_ENABLED 1
|
||||
#define PIOS_USB_HID_MAX_DEVS 1
|
||||
#define PIOS_USB_DETECT_GPIO_PORT GPIOC
|
||||
#define PIOS_USB_MAX_DEVS 1
|
||||
#define PIOS_USB_COM_MAX_DEVS 1
|
||||
#define PIOS_USB_DETECT_GPIO_PIN GPIO_Pin_15
|
||||
#define PIOS_USB_DETECT_EXTI_LINE EXTI_Line15
|
||||
#define PIOS_IRQ_USB_PRIORITY PIOS_IRQ_PRIO_MID
|
||||
|
@ -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_id;
|
||||
#define PIOS_COM_TELEM_USB (pios_com_telem_usb_id)
|
||||
extern uint32_t pios_com_telem_usb_hid_id;
|
||||
#define PIOS_COM_TELEM_USB_HID (pios_com_telem_usb_hid_id)
|
||||
#endif
|
||||
|
||||
#if defined(PIOS_COM_DEBUG)
|
||||
@ -393,12 +393,13 @@ extern uint32_t pios_com_telem_usb_id;
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
#define PIOS_USB_ENABLED 1
|
||||
#define PIOS_USB_HID_MAX_DEVS 1
|
||||
#define PIOS_USB_MAX_DEVS 1
|
||||
#define PIOS_USB_DETECT_GPIO_PORT GPIO_IN_2_PORT
|
||||
#define PIOS_USB_DETECT_GPIO_PIN GPIO_IN_2_PIN
|
||||
#define PIOS_USB_DETECT_EXTI_LINE EXTI_Line4
|
||||
#define PIOS_IRQ_USB_PRIORITY 8
|
||||
#endif
|
||||
#define PIOS_USB_COM_MAX_DEVS 1
|
||||
|
||||
// *****************************************************************
|
||||
// RFM22
|
||||
|
@ -152,8 +152,11 @@ 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_id;
|
||||
#define PIOS_COM_TELEM_USB (pios_com_telem_usb_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)
|
||||
|
||||
#ifdef PIOS_ENABLE_AUX_UART
|
||||
extern uint32_t pios_com_aux_id;
|
||||
@ -309,8 +312,9 @@ extern uint32_t pios_com_aux_id;
|
||||
// USB
|
||||
//-------------------------
|
||||
#define PIOS_USB_ENABLED 1
|
||||
#define PIOS_USB_HID_MAX_DEVS 1
|
||||
#define PIOS_USB_DETECT_GPIO_PORT GPIOC
|
||||
#define PIOS_USB_MAX_DEVS 1
|
||||
#define PIOS_USB_COM_MAX_DEVS 1
|
||||
#define PIOS_USB_DETECT_GPIO_PIN GPIO_Pin_4
|
||||
#define PIOS_USB_DETECT_EXTI_LINE EXTI_Line4
|
||||
#define PIOS_IRQ_USB_PRIORITY PIOS_IRQ_PRIO_MID
|
||||
|
584
flight/PiOS/STM32F10x/pios_usb_com.c
Normal file
584
flight/PiOS/STM32F10x/pios_usb_com.c
Normal file
@ -0,0 +1,584 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_USB_COM USB COM Functions
|
||||
* @brief PIOS USB COM implementation
|
||||
* @notes This implements both a simple HID device and a CDC Serial Port
|
||||
* @{
|
||||
*
|
||||
* @file pios_usb_com.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief USB COM functions (STM32 dependent code)
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* Project Includes */
|
||||
#include "pios.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_COM)
|
||||
|
||||
#include "pios_usb.h"
|
||||
#include "usb_lib.h"
|
||||
#include "pios_usb_com_priv.h"
|
||||
|
||||
static void PIOS_USB_COM_RegisterTxCallback(uint32_t usbcom_id, pios_com_callback tx_out_cb, uint32_t context);
|
||||
static void PIOS_USB_COM_RegisterRxCallback(uint32_t usbcom_id, pios_com_callback rx_in_cb, uint32_t context);
|
||||
|
||||
static void PIOS_USB_COM_HID_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail);
|
||||
static void PIOS_USB_COM_HID_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail);
|
||||
|
||||
const struct pios_com_driver pios_usb_hid_com_driver = {
|
||||
.tx_start = PIOS_USB_COM_HID_TxStart,
|
||||
.rx_start = PIOS_USB_COM_HID_RxStart,
|
||||
.bind_tx_cb = PIOS_USB_COM_RegisterTxCallback,
|
||||
.bind_rx_cb = PIOS_USB_COM_RegisterRxCallback,
|
||||
};
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_COM_CDC)
|
||||
|
||||
static void PIOS_USB_COM_CDC_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail);
|
||||
static void PIOS_USB_COM_CDC_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail);
|
||||
|
||||
const struct pios_com_driver pios_usb_cdc_com_driver = {
|
||||
.tx_start = PIOS_USB_COM_CDC_TxStart,
|
||||
.rx_start = PIOS_USB_COM_CDC_RxStart,
|
||||
.bind_tx_cb = PIOS_USB_COM_RegisterTxCallback,
|
||||
.bind_rx_cb = PIOS_USB_COM_RegisterRxCallback,
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_USB_COM_CDC */
|
||||
|
||||
enum pios_usb_com_dev_magic {
|
||||
PIOS_USB_COM_DEV_MAGIC = 0xAABBCCDD,
|
||||
};
|
||||
|
||||
struct pios_usb_com_dev {
|
||||
enum pios_usb_com_dev_magic magic;
|
||||
const struct pios_usb_com_cfg * cfg;
|
||||
|
||||
uint32_t lower_id;
|
||||
|
||||
pios_com_callback rx_in_cb;
|
||||
uint32_t rx_in_context;
|
||||
pios_com_callback tx_out_cb;
|
||||
uint32_t tx_out_context;
|
||||
|
||||
uint8_t rx_packet_buffer[PIOS_USB_COM_DATA_LENGTH + 2];
|
||||
uint8_t tx_packet_buffer[PIOS_USB_COM_DATA_LENGTH + 2];
|
||||
};
|
||||
|
||||
static bool PIOS_USB_COM_validate(struct pios_usb_com_dev * usb_com_dev)
|
||||
{
|
||||
return (usb_com_dev->magic == PIOS_USB_COM_DEV_MAGIC);
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
static struct pios_usb_com_dev * PIOS_USB_COM_alloc(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev;
|
||||
|
||||
usb_com_dev = (struct pios_usb_com_dev *)pvPortMalloc(sizeof(*usb_com_dev));
|
||||
if (!usb_com_dev) return(NULL);
|
||||
|
||||
usb_com_dev->magic = PIOS_USB_COM_DEV_MAGIC;
|
||||
return(usb_com_dev);
|
||||
}
|
||||
#else
|
||||
static struct pios_usb_com_dev pios_usb_com_devs[PIOS_USB_COM_MAX_DEVS];
|
||||
static uint8_t pios_usb_com_num_devs;
|
||||
static struct pios_usb_com_dev * PIOS_USB_COM_alloc(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev;
|
||||
|
||||
if (pios_usb_com_num_devs >= PIOS_USB_COM_MAX_DEVS) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
usb_com_dev = &pios_usb_com_devs[pios_usb_com_num_devs++];
|
||||
usb_com_dev->magic = PIOS_USB_COM_DEV_MAGIC;
|
||||
|
||||
return (usb_com_dev);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void PIOS_USB_COM_HID_EP_IN_Callback(void);
|
||||
static void PIOS_USB_COM_HID_EP_OUT_Callback(void);
|
||||
|
||||
static uint32_t pios_usb_com_hid_id;
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_COM_CDC)
|
||||
|
||||
static void PIOS_USB_COM_CDC_DATA_EP_IN_Callback(void);
|
||||
static void PIOS_USB_COM_CDC_DATA_EP_OUT_Callback(void);
|
||||
static void PIOS_USB_COM_CDC_CTRL_EP_IN_Callback(void);
|
||||
|
||||
static uint32_t pios_usb_com_cdc_id;
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM_CDC */
|
||||
|
||||
int32_t PIOS_USB_COM_Init(uint32_t * usbcom_id, const struct pios_usb_com_cfg * cfg, uint32_t lower_id)
|
||||
{
|
||||
PIOS_Assert(usbcom_id);
|
||||
PIOS_Assert(cfg);
|
||||
|
||||
struct pios_usb_com_dev * usb_com_dev;
|
||||
|
||||
usb_com_dev = (struct pios_usb_com_dev *) PIOS_USB_COM_alloc();
|
||||
if (!usb_com_dev) goto out_fail;
|
||||
|
||||
/* Bind the configuration to the device instance */
|
||||
usb_com_dev->cfg = cfg;
|
||||
usb_com_dev->lower_id = lower_id;
|
||||
|
||||
switch (cfg->type) {
|
||||
#if defined(PIOS_INCLUDE_USB_COM_CDC)
|
||||
case PIOS_USB_COM_CDC:
|
||||
pios_usb_com_cdc_id = (uint32_t) usb_com_dev;
|
||||
pEpInt_OUT[cfg->ctrl_tx_ep - 1] = PIOS_USB_COM_CDC_CTRL_EP_IN_Callback;
|
||||
pEpInt_IN[cfg->data_tx_ep - 1] = PIOS_USB_COM_CDC_DATA_EP_IN_Callback;
|
||||
pEpInt_OUT[cfg->data_rx_ep - 1] = PIOS_USB_COM_CDC_DATA_EP_OUT_Callback;
|
||||
break;
|
||||
#endif /* PIOS_INCLUDE_USB_COM_CDC */
|
||||
case PIOS_USB_COM_HID:
|
||||
pios_usb_com_hid_id = (uint32_t) usb_com_dev;
|
||||
pEpInt_IN[cfg->data_tx_ep - 1] = PIOS_USB_COM_HID_EP_IN_Callback;
|
||||
pEpInt_OUT[cfg->data_rx_ep - 1] = PIOS_USB_COM_HID_EP_OUT_Callback;
|
||||
break;
|
||||
default:
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
|
||||
*usbcom_id = (uint32_t) usb_com_dev;
|
||||
|
||||
return 0;
|
||||
|
||||
out_fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static void PIOS_USB_COM_RegisterRxCallback(uint32_t usbcom_id, pios_com_callback rx_in_cb, uint32_t context)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
/*
|
||||
* Order is important in these assignments since ISR uses _cb
|
||||
* field to determine if it's ok to dereference _cb and _context
|
||||
*/
|
||||
usb_com_dev->rx_in_context = context;
|
||||
usb_com_dev->rx_in_cb = rx_in_cb;
|
||||
}
|
||||
|
||||
static void PIOS_USB_COM_RegisterTxCallback(uint32_t usbcom_id, pios_com_callback tx_out_cb, uint32_t context)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
/*
|
||||
* Order is important in these assignments since ISR uses _cb
|
||||
* field to determine if it's ok to dereference _cb and _context
|
||||
*/
|
||||
usb_com_dev->tx_out_context = context;
|
||||
usb_com_dev->tx_out_cb = tx_out_cb;
|
||||
}
|
||||
|
||||
static void PIOS_USB_COM_HID_SendReport(struct pios_usb_com_dev * usb_com_dev)
|
||||
{
|
||||
uint16_t bytes_to_tx;
|
||||
|
||||
if (!usb_com_dev->tx_out_cb) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool need_yield = false;
|
||||
#ifdef USB_HID
|
||||
bytes_to_tx = (usb_com_dev->tx_out_cb)(usb_com_dev->tx_out_context,
|
||||
&usb_com_dev->tx_packet_buffer[1],
|
||||
sizeof(usb_com_dev->tx_packet_buffer)-1,
|
||||
NULL,
|
||||
&need_yield);
|
||||
#else
|
||||
bytes_to_tx = (usb_com_dev->tx_out_cb)(usb_com_dev->tx_out_context,
|
||||
&usb_com_dev->tx_packet_buffer[2],
|
||||
sizeof(usb_com_dev->tx_packet_buffer)-2,
|
||||
NULL,
|
||||
&need_yield);
|
||||
#endif
|
||||
if (bytes_to_tx == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Always set type as report ID */
|
||||
usb_com_dev->tx_packet_buffer[0] = 1;
|
||||
|
||||
#ifdef USB_HID
|
||||
UserToPMABufferCopy(usb_com_dev->tx_packet_buffer,
|
||||
GetEPTxAddr(usb_com_dev->cfg->data_tx_ep),
|
||||
bytes_to_tx + 1);
|
||||
#else
|
||||
usb_com_dev->tx_packet_buffer[1] = bytes_to_tx;
|
||||
UserToPMABufferCopy(usb_com_dev->tx_packet_buffer,
|
||||
GetEPTxAddr(usb_com_dev->cfg->data_tx_ep),
|
||||
bytes_to_tx + 2);
|
||||
#endif
|
||||
/* Is this correct? Why do we always send the whole buffer? */
|
||||
SetEPTxCount(usb_com_dev->cfg->data_tx_ep, sizeof(usb_com_dev->tx_packet_buffer));
|
||||
SetEPTxValid(usb_com_dev->cfg->data_tx_ep);
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (need_yield) {
|
||||
vPortYieldFromISR();
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_FREERTOS */
|
||||
}
|
||||
|
||||
static void PIOS_USB_COM_HID_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail) {
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If endpoint was stalled and there is now space make it valid
|
||||
PIOS_IRQ_Disable();
|
||||
if ((GetEPRxStatus(usb_com_dev->cfg->data_rx_ep) != EP_RX_VALID) &&
|
||||
(rx_bytes_avail > PIOS_USB_COM_DATA_LENGTH)) {
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
|
||||
}
|
||||
PIOS_IRQ_Enable();
|
||||
}
|
||||
|
||||
static void PIOS_USB_COM_HID_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetEPTxStatus(usb_com_dev->cfg->data_tx_ep) == EP_TX_VALID) {
|
||||
/* Endpoint is already transmitting */
|
||||
return;
|
||||
}
|
||||
|
||||
PIOS_USB_COM_HID_SendReport(usb_com_dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback used to indicate a transmission from device INto host completed
|
||||
* Checks if any data remains, pads it into HID packet and sends.
|
||||
*/
|
||||
static void PIOS_USB_COM_HID_EP_IN_Callback(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_hid_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PIOS_USB_COM_HID_SendReport(usb_com_dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* EP1 OUT Callback Routine
|
||||
*/
|
||||
static void PIOS_USB_COM_HID_EP_OUT_Callback(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_hid_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
uint32_t DataLength = 0;
|
||||
|
||||
/* Read received data (63 bytes) */
|
||||
/* Get the number of received data on the selected Endpoint */
|
||||
DataLength = GetEPRxCount(usb_com_dev->cfg->data_rx_ep);
|
||||
if (DataLength > sizeof(usb_com_dev->rx_packet_buffer)) {
|
||||
DataLength = sizeof(usb_com_dev->rx_packet_buffer);
|
||||
}
|
||||
|
||||
/* Use the memory interface function to read from the selected endpoint */
|
||||
PMAToUserBufferCopy((uint8_t *) usb_com_dev->rx_packet_buffer,
|
||||
GetEPRxAddr(usb_com_dev->cfg->data_rx_ep),
|
||||
DataLength);
|
||||
|
||||
if (!usb_com_dev->rx_in_cb) {
|
||||
/* No Rx call back registered, disable the receiver */
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_NAK);
|
||||
return;
|
||||
}
|
||||
|
||||
/* The first byte is report ID (not checked), the second byte is the valid data length */
|
||||
uint16_t headroom;
|
||||
bool need_yield = false;
|
||||
#ifdef USB_HID
|
||||
(usb_com_dev->rx_in_cb)(usb_com_dev->rx_in_context,
|
||||
&usb_com_dev->rx_packet_buffer[1],
|
||||
sizeof(usb_com_dev->rx_packet_buffer)-1,
|
||||
&headroom,
|
||||
&need_yield);
|
||||
#else
|
||||
(usb_com_dev->rx_in_cb)(usb_com_dev->rx_in_context,
|
||||
&usb_com_dev->rx_packet_buffer[2],
|
||||
usb_com_dev->rx_packet_buffer[1],
|
||||
&headroom,
|
||||
&need_yield);
|
||||
#endif
|
||||
if (headroom > PIOS_USB_COM_DATA_LENGTH) {
|
||||
/* We have room for a maximum length message */
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
|
||||
} else {
|
||||
/* Not enough room left for a message, apply backpressure */
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_NAK);
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (need_yield) {
|
||||
vPortYieldFromISR();
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_FREERTOS */
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_COM_CDC)
|
||||
|
||||
static void PIOS_USB_COM_CDC_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail) {
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If endpoint was stalled and there is now space make it valid
|
||||
PIOS_IRQ_Disable();
|
||||
if ((GetEPRxStatus(usb_com_dev->cfg->data_rx_ep) != EP_RX_VALID) &&
|
||||
(rx_bytes_avail > sizeof(usb_com_dev->rx_packet_buffer))) {
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
|
||||
}
|
||||
PIOS_IRQ_Enable();
|
||||
}
|
||||
|
||||
static void PIOS_USB_COM_CDC_SendData(struct pios_usb_com_dev * usb_com_dev)
|
||||
{
|
||||
uint16_t bytes_to_tx;
|
||||
|
||||
if (!usb_com_dev->tx_out_cb) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool need_yield = false;
|
||||
bytes_to_tx = (usb_com_dev->tx_out_cb)(usb_com_dev->tx_out_context,
|
||||
usb_com_dev->tx_packet_buffer,
|
||||
sizeof(usb_com_dev->tx_packet_buffer),
|
||||
NULL,
|
||||
&need_yield);
|
||||
if (bytes_to_tx == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserToPMABufferCopy(usb_com_dev->tx_packet_buffer,
|
||||
GetEPTxAddr(usb_com_dev->cfg->data_tx_ep),
|
||||
bytes_to_tx);
|
||||
SetEPTxCount(usb_com_dev->cfg->data_tx_ep, bytes_to_tx);
|
||||
SetEPTxValid(usb_com_dev->cfg->data_tx_ep);
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (need_yield) {
|
||||
vPortYieldFromISR();
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_FREERTOS */
|
||||
}
|
||||
|
||||
static void PIOS_USB_COM_CDC_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetEPTxStatus(usb_com_dev->cfg->data_tx_ep) == EP_TX_VALID) {
|
||||
/* Endpoint is already transmitting */
|
||||
return;
|
||||
}
|
||||
|
||||
PIOS_USB_COM_CDC_SendData(usb_com_dev);
|
||||
}
|
||||
|
||||
static void PIOS_USB_COM_CDC_DATA_EP_IN_Callback(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
PIOS_USB_COM_CDC_SendData(usb_com_dev);
|
||||
}
|
||||
|
||||
static void PIOS_USB_COM_CDC_DATA_EP_OUT_Callback(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
uint32_t DataLength = 0;
|
||||
|
||||
/* Get the number of received data on the selected Endpoint */
|
||||
DataLength = GetEPRxCount(usb_com_dev->cfg->data_rx_ep);
|
||||
if (DataLength > sizeof(usb_com_dev->rx_packet_buffer)) {
|
||||
DataLength = sizeof(usb_com_dev->rx_packet_buffer);
|
||||
}
|
||||
|
||||
/* Use the memory interface function to read from the selected endpoint */
|
||||
PMAToUserBufferCopy((uint8_t *) usb_com_dev->rx_packet_buffer,
|
||||
GetEPRxAddr(usb_com_dev->cfg->data_rx_ep),
|
||||
DataLength);
|
||||
|
||||
if (!usb_com_dev->rx_in_cb) {
|
||||
/* No Rx call back registered, disable the receiver */
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_NAK);
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t headroom;
|
||||
bool need_yield = false;
|
||||
(usb_com_dev->rx_in_cb)(usb_com_dev->rx_in_context,
|
||||
usb_com_dev->rx_packet_buffer,
|
||||
sizeof(usb_com_dev->rx_packet_buffer),
|
||||
&headroom,
|
||||
&need_yield);
|
||||
|
||||
if (headroom > sizeof(usb_com_dev->rx_packet_buffer)) {
|
||||
/* We have room for a maximum length message */
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
|
||||
} else {
|
||||
/* Not enough room left for a message, apply backpressure */
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_STALL);
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (need_yield) {
|
||||
vPortYieldFromISR();
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_FREERTOS */
|
||||
}
|
||||
|
||||
RESULT PIOS_CDC_SetControlLineState(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
static uint16_t control_line_state;
|
||||
|
||||
uint8_t wValue0 = pInformation->USBwValue0;
|
||||
uint8_t wValue1 = pInformation->USBwValue1;
|
||||
|
||||
control_line_state = wValue1 << 8 | wValue0;
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
RESULT PIOS_CDC_SetLineCoding(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t *PIOS_CDC_GetLineCoding(uint16_t Length)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint8_t serial_state[] = {
|
||||
0xA1, /* bmRequestType */
|
||||
0x20, /* bNotification (Serial State) */
|
||||
0x00, /* wValue */
|
||||
0x00,
|
||||
0x01, /* wIndex (Interface #, LSB first) */
|
||||
0x00,
|
||||
0x02, /* wLength (Data length) */
|
||||
0x00,
|
||||
|
||||
0x00, /* USART State Bitmap (LSB first) */
|
||||
0x00,
|
||||
};
|
||||
|
||||
static void PIOS_USB_COM_CDC_CTRL_EP_IN_Callback(void)
|
||||
{
|
||||
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
|
||||
|
||||
bool valid = PIOS_USB_COM_validate(usb_com_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
/* Give back UART State Bitmap */
|
||||
/* UART State Bitmap
|
||||
* 15-7: reserved
|
||||
* 6: bOverRun overrun error
|
||||
* 5: bParity parity error
|
||||
* 4: bFraming framing error
|
||||
* 3: bRingSignal RI
|
||||
* 2: bBreak break reception
|
||||
* 1: bTxCarrier DSR
|
||||
* 0: bRxCarrier DCD
|
||||
*/
|
||||
serial_state[8] = 0x03;
|
||||
serial_state[9] = 0x00;
|
||||
|
||||
UserToPMABufferCopy(serial_state,
|
||||
GetEPTxAddr(usb_com_dev->cfg->data_tx_ep),
|
||||
sizeof(serial_state));
|
||||
SetEPTxCount(usb_com_dev->cfg->data_tx_ep, PIOS_USB_COM_DATA_LENGTH + 2);
|
||||
SetEPTxValid(usb_com_dev->cfg->data_tx_ep);
|
||||
}
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM_CDC */
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM */
|
@ -41,90 +41,73 @@
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
|
||||
static void PIOS_USB_HID_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail);
|
||||
static void PIOS_USB_HID_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail);
|
||||
static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbcom_id, pios_com_callback tx_out_cb, uint32_t context);
|
||||
static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbcom_id, pios_com_callback rx_in_cb, uint32_t context);
|
||||
/* Rx/Tx status */
|
||||
static uint8_t transfer_possible = 0;
|
||||
|
||||
const struct pios_com_driver pios_usb_com_driver = {
|
||||
.tx_start = PIOS_USB_HID_TxStart,
|
||||
.rx_start = PIOS_USB_HID_RxStart,
|
||||
.bind_tx_cb = PIOS_USB_HID_RegisterTxCallback,
|
||||
.bind_rx_cb = PIOS_USB_HID_RegisterRxCallback,
|
||||
enum pios_usb_dev_magic {
|
||||
PIOS_USB_DEV_MAGIC = 0x17365904,
|
||||
};
|
||||
|
||||
enum pios_usb_hid_dev_magic {
|
||||
PIOS_USB_HID_DEV_MAGIC = 0xAABBCCDD,
|
||||
struct pios_usb_dev {
|
||||
enum pios_usb_dev_magic magic;
|
||||
const struct pios_usb_cfg * cfg;
|
||||
};
|
||||
|
||||
struct pios_usb_hid_dev {
|
||||
enum pios_usb_hid_dev_magic magic;
|
||||
const struct pios_usb_hid_cfg * cfg;
|
||||
|
||||
pios_com_callback rx_in_cb;
|
||||
uint32_t rx_in_context;
|
||||
pios_com_callback tx_out_cb;
|
||||
uint32_t tx_out_context;
|
||||
|
||||
uint8_t rx_packet_buffer[PIOS_USB_HID_DATA_LENGTH + 2];
|
||||
uint8_t tx_packet_buffer[PIOS_USB_HID_DATA_LENGTH + 2];
|
||||
};
|
||||
|
||||
static bool PIOS_USB_HID_validate(struct pios_usb_hid_dev * usb_hid_dev)
|
||||
#if 0
|
||||
static bool PIOS_USB_validate(struct pios_usb_dev * usb_dev)
|
||||
{
|
||||
return (usb_hid_dev->magic == PIOS_USB_HID_DEV_MAGIC);
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
|
||||
{
|
||||
struct pios_usb_hid_dev * usb_hid_dev;
|
||||
|
||||
usb_hid_dev = (struct pios_usb_hid_dev *)pvPortMalloc(sizeof(*usb_hid_dev));
|
||||
if (!usb_hid_dev) return(NULL);
|
||||
|
||||
usb_hid_dev->magic = PIOS_USB_HID_DEV_MAGIC;
|
||||
return(usb_hid_dev);
|
||||
}
|
||||
#else
|
||||
static struct pios_usb_hid_dev pios_usb_hid_devs[PIOS_USB_HID_MAX_DEVS];
|
||||
static uint8_t pios_usb_hid_num_devs;
|
||||
static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
|
||||
{
|
||||
struct pios_usb_hid_dev * usb_hid_dev;
|
||||
|
||||
if (pios_usb_hid_num_devs >= PIOS_USB_HID_MAX_DEVS) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
usb_hid_dev = &pios_usb_hid_devs[pios_usb_hid_num_devs++];
|
||||
usb_hid_dev->magic = PIOS_USB_HID_DEV_MAGIC;
|
||||
|
||||
return (usb_hid_dev);
|
||||
return (usb_dev->magic == PIOS_USB_DEV_MAGIC);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
static struct pios_usb_dev * PIOS_USB_alloc(void)
|
||||
{
|
||||
struct pios_usb_dev * usb_dev;
|
||||
|
||||
usb_dev = (struct pios_usb_dev *)pvPortMalloc(sizeof(*usb_dev));
|
||||
if (!usb_dev) return(NULL);
|
||||
|
||||
usb_dev->magic = PIOS_USB_DEV_MAGIC;
|
||||
return(usb_dev);
|
||||
}
|
||||
#else
|
||||
static struct pios_usb_dev pios_usb_devs[PIOS_USB_MAX_DEVS];
|
||||
static uint8_t pios_usb_num_devs;
|
||||
static struct pios_usb_dev * PIOS_USB_alloc(void)
|
||||
{
|
||||
struct pios_usb_dev * usb_dev;
|
||||
|
||||
if (pios_usb_num_devs >= PIOS_USB_MAX_DEVS) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
usb_dev = &pios_usb_devs[pios_usb_num_devs++];
|
||||
usb_dev->magic = PIOS_USB_DEV_MAGIC;
|
||||
|
||||
return (usb_dev);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Rx/Tx status */
|
||||
static uint8_t transfer_possible = 0;
|
||||
|
||||
/**
|
||||
* Initialises USB COM layer
|
||||
* \return < 0 if initialisation failed
|
||||
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
||||
*/
|
||||
static uint32_t pios_usb_hid_id;
|
||||
int32_t PIOS_USB_HID_Init(uint32_t * usb_hid_id, const struct pios_usb_hid_cfg * cfg)
|
||||
static uint32_t pios_usb_com_id;
|
||||
int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg)
|
||||
{
|
||||
PIOS_Assert(usb_hid_id);
|
||||
PIOS_Assert(usb_id);
|
||||
PIOS_Assert(cfg);
|
||||
|
||||
struct pios_usb_hid_dev * usb_hid_dev;
|
||||
struct pios_usb_dev * usb_dev;
|
||||
|
||||
usb_hid_dev = (struct pios_usb_hid_dev *) PIOS_USB_HID_alloc();
|
||||
if (!usb_hid_dev) goto out_fail;
|
||||
usb_dev = (struct pios_usb_dev *) PIOS_USB_alloc();
|
||||
if (!usb_dev) goto out_fail;
|
||||
|
||||
/* Bind the configuration to the device instance */
|
||||
usb_hid_dev->cfg = cfg;
|
||||
usb_dev->cfg = cfg;
|
||||
|
||||
PIOS_USB_HID_Reenumerate();
|
||||
|
||||
@ -132,10 +115,10 @@ int32_t PIOS_USB_HID_Init(uint32_t * usb_hid_id, const struct pios_usb_hid_cfg *
|
||||
* This is a horrible hack to make this available to
|
||||
* the interrupt callbacks. This should go away ASAP.
|
||||
*/
|
||||
pios_usb_hid_id = (uint32_t) usb_hid_dev;
|
||||
pios_usb_com_id = (uint32_t) usb_dev;
|
||||
|
||||
/* Enable the USB Interrupts */
|
||||
NVIC_Init(&usb_hid_dev->cfg->irq.init);
|
||||
NVIC_Init(&usb_dev->cfg->irq.init);
|
||||
|
||||
/* Select USBCLK source */
|
||||
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
|
||||
@ -152,7 +135,7 @@ int32_t PIOS_USB_HID_Init(uint32_t * usb_hid_id, const struct pios_usb_hid_cfg *
|
||||
USB_Init();
|
||||
USB_SIL_Init();
|
||||
|
||||
*usb_hid_id = (uint32_t) usb_hid_dev;
|
||||
*usb_id = (uint32_t) usb_dev;
|
||||
|
||||
return 0; /* No error */
|
||||
|
||||
@ -231,202 +214,11 @@ int32_t PIOS_USB_HID_Reenumerate()
|
||||
* \return 0: interface not available
|
||||
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
||||
*/
|
||||
int32_t PIOS_USB_HID_CheckAvailable(uint8_t id)
|
||||
bool PIOS_USB_HID_CheckAvailable(uint8_t id)
|
||||
{
|
||||
return (PIOS_USB_DETECT_GPIO_PORT->IDR & PIOS_USB_DETECT_GPIO_PIN) != 0 && transfer_possible ? 1 : 0;
|
||||
}
|
||||
|
||||
static void PIOS_USB_HID_SendReport(struct pios_usb_hid_dev * usb_hid_dev)
|
||||
{
|
||||
uint16_t bytes_to_tx;
|
||||
|
||||
if (!usb_hid_dev->tx_out_cb) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool need_yield = false;
|
||||
#ifdef USB_HID
|
||||
bytes_to_tx = (usb_hid_dev->tx_out_cb)(usb_hid_dev->tx_out_context,
|
||||
&usb_hid_dev->tx_packet_buffer[1],
|
||||
sizeof(usb_hid_dev->tx_packet_buffer)-1,
|
||||
NULL,
|
||||
&need_yield);
|
||||
#else
|
||||
bytes_to_tx = (usb_hid_dev->tx_out_cb)(usb_hid_dev->tx_out_context,
|
||||
&usb_hid_dev->tx_packet_buffer[2],
|
||||
sizeof(usb_hid_dev->tx_packet_buffer)-2,
|
||||
NULL,
|
||||
&need_yield);
|
||||
#endif
|
||||
if (bytes_to_tx == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Always set type as report ID */
|
||||
usb_hid_dev->tx_packet_buffer[0] = 1;
|
||||
|
||||
#ifdef USB_HID
|
||||
UserToPMABufferCopy(usb_hid_dev->tx_packet_buffer, GetEPTxAddr(EP1_IN & 0x7F), bytes_to_tx + 1);
|
||||
#else
|
||||
usb_hid_dev->tx_packet_buffer[1] = bytes_to_tx;
|
||||
UserToPMABufferCopy(usb_hid_dev->tx_packet_buffer, GetEPTxAddr(EP1_IN & 0x7F), bytes_to_tx + 2);
|
||||
#endif
|
||||
/* Is this correct? Why do we always send the whole buffer? */
|
||||
SetEPTxCount((EP1_IN & 0x7F), sizeof(usb_hid_dev->tx_packet_buffer));
|
||||
SetEPTxValid(ENDP1);
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (need_yield) {
|
||||
vPortYieldFromISR();
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_FREERTOS */
|
||||
}
|
||||
|
||||
static void PIOS_USB_HID_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail) {
|
||||
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
if (!transfer_possible) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If endpoint was stalled and there is now space make it valid
|
||||
PIOS_IRQ_Disable();
|
||||
if ((GetEPRxStatus(ENDP1) != EP_RX_VALID) &&
|
||||
(rx_bytes_avail > PIOS_USB_HID_DATA_LENGTH)) {
|
||||
SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
}
|
||||
PIOS_IRQ_Enable();
|
||||
}
|
||||
|
||||
static void PIOS_USB_HID_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail)
|
||||
{
|
||||
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
if (!transfer_possible) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetEPTxStatus(ENDP1) == EP_TX_VALID) {
|
||||
/* Endpoint is already transmitting */
|
||||
return;
|
||||
}
|
||||
|
||||
PIOS_USB_HID_SendReport(usb_hid_dev);
|
||||
}
|
||||
|
||||
static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbcom_id, pios_com_callback rx_in_cb, uint32_t context)
|
||||
{
|
||||
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
/*
|
||||
* Order is important in these assignments since ISR uses _cb
|
||||
* field to determine if it's ok to dereference _cb and _context
|
||||
*/
|
||||
usb_hid_dev->rx_in_context = context;
|
||||
usb_hid_dev->rx_in_cb = rx_in_cb;
|
||||
}
|
||||
|
||||
static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbcom_id, pios_com_callback tx_out_cb, uint32_t context)
|
||||
{
|
||||
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbcom_id;
|
||||
|
||||
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
/*
|
||||
* Order is important in these assignments since ISR uses _cb
|
||||
* field to determine if it's ok to dereference _cb and _context
|
||||
*/
|
||||
usb_hid_dev->tx_out_context = context;
|
||||
usb_hid_dev->tx_out_cb = tx_out_cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback used to indicate a transmission from device INto host completed
|
||||
* Checks if any data remains, pads it into HID packet and sends.
|
||||
*/
|
||||
void PIOS_USB_HID_EP1_IN_Callback(void)
|
||||
{
|
||||
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)pios_usb_hid_id;
|
||||
|
||||
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
if (!transfer_possible) {
|
||||
return;
|
||||
}
|
||||
|
||||
PIOS_USB_HID_SendReport(usb_hid_dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* EP1 OUT Callback Routine
|
||||
*/
|
||||
void PIOS_USB_HID_EP1_OUT_Callback(void)
|
||||
{
|
||||
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)pios_usb_hid_id;
|
||||
|
||||
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
|
||||
PIOS_Assert(valid);
|
||||
|
||||
uint32_t DataLength = 0;
|
||||
|
||||
/* Read received data (63 bytes) */
|
||||
/* Get the number of received data on the selected Endpoint */
|
||||
DataLength = GetEPRxCount(ENDP1 & 0x7F);
|
||||
if (DataLength > sizeof(usb_hid_dev->rx_packet_buffer)) {
|
||||
DataLength = sizeof(usb_hid_dev->rx_packet_buffer);
|
||||
}
|
||||
|
||||
/* Use the memory interface function to write to the selected endpoint */
|
||||
PMAToUserBufferCopy((uint8_t *) usb_hid_dev->rx_packet_buffer, GetEPRxAddr(ENDP1 & 0x7F), DataLength);
|
||||
|
||||
if (!usb_hid_dev->rx_in_cb) {
|
||||
/* No Rx call back registered, disable the receiver */
|
||||
SetEPRxStatus(ENDP1, EP_RX_NAK);
|
||||
return;
|
||||
}
|
||||
|
||||
/* The first byte is report ID (not checked), the second byte is the valid data length */
|
||||
uint16_t headroom;
|
||||
bool need_yield = false;
|
||||
#ifdef USB_HID
|
||||
(usb_hid_dev->rx_in_cb)(usb_hid_dev->rx_in_context,
|
||||
&usb_hid_dev->rx_packet_buffer[1],
|
||||
sizeof(usb_hid_dev->rx_packet_buffer)-1,
|
||||
&headroom,
|
||||
&need_yield);
|
||||
#else
|
||||
(usb_hid_dev->rx_in_cb)(usb_hid_dev->rx_in_context,
|
||||
&usb_hid_dev->rx_packet_buffer[2],
|
||||
usb_hid_dev->rx_packet_buffer[1],
|
||||
&headroom,
|
||||
&need_yield);
|
||||
#endif
|
||||
if (headroom > PIOS_USB_HID_DATA_LENGTH) {
|
||||
/* We have room for a maximum length message */
|
||||
SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
} else {
|
||||
/* Not enough room left for a message, apply backpressure */
|
||||
SetEPRxStatus(ENDP1, EP_RX_NAK);
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (need_yield) {
|
||||
vPortYieldFromISR();
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_FREERTOS */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -128,7 +128,7 @@ const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC] = {
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, PIOS_USB_HID_DATA_LENGTH + 1, /* REPORT_COUNT (1) */
|
||||
0x95, PIOS_USB_COM_DATA_LENGTH + 1, /* REPORT_COUNT (1) */
|
||||
0x81, 0x83, /* INPUT (Const,Var,Array) */
|
||||
/* 20 */
|
||||
|
||||
@ -138,7 +138,7 @@ const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC] = {
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, PIOS_USB_HID_DATA_LENGTH + 1, /* REPORT_COUNT (1) */
|
||||
0x95, PIOS_USB_COM_DATA_LENGTH + 1, /* REPORT_COUNT (1) */
|
||||
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
|
||||
/* 34 */
|
||||
|
||||
|
@ -32,10 +32,10 @@ __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* function pointers to non-control endpoints service routines */
|
||||
void (*pEpInt_IN[7]) (void) = {
|
||||
PIOS_USB_HID_EP1_IN_Callback, EP2_IN_Callback, EP3_IN_Callback, EP4_IN_Callback, EP5_IN_Callback, EP6_IN_Callback, EP7_IN_Callback,};
|
||||
EP1_IN_Callback, EP2_IN_Callback, EP3_IN_Callback, EP4_IN_Callback, EP5_IN_Callback, EP6_IN_Callback, EP7_IN_Callback,};
|
||||
|
||||
void (*pEpInt_OUT[7]) (void) = {
|
||||
PIOS_USB_HID_EP1_OUT_Callback, EP2_OUT_Callback, EP3_OUT_Callback, EP4_OUT_Callback, EP5_OUT_Callback, EP6_OUT_Callback, EP7_OUT_Callback,};
|
||||
EP1_OUT_Callback, EP2_OUT_Callback, EP3_OUT_Callback, EP4_OUT_Callback, EP5_OUT_Callback, EP6_OUT_Callback, EP7_OUT_Callback,};
|
||||
|
||||
#ifndef STM32F10X_CL
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "pios_usb_hid_desc.h"
|
||||
#include "pios_usb_hid_pwr.h"
|
||||
#include "pios_usb_hid.h"
|
||||
#include "pios_usb_com_priv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
@ -151,24 +152,47 @@ void PIOS_HID_Reset(void)
|
||||
#else
|
||||
SetBTABLE(BTABLE_ADDRESS);
|
||||
|
||||
/* Initialize Endpoint 0 */
|
||||
/* Initialize Endpoint 0 (Control) */
|
||||
SetEPType(ENDP0, EP_CONTROL);
|
||||
SetEPTxStatus(ENDP0, EP_TX_STALL);
|
||||
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
|
||||
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
|
||||
SetEPTxStatus(ENDP0, EP_TX_STALL);
|
||||
Clear_Status_Out(ENDP0);
|
||||
|
||||
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
|
||||
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
|
||||
SetEPRxValid(ENDP0);
|
||||
|
||||
/* Initialize Endpoint 1 */
|
||||
/* Initialize Endpoint 1 (HID) */
|
||||
SetEPType(ENDP1, EP_INTERRUPT);
|
||||
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
|
||||
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
|
||||
SetEPTxCount(ENDP1, PIOS_USB_HID_DATA_LENGTH + 2); /* add two for indicating report id and valid data length */
|
||||
SetEPRxCount(ENDP1, PIOS_USB_HID_DATA_LENGTH + 2);
|
||||
SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
SetEPTxCount(ENDP1, PIOS_USB_COM_DATA_LENGTH + 2);
|
||||
SetEPTxStatus(ENDP1, EP_TX_NAK);
|
||||
|
||||
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
|
||||
SetEPRxCount(ENDP1, PIOS_USB_COM_DATA_LENGTH + 2);
|
||||
SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_COM_CDC)
|
||||
/* Initialize Endpoint 2 (CDC Call Control) */
|
||||
SetEPType(ENDP2, EP_INTERRUPT);
|
||||
SetEPTxAddr(ENDP2, ENDP2_TXADDR);
|
||||
SetEPTxStatus(ENDP2, EP_TX_NAK);
|
||||
|
||||
SetEPRxAddr(ENDP2, ENDP2_RXADDR);
|
||||
SetEPRxCount(ENDP2, PIOS_USB_COM_DATA_LENGTH + 2);
|
||||
SetEPRxStatus(ENDP2, EP_RX_DIS);
|
||||
|
||||
/* Initialize Endpoint 3 (CDC Data) */
|
||||
SetEPType(ENDP3, EP_BULK);
|
||||
SetEPTxAddr(ENDP3, ENDP3_TXADDR);
|
||||
SetEPTxStatus(ENDP3, EP_TX_NAK);
|
||||
|
||||
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
|
||||
SetEPRxCount(ENDP3, PIOS_USB_COM_DATA_LENGTH + 2);
|
||||
SetEPRxStatus(ENDP3, EP_RX_VALID);
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM_CDC */
|
||||
|
||||
/* Set this device to response on default address */
|
||||
SetDeviceAddress(0);
|
||||
#endif /* STM32F10X_CL */
|
||||
@ -178,8 +202,7 @@ void PIOS_HID_Reset(void)
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PIOS_HID_SetConfiguration.
|
||||
* Description : Udpade the device state to configured and command the ADC
|
||||
* conversion.
|
||||
* Description : Update the device state to configured
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
@ -197,7 +220,7 @@ void PIOS_HID_SetConfiguration(void)
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PIOS_HID_SetConfiguration.
|
||||
* Description : Udpade the device state to addressed.
|
||||
* Description : Update the device state to addressed.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
@ -242,23 +265,54 @@ RESULT PIOS_HID_Data_Setup(uint8_t RequestNo)
|
||||
|
||||
CopyRoutine = NULL;
|
||||
|
||||
if ((RequestNo == GET_DESCRIPTOR)
|
||||
&& (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
|
||||
&& (pInformation->USBwIndex0 == 0)) {
|
||||
|
||||
if (pInformation->USBwValue1 == REPORT_DESCRIPTOR) {
|
||||
CopyRoutine = PIOS_HID_GetReportDescriptor;
|
||||
} else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE) {
|
||||
CopyRoutine = PIOS_HID_GetHIDDescriptor;
|
||||
switch (Type_Recipient) {
|
||||
case (STANDARD_REQUEST | INTERFACE_RECIPIENT):
|
||||
switch (pInformation->USBwIndex0) {
|
||||
case 0: /* HID Interface */
|
||||
switch (RequestNo) {
|
||||
case GET_DESCRIPTOR:
|
||||
switch (pInformation->USBwValue1) {
|
||||
case REPORT_DESCRIPTOR:
|
||||
CopyRoutine = PIOS_HID_GetReportDescriptor;
|
||||
break;
|
||||
case HID_DESCRIPTOR_TYPE:
|
||||
CopyRoutine = PIOS_HID_GetHIDDescriptor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
case (CLASS_REQUEST | INTERFACE_RECIPIENT):
|
||||
switch (pInformation->USBwIndex0) {
|
||||
case 0: /* HID Interface */
|
||||
switch (RequestNo) {
|
||||
case GET_PROTOCOL:
|
||||
CopyRoutine = PIOS_HID_GetProtocolValue;
|
||||
break;
|
||||
}
|
||||
|
||||
/* End of GET_DESCRIPTOR */
|
||||
/*** GET_PROTOCOL ***/
|
||||
else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
&& RequestNo == GET_PROTOCOL) {
|
||||
CopyRoutine = PIOS_HID_GetProtocolValue;
|
||||
break;
|
||||
#if defined(PIOS_INCLUDE_USB_COM_CDC)
|
||||
case 1: /* CDC Call Control Interface */
|
||||
switch (RequestNo) {
|
||||
case GET_LINE_CODING:
|
||||
CopyRoutine = PIOS_CDC_GetLineCoding;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 2: /* CDC Data Interface */
|
||||
switch (RequestNo) {
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
#endif /* PIOS_INCLUDE_USB_COM_CDC */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (CopyRoutine == NULL) {
|
||||
@ -280,14 +334,37 @@ RESULT PIOS_HID_Data_Setup(uint8_t RequestNo)
|
||||
*******************************************************************************/
|
||||
RESULT PIOS_HID_NoData_Setup(uint8_t RequestNo)
|
||||
{
|
||||
if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
&& (RequestNo == SET_PROTOCOL)) {
|
||||
return PIOS_HID_SetProtocol();
|
||||
switch (Type_Recipient) {
|
||||
case (CLASS_REQUEST | INTERFACE_RECIPIENT):
|
||||
switch (pInformation->USBwIndex0) {
|
||||
case 0: /* HID */
|
||||
switch (RequestNo) {
|
||||
case SET_PROTOCOL:
|
||||
return PIOS_HID_SetProtocol();
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_COM_CDC)
|
||||
case 1: /* CDC Call Control Interface */
|
||||
switch (RequestNo) {
|
||||
case SET_LINE_CODING:
|
||||
return PIOS_CDC_SetLineCoding();
|
||||
break;
|
||||
case SET_CONTROL_LINE_STATE:
|
||||
return PIOS_CDC_SetControlLineState();
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
#endif /* PIOS_INCLUDE_USB_COM_CDC */
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
else {
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
@ -32,9 +32,7 @@
|
||||
#ifndef PIOS_COM_PRIV_H
|
||||
#define PIOS_COM_PRIV_H
|
||||
|
||||
#include <pios.h>
|
||||
|
||||
extern int32_t PIOS_COM_ReceiveHandler(uint32_t com_id);
|
||||
//#include <pios.h>
|
||||
|
||||
#endif /* PIOS_COM_PRIV_H */
|
||||
|
||||
|
66
flight/PiOS/inc/pios_usb_com_priv.h
Normal file
66
flight/PiOS/inc/pios_usb_com_priv.h
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_USB_COM USB COM layer functions
|
||||
* @brief Hardware communication layer
|
||||
* @{
|
||||
*
|
||||
* @file pios_usb_com_priv.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief USB COM private definitions.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef PIOS_USB_COM_PRIV_H
|
||||
#define PIOS_USB_COM_PRIV_H
|
||||
|
||||
#include "usb_core.h" /* RESULT */
|
||||
|
||||
enum pios_usb_com_type {
|
||||
PIOS_USB_COM_CDC,
|
||||
PIOS_USB_COM_HID,
|
||||
};
|
||||
|
||||
struct pios_usb_com_cfg {
|
||||
enum pios_usb_com_type type;
|
||||
|
||||
uint8_t ctrl_if;
|
||||
uint8_t ctrl_tx_ep;
|
||||
|
||||
uint8_t data_if;
|
||||
uint8_t data_rx_ep;
|
||||
uint8_t data_tx_ep;
|
||||
};
|
||||
|
||||
extern const struct pios_com_driver pios_usb_hid_com_driver;
|
||||
extern const struct pios_com_driver pios_usb_cdc_com_driver;
|
||||
|
||||
extern int32_t PIOS_USB_COM_Init(uint32_t * usbcom_id, const struct pios_usb_com_cfg * cfg, uint32_t lower_id);
|
||||
|
||||
extern uint8_t *PIOS_CDC_GetLineCoding(uint16_t Length);
|
||||
extern RESULT PIOS_CDC_SetControlLineState(void);
|
||||
extern RESULT PIOS_CDC_SetLineCoding(void);
|
||||
|
||||
#endif /* PIOS_USB_COM_PRIV_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -32,23 +32,21 @@
|
||||
#define PIOS_USB_HID_H
|
||||
|
||||
/* Global Definitions */
|
||||
#define PIOS_USB_HID_SIZ_REPORT_DESC 32
|
||||
#define PIOS_USB_HID_SIZ_REPORT_DESC 36
|
||||
#define PIOS_USB_HID_REPORT_DESCRIPTOR 0x22
|
||||
#define PIOS_USB_HID_HID_DESCRIPTOR_TYPE 0x21
|
||||
#define PIOS_USB_HID_OFF_HID_DESC 0x12
|
||||
#define PIOS_USB_HID_SIZ_HID_DESC 0x09
|
||||
|
||||
#define PIOS_USB_HID_DATA_LENGTH 62
|
||||
#define PIOS_USB_COM_DATA_LENGTH 62
|
||||
|
||||
/* Global functions */
|
||||
extern int32_t PIOS_USB_HID_Reenumerate();
|
||||
extern int32_t PIOS_USB_HID_ChangeConnectionState(uint32_t Connected);
|
||||
extern int32_t PIOS_USB_HID_CheckAvailable(uint8_t id);
|
||||
extern bool PIOS_USB_HID_CheckAvailable(uint8_t id);
|
||||
|
||||
extern int32_t PIOS_USB_HID_CB_Data_Setup(uint8_t RequestNo);
|
||||
extern int32_t PIOS_USB_HID_CB_NoData_Setup(uint8_t RequestNo);
|
||||
extern void PIOS_USB_HID_EP1_IN_Callback(void);
|
||||
extern void PIOS_USB_HID_EP1_OUT_Callback(void);
|
||||
|
||||
#endif /* PIOS_USB_HID_H */
|
||||
|
||||
|
@ -34,11 +34,11 @@
|
||||
#include <pios.h>
|
||||
#include <pios_stm32.h>
|
||||
|
||||
struct pios_usb_hid_cfg {
|
||||
struct pios_usb_cfg {
|
||||
struct stm32_irq irq;
|
||||
};
|
||||
|
||||
extern int32_t PIOS_USB_HID_Init(uint32_t * usb_hid_id, const struct pios_usb_hid_cfg * cfg);
|
||||
extern int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg);
|
||||
|
||||
#endif /* PIOS_USB_HID_PRIV_H */
|
||||
|
||||
|
@ -29,6 +29,12 @@ typedef enum _HID_REQUESTS {
|
||||
SET_PROTOCOL
|
||||
} HID_REQUESTS;
|
||||
|
||||
typedef enum CDC_REQUESTS {
|
||||
SET_LINE_CODING = 0x20,
|
||||
GET_LINE_CODING = 0x21,
|
||||
SET_CONTROL_LINE_STATE = 0x23,
|
||||
} CDC_REQUESTS;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
@ -27,7 +27,7 @@
|
||||
/* EP_NUM */
|
||||
/* defines how many endpoints are used by the device */
|
||||
/*-------------------------------------------------------------*/
|
||||
#define EP_NUM (2)
|
||||
#define EP_NUM (4)
|
||||
|
||||
#ifndef STM32F10X_CL
|
||||
/*-------------------------------------------------------------*/
|
||||
@ -39,13 +39,23 @@
|
||||
|
||||
/* EP0 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP0_RXADDR (0x18)
|
||||
#define ENDP0_TXADDR (0x58)
|
||||
#define ENDP0_RXADDR (0x20)
|
||||
#define ENDP0_TXADDR (0x40)
|
||||
|
||||
/* EP1 */
|
||||
/* tx buffer base address */
|
||||
#define ENDP1_TXADDR (0x100)
|
||||
#define ENDP1_RXADDR (0x124)
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP1_TXADDR (0x60)
|
||||
#define ENDP1_RXADDR (0x80)
|
||||
|
||||
/* EP2 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP2_TXADDR (0x100)
|
||||
#define ENDP2_RXADDR (0x140)
|
||||
|
||||
/* EP3 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP3_TXADDR (0x180)
|
||||
#define ENDP3_RXADDR (0x1C0)
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* ------------------- ISTR events -------------------------*/
|
||||
@ -171,7 +181,7 @@
|
||||
#define EP6_IN_Callback NOP_Process
|
||||
#define EP7_IN_Callback NOP_Process
|
||||
|
||||
//#define EP1_OUT_Callback NOP_Process
|
||||
#define EP1_OUT_Callback NOP_Process
|
||||
#define EP2_OUT_Callback NOP_Process
|
||||
#define EP3_OUT_Callback NOP_Process
|
||||
#define EP4_OUT_Callback NOP_Process
|
||||
|
@ -121,6 +121,7 @@ ifeq ($(USE_USB), YES)
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
|
||||
endif
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
|
@ -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;
|
||||
apiconfig_comm_port = PIOS_COM_TELEM_USB_HID;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -40,5 +40,6 @@
|
||||
#define PIOS_INCLUDE_GPIO
|
||||
#define PIOS_INCLUDE_EXTI
|
||||
#define PIOS_INCLUDE_USB_HID
|
||||
#define PIOS_INCLUDE_USB_COM
|
||||
|
||||
#endif /* PIOS_CONFIG_H */
|
||||
|
@ -39,13 +39,23 @@
|
||||
|
||||
/* EP0 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP0_RXADDR (0x18)
|
||||
#define ENDP0_TXADDR (0x58)
|
||||
#define ENDP0_RXADDR (0x20)
|
||||
#define ENDP0_TXADDR (0x40)
|
||||
|
||||
/* EP1 */
|
||||
/* tx buffer base address */
|
||||
#define ENDP1_TXADDR (0x100)
|
||||
#define ENDP1_RXADDR (0x124)
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP1_TXADDR (0x60)
|
||||
#define ENDP1_RXADDR (0x80)
|
||||
|
||||
/* EP2 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP2_TXADDR (0x100)
|
||||
#define ENDP2_RXADDR (0x140)
|
||||
|
||||
/* EP3 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP3_TXADDR (0x180)
|
||||
#define ENDP3_RXADDR (0x1C0)
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* ------------------- ISTR events -------------------------*/
|
||||
@ -172,7 +182,7 @@
|
||||
#define EP6_IN_Callback NOP_Process
|
||||
#define EP7_IN_Callback NOP_Process
|
||||
|
||||
//#define EP1_OUT_Callback NOP_Process
|
||||
#define EP1_OUT_Callback NOP_Process
|
||||
#define EP2_OUT_Callback NOP_Process
|
||||
#define EP3_OUT_Callback NOP_Process
|
||||
#define EP4_OUT_Callback NOP_Process
|
||||
|
@ -314,7 +314,7 @@ static uint8_t pios_com_serial_tx_buffer[PIOS_COM_SERIAL_TX_BUF_LEN];
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
#include "pios_usb_hid_priv.h"
|
||||
|
||||
static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
static const struct pios_usb_cfg pios_usb_main_cfg = {
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
|
||||
@ -326,10 +326,21 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
||||
extern const struct pios_com_driver pios_usb_com_driver;
|
||||
#if defined(PIOS_INCLUDE_USB_COM)
|
||||
#include <pios_usb_com_priv.h>
|
||||
|
||||
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
|
||||
.type = PIOS_USB_COM_HID,
|
||||
.data_if = 0,
|
||||
.data_rx_ep = 1,
|
||||
.data_tx_ep = 1,
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_COM */
|
||||
|
||||
uint32_t pios_com_serial_id;
|
||||
uint32_t pios_com_telem_usb_id;
|
||||
uint32_t pios_com_telem_usb_hid_id;
|
||||
uint32_t pios_com_telem_usb_cdc_id;
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
@ -360,10 +371,14 @@ void PIOS_Board_Init(void) {
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
uint32_t pios_usb_hid_id;
|
||||
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
|
||||
uint32_t pios_usb_id;
|
||||
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
|
||||
#if defined(PIOS_INCLUDE_COM)
|
||||
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_com_driver, pios_usb_hid_id,
|
||||
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);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_telem_usb_hid_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);
|
||||
|
@ -123,7 +123,7 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0xff, // LOGICAL_MAXIMUM (255)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, PIOS_USB_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
|
||||
0x95, PIOS_USB_COM_DATA_LENGTH+1, // REPORT_COUNT (1)
|
||||
0x81, 0x83, // INPUT (Const,Var,Array)
|
||||
// 20
|
||||
|
||||
@ -133,7 +133,7 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0xff, // LOGICAL_MAXIMUM (255)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, PIOS_USB_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
|
||||
0x95, PIOS_USB_COM_DATA_LENGTH+1, // REPORT_COUNT (1)
|
||||
0x91, 0x82, // OUTPUT (Data,Var,Abs,Vol)
|
||||
// 34
|
||||
|
||||
|
@ -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;
|
||||
comm_port = PIOS_COM_TELEM_USB_HID;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user