Adaptateur de manette pour ; - Master system - Megadrive - Saturn - Dreamcast - Nes - Snes - N64 - PS1 - PS2
Dependencies: mbed mbed-MapleMini USBDevice_STM32F103 USBJoystick
Revision 0:0ce3bda826e8, committed 2019-05-26
- Comitter:
- fabdu117
- Date:
- Sun May 26 20:50:21 2019 +0000
- Commit message:
- Test
Changed in this revision
diff -r 000000000000 -r 0ce3bda826e8 USBDevice_STM32F103.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice_STM32F103.lib Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/hudakz/code/USBDevice_STM32F103/#faedf6c65e43
diff -r 000000000000 -r 0ce3bda826e8 USBJoystick.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBJoystick.lib Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/wim/code/USBJoystick/#e086541742c3
diff -r 000000000000 -r 0ce3bda826e8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,108 @@ +#include "MapleMini.h" +#include "mbed.h" +#include "USBJoystick.h" + +#include "nintendo.h" +#include "sega.h" + + DigitalInOut USB2(PB_12); + DigitalInOut USB3(PB_13); + DigitalInOut USB4(PB_14); + DigitalInOut USB5(PB_15); + DigitalInOut USB6(PA_8); + DigitalInOut USB7(PA_9); + DigitalInOut USB8(PA_10); + DigitalInOut USB9(PA_15); + +int main() { + + DigitalOut myled(LED1); + + confSysClock(); + USBJoystick joystick; + Serial pc(USBTX, USBRX); + + int controller = 0; + + while(1) { + + int idLow = 0; + int idHigh = 0; + + USB5.input(); + USB6.input(); + USB7.input(); + USB8.output(); + USB9.input(); + + USB5.mode(PullUp); + USB6.mode(PullUp); + USB7.mode(PullUp); + USB9.mode(PullUp); + + if(!USB9) { + USB8 = 0; + wait_us(1); + if(!USB7) { + idLow = idLow + 1; + } + if(!USB6) { + idLow = idLow + 2; + } + if(!USB5) { + idLow = idLow + 4; + } + + USB8 = 1; + wait_us(1); + if(USB7) { + idHigh = idHigh + 1; + } + if(USB6) { + idHigh = idHigh + 2; + } + if(USB5) { + idHigh = idHigh + 4; + } + + if(idHigh == 7) { + controller = idLow; + //pc.printf("idLow : %i idHigh : %i\r\n",idLow,idHigh); + } else { +// pc.printf("Error idLow : %i idHigh : %i\r\n",idLow,idHigh); + //wait_ms(100); + } + switch(controller) { + case 0: + int *sega = SegaMasterGenesisSaturn(); + joystick.update(sega[0],sega[1],sega[2],sega[3],sega[4],sega[5]); // Envoi des position des noutton au pc + // pc.printf("Sega ou Saturn \r\n"); + //pc.printf("X : %i - Y : %i \r\n", sega[2], sega[3]); + break; + case 3: + // pc.printf("PS1\r\n"); + break; + case 4: + int *nes = NintendoNes(); + joystick.update(nes[0],nes[1],nes[2],nes[3],nes[4],nes[5]); // Envoi des position des noutton au pc + // pc.printf("NES\r\n"); + break; + case 5: + int *snes = NintendoSnes(); + joystick.update(snes[0],snes[1],snes[2],snes[3],snes[4],snes[5]); // Envoi des position des noutton au pc +// pc.printf("SNES\r\n"); + break; + case 6: + // pc.printf("Dreamcast\r\n"); + break; + case 7: +// pc.printf("N64\r\n"); + break; + } + } else { + pc.printf("Pas d'adaptateur\r\n"); + wait_ms(100); + } + myled = !myled; + } +} \ No newline at end of file
diff -r 000000000000 -r 0ce3bda826e8 mbed-MapleMini.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-MapleMini.lib Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/hudakz/code/mbed-MapleMini/#f0b2ddbf8ba6
diff -r 000000000000 -r 0ce3bda826e8 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
diff -r 000000000000 -r 0ce3bda826e8 nintendo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nintendo.cpp Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,125 @@ +#include "MapleMini.h" +#include "mbed.h" +#include "nintendo.h" + +int *NintendoNes() +{ + USB2.output(); // CLOCK + USB3.output(); // LATCH + USB4.input(); // DATA + USB4.mode(PullUp); + + USB3 = 0; + USB2 = 0; + + // Flag des boutton + const int UP = 1; + const int DOWN = 2; + const int LEFT = 4; + const int RIGHT = 8; + const int A = 64; + const int B = 128; + const int SELECT = 1024; + const int START = 2048; + + int buttonMap[] = { + A, + B, + SELECT, + START, + UP, + DOWN, + LEFT, + RIGHT + }; + + int buttons = 0; + + // Envoi impulsion LATCH + USB3 = 1; + wait_us(12); + USB3 = 0; + wait_us(6); + + // Lecture des boutons + for (int i = 0; i < 8; i++) { + if(!USB4) { // Lecture du boutton + buttons |= buttonMap[i]; + } + // Envoi impulsion CLOCK + USB2 = 1; + wait_us(6); + USB2 = 0; + wait_us(6); + } + int array[] = {0, 0, 0, 0, buttons, 0}; + return array; + //joystick.update(0, 0, 0, 0, buttons, 0); // Envoi des position des noutton au pc +} + +int *NintendoSnes() +{ + USB2.output(); // CLOCK + USB3.output(); // LATCH + USB4.input(); // DATA + USB4.mode(PullUp); + + USB3 = 0; + USB2 = 0; + + + + // Flag des boutton + const int UP = 1; + const int DOWN = 2; + const int LEFT = 4; + const int RIGHT = 8; + const int L = 16; + const int R = 32; + const int A = 64; + const int B = 128; + const int X = 256; + const int Y = 512; + const int SELECT = 1024; + const int START = 2048; + + int buttonMap[] = { + B, + Y, + SELECT, + START, + UP, + DOWN, + LEFT, + RIGHT, + A, + X, + L, + R + }; + + int buttons = 0; + int analog_l = -128; + int analog_r = -128; + + // Envoi impulsion LATCH + USB3 = 1; + wait_us(12); + USB3 = 0; + wait_us(6); + + // Lecture des boutons + for (int i = 0; i < 12; i++) { + if(!USB4) { // Lecture du boutton + buttons |= buttonMap[i]; + } + // Envoi impulsion CLOCK + USB2 = 1; + wait_us(6); + USB2 = 0; + wait_us(6); + } + int array[] = {analog_r, analog_l, 0, 0, buttons, 0}; + return array; + //joystick.update(0, 0, 0, 0, buttons, 0); // Envoi des position des noutton au pc +} \ No newline at end of file
diff -r 000000000000 -r 0ce3bda826e8 nintendo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nintendo.h Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,15 @@ +#ifndef __nintendo_h__ +#define __nintendo_h__ + +extern DigitalInOut USB2; +extern DigitalInOut USB3; +extern DigitalInOut USB4; +extern DigitalInOut USB5; +extern DigitalInOut USB6; +extern DigitalInOut USB7; +extern DigitalInOut USB8; +extern DigitalInOut USB9; + +int *NintendoNes(); +int *NintendoSnes(); +#endif \ No newline at end of file
diff -r 000000000000 -r 0ce3bda826e8 sega.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sega.cpp Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,426 @@ +#include "MapleMini.h" +#include "mbed.h" +#include "nintendo.h" + +int *SegaMasterGenesisSaturn() +{ // AUTRE SATURN SATURN 3D + USB2.input(); // UP DATA 1 0v DATA 1 0v + USB3.input(); // DOWN DATA 0 0v DATA 0 5v + USB4.input(); // LEFT SELECT0 SELECT + USB5.input(); // RIGHT DATA 3 5v DATA 3 0v + USB6.input(); // B DATA 2 5v DATA 2 0v + USB7.output(); // SELECT SELECT1 REQ + USB8.input(); // C -- ACK + + USB2.mode(PullUp); + USB3.mode(PullUp); + USB4.mode(PullUp); + USB5.mode(PullUp); + USB6.mode(PullUp); + USB8.mode(PullUp); + + // Flag des boutton + const int UP = 1; + const int DOWN = 2; + const int LEFT = 4; + const int RIGHT = 8; + const int X = 16; + const int Z = 32; + const int C = 64; + const int B = 128; + const int Y = 256; + const int A = 512; + const int START = 2048; + const int GND = 0; + const int MODE = 8192; + + // Tableau avec les pin et leur valeur + // pin, Master System, 3 btn select 0V, 3 btn select 5V, 6 btn........ +/* int buttonMap[6][11] = { + //SMS SMD - SMD6 - - - - - - - + //0V 0V 5V 0 1 2 3 4 5 6 7 + {UP, UP, UP, UP, UP, UP, UP, GND, Z, 0, 0}, //USB2 + {DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, GND, Y, 0, 0}, //USB3 + {LEFT, GND, LEFT, GND, LEFT, GND, LEFT, 0, X, 0, 0}, //USB4 + {RIGHT, GND, RIGHT, GND, RIGHT, GND, RIGHT, 0, MODE, 0, 0}, //USB5 + {B, A, B, A, B, A, B, 0, 0, 0, 0}, //USB6 + {C, START, C, START, C, START, C, 0, 0, 0, 0} //USB8 + }; + + USB2 DATA 1 + USB3 DATA 0 + USB4 SELECT0 SELECT + USB5 DATA 3 + USB6 DATA 2 + USB7 SELECT1 REQ + USB8 ACK + + */ + + int buttons = 0; + int analog_x = 0; + int analog_y = 0; + int analog_l = -128; + int analog_r = -128; + + int controller = 0; // 0 master system, 3 btn megadrive, 6 btn megadrive + // 4 saturn, 5 saturn 3d + int controllerOld = 0; + + + USB7 = 0; + wait_us(1700); + for (int i = 0; i < 8; i++) + { + if (i % 2 == 0) //nombre pair + { + USB7 = 0; + wait_us(20); + if (i == 2 && !USB4 && !USB5) + { + controller = 3; // Magadrive + } + if (i == 4 && !USB2 && !USB3) + { + controller = 6; // Megadrive 6 btn + } + } + else //nombre impair + { + USB7 = 1; + wait_us(20); + if (i == 7 && !USB2 && !USB3 && USB6) // && USB5 && USB6) + { + controller = 4; // Saturn + break; + } + if (i == 7 && !USB2 && USB3 && !USB6) // && !USB5 && !USB6) + { + controller = 5; // Saturn 3D + break; + } + if (i == 5 && controller == 6 && controllerOld == 0 && !USB5) // Utile ou pas utile ???? + { + controller = 3; // Magadrive + } + } + } + + switch (controller) { + case 0: // Master system + // Lecture des boutons + if(!USB2) buttons |= UP; + if(!USB3) buttons |= DOWN; + if(!USB4) buttons |= LEFT; + if(!USB5) buttons |= RIGHT; + if(!USB6) buttons |= B; + if(!USB8) buttons |= C; + + //buttons |= 16384; + break; + case 3: // Megadrive 3 btns + USB7 = 0; + wait_us(1700); + if(!USB2) buttons |= UP; + if(!USB3) buttons |= DOWN; + // if(!USB4) buttons |= GND; + // if(!USB5) buttons |= GND; + if(!USB6) buttons |= A; + if(!USB8) buttons |= START; + USB7 = 1; + wait_us(20); + if(!USB2) buttons |= UP; + if(!USB3) buttons |= DOWN; + if(!USB4) buttons |= LEFT; + if(!USB5) buttons |= RIGHT; + if(!USB6) buttons |= B; + if(!USB8) buttons |= C; + + //buttons |= 32768; + //getMegadrive3Buttons(); + //return controller; + break; + case 4: // Saturn + //buttons = 2; + // Lecture des boutons + USB4.output(); + + USB4 = 1; + USB7 = 1; + wait_us(100); + + USB4 = 0; + USB7 = 1; + wait_us(30); + + if(!USB5) buttons |= RIGHT; + if(!USB6) buttons |= LEFT; + if(!USB2) buttons |= DOWN; + if(!USB3) buttons |= UP; + + USB4 = 1; + USB7 = 0; + wait_us(30); + + if(!USB5) buttons |= START; + if(!USB6) buttons |= A; + if(!USB2) buttons |= C; + if(!USB3) buttons |= B; + + USB4 = 0; + USB7 = 0; + wait_us(30); + + if(!USB5) analog_r = 127; // 8192 + if(!USB6) buttons |= X; + if(!USB2) buttons |= Y; + if(!USB3) buttons |= Z; + + USB4 = 1; + USB7 = 1; + wait_us(30); + + if(!USB5) analog_l = 127; // 4096 + + //buttons |= 131072; + + break; + case 5: // Saturn 3D + //buttons = 4; + int bite = 0; + bool analog = false; + + USB4.output(); + + USB4 = 0; + wait_us(50); + USB7 = 0; + + for (int i = 0; i <= 100; i++) { + if(!USB8) break; + wait_us(5); + } + + if(USB3) analog = true; + + USB7 = 1; + + for (int i = 0; i <= 100; i++) { + if(USB8) break; + wait_us(5); + } + + if(USB3) bite |= 1; + if(USB2) bite |= 2; + if(USB6) bite |= 4; + if(USB5) bite |= 8; + + USB7 = 0; + + for (int i = 0; i <= 100; i++) { + if(!USB8) break; + wait_us(5); + } + + if(!USB3) buttons |= UP; + if(!USB2) buttons |= DOWN; + if(!USB6) buttons |= LEFT; + if(!USB5) buttons |= RIGHT; + + USB7 = 1; + + for (int i = 0; i <= 100; i++) { + if(USB8) break; + wait_us(5); + } + + if(!USB3) buttons |= B; + if(!USB2) buttons |= C; + if(!USB6) buttons |= A; + if(!USB5) buttons |= START; + + USB7 = 0; + + for (int i = 0; i <= 100; i++) { + if(!USB8) break; + wait_us(5); + } + + if(!USB3) buttons |= Z; + if(!USB2) buttons |= Y; + if(!USB6) buttons |= X; + if(!USB5) analog_r = 127; + + USB7 = 1; + + for (int i = 0; i <= 100; i++) { + if(USB8) break; + wait_us(5); + } + + /*if(!USB3) buttons |= 4096; + if(!USB2) buttons |= 8192; + if(!USB6) buttons |= 16384;*/ + if(!USB5) analog_l = 127; + + if(bite == 6 && analog){ + + analog_l = 0; + analog_r = 0; + + USB7 = 0; + + for (int i = 0; i <= 100; i++) { + if(!USB8) break; + wait_us(5); + } + + if(USB3) analog_x |= 16; + if(USB2) analog_x |= 32; + if(USB6) analog_x |= 64; + if(USB5) analog_x |= 128; + + USB7 = 1; + + for (int i = 0; i <= 100; i++) { + if(USB8) break; + wait_us(5); + } + + if(USB3) analog_x |= 1; + if(USB2) analog_x |= 2; + if(USB6) analog_x |= 4; + if(USB5) analog_x |= 8; + + USB7 = 0; + + for (int i = 0; i <= 100; i++) { + if(!USB8) break; + wait_us(5); + } + + if(USB3) analog_y |= 16; + if(USB2) analog_y |= 32; + if(USB6) analog_y |= 64; + if(USB5) analog_y |= 128; + + USB7 = 1; + + for (int i = 0; i <= 100; i++) { + if(USB8) break; + wait_us(5); + } + + if(USB3) analog_y |= 1; + if(USB2) analog_y |= 2; + if(USB6) analog_y |= 4; + if(USB5) analog_y |= 8; + + USB7 = 0; + + for (int i = 0; i <= 100; i++) { + if(!USB8) break; + wait_us(5); + } + + if(USB3) analog_r |= 16; + if(USB2) analog_r |= 32; + if(USB6) analog_r |= 64; + if(USB5) analog_r |= 128; + + USB7 = 1; + + for (int i = 0; i <= 100; i++) { + if(USB8) break; + wait_us(5); + } + + if(USB3) analog_r |= 1; + if(USB2) analog_r |= 2; + if(USB6) analog_r |= 4; + if(USB5) analog_r |= 8; + + USB7 = 0; + + for (int i = 0; i <= 100; i++) { + if(!USB8) break; + wait_us(5); + } + + if(USB3) analog_l |= 16; + if(USB2) analog_l |= 32; + if(USB6) analog_l |= 64; + if(USB5) analog_l |= 128; + + USB7 = 1; + + for (int i = 0; i <= 100; i++) { + if(USB8) break; + wait_us(5); + } + + if(USB3) analog_l |= 1; + if(USB2) analog_l |= 2; + if(USB6) analog_l |= 4; + if(USB5) analog_l |= 8; + + analog_x = analog_x - 128; + analog_y = analog_y - 128; + analog_l = analog_l - 128; + analog_r = analog_r - 128; + + } + + //buttons |= 262144; + + break; + case 6: // Megadrive 6 btns + USB7 = 0; + wait_us(1700); + + USB7 = 1; + wait_us(20); + + USB7 = 0; + wait_us(20); + if(!USB2) buttons |= UP; + if(!USB3) buttons |= DOWN; + // if(!USB4) buttons |= GND; + // if(!USB5) buttons |= GND; + if(!USB6) buttons |= A; + if(!USB8) buttons |= START; + USB7 = 1; + wait_us(20); + if(!USB2) buttons |= UP; + if(!USB3) buttons |= DOWN; + if(!USB4) buttons |= LEFT; + if(!USB5) buttons |= RIGHT; + if(!USB6) buttons |= B; + if(!USB8) buttons |= C; + USB7 = 0; + wait_us(20); + // if(!USB2) buttons |= GND; + // if(!USB3) buttons |= GND; + USB7 = 1; + wait_us(20); + if(!USB2) buttons |= Z; + if(!USB3) buttons |= Y; + if(!USB4) buttons |= X; + if(!USB5) buttons |= MODE; + + //buttons |= 65536; // 15 + //getMegadrive6Buttons(); + //return controller; + break; + } + + controllerOld = controller; + int array[] = {analog_r, analog_l, analog_x, analog_y, buttons, 0}; + return array; +} + +int *SegaDreamcast() +{ + int array[] = {0, 0, 0, 0, 0, 0}; + return array; +} \ No newline at end of file
diff -r 000000000000 -r 0ce3bda826e8 sega.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sega.h Sun May 26 20:50:21 2019 +0000 @@ -0,0 +1,15 @@ +#ifndef __sega_h__ +#define __sega_h__ + +extern DigitalInOut USB2; +extern DigitalInOut USB3; +extern DigitalInOut USB4; +extern DigitalInOut USB5; +extern DigitalInOut USB6; +extern DigitalInOut USB7; +extern DigitalInOut USB8; +extern DigitalInOut USB9; + +int *SegaMasterGenesisSaturn(); +int *SegaDreamcast(); +#endif \ No newline at end of file
diff -r 000000000000 -r 0ce3bda826e8 sony.cpp
diff -r 000000000000 -r 0ce3bda826e8 sony.h