Hoy estuve revisando y probando en mi PIC18F2550 como activar dos ENDPOINTS y lo logre, también configure la mpusbapi para tal función.
Leyendo de un post del foro pero que no recuerdo que palabras usé, empece a probar y realice unos cambios en los descriptores.
Esto es la parte importante del archivo PICUSB.c. Copié esto solamente ya que en USB_CONFIG_DESC[] fue donde modifique y añadí cosas
#DEFINE USB_TOTAL_CONFIG_LEN 46 //config+interface+class+endpoint
char const USB_CONFIG_DESC[] = {
//config_descriptor for config index 1
USB_DESC_CONFIG_LEN, //length of descriptor size =1
USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (0x02)
USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==3,4
1, //number of interfaces this device supports
0x01, //identifier for this configuration. (IF we had more than one configurations)
0x00, //index of string descriptor for this configuration
0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 reserved and bit7=1
0x32, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) =9
//interface descriptor 0 alt 0
USB_DESC_INTERFACE_LEN, //length of descriptor ==10
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (0x04)
0x00, //number defining this interface (IF we had more than one interface)
0x00, //alternate setting
4, //number of endpoints, not counting endpoint 0.-------------------------------------------------------------------------->NOTA1
0xFF, //class code, FF = vendor defined
0xFF, //subclass code, FF = vendor
0xFF, //protocol code, FF = vendor
0x00, //index of string descriptor for interface =18
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x81, //endpoint number and direction (0x81 = EP1 IN)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP1_TX_SIZE,0x00, //maximum packet size supported =23,24
0x01, //polling interval in ms. (for interrupt transfers ONLY)=25
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==26
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x01, //endpoint number and direction (0x01 = EP1 OUT)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP1_RX_SIZE,0x00, //maximum packet size supported =30,31
0x01, //polling interval in ms. (for interrupt transfers ONLY) =32
//endpoint descriptor ////AGREGADO
USB_DESC_ENDPOINT_LEN, //length of descriptor == 33
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x82, //endpoint number and direction (0x82 = EP2 IN)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP2_TX_SIZE,0x00, //maximum packet size supported ==37,38
0x01, //polling interval in ms. (for interrupt transfers ONLY) ==39
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==40
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x02, //endpoint number and direction (0x02 = EP2 OUT)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP2_RX_SIZE,0x00, //maximum packet size supported ==44,45
0x01 //polling interval in ms. (for interrupt transfers ONLY) == 46[/b]
};
NOTA1: Agregué la información para usar el ENDPOINT 2, por lo que donde indico se debe poner un 4. Sin contar el EP0 serian 4 Endpoints en total (2 in y 2 OUT). También modifiqué respectivamente #DEFINE USB_TOTAL_CONFIG_LEN 46 //config+interface+class+endpoint. De esta forma ya tengo habilitados dos endpoints. Si quisiera añadir 3 Endpoints deberia agregar dos "endpoint descriptor" (uno para In y otro para OUT) asi como también contar nuevamente las lineas para poner el numero respectivo en USB_TOTAL_CONFIG_LEN. Además donde indico la NOTA1 no sería 4, sino un 6.
Por otra parte, en el archivo que tiene el main(), fuses y todo lo demás; para ver si hay datos en cada ENDPOINT se procede de la misma forma como lo hizo J1M en su proyecto PicUSB pero hay que ir constatando usb_kbhit() por cada endpoint, es decir:
usb_kbhit(1) para endpoint 1
usb_kbhit(2) para endpoint 2, y asi suma y sigue.
Se me olvidaba, declaren los #define para cada enpoint IN y/o OUT.
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK // turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK // turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP2_TX_ENABLE USB_ENABLE_BULK // turn on EP2(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP2_RX_ENABLE USB_ENABLE_BULK // turn on EP2(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 5 // size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 1 // size to allocate for the rx endpoint 1 buffer
#define USB_EP2_TX_SIZE 5 // size to allocate for the tx endpoint 2 buffer
#define USB_EP2_RX_SIZE 1
Para enviar y/o recibir, hacer uso de las funciones que me enseñaron uds aca como usb_get_packet(0x02, recibe, 1) y usb_put_packet(0x02, envia, 5, USB_DTS_TOGGLE). si se fijan use el Endpoint 2 para enviar y recibir algo.
Finalmente, ahora solo constaté cambiando el STRING que define el endpoint para usar con la libreria importada mpusbapi que usa J1M para realizar su programa PicUSB, o sea:
#region Definición de los Strings: EndPoint y VID_PID
string vid_pid_norm = "vid_04d8&pid_0011";
string out_pipe = "\\MCHP_EP2";
string in_pipe = "\\MCHP_EP2";
#endregion
y funcionó igual que como si hubiese estado con el ENDPOINT1. En un rato más probare usando dos enpoint con BULK TRANSFERS simultaneamente para una aplicación que estoy realizando para mi seminario. Les aviso luego.
migsantiago como te manejas más con el código quizas le saques más provecho, me gustaria saber que tendra esa mente tuya para este tema
PD: como miercale se usa el Geshi?, quiero poner codigo con colores y cosas bonitas