I'm tyring to create a Data Acquisition device based on V-USB. I tired to describe my device as an HID joystick. Then I can transfer my date through axises information.
Here is the problem, I do not know how to transfer my data through axises information.
here is my main.c:
Code: Select all
char usbHidReportDescriptor[69] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x09, 0x04, // USAGE (Joystick)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x09, 0x32, // USAGE (Z)
0x09, 0x33, // USAGE (U)
0x95, 0x04, // REPORT_COUNT (4)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0x09, 0x39, // USAGE (Hat switch)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x03, // LOGICAL_MAXIMUM (3)
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x0e, 0x01, // PHYSICAL_MAXIMUM (270)
0x65, 0x14, // UNIT (Eng Rot:Angular Pos)
0x75, 0x04, // REPORT_SIZE (4)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x04, // USAGE_MAXIMUM (Button 4)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x04, // REPORT_COUNT (4)
0x55, 0x00, // UNIT_EXPONENT (0)
0x65, 0x00, // UNIT (None)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0 // END_COLLECTION
};
unsigned int array[8]={0};
//unsigned int value;
void adc_init()
{
ADMUX=0x00;
ADCSRA=0x00;
ADMUX = (1<<REFS0)|(1<<REFS1);
ADCSRA|=(1<<ADEN)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADFR);
}
unsigned int ReadADC(unsigned char channel)
{
unsigned int ad;
ADMUX &= 0xF8;
ADMUX |= channel; // Select channel
ADCSRA |= (1<<ADSC); // Start conversion
while (!(ADCSRA & (1<<ADIF))); // Check if converstion is ready
ADCSRA|= (1<<ADIF) ; // Clear Conversion ready flag by setting the bit
ad = ADCL; // Read 8 low bits first (important)
ad += (unsigned int)ADCH << 8; // Read 2 high bits and multiply with 256
return ad;
}
static uchar reportBuffer[4]={0,0,0,0};
uchar usbFunctionSetup(uchar data[8])
{
reportBuffer[0] = data[2];
reportBuffer[1] = data[3];
reportBuffer[2] = data[4];
reportBuffer[3] = data[5];
usbMsgPtr=reportBuffer;
return 4;
}
int main(void)
{
unsigned char i;
unsigned int dat;
//unsigned char PC;
DDRA=0xff;
DDRC=0xff;
DDRF=0x00;
adc_init();
usbInit();
sei();
for(;;)
{
for(i=0;i<1;i++)
{
dat=ReadADC(i);
array [ i ]=dat;
}
usbPoll();
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
}
}
Any ideas, anyone? thank you!!