Commit 01b3f0af826369ec8732e353e824a0da70dc76c8

Authored by rguillom
1 parent ca6bb997

PAD.c modif fonctions Send_EP_IN_Report + Receive_EP_OUT_Report + ajout Reception_Serie et PAD_Task

Débugage (non terminé)
Quelques fix supplémentaires
@@ -55,7 +55,7 @@ void enum_periph(){ @@ -55,7 +55,7 @@ void enum_periph(){
55 uint8_t address=libusb_get_device_address(device); 55 uint8_t address=libusb_get_device_address(device);
56 printf("Device Found @ (Bus:Address) %d:%d\n",bus,address); 56 printf("Device Found @ (Bus:Address) %d:%d\n",bus,address);
57 printf("Vendor ID 0x0%x\n",desc.idVendor); 57 printf("Vendor ID 0x0%x\n",desc.idVendor);
58 - printf("Product ID 0x0%x\n",desc.idProduct); 58 + printf("Product ID 0x0%x\n\n",desc.idProduct);
59 59
60 /* Recherche de notre périphérique et sauvegarde dans 'found' */ 60 /* Recherche de notre périphérique et sauvegarde dans 'found' */
61 if(desc.idVendor == VENDOR_ID && desc.idProduct == PRODUCT_ID){ 61 if(desc.idVendor == VENDOR_ID && desc.idProduct == PRODUCT_ID){
@@ -74,7 +74,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){ @@ -74,7 +74,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){
74 /* Récupération de la 1ère configuration du périphérique (indice 0) */ 74 /* Récupération de la 1ère configuration du périphérique (indice 0) */
75 struct libusb_config_descriptor *config_desc=NULL; 75 struct libusb_config_descriptor *config_desc=NULL;
76 int status = libusb_get_config_descriptor(found,0,&config_desc); //config d'indice 0 76 int status = libusb_get_config_descriptor(found,0,&config_desc); //config d'indice 0
77 - printf("ID de la configuration d'indice 0 : %d\n",config_desc->bConfigurationValue); 77 + printf("La valeur de la configuration d'indice 0 est %d\n",config_desc->bConfigurationValue);
78 78
79 int interface; 79 int interface;
80 80
@@ -95,7 +95,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){ @@ -95,7 +95,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){
95 /* Utilisation de la configuration */ 95 /* Utilisation de la configuration */
96 int configuration=config_desc->bConfigurationValue; 96 int configuration=config_desc->bConfigurationValue;
97 97
98 - printf("valeur config %d\n", configuration); // Affichage valeur de la configuration 98 + //printf("valeur config %d\n", configuration); // Affichage valeur de la configuration
99 status=libusb_set_configuration(handle,configuration); 99 status=libusb_set_configuration(handle,configuration);
100 if(status!=0){ perror("libusb_set_configuration"); exit(-1); } 100 if(status!=0){ perror("libusb_set_configuration"); exit(-1); }
101 101
@@ -107,7 +107,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){ @@ -107,7 +107,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){
107 107
108 status=libusb_claim_interface(handle,indice_intf); 108 status=libusb_claim_interface(handle,indice_intf);
109 if(status!=0){ perror("libusb_claim_interface"); exit(-1); } 109 if(status!=0){ perror("libusb_claim_interface"); exit(-1); }
110 - printf("Interface d'indice %d et de numéro %d réclamée\n",indice_intf,num_intf); 110 + printf("\tInterface d'indice %d et de numéro %d réclamée\n",indice_intf,num_intf);
111 111
112 112
113 113
@@ -116,7 +116,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){ @@ -116,7 +116,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){
116 116
117 int type_PA = config_desc->interface[indice_intf].altsetting[0].endpoint[num_PA].bmAttributes; 117 int type_PA = config_desc->interface[indice_intf].altsetting[0].endpoint[num_PA].bmAttributes;
118 uint8_t adresse_PA = config_desc->interface[indice_intf].altsetting[0].endpoint[num_PA].bEndpointAddress; 118 uint8_t adresse_PA = config_desc->interface[indice_intf].altsetting[0].endpoint[num_PA].bEndpointAddress;
119 - printf("Point d'accès trouvé. Adresse :%d\n",adresse_PA); 119 + printf("\t\tPoint d'accès trouvé. Adresse : %d\n",adresse_PA);
120 120
121 /* Regarde si le point d'accès est de type interruption. 121 /* Regarde si le point d'accès est de type interruption.
122 Si oui, on le sauvegarde. */ 122 Si oui, on le sauvegarde. */
@@ -125,7 +125,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){ @@ -125,7 +125,7 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){
125 //struct EP ep1; 125 //struct EP ep1;
126 dernier_PA++; 126 dernier_PA++;
127 tab_PA[dernier_PA] = adresse_PA; 127 tab_PA[dernier_PA] = adresse_PA;
128 - printf("Point d'accès numéro %d sauvegardé. Adresse : %d\n", dernier_PA, adresse_PA); 128 + printf("\t\tPoint d'accès numéro %d sauvegardé. Adresse : %d\n", dernier_PA, adresse_PA);
129 129
130 /* 130 /*
131 ep1.ep=config_desc->interface[indice_intf].altsetting[0].endpoint->bEndpointAddress; 131 ep1.ep=config_desc->interface[indice_intf].altsetting[0].endpoint->bEndpointAddress;
@@ -166,7 +166,7 @@ void liberer_interfaces(){ @@ -166,7 +166,7 @@ void liberer_interfaces(){
166 status=libusb_release_interface(handle,num_intf); 166 status=libusb_release_interface(handle,num_intf);
167 if(status!=0){ perror("libusb_release_interface"); exit(-1); } 167 if(status!=0){ perror("libusb_release_interface"); exit(-1); }
168 168
169 - printf("L'interface numéro %d , d'indice %d a été libérée.\n", num_intf,indice_intf); 169 + printf("\tL'interface numéro %d, d'indice %d a été libérée.\n", num_intf,indice_intf);
170 } 170 }
171 } 171 }
172 172
@@ -175,9 +175,9 @@ void liberer_interfaces(){ @@ -175,9 +175,9 @@ void liberer_interfaces(){
175 void send_data(unsigned char tab_PA[TAB_PA_SIZE], unsigned char data){ 175 void send_data(unsigned char tab_PA[TAB_PA_SIZE], unsigned char data){
176 176
177 unsigned char PA = tab_PA[0]; //LEDs sur le premier point d'accès 177 unsigned char PA = tab_PA[0]; //LEDs sur le premier point d'accès
178 - int *transferred = 1; //nombre d'octets transférés 178 + int transferred = 1; //nombre d'octets transférés
179 unsigned int timeout = 1000; //temps avant un timeout 179 unsigned int timeout = 1000; //temps avant un timeout
180 - int status = libusb_interrupt_transfer(struct libusb_device_handle *handle, PA, &data, sizeof(data), &transferred, timeout) 180 + int status = libusb_interrupt_transfer(handle, PA, &data, sizeof(data), &transferred, timeout);
181 if(status!=0){perror("libusb_interrupt_transfer");exit(-1);} 181 if(status!=0){perror("libusb_interrupt_transfer");exit(-1);}
182 } 182 }
183 183
@@ -187,25 +187,27 @@ void receive_data(unsigned char tab_PA[TAB_PA_SIZE], unsigned char *boutons, uns @@ -187,25 +187,27 @@ void receive_data(unsigned char tab_PA[TAB_PA_SIZE], unsigned char *boutons, uns
187 187
188 /* Lecture du point d'accès des boutons */ 188 /* Lecture du point d'accès des boutons */
189 unsigned char PA = tab_PA[1]; //LEDs sur le premier point d'accès 189 unsigned char PA = tab_PA[1]; //LEDs sur le premier point d'accès
190 - int *transferred = 1; //nombre d'octets transférés 190 + int transferred = 1; //nombre d'octets transférés
191 unsigned int timeout = 1000; //temps avant un timeout 191 unsigned int timeout = 1000; //temps avant un timeout
192 192
193 - int status = libusb_interrupt_transfer(struct libusb_device_handle *handle, PA, &boutons, sizeof(boutons), &transferred, timeout) 193 + int status = libusb_interrupt_transfer(handle, PA, boutons, sizeof(boutons), &transferred, timeout);
194 if(status!=0){perror("libusb_interrupt_transfer");exit(-1);} 194 if(status!=0){perror("libusb_interrupt_transfer");exit(-1);}
195 195
196 /* Lecture du point d'accès du joystick */ 196 /* Lecture du point d'accès du joystick */
197 - unsigned char *joystick_xy; //stocke la donnée du point d'accès (1 octet pour chaque axe) 197 + unsigned char *joystick_xy=NULL; //stocke la donnée du point d'accès (1 octet pour chaque axe)
198 198
199 PA = tab_PA[2]; //LEDs sur le premier point d'accès 199 PA = tab_PA[2]; //LEDs sur le premier point d'accès
200 - *transferred = 2; //nombre d'octets transférés 200 + transferred = 2; //nombre d'octets transférés
201 timeout = 1000; //temps avant un timeout 201 timeout = 1000; //temps avant un timeout
202 202
203 - int status = libusb_interrupt_transfer(struct libusb_device_handle *handle, PA, &joystick_xy, sizeof(joystick_xy), &transferred, timeout) 203 + status = libusb_interrupt_transfer(handle, PA, joystick_xy, sizeof(joystick_xy), &transferred, timeout);
204 if(status!=0){perror("libusb_interrupt_transfer");exit(-1);} 204 if(status!=0){perror("libusb_interrupt_transfer");exit(-1);}
205 205
206 //TODO Pas sûr !!! 206 //TODO Pas sûr !!!
207 - *joystick_x = joystick_xy[0]; //On sépare la data de chaque axe  
208 - *joystick_y = joystick_xy[1]; 207 + if (joystick_xy !=NULL){
  208 + *joystick_x = joystick_xy[0]; //On sépare la data de chaque axe
  209 + *joystick_y = joystick_xy[1];
  210 + }
209 } 211 }
210 212
211 213
@@ -230,13 +232,30 @@ int main(){ @@ -230,13 +232,30 @@ int main(){
230 char tab_PA[TAB_PA_SIZE]; 232 char tab_PA[TAB_PA_SIZE];
231 config_periph(tab_PA); 233 config_periph(tab_PA);
232 234
233 - unsigned char *boutons;  
234 - unsigned char *joystick_x;  
235 - unsigned char *joystick_x; 235 + unsigned char *boutons, *boutons_anc = NULL;
  236 + unsigned char *joystick_x, *joystick_x_anc = NULL;
  237 + unsigned char *joystick_y, *joystick_y_anc = NULL;
  238 + unsigned char caractere;
236 239
  240 + /*
237 //boucle while(pas d'arrêt), envoi et rcpt 241 //boucle while(pas d'arrêt), envoi et rcpt
238 // "pas d'arrêt" = appui sur 's' par exemple 242 // "pas d'arrêt" = appui sur 's' par exemple
  243 +
  244 + if (appui sur une touche){
  245 + //récupération caractère
  246 + send_data(tab_PA, caractere); //Envoi de la commande des leds
  247 + }
  248 + else {
  249 + receive_data(tab_PA, boutons, joystick_x, joystick_y); //Réception des boutons et joystick
  250 + if ((*boutons != *boutons_anc) || (joystick_x != joystick_x_anc) || (joystick_y != joystick_y_anc)) printf("Boutons : %c, Joystick_x : %c, Joystick_y :%c\n", *boutons, *joystick_x, *joystick_y); //Affichage si changement
  251 +
  252 + *boutons_anc = *boutons;
  253 + *joystick_x_anc = *joystick_x;
  254 + *joystick_y_anc = *joystick_y;
  255 + }
  256 +
239 257
  258 + */
240 259
241 /* Libération des interfaces*/ 260 /* Libération des interfaces*/
242 liberer_interfaces(); 261 liberer_interfaces();
lufa-master/PolytechLille/PAD/Descriptors.c
@@ -38,6 +38,9 @@ @@ -38,6 +38,9 @@
38 38
39 #include "Descriptors.h" 39 #include "Descriptors.h"
40 40
  41 +#define VENDOR_ID 0x2341
  42 +#define PRODUCT_ID 0x0001
  43 +
41 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall 44 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
42 * device characteristics, including the supported USB version, control endpoint size and the 45 * device characteristics, including the supported USB version, control endpoint size and the
43 * number of device configurations. The descriptor is read out by the USB host when the enumeration 46 * number of device configurations. The descriptor is read out by the USB host when the enumeration
@@ -54,8 +57,8 @@ const USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor = @@ -54,8 +57,8 @@ const USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor =
54 57
55 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, 58 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
56 59
57 - .VendorID = 0x04B4, //A MODIFIER avec VendorID Carte  
58 - .ProductID = 0xFD11, //A MODIFIER 60 + .VendorID = VENDOR_ID,
  61 + .ProductID = PRODUCT_ID,
59 .ReleaseNumber = VERSION_BCD(2,0,0), 62 .ReleaseNumber = VERSION_BCD(2,0,0),
60 63
61 .ManufacturerStrIndex = STRING_ID_Manufacturer, 64 .ManufacturerStrIndex = STRING_ID_Manufacturer,
@@ -88,12 +91,12 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor @@ -88,12 +91,12 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor
88 }, 91 },
89 92
90 /* Description Interface SORTIE (LED)*/ 93 /* Description Interface SORTIE (LED)*/
91 - .InferfaceOUT = 94 + .InterfaceOUT =
92 { 95 {
93 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, 96 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
94 97
95 .InterfaceNumber = INTERFACE_ID_InterfaceOUT, 98 .InterfaceNumber = INTERFACE_ID_InterfaceOUT,
96 - .AlternateSetting = 0, 99 + .AlternateSetting = 0x00,
97 100
98 .TotalEndpoints = 1, 101 .TotalEndpoints = 1,
99 102
@@ -104,19 +107,6 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor @@ -104,19 +107,6 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor
104 .InterfaceStrIndex = NO_DESCRIPTOR 107 .InterfaceStrIndex = NO_DESCRIPTOR
105 }, 108 },
106 109
107 - /*  
108 - .HID_KeyboardHID =  
109 - {  
110 - .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},  
111 -  
112 - .HIDSpec = VERSION_BCD(1,1,1),  
113 - .CountryCode = 0x00,  
114 - .TotalReportDescriptors = 1,  
115 - .HIDReportType = HID_DTYPE_Report,  
116 - .HIDReportLength = sizeof(KeyboardReport)  
117 - },  
118 - */  
119 -  
120 .ReportOUTEndpoint = 110 .ReportOUTEndpoint =
121 { 111 {
122 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, 112 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
@@ -133,7 +123,7 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor @@ -133,7 +123,7 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor
133 { 123 {
134 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, 124 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
135 125
136 - .InterfaceNumber = INTERFACE_ID_InterfaceIN 126 + .InterfaceNumber = INTERFACE_ID_InterfaceIN,
137 .AlternateSetting = 0x00, 127 .AlternateSetting = 0x00,
138 128
139 .TotalEndpoints = 2, 129 .TotalEndpoints = 2,
@@ -163,7 +153,7 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor @@ -163,7 +153,7 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor
163 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 153 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
164 .EndpointSize = JOYSTICK_EPSIZE, 154 .EndpointSize = JOYSTICK_EPSIZE,
165 .PollingIntervalMS = 0x05 155 .PollingIntervalMS = 0x05
166 - } 156 + },
167 }; 157 };
168 158
169 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests 159 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
lufa-master/PolytechLille/PAD/Descriptors.h
@@ -52,7 +52,6 @@ @@ -52,7 +52,6 @@
52 52
53 // Relay Board Interface 53 // Relay Board Interface
54 USB_Descriptor_Interface_t InterfaceOUT; 54 USB_Descriptor_Interface_t InterfaceOUT;
55 - //USB_HID_Descriptor_HID_t HID_KeyboardHID; //UTILE ?  
56 USB_Descriptor_Endpoint_t ReportOUTEndpoint; 55 USB_Descriptor_Endpoint_t ReportOUTEndpoint;
57 56
58 USB_Descriptor_Interface_t InterfaceIN; 57 USB_Descriptor_Interface_t InterfaceIN;
@@ -84,15 +83,17 @@ @@ -84,15 +83,17 @@
84 83
85 /* Macros: */ 84 /* Macros: */
86 85
87 - 86 + /** Endpoint address of the Keyboard HID reporting OUT endpoint. */
  87 + #define KEYBOARD_OUT_EPADDR (ENDPOINT_DIR_OUT | 1)
  88 +
  89 +
88 /** Endpoint address of the Keyboard HID reporting IN endpoint. */ 90 /** Endpoint address of the Keyboard HID reporting IN endpoint. */
89 - #define KEYBOARD_IN_Bout_EPADDR (ENDPOINT_DIR_IN | 1) //Adr. EP Boutons  
90 - #define KEYBOARD_IN_Joy_EPADDR (ENDPOINT_DIR_IN | 1) //Adr. EP Joystick 91 + #define KEYBOARD_IN_Bout_EPADDR (ENDPOINT_DIR_IN | 2) //Adr. EP Boutons (direction | numéro du point d'accès)
  92 + #define KEYBOARD_IN_Joy_EPADDR (ENDPOINT_DIR_IN | 3) //Adr. EP Joystick
91 93
92 - /** Endpoint address of the Keyboard HID reporting OUT endpoint. */  
93 - #define KEYBOARD_OUT_EPADDR (ENDPOINT_DIR_OUT | 2)  
94 94
95 - /** Size in bytes of the Keyboard HID reporting IN and OUT endpoints. */ 95 +
  96 + /** Size in bytes of the PAD HID reporting IN and OUT endpoints. */
96 #define LED_EPSIZE 1 97 #define LED_EPSIZE 1
97 #define BOUTONS_EPSIZE 1 98 #define BOUTONS_EPSIZE 1
98 #define JOYSTICK_EPSIZE 2 99 #define JOYSTICK_EPSIZE 2
lufa-master/PolytechLille/PAD/PAD.c
@@ -38,6 +38,13 @@ @@ -38,6 +38,13 @@
38 #include "PAD.h" 38 #include "PAD.h"
39 39
40 40
  41 +#define debut_rcpt 0xff //valeur arbitraire pour détecter un début de trame
  42 +
  43 +uint8_t boutons;
  44 +uint8_t joystick_x;
  45 +uint8_t joystick_y;
  46 +
  47 +
41 /** Main program entry point. This routine contains the overall program flow, including initial 48 /** Main program entry point. This routine contains the overall program flow, including initial
42 * setup of all components and the main program loop. 49 * setup of all components and the main program loop.
43 */ 50 */
@@ -58,23 +65,23 @@ int main(void) @@ -58,23 +65,23 @@ int main(void)
58 /** Configures the board hardware and chip peripherals for the project's functionality. */ 65 /** Configures the board hardware and chip peripherals for the project's functionality. */
59 void SetupHardware(void) 66 void SetupHardware(void)
60 { 67 {
61 -#if (ARCH == ARCH_AVR8) 68 + #if (ARCH == ARCH_AVR8)
62 /* Disable watchdog if enabled by bootloader/fuses */ 69 /* Disable watchdog if enabled by bootloader/fuses */
63 MCUSR &= ~(1 << WDRF); 70 MCUSR &= ~(1 << WDRF);
64 wdt_disable(); 71 wdt_disable();
65 72
66 /* Disable clock division */ 73 /* Disable clock division */
67 clock_prescale_set(clock_div_1); 74 clock_prescale_set(clock_div_1);
68 - 75 + #endif
69 76
70 -/**INITIALISATIONS*/ 77 + /**INITIALISATIONS*/
71 /* Hardware Initialization */ 78 /* Hardware Initialization */
72 USB_Init(); 79 USB_Init();
73 - Serial_init(9600,0); //9600 Bauds, configuration 80 + Serial_Init(9600,0); //9600 Bauds, configuration
74 81
75 /* Initialize Relays */ 82 /* Initialize Relays */
76 - DDRD |= ALL_RELAYS; // Port pour la liaison série  
77 - PORTD &= ~ALL_RELAYS; 83 + //DDRD |= ALL_RELAYS; // Port pour la liaison série
  84 + //PORTD &= ~ALL_RELAYS;
78 } 85 }
79 86
80 87
@@ -85,10 +92,11 @@ void EVENT_USB_Device_ConfigurationChanged(void) @@ -85,10 +92,11 @@ void EVENT_USB_Device_ConfigurationChanged(void)
85 { 92 {
86 bool ConfigSuccess = true; 93 bool ConfigSuccess = true;
87 94
88 - /* Setup HID Report Endpoints */ //MODIFS ICI  
89 - ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_Bout_EPADDR, EP_TYPE_INTERRUPT, BOUTONS_EPSIZE, 1); 95 + /* Setup HID Report Endpoints */
  96 + ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPADDR, EP_TYPE_INTERRUPT, LED_EPSIZE, 1);
  97 + ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_Bout_EPADDR, EP_TYPE_INTERRUPT, BOUTONS_EPSIZE, 1);
90 ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_Joy_EPADDR, EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1); 98 ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_Joy_EPADDR, EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1);
91 - ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPADDR, EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1); 99 +
92 100
93 /* Turn on Start-of-Frame events for tracking HID report period expiry */ 101 /* Turn on Start-of-Frame events for tracking HID report period expiry */
94 USB_Device_EnableSOFEvents(); 102 USB_Device_EnableSOFEvents();
@@ -98,70 +106,77 @@ void EVENT_USB_Device_ConfigurationChanged(void) @@ -98,70 +106,77 @@ void EVENT_USB_Device_ConfigurationChanged(void)
98 } 106 }
99 107
100 108
101 -/** Sends the next HID report to the host, via the keyboard data endpoint. */  
102 -void SendNextReport(void) //Envoi liaison Série 109 +
  110 +/** Sends the next PAD report to the host, via the buttons and joystick endpoint. */
  111 +void Send_EP_IN_Report(void)
103 { 112 {
104 - static USB_KeyboardReport_Data_t PrevKeyboardReportData;  
105 - USB_KeyboardReport_Data_t KeyboardReportData;  
106 - bool SendReport = false; 113 + //static USB_KeyboardReport_Data_t PrevKeyboardReportData;
  114 + //USB_KeyboardReport_Data_t KeyboardReportData;
  115 + //bool SendReport = false;
107 116
108 /* Create the next keyboard report for transmission to the host */ 117 /* Create the next keyboard report for transmission to the host */
109 - CreateKeyboardReport(&KeyboardReportData); 118 + //CreateKeyboardReport(&KeyboardReportData);
110 119
111 /* Check if the idle period is set and has elapsed */ 120 /* Check if the idle period is set and has elapsed */
112 - if (IdleCount && (!(IdleMSRemaining)))  
113 - { 121 + //if (IdleCount && (!(IdleMSRemaining)))
  122 + //{
114 /* Reset the idle time remaining counter */ 123 /* Reset the idle time remaining counter */
115 - IdleMSRemaining = IdleCount; 124 + // IdleMSRemaining = IdleCount;
116 125
117 /* Idle period is set and has elapsed, must send a report to the host */ 126 /* Idle period is set and has elapsed, must send a report to the host */
118 - SendReport = true;  
119 - }  
120 - else  
121 - { 127 + //SendReport = true;
  128 + //}
  129 + //else
  130 + //{
122 /* Check to see if the report data has changed - if so a report MUST be sent */ 131 /* Check to see if the report data has changed - if so a report MUST be sent */
123 - SendReport = (memcmp(&PrevKeyboardReportData, &KeyboardReportData, sizeof(USB_KeyboardReport_Data_t)) != 0);  
124 - } 132 + //SendReport = (memcmp(&PrevKeyboardReportData, &KeyboardReportData, sizeof(USB_KeyboardReport_Data_t)) != 0);
  133 + //}
125 134
126 135
127 /** Envoi sur INTERFACE BOUTONS**/ 136 /** Envoi sur INTERFACE BOUTONS**/
128 - /* Select the Keyboard Report Endpoint */ 137 + /* Select the Buttons Report Endpoint */
129 Endpoint_SelectEndpoint(KEYBOARD_IN_Bout_EPADDR); 138 Endpoint_SelectEndpoint(KEYBOARD_IN_Bout_EPADDR);
130 139
131 /* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */ 140 /* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */
132 - if (Endpoint_IsReadWriteAllowed() && SendReport) 141 + if (Endpoint_IsReadWriteAllowed() && Endpoint_IsINReady)
133 { 142 {
134 /* Save the current report data for later comparison to check for changes */ 143 /* Save the current report data for later comparison to check for changes */
135 - PrevKeyboardReportData = KeyboardReportData; 144 + //PrevKeyboardReportData = KeyboardReportData;
136 145
137 /* Write Keyboard Report Data */ 146 /* Write Keyboard Report Data */
138 - Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData), NULL); 147 + //Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData), NULL);
  148 + Endpoint_Write_8(boutons);
139 149
140 /* Finalize the stream transfer to send the last packet */ 150 /* Finalize the stream transfer to send the last packet */
141 Endpoint_ClearIN(); 151 Endpoint_ClearIN();
142 } 152 }
  153 + else printf("Buttons endpoint not ready to send\n");
143 154
144 /** Envoi sur INTERFACE Joystick**/ 155 /** Envoi sur INTERFACE Joystick**/
145 /* Select the Keyboard Report Endpoint */ 156 /* Select the Keyboard Report Endpoint */
146 Endpoint_SelectEndpoint(KEYBOARD_IN_Joy_EPADDR); 157 Endpoint_SelectEndpoint(KEYBOARD_IN_Joy_EPADDR);
147 158
148 /* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */ 159 /* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */
149 - if (Endpoint_IsReadWriteAllowed() && SendReport) 160 + if (Endpoint_IsReadWriteAllowed() && Endpoint_IsINReady)
150 { 161 {
151 /* Save the current report data for later comparison to check for changes */ 162 /* Save the current report data for later comparison to check for changes */
152 - PrevKeyboardReportData = KeyboardReportData; 163 + //PrevKeyboardReportData = KeyboardReportData;
153 164
154 /* Write Keyboard Report Data */ 165 /* Write Keyboard Report Data */
155 - Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData), NULL); 166 + //Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData), NULL);
  167 + Endpoint_Write_8(joystick_x);
  168 + Endpoint_Write_8(joystick_y);
156 169
157 /* Finalize the stream transfer to send the last packet */ 170 /* Finalize the stream transfer to send the last packet */
158 Endpoint_ClearIN(); 171 Endpoint_ClearIN();
159 } 172 }
  173 + else printf("Joystick endpoint not ready to send\n");
160 } 174 }
161 175
162 176
  177 +
163 /** Reads the next LED status report from the host from the LED data endpoint, if one has been sent. */ 178 /** Reads the next LED status report from the host from the LED data endpoint, if one has been sent. */
164 -void ReceiveNextReport(void) //Réception Liaison Série 179 +void Receive_EP_OUT_Report(void) //Réception Liaison Série
165 { 180 {
166 /* Select the Keyboard LED Report Endpoint */ 181 /* Select the Keyboard LED Report Endpoint */
167 Endpoint_SelectEndpoint(KEYBOARD_OUT_EPADDR); 182 Endpoint_SelectEndpoint(KEYBOARD_OUT_EPADDR);
@@ -175,11 +190,47 @@ void ReceiveNextReport(void) //Réception Liaison Série @@ -175,11 +190,47 @@ void ReceiveNextReport(void) //Réception Liaison Série
175 /* Read in the LED report from the host */ 190 /* Read in the LED report from the host */
176 uint8_t LEDReport = Endpoint_Read_8(); 191 uint8_t LEDReport = Endpoint_Read_8();
177 192
178 - /* Process the read LED report from the host */  
179 - ProcessLEDReport(LEDReport); 193 + /* On envoie l'octet de commande de led sur la liaison série */
  194 + Serial_SendByte(LEDReport);
180 } 195 }
  196 + else printf("LED endpoint not ready to receive\n");
181 197
182 /* Handshake the OUT Endpoint - clear endpoint and ready for next report */ 198 /* Handshake the OUT Endpoint - clear endpoint and ready for next report */
183 Endpoint_ClearOUT(); 199 Endpoint_ClearOUT();
184 } 200 }
185 } 201 }
  202 +
  203 +
  204 +
  205 +void Reception_Serie(void){
  206 + if(Serial_IsCharReceived()){ // A la réception d'un caractère...
  207 + /* on vérifie qu'on a bien un début de trame*/
  208 + unsigned char caractere = Serial_ReceiveByte();
  209 +
  210 + /* si oui, on récupère les trois octets suivants*/
  211 + if (caractere==debut_rcpt){
  212 + boutons = Serial_ReceiveByte();
  213 + joystick_x = Serial_ReceiveByte();
  214 + joystick_y = Serial_ReceiveByte();
  215 + }
  216 + }
  217 +}
  218 +
  219 +
  220 +/** Function to manage PAD report generation and transmission to the host, when in report mode. */
  221 +void PAD_Task(void)
  222 +{
  223 + /* Device must be connected and configured for the task to run */
  224 + if (USB_DeviceState != DEVICE_STATE_Configured)
  225 + return;
  226 +
  227 + Reception_Serie(); //Réception des données de la liaison série
  228 +
  229 + /* Send the next button/joystick report to the host */
  230 + Send_EP_IN_Report();
  231 +
  232 + /* Process the LED report sent from the host */
  233 + Receive_EP_OUT_Report();
  234 +}
  235 +
  236 +
lufa-master/PolytechLille/PAD/PAD.h
@@ -46,9 +46,9 @@ @@ -46,9 +46,9 @@
46 #include "Descriptors.h" 46 #include "Descriptors.h"
47 47
48 //#include <LUFA/Drivers/Board/LEDs.h> 48 //#include <LUFA/Drivers/Board/LEDs.h>
49 - //#include <LUFA/Drivers/PeripheralSerial.h> //inventé?  
50 #include <LUFA/Drivers/USB/USB.h> 49 #include <LUFA/Drivers/USB/USB.h>
51 #include <LUFA/Platform/Platform.h> 50 #include <LUFA/Platform/Platform.h>
  51 + #include "LUFA/Drivers/Peripheral/Serial.h"
52 52
53 /* Macros: */ 53 /* Macros: */
54 54
@@ -56,9 +56,10 @@ @@ -56,9 +56,10 @@
56 /* Function Prototypes: */ 56 /* Function Prototypes: */
57 void SetupHardware(void); 57 void SetupHardware(void);
58 void EVENT_USB_Device_ConfigurationChanged(void); 58 void EVENT_USB_Device_ConfigurationChanged(void);
59 - void SendNextReport(void);  
60 - void ReceiveNextReport(void);  
61 - //void EVENT_USB_Device_ControlRequest(void); 59 + void Send_EP_IN_Report(void);
  60 + void Receive_EP_OUT_Report(void);
  61 + void Reception_Serie(void);
  62 + void PAD_Task(void);
62 63
63 #endif 64 #endif
64 65
@@ -3,9 +3,10 @@ @@ -3,9 +3,10 @@
3 3
4 // For the serial port 4 // For the serial port
5 5
6 -#define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz  
7 -#define tempo 25  
8 -#define debit 9600 //débit liaison série en bauds 6 +#define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz
  7 +#define tempo 25
  8 +#define debit 9600 //débit liaison série en bauds
  9 +#define debut_serial_tx 0xff //pour détecter la transmission d'une trame pour le 16u2
9 10
10 void init_serial(int speed) 11 void init_serial(int speed)
11 { 12 {
@@ -24,40 +25,40 @@ UCSR0A &amp;= ~(1 &lt;&lt; U2X0); @@ -24,40 +25,40 @@ UCSR0A &amp;= ~(1 &lt;&lt; U2X0);
24 25
25 void send_serial(unsigned char c) 26 void send_serial(unsigned char c)
26 { 27 {
27 -loop_until_bit_is_set(UCSR0A, UDRE0);  
28 -UDR0 = c; 28 + loop_until_bit_is_set(UCSR0A, UDRE0);
  29 + UDR0 = c;
29 } 30 }
30 31
31 unsigned char get_serial(void) { 32 unsigned char get_serial(void) {
32 -loop_until_bit_is_set(UCSR0A, RXC0);  
33 -return UDR0; 33 + loop_until_bit_is_set(UCSR0A, RXC0);
  34 + return UDR0;
34 } 35 }
35 36
36 // For the AD converter 37 // For the AD converter
37 38
38 void ad_init(unsigned char channel) 39 void ad_init(unsigned char channel)
39 { 40 {
40 -ADCSRA|=(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);  
41 -ADMUX|=(1<<REFS0)|(1<<ADLAR);  
42 -ADMUX=(ADMUX&0xf0)|channel;  
43 -ADCSRA|=(1<<ADEN); 41 + ADCSRA|=(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
  42 + ADMUX|=(1<<REFS0)|(1<<ADLAR);
  43 + ADMUX=(ADMUX&0xf0)|channel;
  44 + ADCSRA|=(1<<ADEN);
44 } 45 }
45 46
46 //récupère la valeur de l'ADCH 47 //récupère la valeur de l'ADCH
47 unsigned int ad_sample(void){ 48 unsigned int ad_sample(void){
48 -ADCSRA|=(1<<ADSC);  
49 -while(bit_is_set(ADCSRA, ADSC));  
50 -return ADCH; 49 + ADCSRA|=(1<<ADSC);
  50 + while(bit_is_set(ADCSRA, ADSC));
  51 + return ADCH;
51 } 52 }
52 53
53 // For the I/O 54 // For the I/O
54 void output_init(void){ 55 void output_init(void){
55 -DDRB |= 0b00111111; // PIN 8-13 as output (LED) 56 + DDRB |= 0b00111111; // PIN 8-13 as output (LED)
56 } 57 }
57 58
58 /* 59 /*
59 void output_set(unsigned char value){ 60 void output_set(unsigned char value){
60 -if(value==0) PORTB &= 0xfe; else PORTB |= 0x01; 61 + if(value==0) PORTB &= 0xfe; else PORTB |= 0x01;
61 } 62 }
62 */ 63 */
63 64
@@ -68,7 +69,7 @@ void input_init(void){ @@ -68,7 +69,7 @@ void input_init(void){
68 69
69 /* 70 /*
70 unsigned char input_get(void){ 71 unsigned char input_get(void){
71 -return ((PIND&0x04)!=0)?1:0; 72 + return ((PIND&0x04)!=0)?1:0;
72 } 73 }
73 */ 74 */
74 75
@@ -116,59 +117,61 @@ unsigned char shape_joy(unsigned char pos){ @@ -116,59 +117,61 @@ unsigned char shape_joy(unsigned char pos){
116 117
117 /* Récupération de la valeur de l'axe du joystick sur la chaîne channel du CAN */ 118 /* Récupération de la valeur de l'axe du joystick sur la chaîne channel du CAN */
118 unsigned char get_joystick(int channel){ 119 unsigned char get_joystick(int channel){
119 - unsigned char axis;  
120 - ad_init(channel);  
121 - axis = ad_sample();  
122 - axis = shape_joy(axis);  
123 - return axis; 120 + unsigned char axis;
  121 + ad_init(channel);
  122 + axis = ad_sample();
  123 + axis = shape_joy(axis);
  124 + return axis;
124 } 125 }
125 126
126 /* Dummy main */ 127 /* Dummy main */
127 int main(void){ 128 int main(void){
128 129
129 //INITIALISATIONS 130 //INITIALISATIONS
130 - unsigned char boutons, boutons_anc;  
131 - unsigned char joystick_x=0x10, joystick_x_anc=0x10;  
132 - unsigned char joystick_y=0x10, joystick_y_anc=0x10; 131 + unsigned char boutons, boutons_anc;
  132 + unsigned char joystick_x=0x10, joystick_x_anc=0x10;
  133 + unsigned char joystick_y=0x10, joystick_y_anc=0x10;
133 134
134 - init_serial(debit);  
135 - output_init();  
136 - input_init(); 135 + init_serial(debit);
  136 + output_init();
  137 + input_init();
137 138
138 //Récupération des valeurs des boutons et joystick, et mise en forme 139 //Récupération des valeurs des boutons et joystick, et mise en forme
139 - boutons = get_buttons();  
140 - joystick_x = get_joystick(0);  
141 - joystick_y = get_joystick(1); 140 + boutons = get_buttons();
  141 + joystick_x = get_joystick(0);
  142 + joystick_y = get_joystick(1);
142 143
143 - while(1){ 144 + while(1){
144 boutons_anc = boutons; 145 boutons_anc = boutons;
145 joystick_x_anc = joystick_x; 146 joystick_x_anc = joystick_x;
146 joystick_y_anc = joystick_y; 147 joystick_y_anc = joystick_y;
147 148
148 - //Récupération des valeurs des boutons et joystick, et mise en forme  
149 - boutons = get_buttons();  
150 - joystick_x = get_joystick(0);  
151 - _delay_ms(tempo);  
152 - joystick_y = get_joystick(1); 149 + //Récupération des valeurs des boutons et joystick, et mise en forme
  150 + boutons = get_buttons();
  151 + joystick_x = get_joystick(0);
  152 + _delay_ms(tempo);
  153 + joystick_y = get_joystick(1);
153 154
154 - //Port série libre  
155 - if ((UCSR0A & (1<<RXC0)) == 0){  
156 - // Si une des grandeurs a changé  
157 - if ((boutons_anc != boutons) || (joystick_x_anc != joystick_x) || (joystick_y_anc != joystick_y)){  
158 - send_serial(boutons); //on envoie l'état global des grandeurs  
159 - send_serial(joystick_x);  
160 - send_serial(joystick_y);  
161 - //retour chariot  
162 - send_serial(0x0a);  
163 - send_serial(0x0d); 155 + //Port série libre
  156 + if ((UCSR0A & (1<<RXC0)) == 0){
  157 + // Si une des grandeurs a changé
  158 + if ((boutons_anc != boutons) || (joystick_x_anc != joystick_x) || (joystick_y_anc != joystick_y)){
  159 + /* On envoie la trame des grandeurs */
  160 + send_serial(debut_serial_tx); //début de trame
  161 + send_serial(boutons); //état global des grandeurs
  162 + send_serial(joystick_x);
  163 + send_serial(joystick_y);
  164 + //retour chariot
  165 + send_serial(0x0a);
  166 + send_serial(0x0d);
164 } 167 }
165 } 168 }
166 169
167 //Port série occupé 170 //Port série occupé
168 else{ 171 else{
169 - commande_leds(); //On gère la commande des leds 172 + commande_leds(); //On gère la commande des leds
170 } 173 }
171 - } 174 + }
172 return 0; 175 return 0;
173 } 176 }
174 177