Recalbox Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • recalbox.com
    • Gitlab repository
    • Documentation
    • Discord

    Solved Retrode

    Emulateurs Arcade/PC/Console
    dualboot openel
    8
    152
    74999
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • acris
      acris last edited by

      Ds emulationstation les deux manettes sont reconnus ou pas ? Tu as.mis joueur 1 et joueur 2 le fichier de config ? essaie ds retodecustom.cfg de commenter cette ligne #joypad_autoconfig_dir = /recalbox/configs/retroarch/inputs/

      1 Reply Last reply Reply Quote 0
      • une-fille-etoilee
        une-fille-etoilee last edited by

        dans emulation station, j'ai qu'une seule manette de reconnue,  "#0 matthias hullin retrode". que je l'affecte seulement au joueur 1 ou au joueur 1 et 2, c'est pareil dans quel fichier config faut il que je mette joueur 1 et 2 ? et enfin, j'ai commentée la ligne que tu m'a dit de commenter..... aucune amélioration

        1 Reply Last reply Reply Quote 0
        • acris
          acris last edited by

          Bouton start > configuration manette > manette joueur 1 #0 et manette joueur 2 #0 peux tu me poster ton fichier retrodecustom.cfg entièrement. apparemment le retrode se comporte comme les controleurs xi-mo il voit qu'un seul truc. met en commentaire tout ses lignes : #input_player1_joypad_index = 0 #input_player2_joypad_index = 1 #input_player3_joypad_index = 2 #input_player4_joypad_index = 3 #input_player1_analog_dpad_mode = « 0 » #input_player2_analog_dpad_mode = « 1 » #input_player3_analog_dpad_mode = « 1 » #input_player4_analog_dpad_mode = « 1 » reboot le rpi vérifie les droits sur ton fichier retrodecustom.cfg et retrodecontroller.cfg soit bien en 0775 tests de nouveaux avec les deux manettes

          1 Reply Last reply Reply Quote 0
          • une-fille-etoilee
            une-fille-etoilee last edited by

            <span style="color: #737c85; font-family: 'Open Sans', sans-serif; font-size: 12px; line-height: 26px;">Bouton start > configuration manette > manette joueur 1 #0 et manette joueur 2 #0</span> ca je l'ai fait, ca change rien....manette 1 tout marche, manette 2, j'ai que la croix et elle est reconnue dans le jeu comme manette 1   je te joint mon retrodecustom.cfg

            core_options_path = /recalbox/configs/retroarch/cores/retroarch-core-options.cfg   system_directory = /recalbox/share/bios/   config_save_on_exit = false   video_threaded = true   #video_aspect_ratio = 1.33 #aspect_ratio_index = "21" #aspect_ratio_index = "0" #video_force_aspect = false video_aspect_ratio_auto = true #video_scale_integer = true   rewind_enable = false rewind_buffer_size = 10 rewind_granularity = 2   video_gpu_screenshot = true   video_shader = "/recalbox/share/system/shaders/scanline.glsl"   video_shader_dir = "/recalbox/share/system/shaders/"   video_shader_enable = "true"   screenshot_directory = /recalbox/share/screenshots/ savestate_directory = /recalbox/share/retrode/ savefile_directory = /recalbox/share/retrode/ extraction_directory = /recalbox/share/extractions/   fastforward_ratio = -1.0 input_autodetect_enable = true   #joypad_autoconfig_dir = /recalbox/configs/retroarch/inputs/   input_player1_analog_dpad_mode = "0" input_player2_analog_dpad_mode = "1" input_player3_analog_dpad_mode = "1" input_player4_analog_dpad_mode = "1"   input_enable_hotkey_btn = 2   input_enable_hotkey = "escape" input_exit_emulator = "escape"   input_player1_joypad_index = 0 input_player2_joypad_index = 1 input_player3_joypad_index = 2 input_player4_joypad_index = 3

            j'ai mis en commentaire les 8 lignes sur le retrodecustom.cfg et vérifié que retrodecustom.cfg et retrodecontroller.cfg soient en 0775 toujours le meme  comportement....   c'est fou cette affaire....surtout que le machin est prévu pour les 2 manettes, doit bien y avoir un moyen...   le site du retrode me donne des code hexa pour l'affectation des manettes

            [kbL] 06 1b 28 2c 52 51 50 4f 09 07 04 16 [kbR] 10 11 05 19 33 37 36 38 0e 0d 0a 0b <span style="color: #000000; font-family: arial, sans-serif; font-size: 13px; line-height: normal;">SNES controllers, the order is B Y SELECT START UP DOWN LEFT RIGHT A X L R</span>

            y'a pas moyen de dire a recalbox d'aller chercher cet adressage la ?

            1 Reply Last reply Reply Quote 0
            • acris
              acris last edited by

              Salut je ne vois pas comment on pourrait faire pour les codes hex. J 'avoue que c'est difficile de regler ses problèmes sans avoir le retrode. le problème étant que recalbox crée un seul fichier de configuration pour le même type de manette. C'est "un problème" connu. La seule astuce pour le moment est d'utiliser deux manettes différentes. Là tu m'as dit que ça fonctionnait. Ou de t'offir une manette compatible recalbox pour la brancher directement sur le port usb du rpi.

              1 Reply Last reply Reply Quote 0
              • une-fille-etoilee
                une-fille-etoilee last edited by

                J'imagine, difficile de bosser sans le matos....t'habite pas en provence par hasard ? le problème n'est pas tant d'avoir 2 manettes...j'ai aussi un dongle bluetooth et mes manettes ps3....l'idée c'est que j'aurais voulu utiliser les 2 manettes d'origine pour intégrer tout ca dans une belle snes histoire qu'extérieurement parlant, tout ressemble a une snes d'origine... si c'est pas possible de faire mieux, c'est pas un drame, te prends pas la tete....t'a deja fais beaucoup. si je peux vraiment pas utiliser plus d'une manette avec le retrode, au pire, je m’achète un adaptateur snes-usb supplépentaire pour la 2eme...ca vaut 20 euros...c'est pas la mort... pareil pour la lenteur au démarrage....c'est chiant, mais c'est pas non plus monstrueux....le plus important etait de se servir de la cartouche d'origine et que sa sauvegarde marche...c'est chose faite.. le reste, c'est si tu veut continuer a te triturer les méninges pour rendre l'expérience encore plus simple... tiens, j'ai pensé a ca aussi....j'ai vu qu'il était possible d'utiliser le port GPIO pour simuler le bouton esc du clavier....j'aimerais bien cabler le bouton reset de ma console pour revenir au menu emulationstation....ca a deja été traité dans le forum ?

                1 Reply Last reply Reply Quote 0
                • acris
                  acris last edited by

                  Salut Violene, nop j'habite en Suisse Oui si c'est une question d’esthétisme j'aime aussi "recyclé" le matos que j'ai déja. Juste pour les personnes qui auraient suivi ce sujet il existe des manettes SNES en usb si jamais retrolink SNES et SFC30 8bitdo A ma connaissance le gpio + esc du clavier n'a jamais été traité sur le forum.¨ pour sortir du jeu et revenir sur emulationstation hotkey+start (select+start) ne fonctionne pas ? Pour la lenteur j'ai lu un tweet où une personne demandait si matthieu avait trouvé une solution pour le transfert limité entre un rpi et le retrode.

                  @Retrode Hi Matthias, have you ever solved the slow transfer problem when you connect a Retrode to a RPi ? i get 45KB/s it's frustrating.

                  1 Reply Last reply Reply Quote 0
                  • une-fille-etoilee
                    une-fille-etoilee last edited by

                    si, select+start fonctionne....c'est juste pour pouvoir transformer le bouton reset en un bien plus sympatique bouton de retour au menu... ca m'est venu a l'idée en lisant ca sur un forum

                    <br style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.2399997711182px; background-color: #fefeff;" /><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.2399997711182px; background-color: #fefeff;">- utiliser le bouton RESET pour revenir au menu de selection des jeux</span><br style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.2399997711182px; background-color: #fefeff;" /><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.2399997711182px; background-color: #fefeff;">tuto :</span>https://learn.adafruit.com/retro-gaming-with-raspberry-pi/overview<br style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.2399997711182px; background-color: #fefeff;" /><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.2399997711182px; background-color: #fefeff;">Download : </span>https://github.com/adafruit/Adafruit-Retrogame<br style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.2399997711182px; background-color: #fefeff;" /><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.2399997711182px; background-color: #fefeff;">c'est un super programme qui simule les touche du clavier par contact avec les gpio. En gros tu relie les contacts du bouton reset avec la terre et la gpio numero X et dans le programme tu dis que la gpio X correspond à la touche escape et quand t'appuie sur reset sa reviens au menu de sélection.</span>

                    mais je t'avoue que j'ai pas compris grand chose....et je ne sais meme pas si ce truc a télécharger...adafruit, est compatible avec recalbox...   pour le problème de lenteur, c'est sur que 45Kb/s, c'est peu...c'est peut etre la puce atmel qui sers au décodage de tout ca qui pose problème... pense tu qu'il serait possible de forcer une mise en cache du contenu du retrode dès le démarage de recalbox ? je me doute de la réponse...on est plus dans l'ajout d'un périphérique la mais dans le tripatouillage d'entraille...faut reconnaitre que c'est frustrant d'avoir un pi qui a 1Go de ram et d'etre limité a cause d'une lenteur de transfert...

                    1 Reply Last reply Reply Quote 0
                    • acris
                      acris last edited by

                      Non ce n'est pas "compatible" on ne peut pas installer quoi que ce soit sur recalboxOS via apt-get comme ça pourrait être le cas avec RASPBian. faudrait voir avec retroboy si il y a moyen d adapter ou intégré. passe sur le canal IRC si jamais il passe parfois le soir https://kiwiirc.com/client/irc.freenode.net/#recalbox La mise en cache je pense pas. La seule qui me vient à l'esprit est de transférer le contenu du retrode directement su le rpi et de l executer de là.

                      1 Reply Last reply Reply Quote 0
                      • une-fille-etoilee
                        une-fille-etoilee last edited by

                        oui, j'y ai pensé aussi a transferer la rom sur le pi, mais ca fait refaire pas mal de boulot, sans compter cette histoire de sauvegarde ingame qu'a pas été des plus simple a mettre en place....reste plus qu'a espérer une maj frimware qui résoudrais cela (mais j'en doute, la derniere date de 2013)   sinon, pour le bouton reset qui ramenerais au menu emulationstation, j'ai trouvé cette page https://github.com/digitalLumberjack/recalbox-os/wiki/Notice-(FR) ils disent qu'on peux brancher sur le gpio les boutons d'une manette....si je me branche directement dessus et que mon bouton reset  fais start et select en meme temps, ca devrais marcher...

                        1 Reply Last reply Reply Quote 0
                        • acris
                          acris last edited by

                          Salut Violene, je pense que tu devrais passer sur le canal irc tu trouveras peut etre plus d aide et d explication sur les gpio. ce n est pas trop mon domaine pour le moment. edit : je vais ouvrir une issue pour https://github.com/adafruit/Adafruit-Retrogame , ça permettra d'ajouter le binaire dans recalbox si besoin.

                          1 Reply Last reply Reply Quote 0
                          • une-fille-etoilee
                            une-fille-etoilee last edited by

                            okay.....c'est cool...   j'ai vu sur irc, le bigboss m'a dit qu'il avais intégré ca, et que t'etais en train de tester le truc..... 🙂

                            1 Reply Last reply Reply Quote 0
                            • acris
                              acris last edited by

                              Salut trop fatiguée pour tester le truc mais j y jete un oeil et oui retropboy a compilé le binaire mais je me demande si il a ajouté le gpio pour le bouton echap lol.

                              1 Reply Last reply Reply Quote 0
                              • une-fille-etoilee
                                une-fille-etoilee last edited by

                                pas de soucis, prends ton temps....y'a rien qui presse...^^

                                1 Reply Last reply Reply Quote 0
                                • acris
                                  acris last edited by

                                  Salut j'ai pas de clavier peux tu testé si en faisant echap tu sors bien de retroarch ou lui faudrait-il une combinaison de touche aussi avec un clavier ? merci d'avance

                                  1 Reply Last reply Reply Quote 0
                                  • une-fille-etoilee
                                    une-fille-etoilee last edited by

                                    je te confirme, la touche echap du clavier fais bien sortir de l'émulateur pour revenir au menu des émulateurs

                                    1 Reply Last reply Reply Quote 0
                                    • digitaLumberjack
                                      digitaLumberjack Staff last edited by

                                      Non j'ai compilé a l'arrache... 🙂

                                      1 Reply Last reply Reply Quote 0
                                      • digitaLumberjack
                                        digitaLumberjack Staff last edited by

                                        Si tu me modifie le fichier acris je te le compile comme tu le veux 🙂

                                        1 Reply Last reply Reply Quote 0
                                        • acris
                                          acris last edited by

                                          @Violene merci pour le test. @retroboy merci beaucoup si j'ai bien compris il faut déclarer la touche dans retrogame.c puis lancer le make. J'ai ajouté ceci : GPIO 11

                                          {  11,      KEY_ESC       },   // escape, out of emulator
                                          
                                          /*
                                          ADAFRUIT RETROGAME UTILITY: remaps buttons on Raspberry Pi GPIO header
                                          to virtual USB keyboard presses.  Great for classic game emulators!
                                          Retrogame is interrupt-driven and efficient (usually under 0.3% CPU use)
                                          and debounces inputs for glitch-free gaming.
                                          Connect one side of button(s) to GND pin (there are several on the GPIO
                                          header, but see later notes) and the other side to GPIO pin of interest.
                                          Internal pullups are used; no resistors required.  Avoid pins 8 and 10;
                                          these are configured as a serial port by default on most systems (this
                                          can be disabled but takes some doing).  Pin configuration is currently
                                          set in global table; no config file yet.  See later comments.
                                          Must be run as root, i.e. 'sudo ./retrogame &' or configure init scripts
                                          to launch automatically at system startup.
                                          Requires uinput kernel module.  This is typically present on popular
                                          Raspberry Pi Linux distributions but not enabled on some older varieties.
                                          To enable, either type:
                                              sudo modprobe uinput
                                          Or, to make this persistent between reboots, add a line to /etc/modules:
                                              uinput
                                          Prior versions of this code, when being compiled for use with the Cupcade
                                          or PiGRRL projects, required CUPCADE to be #defined.  This is no longer
                                          the case; instead a test is performed to see if a PiTFT is connected, and
                                          one of two I/O tables is automatically selected.
                                          Written by Phil Burgess for Adafruit Industries, distributed under BSD
                                          License.  Adafruit invests time and resources providing this open source
                                          code, please support Adafruit and open-source hardware by purchasing
                                          products from Adafruit!
                                          Copyright (c) 2013 Adafruit Industries.
                                          All rights reserved.
                                          Redistribution and use in source and binary forms, with or without
                                          modification, are permitted provided that the following conditions are met:
                                          - Redistributions of source code must retain the above copyright notice,
                                            this list of conditions and the following disclaimer.
                                          - Redistributions in binary form must reproduce the above copyright notice,
                                            this list of conditions and the following disclaimer in the documentation
                                            and/or other materials provided with the distribution.
                                          THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
                                          AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                                          IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                                          ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
                                          LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                                          CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                                          SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                                          INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                                          CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                                          ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                                          POSSIBILITY OF SUCH DAMAGE.
                                          */
                                          
                                          #include <stdio.h>
                                          #include <stdlib.h>
                                          #include <string.h>
                                          #include <unistd.h>
                                          #include <fcntl.h>
                                          #include <poll.h>
                                          #include <signal.h>
                                          #include <sys/mman.h>
                                          #include <linux/input.h>
                                          #include <linux/uinput.h>
                                          
                                          // START HERE ------------------------------------------------------------
                                          // This table remaps GPIO inputs to keyboard values.  In this initial
                                          // implementation there's a 1:1 relationship (can't attach multiple keys
                                          // to a button) and the list is fixed in code; there is no configuration
                                          // file.  Buttons physically connect between GPIO pins and ground.  There
                                          // are only a few GND pins on the GPIO header, so a breakout board is
                                          // often needed.  If you require just a couple extra ground connections
                                          // and have unused GPIO pins, set the corresponding key value to GND to
                                          // create a spare ground point.
                                          
                                          #define GND -1
                                          struct {
                                          	int pin;
                                          	int key;
                                          } *io, // In main() this pointer is set to one of the two tables below.
                                             ioTFT[] = {
                                          	// This pin/key table is used if an Adafruit PiTFT display
                                          	// is detected (e.g. Cupcade or PiGRRL).
                                          	// Input   Output (from /usr/include/linux/input.h)
                                          	{   2,     KEY_LEFT     },   // Joystick (4 pins)
                                          	{   3,     KEY_RIGHT    },
                                          	{   4,     KEY_DOWN     },
                                          	{  17,     KEY_UP       },
                                          	{  27,     KEY_Z        },   // A/Fire/jump/primary
                                          	{  22,     KEY_X        },   // B/Bomb/secondary
                                          	{  23,     KEY_R        },   // Credit
                                          	{  18,     KEY_Q        },   // Start 1P
                                                  {  11,     KEY_ESC       },   // escape, out of emulator
                                          	{  -1,     -1           } }, // END OF LIST, DO NOT CHANGE
                                          	// MAME must be configured with 'z' & 'x' as buttons 1 & 2 -
                                          	// this was required for the accompanying 'menu' utility to
                                          	// work (catching crtl/alt w/ncurses gets totally NASTY).
                                          	// Credit/start are likewise moved to 'r' & 'q,' reason being
                                          	// to play nicer with certain emulators not liking numbers.
                                          	// GPIO options are 'maxed out' with PiTFT + above table.
                                          	// If additional buttons are desired, will need to disable
                                          	// serial console and/or use P5 header.  Or use keyboard.
                                             ioStandard[] = {
                                          	// This pin/key table is used when the PiTFT isn't found
                                          	// (using HDMI or composite instead), as with our original
                                          	// retro gaming guide.
                                          	// Input   Output (from /usr/include/linux/input.h)
                                          	{  25,     KEY_LEFT     },   // Joystick (4 pins)
                                          	{   9,     KEY_RIGHT    },
                                          	{  10,     KEY_UP       },
                                          	{  17,     KEY_DOWN     },
                                          	{  23,     KEY_LEFTCTRL },   // A/Fire/jump/primary
                                          	{   7,     KEY_LEFTALT  },   // B/Bomb/secondary
                                          	// For credit/start/etc., use USB keyboard or add more buttons.
                                          	{  -1,     -1           } }; // END OF LIST, DO NOT CHANGE
                                          
                                          // A "Vulcan nerve pinch" (holding down a specific button combination
                                          // for a few seconds) issues an 'esc' keypress to MAME (which brings up
                                          // an exit menu or quits the current game).  The button combo is
                                          // configured with a bitmask corresponding to elements in the above io[]
                                          // array.  The default value here uses elements 6 and 7 (credit and start
                                          // in the Cupcade pinout).  If you change this, make certain it's a combo
                                          // that's not likely to occur during actual gameplay (i.e. avoid using
                                          // joystick directions or hold-for-rapid-fire buttons).
                                          // Also key auto-repeat times are set here.  This is for navigating the
                                          // game menu using the 'gamera' utility; MAME disregards key repeat
                                          // events (as it should).
                                          const unsigned long vulcanMask = (1L << 6) | (1L << 7);
                                          const int           vulcanKey  = KEY_ESC, // Keycode to send
                                                              vulcanTime = 1500,    // Pinch time in milliseconds
                                                              repTime1   = 500,     // Key hold time to begin repeat
                                                              repTime2   = 100;     // Time between key repetitions
                                          
                                          // A few globals ---------------------------------------------------------
                                          
                                          char
                                            *progName,                         // Program name (for error reporting)
                                             sysfs_root[] = "/sys/class/gpio", // Location of Sysfs GPIO files
                                             running      = 1;                 // Signal handler will set to 0 (exit)
                                          volatile unsigned int
                                            *gpio;                             // GPIO register table
                                          const int
                                             debounceTime = 20;                // 20 ms for button debouncing
                                          
                                          // Some utility functions ------------------------------------------------
                                          
                                          // Set one GPIO pin attribute through the Sysfs interface.
                                          int pinConfig(int pin, char *attr, char *value) {
                                          	char filename[50];
                                          	int  fd, w, len = strlen(value);
                                          	sprintf(filename, "%s/gpio%d/%s", sysfs_root, pin, attr);
                                          	if((fd = open(filename, O_WRONLY)) < 0) return -1;
                                          	w = write(fd, value, len);
                                          	close(fd);
                                          	return (w != len); // 0 = success
                                          }
                                          
                                          // Un-export any Sysfs pins used; don't leave filesystem cruft.  Also
                                          // restores any GND pins to inputs.  Write errors are ignored as pins
                                          // may be in a partially-initialized state.
                                          void cleanup() {
                                          	char buf[50];
                                          	int  fd, i;
                                          	sprintf(buf, "%s/unexport", sysfs_root);
                                          	if((fd = open(buf, O_WRONLY)) >= 0) {
                                          		for(i=0; io[i].pin >= 0; i++) {
                                          			// Restore GND items to inputs
                                          			if(io[i].key == GND)
                                          				pinConfig(io[i].pin, "direction", "in");
                                          			// And un-export all items regardless
                                          			sprintf(buf, "%d", io[i].pin);
                                          			write(fd, buf, strlen(buf));
                                          		}
                                          		close(fd);
                                          	}
                                          }
                                          
                                          // Quick-n-dirty error reporter; print message, clean up and exit.
                                          void err(char *msg) {
                                          	printf("%s: %s.  Try 'sudo %s'.\n", progName, msg, progName);
                                          	cleanup();
                                          	exit(1);
                                          }
                                          
                                          // Interrupt handler -- set global flag to abort main loop.
                                          void signalHandler(int n) {
                                          	running = 0;
                                          }
                                          
                                          // Detect Pi board type.  Doesn't return super-granular details,
                                          // just the most basic distinction needed for GPIO compatibility:
                                          // 0: Pi 1 Model B revision 1
                                          // 1: Pi 1 Model B revision 2, Model A, Model B+, Model A+
                                          // 2: Pi 2 Model B
                                          
                                          static int boardType(void) {
                                          	FILE *fp;
                                          	char  buf[1024], *ptr;
                                          	int   n, board = 1; // Assume Pi1 Rev2 by default
                                          
                                          	// Relies on info in /proc/cmdline.  If this becomes unreliable
                                          	// in the future, alt code below uses /proc/cpuinfo if any better.
                                          #if 1
                                          	if((fp = fopen("/proc/cmdline", "r"))) {
                                          		while(fgets(buf, sizeof(buf), fp)) {
                                          			if((ptr = strstr(buf, "mem_size=")) &&
                                          			   (sscanf(&ptr[9], "%x", &n) == 1) &&
                                          			   (n == 0x3F000000)) {
                                          				board = 2; // Appears to be a Pi 2
                                          				break;
                                          			} else if((ptr = strstr(buf, "boardrev=")) &&
                                          			          (sscanf(&ptr[9], "%x", &n) == 1) &&
                                          			          ((n == 0x02) || (n == 0x03))) {
                                          				board = 0; // Appears to be an early Pi
                                          				break;
                                          			}
                                          		}
                                          		fclose(fp);
                                          	}
                                          #else
                                          	char s[8];
                                          	if((fp = fopen("/proc/cpuinfo", "r"))) {
                                          		while(fgets(buf, sizeof(buf), fp)) {
                                          			if((ptr = strstr(buf, "Hardware")) &&
                                          			   (sscanf(&ptr[8], " : %7s", s) == 1) &&
                                          			   (!strcmp(s, "BCM2709"))) {
                                          				board = 2; // Appears to be a Pi 2
                                          				break;
                                          			} else if((ptr = strstr(buf, "Revision")) &&
                                          			          (sscanf(&ptr[8], " : %x", &n) == 1) &&
                                          			          ((n == 0x02) || (n == 0x03))) {
                                          				board = 0; // Appears to be an early Pi
                                          				break;
                                          			}
                                          		}
                                          		fclose(fp);
                                          	}
                                          #endif
                                          
                                          	return board;
                                          }
                                          
                                          // Main stuff ------------------------------------------------------------
                                          
                                          #define PI1_BCM2708_PERI_BASE 0x20000000
                                          #define PI1_GPIO_BASE         (PI1_BCM2708_PERI_BASE + 0x200000)
                                          #define PI2_BCM2708_PERI_BASE 0x3F000000
                                          #define PI2_GPIO_BASE         (PI2_BCM2708_PERI_BASE + 0x200000)
                                          #define BLOCK_SIZE            (4*1024)
                                          #define GPPUD                 (0x94 / 4)
                                          #define GPPUDCLK0             (0x98 / 4)
                                          
                                          int main(int argc, char *argv[]) {
                                          
                                          	// A few arrays here are declared with 32 elements, even though
                                          	// values aren't needed for io[] members where the 'key' value is
                                          	// GND.  This simplifies the code a bit -- no need for mallocs and
                                          	// tests to create these arrays -- but may waste a handful of
                                          	// bytes for any declared GNDs.
                                          	char                   buf[50],      // For sundry filenames
                                          	                       c,            // Pin input value ('0'/'1')
                                          	                       board;        // 0=Pi1Rev1, 1=Pi1Rev2, 2=Pi2
                                          	int                    fd,           // For mmap, sysfs, uinput
                                          	                       i, j,         // Asst. counter
                                          	                       bitmask,      // Pullup enable bitmask
                                          	                       timeout = -1, // poll() timeout
                                          	                       intstate[32], // Last-read state
                                          	                       extstate[32], // Debounced state
                                          	                       lastKey = -1; // Last key down (for repeat)
                                          	unsigned long          bitMask, bit; // For Vulcan pinch detect
                                          	volatile unsigned char shortWait;    // Delay counter
                                          	struct input_event     keyEv, synEv; // uinput events
                                          	struct pollfd          p[32];        // GPIO file descriptors
                                          
                                          	progName = argv[0];             // For error reporting
                                          	signal(SIGINT , signalHandler); // Trap basic signals (exit cleanly)
                                          	signal(SIGKILL, signalHandler);
                                          
                                          	// Select io[] table for Cupcade (TFT) or 'normal' project.
                                          	io = (access("/etc/modprobe.d/adafruit.conf", F_OK) ||
                                          	      access("/dev/fb1", F_OK)) ? ioStandard : ioTFT;
                                          
                                          	// If this is a "Revision 1" Pi board (no mounting holes),
                                          	// remap certain pin numbers in the io[] array for compatibility.
                                          	// This way the code doesn't need modification for old boards.
                                          	board = boardType();
                                          	if(board == 0) {
                                          		for(i=0; io[i].pin >= 0; i++) {
                                          			if(     io[i].pin ==  2) io[i].pin = 0;
                                          			else if(io[i].pin ==  3) io[i].pin = 1;
                                          			else if(io[i].pin == 27) io[i].pin = 21;
                                          		}
                                          	}
                                          
                                          	// ----------------------------------------------------------------
                                          	// Although Sysfs provides solid GPIO interrupt handling, there's
                                          	// no interface to the internal pull-up resistors (this is by
                                          	// design, being a hardware-dependent feature).  It's necessary to
                                          	// grapple with the GPIO configuration registers directly to enable
                                          	// the pull-ups.  Based on GPIO example code by Dom and Gert van
                                          	// Loo on elinux.org
                                          
                                          	if((fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0)
                                          		err("Can't open /dev/mem");
                                          	gpio = mmap(            // Memory-mapped I/O
                                          	  NULL,                 // Any adddress will do
                                          	  BLOCK_SIZE,           // Mapped block length
                                          	  PROT_READ|PROT_WRITE, // Enable read+write
                                          	  MAP_SHARED,           // Shared with other processes
                                          	  fd,                   // File to map
                                          	  (board == 2) ?
                                          	   PI2_GPIO_BASE :      // -> GPIO registers
                                          	   PI1_GPIO_BASE);
                                          
                                          	close(fd);              // Not needed after mmap()
                                          	if(gpio == MAP_FAILED) err("Can't mmap()");
                                          	// Make combined bitmap of pullup-enabled pins:
                                          	for(bitmask=i=0; io[i].pin >= 0; i++)
                                          		if(io[i].key != GND) bitmask |= (1 << io[i].pin);
                                          	gpio[GPPUD]     = 2;                    // Enable pullup
                                          	for(shortWait=150;--shortWait;);        // Min 150 cycle wait
                                          	gpio[GPPUDCLK0] = bitmask;              // Set pullup mask
                                          	for(shortWait=150;--shortWait;);        // Wait again
                                          	gpio[GPPUD]     = 0;                    // Reset pullup registers
                                          	gpio[GPPUDCLK0] = 0;
                                          	(void)munmap((void *)gpio, BLOCK_SIZE); // Done with GPIO mmap()
                                          
                                          	// ----------------------------------------------------------------
                                          	// All other GPIO config is handled through the sysfs interface.
                                          
                                          	sprintf(buf, "%s/export", sysfs_root);
                                          	if((fd = open(buf, O_WRONLY)) < 0) // Open Sysfs export file
                                          		err("Can't open GPIO export file");
                                          	for(i=j=0; io[i].pin >= 0; i++) { // For each pin of interest...
                                          		sprintf(buf, "%d", io[i].pin);
                                          		write(fd, buf, strlen(buf));             // Export pin
                                          		pinConfig(io[i].pin, "active_low", "0"); // Don't invert
                                          		if(io[i].key == GND) {
                                          			// Set pin to output, value 0 (ground)
                                          			if(pinConfig(io[i].pin, "direction", "out") ||
                                          			   pinConfig(io[i].pin, "value"    , "0"))
                                          				err("Pin config failed (GND)");
                                          		} else {
                                          			// Set pin to input, detect rise+fall events
                                          			if(pinConfig(io[i].pin, "direction", "in") ||
                                          			   pinConfig(io[i].pin, "edge"     , "both"))
                                          				err("Pin config failed");
                                          			// Get initial pin value
                                          			sprintf(buf, "%s/gpio%d/value",
                                          			  sysfs_root, io[i].pin);
                                          			// The p[] file descriptor array isn't necessarily
                                          			// aligned with the io[] array.  GND keys in the
                                          			// latter are skipped, but p[] requires contiguous
                                          			// entries for poll().  So the pins to monitor are
                                          			// at the head of p[], and there may be unused
                                          			// elements at the end for each GND.  Same applies
                                          			// to the intstate[] and extstate[] arrays.
                                          			if((p[j].fd = open(buf, O_RDONLY)) < 0)
                                          				err("Can't access pin value");
                                          			intstate[j] = 0;
                                          			if((read(p[j].fd, &c, 1) == 1) && (c == '0'))
                                          				intstate[j] = 1;
                                          			extstate[j] = intstate[j];
                                          			p[j].events  = POLLPRI; // Set up poll() events
                                          			p[j].revents = 0;
                                          			j++;
                                          		}
                                          	} // 'j' is now count of non-GND items in io[] table
                                          	close(fd); // Done exporting
                                          
                                          	// ----------------------------------------------------------------
                                          	// Set up uinput
                                          
                                          #if 1
                                          	// Retrogame normally uses /dev/uinput for generating key events.
                                          	// Cupcade requires this and it's the default.  SDL2 (used by
                                          	// some newer emulators) doesn't like it, wants /dev/input/event0
                                          	// instead.  Enable that code by changing to "#if 0" above.
                                          	if((fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK)) < 0)
                                          		err("Can't open /dev/uinput");
                                          	if(ioctl(fd, UI_SET_EVBIT, EV_KEY) < 0)
                                          		err("Can't SET_EVBIT");
                                          	for(i=0; io[i].pin >= 0; i++) {
                                          		if(io[i].key != GND) {
                                          			if(ioctl(fd, UI_SET_KEYBIT, io[i].key) < 0)
                                          				err("Can't SET_KEYBIT");
                                          		}
                                          	}
                                          	if(ioctl(fd, UI_SET_KEYBIT, vulcanKey) < 0) err("Can't SET_KEYBIT");
                                          	struct uinput_user_dev uidev;
                                          	memset(&uidev, 0, sizeof(uidev));
                                          	snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "retrogame");
                                          	uidev.id.bustype = BUS_USB;
                                          	uidev.id.vendor  = 0x1;
                                          	uidev.id.product = 0x1;
                                          	uidev.id.version = 1;
                                          	if(write(fd, &uidev, sizeof(uidev)) < 0)
                                          		err("write failed");
                                          	if(ioctl(fd, UI_DEV_CREATE) < 0)
                                          		err("DEV_CREATE failed");
                                          #else // SDL2 prefers this event methodology
                                          	if((fd = open("/dev/input/event0", O_WRONLY | O_NONBLOCK)) < 0)
                                          		err("Can't open /dev/input/event0");
                                          #endif
                                          
                                          	// Initialize input event structures
                                          	memset(&keyEv, 0, sizeof(keyEv));
                                          	keyEv.type  = EV_KEY;
                                          	memset(&synEv, 0, sizeof(synEv));
                                          	synEv.type  = EV_SYN;
                                          	synEv.code  = SYN_REPORT;
                                          	synEv.value = 0;
                                          
                                          	// 'fd' is now open file descriptor for issuing uinput events
                                          
                                          	// ----------------------------------------------------------------
                                          	// Monitor GPIO file descriptors for button events.  The poll()
                                          	// function watches for GPIO IRQs in this case; it is NOT
                                          	// continually polling the pins!  Processor load is near zero.
                                          
                                          	while(running) { // Signal handler can set this to 0 to exit
                                          		// Wait for IRQ on pin (or timeout for button debounce)
                                          		if(poll(p, j, timeout) > 0) { // If IRQ...
                                          			for(i=0; i<j; i++) {       // Scan non-GND pins...
                                          				if(p[i].revents) { // Event received?
                                          					// Read current pin state, store
                                          					// in internal state flag, but
                                          					// don't issue to uinput yet --
                                          					// must wait for debounce!
                                          					lseek(p[i].fd, 0, SEEK_SET);
                                          					read(p[i].fd, &c, 1);
                                          					if(c == '0')      intstate[i] = 1;
                                          					else if(c == '1') intstate[i] = 0;
                                          					p[i].revents = 0; // Clear flag
                                          				}
                                          			}
                                          			timeout = debounceTime; // Set timeout for debounce
                                          			c       = 0;            // Don't issue SYN event
                                          			// Else timeout occurred
                                          		} else if(timeout == debounceTime) { // Button debounce timeout
                                          			// 'j' (number of non-GNDs) is re-counted as
                                          			// it's easier than maintaining an additional
                                          			// remapping table or a duplicate key[] list.
                                          			bitMask = 0L; // Mask of buttons currently pressed
                                          			bit     = 1L;
                                          			for(c=i=j=0; io[i].pin >= 0; i++, bit<<=1) {
                                          				if(io[i].key != GND) {
                                          					// Compare internal state against
                                          					// previously-issued value.  Send
                                          					// keystrokes only for changed states.
                                          					if(intstate[j] != extstate[j]) {
                                          						extstate[j] = intstate[j];
                                          						keyEv.code  = io[i].key;
                                          						keyEv.value = intstate[j];
                                          						write(fd, &keyEv,
                                          						  sizeof(keyEv));
                                          						c = 1; // Follow w/SYN event
                                          						if(intstate[j]) { // Press?
                                          							// Note pressed key
                                          							// and set initial
                                          							// repeat interval.
                                          							lastKey = i;
                                          							timeout = repTime1;
                                          						} else { // Release?
                                          							// Stop repeat and
                                          							// return to normal
                                          							// IRQ monitoring
                                          							// (no timeout).
                                          							lastKey = timeout = -1;
                                          						}
                                          					}
                                          					j++;
                                          					if(intstate[i]) bitMask |= bit;
                                          				}
                                          			}
                                          
                                          			// If the "Vulcan nerve pinch" buttons are pressed,
                                          			// set long timeout -- if this time elapses without
                                          			// a button state change, esc keypress will be sent.
                                          			if((bitMask & vulcanMask) == vulcanMask)
                                          				timeout = vulcanTime;
                                          		} else if(timeout == vulcanTime) { // Vulcan timeout occurred
                                          			// Send keycode (MAME exits or displays exit menu)
                                          			keyEv.code = vulcanKey;
                                          			for(i=1; i>= 0; i--) { // Press, release
                                          				keyEv.value = i;
                                          				write(fd, &keyEv, sizeof(keyEv));
                                          				usleep(10000); // Be slow, else MAME flakes
                                          				write(fd, &synEv, sizeof(synEv));
                                          				usleep(10000);
                                          			}
                                          			timeout = -1; // Return to normal processing
                                          			c       = 0;  // No add'l SYN required
                                          		} else if(lastKey >= 0) { // Else key repeat timeout
                                          			if(timeout == repTime1) timeout = repTime2;
                                          			else if(timeout > 30)   timeout -= 5; // Accelerate
                                          			c           = 1; // Follow w/SYN event
                                          			keyEv.code  = io[lastKey].key;
                                          			keyEv.value = 2; // Key repeat event
                                          			write(fd, &keyEv, sizeof(keyEv));
                                          		}
                                          		if(c) write(fd, &synEv, sizeof(synEv));
                                          	}
                                          
                                          	// ----------------------------------------------------------------
                                          	// Clean up
                                          
                                          	ioctl(fd, UI_DEV_DESTROY); // Destroy and
                                          	close(fd);                 // close uinput
                                          	cleanup();                 // Un-export pins
                                          
                                          	puts("Done.");
                                          
                                          	return 0;
                                          }
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • julien-tomulic
                                            julien-tomulic last edited by

                                            je penche sur une réalisation du même genre (le reset sur gpio avec un retour sous emulationstation) mon niveau de programmation étant proche de 0 je suis attentif a votre poste si vous arrivez a quelque choses ça m’intéresse 😄 je suis tomber sur un principe quelque peu différent peut être que vous y comprendrait plus que moi 😉 au lieu de passé par ADAFRUIT c'est un script python qui simule l’appuie sur echap   http://carrefour-numerique.cite-sciences.fr/fablab/wiki/doku.php?id=projets:retropie_gpio_additions

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Want to support us ?

                                            59
                                            Online

                                            99.6k
                                            Users

                                            28.1k
                                            Topics

                                            187.1k
                                            Posts

                                            Copyright © 2021 recalbox.com