1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Got better HID report design with valid data length embedded in report

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1164 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
peabody124 2010-07-27 17:41:56 +00:00 committed by peabody124
parent 66e22b56ce
commit 27d429fe18
7 changed files with 54 additions and 21 deletions

View File

@ -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;
}

View File

@ -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 */

View File

@ -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,

View File

@ -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]);

View File

@ -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);

View File

@ -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

View File

@ -45,7 +45,7 @@
/* EP1 */
/* tx buffer base address */
#define ENDP1_TXADDR (0x100)
#define ENDP1_RXADDR (0x104)
#define ENDP1_RXADDR (0x124)
/*-------------------------------------------------------------*/
/* ------------------- ISTR events -------------------------*/