I am trying to implement a streaming sensor using Interrupt-in endpoint but nothing seems to be working. Control endpoint communication works fine.
What am I missing?
I am using custom class and have set the
Code: Select all
#define USB_CFG_HAVE_INTRIN_ENDPOINT 1
AVR code:
Code: Select all
static uchar dataBuffer[4];
int main(void) {
newMeas = 0;
hardware_init();
uchar i = 0;
usbDeviceDisconnect();
while(--i) /* fake USB disconnect for > 250 ms */
_delay_ms(1);
usbDeviceConnect();
usbInit();
sei();
while(1)
{
usbPoll();
if(newMeas && usbInterruptIsReady()) {
dataBuffer[0] = 5;
dataBuffer[1] = 5;
usbSetInterrupt(dataBuffer, 2);
newMeas = 0;
}
}
}
usbFunctionSetup() is omitted from the quote as it only handles the control end point
Commandlinecode on Linux 2.6.27:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <usb.h>
#include "opendevice.h"
struct usb_bus *busses;
usb_dev_handle *find_sensor(void) {
struct usb_bus *bus;
char Manufacturer[256], Product[256];
struct usb_device *dev;
struct usb_dev_handle *devh = NULL;
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
for(bus = busses; bus; bus = bus->next) {
for(dev = bus->devices; dev; dev = dev->next) {
if(dev->descriptor.idVendor == 0x16C0 &&
dev->descriptor.idProduct == 0x05DC) {
devh = usb_open(dev);
if(!devh) {
perror("usb_open");
goto xit;
}
if(usb_get_string_simple(devh, dev->descriptor.iManufacturer,
Manufacturer, 255) < 0) {
perror("usb_get_string_simple(iManufacturer)");
goto xit;
}
if(usb_get_string_simple(devh, dev->descriptor.iProduct, Product,
255) < 0) {
perror("usb_get_string_simple(iProduct)");
goto xit;
}
printf("Found %s %s\n",Manufacturer,Product);
if(usb_set_configuration(devh, 1) < 0) {
perror("usb_set_configuration"); exit(1);
}
if(usb_claim_interface(devh, 0) < 0) {
perror("usb_claim_interface"); exit(1);
}
if((dev->config->interface->altsetting->endpoint->bmAttributes &
USB_ENDPOINT_TYPE_MASK) != USB_ENDPOINT_TYPE_INTERRUPT) {
fprintf(stderr, "Endpoint 1 is not an interrupt endpoint\n");
goto xit;
}
return devh;
}
xit:
if(devh) {
usb_release_interface(devh, 0);
usb_close(devh);
devh = NULL;
}
}
}
return NULL;
}
void close_sensor(usb_dev_handle *devh) {
if(devh) {
usb_release_interface(devh, 0);
usb_close(devh);
}
}
int main(int argc, char **argv)
{
usb_dev_handle *devh;
int len;
char buffer[4];
if(!(devh = find_sensor())) {
fprintf(stderr, "No module found\n");
exit(1);
}
printf("stream begin\n");
len = usb_interrupt_read(devh, 1, buffer, sizeof(buffer), 3000);
if(len < 0){
fprintf(stderr, "USB error: %s\n", usb_strerror());
}else{
printf("Value is %u\n", (buffer[0]<<8 | buffer[1])&0xff);
}
printf("stream end\n");
close_sensor(devh);
return 0;
}
Console output:
Code: Select all
Found A.Mejnertsen PowerMeas
stream
<---3 sec wait--->
USB error: No error
stream end
I really can't see why this shouldn't be working. Can anybody give me some pointer as to what I'm missing?
Best regards
Asbjørn Mejnertsen