Using at90usb1287

This source code shows a little driver i wrote for the at90usb128-demo-template example from Atmel corporation.

I tested it using the usbkey board and everything was fine.

I hope this helps.

/Archivos de cabecera/
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>

/Prototipos para POSIX Threads/
#include <pthread.h>

/Prototipos para libusbdiS.a/
#include <sys/usbdi.h>

/Códigos de error/
#include <errno.h>

/Código del vendor Nokia/
#define USB_VENDOR_NOKIA 0x0421
/Código del producto 5310/
#define USB_PRODUCT_NOKIA_5310 0x006b

/Código del vendor Atmel/
#define USB_VENDOR_ATMEL 0x03eb
/Código del producto AVR USB DEVICE/
#define USB_PRODUCT_AVR_USB_DEVICE 0x0000

/Definir con el fabricante y dispositivo específico respectivamente/

#define USB_VENDOR USB_VENDOR_ATMEL
#define USB_PRODUCT USB_PRODUCT_AVR_USB_DEVICE

/Manejador del dispositivo/
struct usbd_device *device;

/Punteros a URBs IN y OUT respectivamente para las transferencias bulk/
struct usbd_urb *urb1,*urb2;

/Punteros a la tuberías IN y OUT respectivamente/
struct usbd_pipe *pipe_in,*pipe_out;

/Puntero a los datos/
char *data;

/Mutex para el flag que sincroniza el principal con el hilo de ejecución usb/
pthread_mutex_t mutex;

/Flag que sincroniza el principal con el hilo de ejecución usb/
char isConnected=0;

/*Callback que se ejecuta cuando se ha conectado el dispositivo */
void insertion(struct usbd_connection *connection, usbd_device_instance_t *instance){

/*Vector en el cual se almacenarán los descriptores*/
char descriptor[200];
 
/*Condiciones de error de las funciones*/
int status;

/*Ã

Hi,

First of all thanks for posting your usb driver!, it is helping me a lot to develop my own device driver

I have mostly replicated your insertion() callback but I’m getting an error when opening the Pipe In. In fact I don’t understand some small things in your code, thus I’m not able to fix it. Basically my questions are:

  1. Why you define the buffer to put the descriptor as a char descriptor[200] ? (I had to define it as _uint8 because char gave me a type error). The size 200 is defined by the USB standard (I haven’t find this info) or it depends on your device?

  2. Why do you define the descriptor for the endpoint in and endpoint out as:
    aux_base_endpoint=descriptor[0]+descriptor[(int)descriptor[0]]; and aux_base_endpoint=descriptor[0]+descriptor[(int)descriptor[0]]+descriptor[descriptor[0]+descriptor[(int)descriptor[0]]];
    is it also because USB standard says so?

Thanks in advance