Bonjour,

Je travaille actuellement sur un PIC18F2550. Je cherche à le faire reconnaitre en tant que périphérique de souris.

Voici le fichier .c
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*********************************************************************
 * Descriptor specific type definitions are defined in:
 * usb_device.h
 *
 * Configuration options are defined in:
 * usb_config.h
 ********************************************************************/
#ifndef __USB_DESCRIPTORS_C
#define __USB_DESCRIPTORS_C

/** INCLUDES *******************************************************/
#include "usb.h"
#include "usb_function_hid.h"


/** CONSTANTS ******************************************************/
#if defined(__18CXX)
// JMCV #pragma romdata
#endif

/* Device Descriptor */
const /* ROM JMCV */ USB_DEVICE_DESCRIPTOR device_dsc=
{
    0x09,/*sizeof(USB_DEVICE_DESCRIPTOR),*/    // Size of this descriptor in bytes
    USB_DESCRIPTOR_DEVICE,                // DEVICE descriptor type
    0x0200,                 // USB Spec Release Number in BCD format
    0x00,                   // Class Code
    0x00,                   // Subclass code
    0x00,                   // Protocol code
    USB_EP0_BUFF_SIZE,          // Max packet size for EP0, see usbcfg.h
    MY_VID,                 // Vendor ID 										yts
    MY_PID,                 // Product ID: Mouse in a circle fw demo			yts
    0x0001,                 // Device release number in BCD format
    0x01,                   // Manufacturer string index
    0x02,                   // Product string index
    0x00,                   // Device serial number string index
    0x01                    // Number of possible configurations
};

/* Configuration 1 Descriptor */
const /* ROM  JMCV */BYTE configDescriptor1[]={
    /* Configuration Descriptor */
    0x09,/*sizeof(USB_DESCRIPTOR_CONFIGURATION), */   // Size of this descriptor in bytes
    USB_DESCRIPTOR_CONFIGURATION,                // CONFIGURATION descriptor type
    DESC_CONFIG_WORD((UINT16) 0x0029),   // Total length of data for this cfg/*sizeof(configDescriptor1),*/   // Total length of data for this cfg
    1,                      // Number of interfaces in this cfg
    1,                      // Index value of this configuration
    0,                      // Configuration string index
    _DEFAULT/*JMCV | _SELF*/ | _RWU,               // Attributes, see usb_device.h
    50,                     // Max power consumption (2X mA)

    /* Interface Descriptor */
    0x09,/*sizeof(USB_DESCRIPTOR_INTERFACE),*/   // Size of this descriptor in bytes
    USB_DESCRIPTOR_INTERFACE,               // INTERFACE descriptor type
    0,                      // Interface Number
    0,                      // Alternate Setting Number
    1,                      // Number of endpoints in this intf
    HID_INTF,               // Class code
    BOOT_INTF_SUBCLASS,     // Subclass code
    HID_PROTOCOL_MOUSE,     // Protocol code
    0,                      // Interface string index

    /* HID Class-Specific Descriptor */
    0x09,/*sizeof(USB_HID_DSC)+3,*/    // Size of this descriptor in bytes RRoj hack
    DSC_HID,                // HID descriptor type
    DESC_CONFIG_WORD(0x0101),                 // HID Spec Release Number in BCD format (1.11)
    0x00,                   // Country Code (0x00 for Not supported)
    HID_NUM_OF_DSC,         // Number of class descriptors, see usbcfg.h
    DSC_RPT,                // Report descriptor type
    DESC_CONFIG_WORD((UINT16) 52),      // Size of the report descriptor
    
    /* Endpoint Descriptor */
  0x07,/*sizeof(USB_DESCRIPTOR_ENDPOINT),*/
    USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
    HID_EP | _EP_IN,            //EndpointAddress
    _INTERRUPT,                       //Attributes
    DESC_CONFIG_WORD((UINT16) 8),        //size
    0x01,                        //Interval

 

};


//Language code string descriptor
const /*ROM  JMCV */struct{BYTE bLength;BYTE bDscType;WORD string[1];}sd000={
sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409
}};

//Manufacturer string descriptor
const /* ROM  JMCV */struct{BYTE bLength;BYTE bDscType;WORD string[25];}sd001={
sizeof(sd001),USB_DESCRIPTOR_STRING,
{'M','i','c','r','o','c','h','i','p',' ',
'T','e','c','h','n','o','l','o','g','y',' ','I','n','c','.'
}};

//Product string descriptor
const /*ROM  JMCV */struct{BYTE bLength;BYTE bDscType;WORD string[13];}sd002={
sizeof(sd002),USB_DESCRIPTOR_STRING,
{'M','o','u','s','e','b','y','t',' ','D','e','m','o'
}}; 

//Class specific descriptor - HID Mouse
const /*ROM  JMCV */struct{BYTE report[HID_RPT01_SIZE];}hid_rpt01={
{   0x05, 0x01, /* Usage Page (Generic Desktop)             */
    0x09, 0x02, /* Usage (Mouse)                            */
    0xA1, 0x01, /* Collection (Application)                 */
    0x09, 0x01, /*  Usage (Pointer)                         */
    0xA1, 0x00, /*  Collection (Physical)                   */
    0x85, 0x01,  /*   Report ID  */
    0x05, 0x09, /*      Usage Page (Buttons)                */
    0x19, 0x01, /*      Usage Minimum (01)                  */
    0x29, 0x03, /*      Usage Maximum (03)                  */
    0x15, 0x00, /*      Logical Minimum (0)                 */
    0x25, 0x01, /*      Logical Maximum (0)                 */
    0x95, 0x03, /*      Report Count (3)                    */
    0x75, 0x01, /*      Report Size (1)                     */
    0x81, 0x02, /*      Input (Data, Variable, Absolute)    */
    0x95, 0x01, /*      Report Count (1)                    */
    0x75, 0x05, /*      Report Size (5)                     */
    0x81, 0x01, /*      Input (Constant)    ;5 bit padding  */
    0x05, 0x01, /*      Usage Page (Generic Desktop)        */
    0x09, 0x30, /*      Usage (X)                           */
    0x09, 0x31, /*      Usage (Y)                           */
    0x15, 0x81, /*      Logical Minimum (-127)              */
    0x25, 0x7F, /*      Logical Maximum (127)               */
    0x75, 0x08, /*      Report Size (8)                     */
    0x95, 0x02, /*      Report Count (2)                    */
    0x81, 0x06, /*      Input (Data, Variable, Relative)    */
0xC0, /* End Collection*/
0xC0,/* End Collection        */



}



};





//Array of configuration descriptors
// JMCV ROM BYTE *ROM USB_CD_Ptr[]=
const BYTE *const USB_CD_Ptr[]=
{
   /* (ROM BYTE *ROM) JMCV*/ &configDescriptor1
};

//Array of string descriptors
// JMCV ROM  BYTE *ROM USB_SD_Ptr[]=
const BYTE *const USB_SD_Ptr[]=
{
	/* JMCV
    (ROM BYTE *ROM)&sd000,
    (ROM BYTE *ROM)&sd001,
    (ROM BYTE *ROM)&sd002
    */
   &sd000,
   &sd001,
   &sd002
};

/** EOF usb_descriptors.c ***************************************************/

#endif
Voici le fichier .h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Created by the Microchip USBConfig Utility, Version 2.7.1.0, 7/29/2013, 22:36:21

#ifndef _usb_config_h_
#define _usb_config_h_

#include <pic18fregs.h>

#define _USB_CONFIG_VERSION_MAJOR 2
#define _USB_CONFIG_VERSION_MINOR 7
#define _USB_CONFIG_VERSION_DOT   1
#define _USB_CONFIG_VERSION_BUILD 0

// Supported USB Configurations

#define USB_SUPPORT_DEVICE

// Hardware Configuration

#define USB_PING_PONG_MODE  USB_PING_PONG__FULL_PING_PONG

// Peripheral Configuration

#define MY_VID            0x0000
#define MY_PID            0x0000
#define USB_SPEED_OPTION       USB_FULL_SPEED
#define USB_INTERRUPT
#define USB_PULLUP_OPTION      USB_PULLUP_ENABLE
#define USB_TRANSCEIVER_OPTION USB_INTERNAL_TRANSCEIVER
#define USB_EP0_BUFF_SIZE     8
#define USB_MAX_NUM_INT       (0+1)
#define USB_MAX_EP_NUMBER 1
#define USB_NUM_STRING_DESCRIPTORS 3

//#define USB_DISABLE_SOF_HANDLER                 
//#define USB_DISABLE_ERROR_HANDLER               
//#define USB_DISABLE_SET_DESCRIPTOR_HANDLER      

// HID Function Configuration

#define USB_USE_HID
#define HID_INTF_ID             0x00
#define HID_EP 					1
#define HID_INT_IN_EP_SIZE      8
#define HID_INT_OUT_EP_SIZE     8
#define HID_NUM_OF_DSC          1
#define HID_RPT01_SIZE          52

#endif
Il me semble que le descripteur en lui-même est correct. Cependant je ne suis pas sûr des différentes tailles des descripteurs. Le PC le détecte bien en tant que périphérique mais pas en tant que souris.

Je vous remercie par avance de votre aide