Autor Tema: usb_rx_packet_size devuelve un cero  (Leído 4307 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado kyle_katarn

  • PIC10
  • *
  • Mensajes: 5
Re: usb_rx_packet_size devuelve un cero
« Respuesta #15 en: 05 de Junio de 2012, 14:36:09 »
Buenas, necesito ayuda con los endpoints RX y aprovecho este hilo, ya antiguo, para exponer mi duda, por que en el he visto que mi codigo es bastante similar y me deja mas dudas sobre donde me estoy equivocando.

Yo tenia un dispositivo hid con unos botones y unos ejes funcionando perfectamente, pero ahora necesito enviar datos desde el PC al PIC, y al definir el EP1_RX y añadir las lineas al descriptor, con el report size y el report count para las entradas, ahora el dispositivo no se instala correctamente y el SO aborta su instalacion.
Os pondre aqui las partes del codigo que creo son las necesarias para la definicion correcta del EP1_RX y a ver si me cazais el error, por que yo he estado rebuscando por el foro y por internet y no consigo sacarlo, es mas, segun el codigo de este post, todo lo tengo correcto.

Este es el codigo del descriptor, donde se puede ver que las ultimas lineas son para las entradas de datos.
Si no me he vuelto tonto son dos reportes de 8 bits, entonces 2 bytes.

Código: [Seleccionar]
   0x05, 0x01,        //   Usage Page (Generic Desktop) 1, 2
   0x09, 0x04,        //   Usage (Joy) 3, 4
   0xA1, 0x00,        //   Collection (Physical) 5, 6
   0x09, 0x30,        //     Usage (X) 7, 8
   0x09, 0x31,        //     Usage (Y) 9, 10
   0x15, 0x00,        //     Log Min (0) 11, 12
   0x26, 0xFF, 0x03,  //     Log Max (1023) 13, 14, 15
   0x75, 0x10,        //     Report Size (16) 16, 17
   0x95, 0x02,        //     Report Count (2) 18, 19
   0x81, 0x02,        //     Input (Data, Variable, Absolute) 20, 21
   0x09, 0x32,        //     Usage (Z) 22, 23
   0x15, 0x00,        //     Log Min (0) 24, 25
   0x26, 0xFF, 0x03,  //     Log Max (1023) 26, 27, 28
   0x75, 0x10,        //     Report Size (16) 29, 30
   0x95, 0x01,        //     Report Count (1) 31, 32
   0x81, 0x02,        //     Input (Data, Variable, Absolute) 33, 34
   0x09, 0x33,        //     Usage (Rx) 35, 36
   0x15, 0x00,        //     Log Min (0) 37
   0x26, 0xFF, 0x03,  //     Log Max (1023) 38, 39, 40
   0x75, 0x10,        //     Report Size (16) 41, 42
   0x95, 0x01,        //     Report Count (1) 43, 44
   0x81, 0x02,        //     Input (Data, Variable, Absolute) 45, 46
   0x09, 0x34,        //     Usage (Ry) 47, 48
   0x15, 0x00,        //     Log Min (0) 49, 50
   0x26, 0xFF, 0x03,  //     Log Max (1023) 51, 52, 53
   0x75, 0x10,        //     Report Size (16) 54, 55
   0x95, 0x01,        //     Report Count (1) 56, 57
   0x81, 0x02,        //     Input (Data, Variable, Absolute) 58, 59
   0x05, 0x09,        //     USAGE_PAGE (Button) 60, 61
   0x19, 0x01,        //     USAGE_MINIMUM (Button 1) 62, 63
   0x29, 0x10,        //     USAGE_MAXIMUM (Button 16) 64, 65
   0x15, 0x00,        //     LOGICAL_MINIMUM (0) 66, 67
   0x25, 0x01,        //     LOGICAL_MAXIMUM (1) 68, 69
   0x75, 0x01,        //     REPORT_SIZE (1) Tamaño del boton en bits 70, 71
   0x95, 0x10,        //     REPORT_COUNT (16) Numero de botones 72, 73
   0x81, 0x02,        //     INPUT (Data,Var,Abs) 74, 75
   0x75, 0x08,        //report size (8) //78, 79
   0x95, 0x02,        //report count (2)   //76, 77
   0x91, 0x02,        //output (data, var, abs) //80, 81
0xc0                  //                          82

Tambien he añadido este codigo al USB_CONFIG_DESC, y cambiado USB_TOTAL_CONFIG_LEN de 34 a 41, que es el nuevo tamaño:

Código: [Seleccionar]
   //endpoint descriptor 1 OUT
         USB_DESC_ENDPOINT_LEN, //length of descriptor                   ==35
         USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05)          ==36
         0x01, //endpoint number and direction (0x01 = EP1 OUT)       ==37
         USB_ENDPOINT_TYPE_INTERRUPT, //transfer type supported (0x03 is interrupt)         ==38
         USB_EP1_RX_SIZE,0x00, //maximum packet size supported                  ==39,40
         10  //polling interval, in ms.  (cant be smaller than 10 for slow speed devices)     ==41
   };

Los endpoint los defino asi:

Código: [Seleccionar]
#define USB_EP1_TX_ENABLE  USB_ENABLE_INTERRUPT
#define USB_EP1_TX_SIZE 12     //max packet size of this endpoint

//turn on EP1 for OUT interrupt transfers.  (OUT = PC -> PIC)
#define USB_EP1_RX_ENABLE  USB_ENABLE_INTERRUPT
#define USB_EP1_RX_SIZE 8     //max packet size of this endpoint

En el codigo del main tengo lo siguiente:

Código: [Seleccionar]
void main(void) {

   long out_data[6];
   int8 in_data[8];
   long giro;
   int i;


   disable_interrupts(global);
   disable_interrupts(int_timer1);
   disable_interrupts(int_rda);
   disable_interrupts(int_ext);
   disable_interrupts(int_ext1);
   disable_interrupts(int_ext2);
   setup_spi(FALSE);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   port_b_pullups(FALSE);


     set_tris_a (0b0101111);
     set_tris_b (0b00001000);
     set_tris_c (0b00000000);
         
   SETUP_ADC(ADC_CLOCK_DIV_64 || VSS_VREF);
   SETUP_ADC_PORTS(AN0_TO_AN4);
   usb_init_cs();
   config_adcon2(); // Configuramos el conversor analógico digital.


//   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
//   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,255,1);
   setup_ccp1(CCP_PWM);

   while (TRUE)
   {
      usb_task();
      usb_debug_task();
      if (usb_enumerated())
      {
        SET_ADC_CHANNEL(PIN_A0);
        delay_us(5);
        out_data[0]=read_adc();
        giro=out_data[0];
        SET_ADC_CHANNEL(PIN_A1);
        delay_us(5);
        out_data[1]=read_adc();
        SET_ADC_CHANNEL(PIN_A2);
        delay_us(5);
        out_data[2]=read_adc();
        SET_ADC_CHANNEL(PIN_A3);
        delay_us(5);
        out_data[3]=read_adc();
        SET_ADC_CHANNEL(PIN_A4);
        delay_us(5);
        out_data[4]=read_adc();
        out_data[5]=interroga_botones();
        usb_put_packet(1,out_data,12,USB_DTS_TOGGLE);
        giro_variable(giro);
        i=usb_get_packet(1,in_data,USB_EP1_RX_SIZE);
      }
   }
}

Y con esto el dispositivo no se instala cuando se conecta por primera vez, me preocupo de eliminar el dispositivo cada vez que lo desenchufo para comprobar que todo el proceso se realiza correctamente cuando hago cambios importantes en el codigo, ademas que se que da problemas enchufar muchas veces el mismo dispositivo con caracteristicas distintas.

Muchas gracias, paso mucho tiempo releyendo post para aclarar dudas, pero hay algunas que la inexperiencia las hacen insalvables.
« Última modificación: 05 de Junio de 2012, 14:45:37 por kyle_katarn »


 

anything