From 929d5fe51b7297542477013abe3fb885f834883f Mon Sep 17 00:00:00 2001 From: gussy Date: Fri, 5 Feb 2010 10:33:56 +0000 Subject: [PATCH] Added custom HID report descriptors. Updated packet length to 64 bytes for now. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@175 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/PiOS/STM32F10x/pios_usb.c | 6 +- flight/PiOS/STM32F10x/pios_usb_hid.c | 115 +++++++++++++-------------- flight/PiOS/inc/pios_usb_hid.h | 2 +- flight/PiOS/pios.c | 25 +++--- 4 files changed, 71 insertions(+), 77 deletions(-) diff --git a/flight/PiOS/STM32F10x/pios_usb.c b/flight/PiOS/STM32F10x/pios_usb.c index bc83e9446..dcd0f5897 100644 --- a/flight/PiOS/STM32F10x/pios_usb.c +++ b/flight/PiOS/STM32F10x/pios_usb.c @@ -160,7 +160,7 @@ static const uint8_t PIOS_USB_ConfigDescriptor[PIOS_USB_SIZ_CONFIG_DESC] = { 0x81, /* bEndpointAddress: Endpoint Address (IN) */ 0x03, /* bmAttributes: Interrupt endpoint */ - 0x02, /* wMaxPacketSize: 2 Bytes max */ + 64,//0x02, /* wMaxPacketSize: 2 Bytes max */ 0x00, 0x20, /* bInterval: Polling Interval (32 ms) */ /* 34 */ @@ -170,7 +170,7 @@ static const uint8_t PIOS_USB_ConfigDescriptor[PIOS_USB_SIZ_CONFIG_DESC] = { 0x01, /* bEndpointAddress: */ /* Endpoint Address (OUT) */ 0x03, /* bmAttributes: Interrupt endpoint */ - 0x02, /* wMaxPacketSize: 2 Bytes max */ + 64,//0x02, /* wMaxPacketSize: 2 Bytes max */ 0x00, 0x20, /* bInterval: Polling Interval (20 ms) */ /* 41 */ }; @@ -348,6 +348,8 @@ int32_t PIOS_USB_Init(uint32_t mode) NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); + pInformation->Ctrl_Info.Usb_wLength = 64; + /* No error */ return 0; } diff --git a/flight/PiOS/STM32F10x/pios_usb_hid.c b/flight/PiOS/STM32F10x/pios_usb_hid.c index ab982b576..df8a73585 100644 --- a/flight/PiOS/STM32F10x/pios_usb_hid.c +++ b/flight/PiOS/STM32F10x/pios_usb_hid.c @@ -52,7 +52,7 @@ const uint8_t PIOS_USB_HID_ReportDescriptor[PIOS_USB_HID_SIZ_REPORT_DESC] = { 0x09, 0x01, /* USAGE (Demo Kit) */ 0xa1, 0x01, /* COLLECTION (Application) */ /* 6 */ - +#if 0 /* Led 1 */ 0x85, 0x01, /* REPORT_ID (1) */ 0x09, 0x01, /* USAGE (LED 1) */ @@ -81,34 +81,6 @@ const uint8_t PIOS_USB_HID_ReportDescriptor[PIOS_USB_HID_SIZ_REPORT_DESC] = { 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ /* 46 */ - /* Led 3 */ - 0x85, 0x03, /* REPORT_ID (3) */ - 0x09, 0x03, /* USAGE (LED 3) */ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ - 0x75, 0x08, /* REPORT_SIZE (8) */ - 0x95, 0x01, /* REPORT_COUNT (1) */ - 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ - - 0x85, 0x03, /* REPORT_ID (3) */ - 0x09, 0x03, /* USAGE (LED 3) */ - 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ - /* 66 */ - - /* Led 4 */ - 0x85, 0x04, /* REPORT_ID 4) */ - 0x09, 0x04, /* USAGE (LED 4) */ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ - 0x75, 0x08, /* REPORT_SIZE (8) */ - 0x95, 0x01, /* REPORT_COUNT (1) */ - 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ - - 0x85, 0x04, /* REPORT_ID (4) */ - 0x09, 0x04, /* USAGE (LED 4) */ - 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ - /* 86 */ - /* key Push Button */ 0x85, 0x05, /* REPORT_ID (5) */ 0x09, 0x05, /* USAGE (Push Button) */ @@ -127,7 +99,7 @@ const uint8_t PIOS_USB_HID_ReportDescriptor[PIOS_USB_HID_SIZ_REPORT_DESC] = { 0x75, 0x07, /* REPORT_SIZE (7) */ 0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */ - /* 114 */ + /* 74 */ /* Tamper Push Button */ 0x85, 0x06, /* REPORT_ID (6) */ @@ -147,7 +119,7 @@ const uint8_t PIOS_USB_HID_ReportDescriptor[PIOS_USB_HID_SIZ_REPORT_DESC] = { 0x75, 0x07, /* REPORT_SIZE (7) */ 0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */ - /* 142 */ + /* 102 */ /* ADC IN */ 0x85, 0x07, /* REPORT_ID (7) */ @@ -156,12 +128,55 @@ const uint8_t PIOS_USB_HID_ReportDescriptor[PIOS_USB_HID_SIZ_REPORT_DESC] = { 0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */ 0x75, 0x08, /* REPORT_SIZE (8) */ 0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */ + 0x85, 0x07, /* REPORT_ID (7) */ 0x09, 0x07, /* USAGE (ADC in) */ 0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ - /* 161 */ + /* 121 */ +#endif - 0xc0 /* END_COLLECTION */ + /* In Control */ + 0x85, 0x06, // Report ID (6) + 0x95, 0x02, // REPORT_COUNT (2) + 0x75, 0x08, // REPORT_SIZE (8) + 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x09, 0x01, // USAGE (Vendor Usage 1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + /*21*/ + + /* Out Control */ + 0x85, 0x07, // Report ID (7) + 0x95, 0x02, // REPORT_COUNT (2) + 0x75, 0x08, // REPORT_SIZE (8) + 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x09, 0x01, // USAGE (Vendor Usage 1) + 0x91, 0x02, // OUTPUT (Data,Var,Abs) + /*36*/ + + /* In Data */ + 0x85, 0x01, // Report ID (1) + 0x95, 0x40, // REPORT_COUNT (64) + 0x75, 0x08, // REPORT_SIZE (8) + 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x09, 0x01, // USAGE (Vendor Usage 1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + /*51*/ + + /* Out Data */ + 0x85, 0x02, // Report ID (2) + 0x95, 0x40, // REPORT_COUNT (64) + 0x75, 0x08, // REPORT_SIZE (8) + 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x09, 0x01, // USAGE (Vendor Usage 1) + 0x91, 0x02, // OUTPUT (Data,Var,Abs) + /*66*/ + + 0xc0 /* END_COLLECTION */ + /*67*/ }; ONE_DESCRIPTOR PIOS_USB_HID_Report_Descriptor = {(uint8_t *) PIOS_USB_HID_ReportDescriptor, PIOS_USB_HID_SIZ_REPORT_DESC}; ONE_DESCRIPTOR PIOS_USB_HID_Hid_Descriptor = {(uint8_t*) PIOS_USB_HID_ReportDescriptor + PIOS_USB_HID_OFF_HID_DESC, PIOS_USB_HID_SIZ_HID_DESC}; @@ -267,38 +282,18 @@ static uint8_t *PIOS_USB_HID_GetProtocolValue(uint16_t Length) void PIOS_USB_HID_EP1_OUT_Callback(void) { uint8_t Receive_Buffer[2]; - BitAction Led_State; + uint32_t DataLength = 0; /* Read received data (2 bytes) */ - USB_SIL_Read(0x01, Receive_Buffer); + //USB_SIL_Read(ENDP1, Receive_Buffer); - if(Receive_Buffer[1] == 0) { - Led_State = Bit_RESET; - } else { - Led_State = Bit_SET; - } + /* Get the number of received data on the selected Endpoint */ + DataLength = GetEPRxCount(ENDP1 & 0x7F); - switch(Receive_Buffer[0]) { - case 1: /* Led 1 */ - if(Led_State != Bit_RESET) { - PIOS_LED_On(LED1); - } else { - PIOS_LED_Off(LED1); - } - break; - case 2: /* Led 2 */ - if(Led_State != Bit_RESET) { - PIOS_LED_On(LED2); - } else { - PIOS_LED_Off(LED2); - } - break; - default: + /* Use the memory interface function to write to the selected endpoint */ + PMAToUserBufferCopy((uint8_t *) Receive_Buffer, GetEPRxAddr(ENDP1 & 0x7F), DataLength); - PIOS_LED_Off(LED1); - PIOS_LED_Off(LED2); - break; - } + /* Do stuff here */ SetEPRxStatus(ENDP1, EP_RX_VALID); } diff --git a/flight/PiOS/inc/pios_usb_hid.h b/flight/PiOS/inc/pios_usb_hid.h index 55d33058f..75034bc41 100644 --- a/flight/PiOS/inc/pios_usb_hid.h +++ b/flight/PiOS/inc/pios_usb_hid.h @@ -28,7 +28,7 @@ #define PIOS_USB_HID_H /* Global Definitions */ -#define PIOS_USB_HID_SIZ_REPORT_DESC 162 +#define PIOS_USB_HID_SIZ_REPORT_DESC 67 #define PIOS_USB_HID_REPORT_DESCRIPTOR 0x22 #define PIOS_USB_HID_HID_DESCRIPTOR_TYPE 0x21 #define PIOS_USB_HID_OFF_HID_DESC 0x12 diff --git a/flight/PiOS/pios.c b/flight/PiOS/pios.c index e40676e97..0cca53d75 100644 --- a/flight/PiOS/pios.c +++ b/flight/PiOS/pios.c @@ -174,26 +174,23 @@ static void TaskHIDTest(void *pvParameters) { portTickType xDelay = 250 / portTICK_RATE_MS;; - __IO uint8_t Send_Buffer[2]; - uint8_t count = 0; + __IO uint8_t Send_Buffer[64]; for(;;) { - /* Report ID */ - Send_Buffer[0] = 0x07; - - /* Report Data */ - Send_Buffer[1] = count; + Send_Buffer[0] = 0x01; + Send_Buffer[1] = 't'; + Send_Buffer[2] = 'e'; + Send_Buffer[3] = 's'; + Send_Buffer[4] = 't'; + Send_Buffer[5] = '!'; + Send_Buffer[6] = '!'; /* Write the data to the pipe */ - USB_SIL_Write(EP1_IN, (uint8_t*) Send_Buffer, 2); - SetEPTxValid(ENDP1); + UserToPMABufferCopy((uint8_t*) Send_Buffer, GetEPTxAddr(EP1_IN & 0x7F), 64); + SetEPTxCount(ENDP1, 64); - if(count >= 255) { - count = 0; - } else { - count++; - } + SetEPTxValid(ENDP1); vTaskDelay(xDelay); }