From 3966cf832747682d6e7156b8c4bf7b8f0dfae5ee Mon Sep 17 00:00:00 2001 From: rguillom Date: Mon, 20 Jan 2020 12:16:53 +0100 Subject: [PATCH] modifs diverses : valeur octet début de trame, main.c, débogage init_USB.c, README --- Pgm PC/init_USB.c | 46 +++++++++++++++++++++++++++++----------------- README.md | 29 ++++++++++++++++++----------- lufa-master/PolytechLille/PAD/Descriptors.c | 2 +- lufa-master/PolytechLille/PAD/Descriptors.h | 2 +- lufa-master/PolytechLille/PAD/PAD.c | 7 ++++--- main.c | 2 +- 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/Pgm PC/init_USB.c b/Pgm PC/init_USB.c index f9c71cc..6ede487 100644 --- a/Pgm PC/init_USB.c +++ b/Pgm PC/init_USB.c @@ -69,7 +69,7 @@ void enum_periph(){ } -void config_periph(char tab_PA[TAB_PA_SIZE]){ +void config_periph(unsigned char tab_PA[TAB_PA_SIZE]){ /* Récupération de la 1ère configuration du périphérique (indice 0) */ struct libusb_config_descriptor *config_desc=NULL; @@ -93,6 +93,8 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){ /* Utilisation de la configuration */ + + int dernier_PA=-1; int configuration=config_desc->bConfigurationValue; //printf("valeur config %d\n", configuration); // Affichage valeur de la configuration @@ -112,15 +114,15 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){ /* Parcours des points d'accès (Endpoint) pour chaque interface*/ - for(int num_PA=0;num_PAinterface[indice_intf].altsetting[0].bNumEndpoints ;num_PA++){ + for(int num_PA=0;num_PAinterface[indice_intf].altsetting[0].bNumEndpoints ;num_PA++){ + int type_PA = config_desc->interface[indice_intf].altsetting[0].endpoint[num_PA].bmAttributes; uint8_t adresse_PA = config_desc->interface[indice_intf].altsetting[0].endpoint[num_PA].bEndpointAddress; printf("\t\tPoint d'accès trouvé. Adresse : %d\n",adresse_PA); /* Regarde si le point d'accès est de type interruption. Si oui, on le sauvegarde. */ - int dernier_PA=-1; if((type_PA & 0b11)==LIBUSB_TRANSFER_TYPE_INTERRUPT){ //struct EP ep1; dernier_PA++; @@ -143,8 +145,10 @@ void config_periph(char tab_PA[TAB_PA_SIZE]){ // Le if et else ci-dessus doivent pouvoir être simplifiés. */ } - } + + } } + //printf("dernier indice tab_PA : %d\n", dernier_PA); } @@ -175,6 +179,7 @@ void liberer_interfaces(){ void send_data(unsigned char tab_PA[TAB_PA_SIZE], unsigned char data){ unsigned char PA = tab_PA[0]; //LEDs sur le premier point d'accès + printf("adresse PA %d\n", tab_PA[0]); int transferred = 1; //nombre d'octets transférés unsigned int timeout = 1000; //temps avant un timeout int status = libusb_interrupt_transfer(handle, PA, &data, sizeof(data), &transferred, timeout); @@ -187,16 +192,18 @@ void receive_data(unsigned char tab_PA[TAB_PA_SIZE], unsigned char *boutons, uns /* Lecture du point d'accès des boutons */ unsigned char PA = tab_PA[1]; //LEDs sur le premier point d'accès + printf("adresse PA %d\n", tab_PA[1]); int transferred = 1; //nombre d'octets transférés unsigned int timeout = 1000; //temps avant un timeout int status = libusb_interrupt_transfer(handle, PA, boutons, sizeof(boutons), &transferred, timeout); - if(status!=0){perror("libusb_interrupt_transfer");exit(-1);} + if(status!=0){perror("libusb_interrupt_transfer");printf("erreur lecture boutons, adresse PA %d\n",tab_PA[1]);exit(-1);} /* Lecture du point d'accès du joystick */ unsigned char *joystick_xy=NULL; //stocke la donnée du point d'accès (1 octet pour chaque axe) PA = tab_PA[2]; //LEDs sur le premier point d'accès + printf("adresse PA %d\n", tab_PA[2]); transferred = 2; //nombre d'octets transférés timeout = 1000; //temps avant un timeout @@ -229,33 +236,38 @@ int main(){ if(status_ouv!=0){ perror("libusb_open"); exit(-1); } /* Configuration du périphérique et sauvegarde des points d'accès */ - char tab_PA[TAB_PA_SIZE]; + unsigned char tab_PA[TAB_PA_SIZE]; config_periph(tab_PA); - unsigned char *boutons, *boutons_anc = NULL; - unsigned char *joystick_x, *joystick_x_anc = NULL; - unsigned char *joystick_y, *joystick_y_anc = NULL; + unsigned char *boutons = NULL, *boutons_anc = NULL; + unsigned char *joystick_x = NULL, *joystick_x_anc = NULL; + unsigned char *joystick_y = NULL, *joystick_y_anc = NULL; unsigned char caractere; - /* - //boucle while(pas d'arrêt), envoi et rcpt - // "pas d'arrêt" = appui sur 's' par exemple - - if (appui sur une touche){ + + //TODO boucle while(pas d'arrêt), envoi et rcpt + //TODO "pas d'arrêt" = appui sur 's' par exemple + + while(1){ + /*if (appui sur une touche){ //récupération caractère send_data(tab_PA, caractere); //Envoi de la commande des leds } else { + */ + printf("début rcpt\n"); receive_data(tab_PA, boutons, joystick_x, joystick_y); //Réception des boutons et joystick + printf("fin rcpt\n"); + if ((boutons == NULL) || (joystick_x == NULL) || (joystick_y == NULL)) printf("Erreur réception : pointeurs boutons ou joystick nul\n"); 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 *boutons_anc = *boutons; *joystick_x_anc = *joystick_x; *joystick_y_anc = *joystick_y; - } - + //} - */ + } + //*/ /* Libération des interfaces*/ liberer_interfaces(); diff --git a/README.md b/README.md index 8e78d69..4b63d9d 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,11 @@ Pour compiler, lancer et ultiliser les programmes : \>lsusb -On doit voir Arduino apparaitre. +On doit voir une ligne "Arduino SA Uno (CDC ACM)" apparaître. -Si flashée : enregistrer le binaire du lien : https://raw.githubusercontent.com/arduino/ArduinoCore-avr/master/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-uno.hex +Si elle est déjà flashée, il faut enregistrer le binaire du lien : https://raw.githubusercontent.com/arduino/ArduinoCore-avr/master/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-uno.hex + +Court-circuiter les broches GND et RESET de l'ATMega16U2 sur l'ICSP de ce micro-contrôleur Puis écrire : @@ -24,40 +26,45 @@ Puis écrire : \>dfu-programmer atmega16u2 reset +Débrancher et rebrancher le port USB de la carte. Étape 2 : -Compiler et Upload le programme main.c sur l'arduino. - -\>gcc -o main main.c -Wall (pas sur que ce soit nécessaire) +Compiler et charger le programme main.c sur l'arduino. \>make all \>make upload -(Remarque : On peut tester ce progrmme directement avec :) +Passer en root pour l'upload si nécessaire. + +Remarque : Nous pouvons tester ce progrmme directement avec : + +\>minicom -8 -o -b 9600 -D /dev/ttyACM0 -\>minicom -8 -o -b 9600 -D /dev/ttyACM0 Le programme est maintenant sur l'Arduino. Étape 3: Flasher la carte -\>cd lufa-master/ - -\>cd PolytechLille PAD/ +\>cd lufa-master/PolytechLille/PAD/ \>make all +Court-circuiter les broches GND et RESET de l'ATMega16U2 sur l'ICSP de ce micro-contrôleur + \>dfu-programmer atmega16u2 erase \>dfu-programmer atmega16u2 flash PAD.hex \>dfu-programmer atmega16u2 reset +Débrancher et rebrancher le port USB de la carte. + Étape 4: Compiler la partie 1 et l'exécuter. +\>cd ../../../Pgm\ PC/ \>gcc -o exe init_USB.c -lusb-1.0 -Wall -Wextra \>./exe @@ -68,4 +75,4 @@ Ce qui marche : _ La Partie 2, fonctionne correctement et compile sans warnings. -Ce qui ne marche pas : (La partie 3 marche-t-elle ?) \ No newline at end of file +Ce qui ne marche pas : (La partie 3 marche-t-elle ?) diff --git a/lufa-master/PolytechLille/PAD/Descriptors.c b/lufa-master/PolytechLille/PAD/Descriptors.c index f07693e..233b4bc 100644 --- a/lufa-master/PolytechLille/PAD/Descriptors.c +++ b/lufa-master/PolytechLille/PAD/Descriptors.c @@ -153,7 +153,7 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = JOYSTICK_EPSIZE, .PollingIntervalMS = 0x05 - }, + } }; /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests diff --git a/lufa-master/PolytechLille/PAD/Descriptors.h b/lufa-master/PolytechLille/PAD/Descriptors.h index d86a40e..975348d 100644 --- a/lufa-master/PolytechLille/PAD/Descriptors.h +++ b/lufa-master/PolytechLille/PAD/Descriptors.h @@ -56,7 +56,7 @@ USB_Descriptor_Interface_t InterfaceIN; USB_Descriptor_Endpoint_t ReportINEndpointBoutons; - USB_Descriptor_Endpoint_t ReportOUTEndpointJoystick; + USB_Descriptor_Endpoint_t ReportINEndpointJoystick; } USB_Descriptor_Configuration_t; /** Enum for the device interface descriptor IDs within the device. Each interface descriptor diff --git a/lufa-master/PolytechLille/PAD/PAD.c b/lufa-master/PolytechLille/PAD/PAD.c index 274eb73..e1f8f63 100644 --- a/lufa-master/PolytechLille/PAD/PAD.c +++ b/lufa-master/PolytechLille/PAD/PAD.c @@ -38,7 +38,7 @@ #include "PAD.h" -#define debut_rcpt 0xff //valeur arbitraire pour détecter un début de trame +#define debut_rcpt 0x40 //valeur arbitraire pour détecter un début de trame uint8_t boutons; uint8_t joystick_x; @@ -59,6 +59,7 @@ int main(void) { USB_USBTask(); //HID_Task(); + PAD_Task(); } } @@ -138,7 +139,7 @@ void Send_EP_IN_Report(void) Endpoint_SelectEndpoint(KEYBOARD_IN_Bout_EPADDR); /* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */ - if (Endpoint_IsReadWriteAllowed() && Endpoint_IsINReady) + if (Endpoint_IsReadWriteAllowed() && Endpoint_IsINReady()) { /* Save the current report data for later comparison to check for changes */ //PrevKeyboardReportData = KeyboardReportData; @@ -157,7 +158,7 @@ void Send_EP_IN_Report(void) Endpoint_SelectEndpoint(KEYBOARD_IN_Joy_EPADDR); /* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */ - if (Endpoint_IsReadWriteAllowed() && Endpoint_IsINReady) + if (Endpoint_IsReadWriteAllowed() && Endpoint_IsINReady()) { /* Save the current report data for later comparison to check for changes */ //PrevKeyboardReportData = KeyboardReportData; diff --git a/main.c b/main.c index c8fa00d..e20263e 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ #define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz #define tempo 25 #define debit 9600 //débit liaison série en bauds -#define debut_serial_tx 0xff //pour détecter la transmission d'une trame pour le 16u2 +#define debut_serial_tx 0x40 //pour détecter la transmission d'une trame pour le 16u2 void init_serial(int speed) { -- libgit2 0.21.2