diff --git a/flight/PiOS/STM32F10x/pios_usb_hid.c b/flight/PiOS/STM32F10x/pios_usb_hid.c index 750350457..5d76159f8 100644 --- a/flight/PiOS/STM32F10x/pios_usb_hid.c +++ b/flight/PiOS/STM32F10x/pios_usb_hid.c @@ -53,7 +53,7 @@ static uint8_t rx_buffer[PIOS_USB_HID_DATA_LENGTH] = {0}; static uint8_t transmit_remaining; static uint8_t *p_tx_buffer; -static uint8_t tx_buffer[PIOS_USB_HID_DATA_LENGTH] = {0}; +static uint8_t tx_buffer[PIOS_USB_HID_DATA_LENGTH+2] = {0}; /** * Initialises USB COM layer @@ -86,6 +86,7 @@ int32_t PIOS_USB_HID_Init(uint32_t mode) RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE); USB_Init(); + USB_SIL_Init(); PIOS_LED_On(LED2); return 0; /* No error */ @@ -126,15 +127,16 @@ int32_t PIOS_USB_HID_CheckAvailable(uint8_t id) */ void PIOS_USB_HID_TxNextByte() { - uint8_t buf[2]; + uint8_t buf[3]; if( transmit_remaining > 0 ) { transmit_remaining--; buf[0] = 1; // report ID 1 - buf[1] = *p_tx_buffer; + buf[1] = 1; // *p_tx_buffer; + buf[2] = 1; p_tx_buffer++; - UserToPMABufferCopy((uint8_t*) buf, GetEPTxAddr(EP1_IN & 0x7F), 2); - SetEPTxCount((EP1_IN & 0x7F), 2); + UserToPMABufferCopy((uint8_t*) buf, GetEPTxAddr(EP1_IN & 0x7F), 3); + SetEPTxCount((EP1_IN & 0x7F), 3); /* Send Buffer */ SetEPTxValid(ENDP1); @@ -158,11 +160,14 @@ int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t id, const uint8_t *buffe return -1; } - memcpy(&tx_buffer[0], buffer, len); - transmit_remaining = len; - p_tx_buffer = tx_buffer; + memcpy(&tx_buffer[2], buffer, len); + tx_buffer[0] = 1; /* report ID */ + tx_buffer[1] = len; /* valid data length */ + UserToPMABufferCopy((uint8_t*) tx_buffer, GetEPTxAddr(EP1_IN & 0x7F), len+2); +// SetEPTxCount((EP1_IN & 0x7F), 10); - PIOS_USB_HID_TxNextByte(); + /* Send Buffer */ + SetEPTxValid(ENDP1); return 0; } diff --git a/flight/PiOS/STM32F10x/pios_usb_hid_desc.c b/flight/PiOS/STM32F10x/pios_usb_hid_desc.c index 564bc9c52..12f212c69 100644 --- a/flight/PiOS/STM32F10x/pios_usb_hid_desc.c +++ b/flight/PiOS/STM32F10x/pios_usb_hid_desc.c @@ -16,6 +16,7 @@ /* Includes ------------------------------------------------------------------*/ #include "usb_lib.h" #include "pios_usb.h" +#include "pios_usb_hid.h" #include "pios_usb_hid_desc.h" /* Private typedef -----------------------------------------------------------*/ @@ -129,11 +130,20 @@ 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, 0x01, /* REPORT_COUNT (1) */ - 0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */ - 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ - /* 22 */ - + 0x95, PIOS_USB_HID_DATA_LENGTH+1, /* REPORT_COUNT (1) */ + 0x81, 0x83, /* INPUT (Const,Var,Array) */ + /* 20 */ + + /* Data 1 */ + 0x85, 0x02, /* REPORT_ID (2) */ + 0x09, 0x01, /* USAGE (LED 1) */ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ + 0x25, 0xff, /* LOGICAL_MAXIMUM (255) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x95, 0x01, /* REPORT_COUNT (1) */ + 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ + /* 34 */ + 0xc0 /* END_COLLECTION */ }; /* CustomHID_ReportDescriptor */ diff --git a/flight/PiOS/STM32F10x/pios_usb_hid_istr.c b/flight/PiOS/STM32F10x/pios_usb_hid_istr.c index 1b0aded03..ac8a540bc 100644 --- a/flight/PiOS/STM32F10x/pios_usb_hid_istr.c +++ b/flight/PiOS/STM32F10x/pios_usb_hid_istr.c @@ -32,7 +32,7 @@ __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */ /* function pointers to non-control endpoints service routines */ void (*pEpInt_IN[7])(void) = { - PIOS_USB_HID_TxNextByte, + EP1_IN_Callback, //PIOS_USB_HID_TxNextByte, EP2_IN_Callback, EP3_IN_Callback, EP4_IN_Callback, diff --git a/flight/PiOS/STM32F10x/pios_usb_hid_prop.c b/flight/PiOS/STM32F10x/pios_usb_hid_prop.c index ff67b65cc..29f7be266 100644 --- a/flight/PiOS/STM32F10x/pios_usb_hid_prop.c +++ b/flight/PiOS/STM32F10x/pios_usb_hid_prop.c @@ -17,9 +17,11 @@ #include "stm32f10x.h" #include "usb_lib.h" #include "usb_conf.h" +#include "pios.h" #include "pios_usb_hid_prop.h" #include "pios_usb_hid_desc.h" #include "pios_usb_hid_pwr.h" +#include "pios_usb_hid.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ @@ -166,8 +168,8 @@ void CustomHID_Reset(void) SetEPType(ENDP1, EP_INTERRUPT); SetEPTxAddr(ENDP1, ENDP1_TXADDR); SetEPRxAddr(ENDP1, ENDP1_RXADDR); - SetEPTxCount(ENDP1, 2); - SetEPRxCount(ENDP1, 2); + 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); SetEPTxStatus(ENDP1, EP_TX_NAK); @@ -335,6 +337,23 @@ uint8_t *CustomHID_GetStringDescriptor(uint16_t Length) { return NULL; } + else if (wValue0 == 3){ /* Need to get this string from hardware on the fly */ + uint8_t serial_number_str[40]; + uint8_t buffer[200]; + uint8_t len = 0;; + if(PIOS_SYS_SerialNumberGet((char *) serial_number_str) >= 0) { + for(uint8_t i = 0, len = 2; serial_number_str[i] != '\0' && len < 200; ++i) { + buffer[len++] = serial_number_str[i]; + buffer[len++] = 0; + } + } + else + return NULL; + buffer[0] = len; /* Descriptor Length */ + buffer[1] = USB_STRING_DESCRIPTOR_TYPE; /* Descriptor Type */ + ONE_DESCRIPTOR desc = {(uint8_t *) buffer, len}; + return Standard_GetDescriptorData(Length, &desc); + } else { return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]); diff --git a/flight/PiOS/inc/pios_usb_hid.h b/flight/PiOS/inc/pios_usb_hid.h index adaf7c00e..6f453f4c8 100644 --- a/flight/PiOS/inc/pios_usb_hid.h +++ b/flight/PiOS/inc/pios_usb_hid.h @@ -38,8 +38,7 @@ #define PIOS_USB_HID_OFF_HID_DESC 0x12 #define PIOS_USB_HID_SIZ_HID_DESC 0x09 -#define PIOS_USB_HID_DATA_LENGTH 63 -//63 +#define PIOS_USB_HID_DATA_LENGTH 62 /* Global functions */ extern int32_t PIOS_USB_HID_Init(uint32_t mode); diff --git a/flight/PiOS/inc/pios_usb_hid_desc.h b/flight/PiOS/inc/pios_usb_hid_desc.h index f47291b0d..a40c214a6 100644 --- a/flight/PiOS/inc/pios_usb_hid_desc.h +++ b/flight/PiOS/inc/pios_usb_hid_desc.h @@ -34,7 +34,7 @@ #define PIOS_HID_SIZ_DEVICE_DESC 18 #define PIOS_HID_SIZ_CONFIG_DESC 41 -#define PIOS_HID_SIZ_REPORT_DESC 24 +#define PIOS_HID_SIZ_REPORT_DESC 36 #define PIOS_HID_SIZ_STRING_LANGID 4 #define PIOS_HID_SIZ_STRING_VENDOR 28 #define PIOS_HID_SIZ_STRING_PRODUCT 20 diff --git a/flight/PiOS/inc/usb_conf.h b/flight/PiOS/inc/usb_conf.h index 5275fefa6..913060c7f 100644 --- a/flight/PiOS/inc/usb_conf.h +++ b/flight/PiOS/inc/usb_conf.h @@ -45,7 +45,7 @@ /* EP1 */ /* tx buffer base address */ #define ENDP1_TXADDR (0x100) -#define ENDP1_RXADDR (0x104) +#define ENDP1_RXADDR (0x124) /*-------------------------------------------------------------*/ /* ------------------- ISTR events -------------------------*/