1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-15 07:29:15 +01:00

HID working on Mac for telemetry. Need to tweak GCS code for Win/Linux

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1166 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
peabody124 2010-07-27 20:50:20 +00:00 committed by peabody124
parent dac82b3c17
commit 27bcd20882
11 changed files with 62 additions and 46 deletions

View File

@ -312,7 +312,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))
if(1) //if(PIOS_USB_HID_CheckAvailable(0))
{
inputPort = PIOS_COM_TELEM_USB;
}
@ -347,7 +347,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))
if(1) //PIOS_USB_HID_CheckAvailable(0))
{
outputPort = PIOS_COM_TELEM_USB;
}

View File

@ -138,7 +138,7 @@ int32_t PIOS_SYS_SerialNumberGet(char *str)
int i;
/* Stored in the so called "electronic signature" */
for(i=0; i<24; ++i) {
for(i=0; i<12; ++i) {
uint8_t b = MEM8(0x1ffff7e8 + (i/2));
if( !(i & 1) )
b >>= 4;

View File

@ -34,6 +34,7 @@
/* Project Includes */
#include "pios.h"
#include "usb_lib.h"
#include "pios_usb_hid_desc.h"
#include "stm32f10x.h"
#if defined(PIOS_INCLUDE_USB_HID)
@ -85,6 +86,25 @@ int32_t PIOS_USB_HID_Init(uint32_t mode)
/* Enable the USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
/* Update the USB serial number from the chip */
uint8_t sn[40];
PIOS_SYS_SerialNumberGet((char *) sn);
/* uint8_t len = 0;;
for(uint8_t i = 0, len = 2; sn[i] != '\0' && len < PIOS_HID_StringSerial[0]; ++i)
{
PIOS_HID_StringSerial[len++] = sn[i];
PIOS_HID_StringSerial[len++] = 0;
}
while(len < PIOS_HID_StringSerial[0])
{
PIOS_HID_StringSerial[len++] = 0;
} */
for(uint8_t i = 0; i < 12; i++)
{
PIOS_HID_StringSerial[2+i*2] = sn[i];
}
USB_Init();
USB_SIL_Init();
PIOS_LED_On(LED2);

View File

@ -119,30 +119,30 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
; /* CustomHID_ConfigDescriptor */
const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC] =
{
0x06, 0xFF, 0x00, /* USAGE_PAGE (Vendor Page: 0xFF00) */
0x06, 0x9c, 0xff, /* USAGE_PAGE (Vendor Page: 0xFF00) */
0x09, 0x01, /* USAGE (Demo Kit) */
0xa1, 0x01, /* COLLECTION (Application) */
/* 6 */
/* Data 1 */
0x85, 0x01, /* REPORT_ID (1) */
0x09, 0x01, /* USAGE (LED 1) */
0x09, 0x02, /* USAGE (LED 1) */
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) */
0x81, 0x83, /* INPUT (Const,Var,Array) */
/* 20 */
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, PIOS_USB_HID_DATA_LENGTH+1, /* REPORT_COUNT (1) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 34 */
/* Data 1 */
0x85, 0x02, /* REPORT_ID (2) */
0x09, 0x03, /* USAGE (LED 1) */
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) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 34 */
0xc0 /* END_COLLECTION */
}; /* CustomHID_ReportDescriptor */
@ -178,7 +178,7 @@ uint8_t PIOS_HID_StringSerial[PIOS_HID_SIZ_STRING_SERIAL] =
{
PIOS_HID_SIZ_STRING_SERIAL, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'S', 0, 'T', 0, 'M', 0,'3', 0,'2', 0, '1', 0, '0', 0
'S', 0, 'T', 0, 'M', 0,'3', 0,'2', 0, '1', 0, '\0', 0
};
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -15,6 +15,7 @@
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
#include "pios.h"
#include "pios_usb_hid_pwr.h"
#include "pios_usb_hid_istr.h"
#include "pios_usb_hid.h"
@ -69,6 +70,7 @@ void USB_LP_CAN1_RX0_IRQHandler(void) //USB_Istr(void)
#if (IMR_MSK & ISTR_CTR)
if (wIstr & ISTR_CTR & wInterrupt_Mask)
{
PIOS_LED_Toggle(LED2);
/* servicing of the endpoint correct transfer interrupt */
/* clear of the CTR flag into the sub */
CTR_LP();

View File

@ -337,23 +337,6 @@ 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

@ -42,7 +42,7 @@ public:
void close(int num);
int send(int num, void *buf, int len, int timeout);
int getserial(int num, char *buf);
void mytest(int num);
private:
};

View File

@ -48,7 +48,7 @@
#define BUFFER_SIZE 64
#define printf qDebug
#define printf
//#define printf
typedef struct hid_struct hid_t;
typedef struct buffer_struct buffer_t;
@ -154,6 +154,7 @@ int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage)
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, detach_callback, NULL);
ret = IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone);
if (ret != kIOReturnSuccess) {
printf("Could not start IOHIDManager");
IOHIDManagerUnscheduleFromRunLoop(hid_manager,
CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
CFRelease(hid_manager);
@ -239,7 +240,11 @@ int pjrc_rawhid::send(int num, void *buf, int len, int timeout)
if (!hid || !hid->open) return -1;
#if 1
#warning "Send timeout not implemented on MACOSX"
IOReturn ret = IOHIDDeviceSetReport(hid->ref, kIOHIDReportTypeOutput, 0, (uint8_t *)buf, len);
uint8_t *report_buf = (uint8_t *) malloc(BUFFER_SIZE);
memcpy(&report_buf[2], buf,len);
report_buf[1] = len;
report_buf[0] = 2; // report ID
IOReturn ret = IOHIDDeviceSetReport(hid->ref, kIOHIDReportTypeOutput, 0, (uint8_t *)report_buf, BUFFER_SIZE);
result = (ret == kIOReturnSuccess) ? len : -1;
#endif
#if 0
@ -276,11 +281,11 @@ int pjrc_rawhid::getserial(int num, char *buf) {
if (!hid || !hid->open) return -1;
CFTypeRef serialnum = IOHIDDeviceGetProperty(hid->ref, CFSTR(kIOHIDSerialNumberKey));
if(CFGetTypeID(serialnum) == CFStringGetTypeID())
if(serialnum && CFGetTypeID(serialnum) == CFStringGetTypeID())
{
/* For some reason the first 8 bytes of 'serialnum' are useless (a struct?) */
char *strptr = (char *)serialnum;
for(int i = 9; i < 33; i++) {
for(int i = 0; i < 24; i++) {
*(buf++) = strptr[i];
}
return 0;
@ -316,14 +321,16 @@ static void input_callback(void *context, IOReturn ret, void *sender, IOHIDRepor
buffer_t *n;
hid_t *hid;
printf("input_callback\n");
printf("input_callback, report id: %i buf: %x %x\n", id, data[0], data[1]);
if (ret != kIOReturnSuccess || len < 1) return;
hid = (hid_t*)context;
if (!hid || hid->ref != sender) return;
n = (buffer_t *)malloc(sizeof(buffer_t));
if (!n) return;
if (len > BUFFER_SIZE) len = BUFFER_SIZE;
memcpy(n->buf, data, len);
/* Real data starts at third byte, second byte is valid data size */
//len = data[1];
memcpy(n->buf, &data[0], len);
n->len = len;
n->next = NULL;
if (!hid->first_buffer || !hid->last_buffer) {

View File

@ -143,7 +143,10 @@ void RawHIDReadThread::run()
if(ret > 0) //read some data
{
m_readBufMtx.lock();
m_readBuffer.append(buffer, ret);
/* First byte is report ID, can be ignored */
/* Second byte is the number of valid bytes */
m_readBuffer.append(&buffer[2], buffer[1]);
// m_readBuffer.append(buffer, ret);
m_readBufMtx.unlock();
emit m_hid->readyRead();
@ -238,7 +241,7 @@ void RawHIDWriteThread::run()
int RawHIDWriteThread::pushDataToWrite(const char *data, int size)
{
QMutexLocker lock(&m_writeBufMtx);
//QMutexLocker lock(&m_writeBufMtx);
m_writeBuffer.append(data, size);
m_newDataToWrite.wakeOne(); //signal that new data arrived
@ -247,7 +250,7 @@ int RawHIDWriteThread::pushDataToWrite(const char *data, int size)
qint64 RawHIDWriteThread::getBytesToWrite()
{
QMutexLocker lock(&m_writeBufMtx);
// QMutexLocker lock(&m_writeBufMtx);
return m_writeBuffer.size();
}

View File

@ -37,6 +37,6 @@ static const int PID = 0x4117;
static const int USAGE_PAGE = 0xFF9C;
static const int USAGE = 0x0001;
static const int DEV_SERIAL_LEN = 24;
static const int DEV_SERIAL_LEN = 4;
#endif // RAWHID_CONST_H

View File

@ -107,7 +107,8 @@ QStringList RawHIDConnection::availableDevices()
{
char serial[256];
dev.getserial(i, serial);
devices.append(QString::fromAscii(serial, DEV_SERIAL_LEN));
QString sn = QString::fromAscii(serial, DEV_SERIAL_LEN);
devices.append(sn);
dev.close(i);
}