The Nintendo 64 Controller Interface is an mbed library that allows one or more Nintendo 64 controllers to be used as input devices for the mbed. With this library, one will be able to control games created for an mbed using a Nintendo 64 controller. In addition, the library can easily be used to forward N64 inputs to a computer. Using the N64 Controller executable, one can communicate with multiple controllers.

Dependencies:   mbed

Committer:
fomartin
Date:
Thu Apr 28 00:10:38 2016 +0000
Revision:
0:95064759a964
N64 Controller Interface;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fomartin 0:95064759a964 1 #ifndef __N64Controller__
fomartin 0:95064759a964 2 #define __N64Controller__
fomartin 0:95064759a964 3
fomartin 0:95064759a964 4 #include "mbed.h"
fomartin 0:95064759a964 5
fomartin 0:95064759a964 6 class N64Controller
fomartin 0:95064759a964 7 {
fomartin 0:95064759a964 8 public:
fomartin 0:95064759a964 9 /*
fomartin 0:95064759a964 10 * Passive Mode makes it so the mbed does not request data from the n64 controller. This allows the controller
fomartin 0:95064759a964 11 * to be plugged into a real n64 and have the signal split to the mbed as well. The mbed will still read the
fomartin 0:95064759a964 12 * incoming inputs in passive mode, but all of the data requests will come from the n64 itself.
fomartin 0:95064759a964 13 */
fomartin 0:95064759a964 14 N64Controller(PinName pin, bool passiveMode);
fomartin 0:95064759a964 15
fomartin 0:95064759a964 16 bool a();
fomartin 0:95064759a964 17 bool b();
fomartin 0:95064759a964 18 bool l();
fomartin 0:95064759a964 19 bool r();
fomartin 0:95064759a964 20 bool z();
fomartin 0:95064759a964 21 bool start();
fomartin 0:95064759a964 22
fomartin 0:95064759a964 23 bool dUp();
fomartin 0:95064759a964 24 bool dDown();
fomartin 0:95064759a964 25 bool dLeft();
fomartin 0:95064759a964 26 bool dRight();
fomartin 0:95064759a964 27
fomartin 0:95064759a964 28 bool cUp();
fomartin 0:95064759a964 29 bool cDown();
fomartin 0:95064759a964 30 bool cLeft();
fomartin 0:95064759a964 31 bool cRight();
fomartin 0:95064759a964 32
fomartin 0:95064759a964 33 int8_t joyX();
fomartin 0:95064759a964 34 int8_t joyY();
fomartin 0:95064759a964 35
fomartin 0:95064759a964 36 void setPassiveMode(bool);
fomartin 0:95064759a964 37
fomartin 0:95064759a964 38 uint32_t getInputData();
fomartin 0:95064759a964 39
fomartin 0:95064759a964 40 private:
fomartin 0:95064759a964 41 void poll();
fomartin 0:95064759a964 42 void writeByte(char data);
fomartin 0:95064759a964 43 void readBytes(char* buffer, int numBytes);
fomartin 0:95064759a964 44 void myWait_us(int numMicroseconds);
fomartin 0:95064759a964 45
fomartin 0:95064759a964 46 DigitalInOut pin;
fomartin 0:95064759a964 47 Ticker ticker;
fomartin 0:95064759a964 48 uint32_t inputData;
fomartin 0:95064759a964 49 bool passiveMode;
fomartin 0:95064759a964 50 Serial debug;
fomartin 0:95064759a964 51
fomartin 0:95064759a964 52 #define RESET 0xFF
fomartin 0:95064759a964 53 #define GET_DATA 0x01
fomartin 0:95064759a964 54
fomartin 0:95064759a964 55 #define POLLING_INTERVAL 10000 //0.01 seconds
fomartin 0:95064759a964 56
fomartin 0:95064759a964 57 #define A_MASK (0x1 << 0)
fomartin 0:95064759a964 58 #define B_MASK (0x1 << 1)
fomartin 0:95064759a964 59 #define Z_MASK (0x1 << 2)
fomartin 0:95064759a964 60 #define START_MASK (0x1 << 3)
fomartin 0:95064759a964 61 #define D_UP_MASK (0x1 << 4)
fomartin 0:95064759a964 62 #define D_DOWN_MASK (0x1 << 5)
fomartin 0:95064759a964 63 #define D_LEFT_MASK (0x1 << 6)
fomartin 0:95064759a964 64 #define D_RIGHT_MASK (0x1 << 7)
fomartin 0:95064759a964 65
fomartin 0:95064759a964 66 //bits 8, 9 unused
fomartin 0:95064759a964 67
fomartin 0:95064759a964 68 #define L_MASK (0x1 << 10)
fomartin 0:95064759a964 69 #define R_MASK (0x1 << 11)
fomartin 0:95064759a964 70 #define C_UP_MASK (0x1 << 12)
fomartin 0:95064759a964 71 #define C_DOWN_MASK (0x1 << 13)
fomartin 0:95064759a964 72 #define C_LEFT_MASK (0x1 << 14)
fomartin 0:95064759a964 73 #define C_RIGHT_MASK (0x1 << 15)
fomartin 0:95064759a964 74
fomartin 0:95064759a964 75 #define X_R_SHIFT 16
fomartin 0:95064759a964 76 #define Y_R_SHIFT 24
fomartin 0:95064759a964 77 };
fomartin 0:95064759a964 78
fomartin 0:95064759a964 79 #endif