Skip to content

Instantly share code, notes, and snippets.

@justinvh
Created February 22, 2016 02:22
Show Gist options
  • Save justinvh/08c2e4c768d6dddc69d8 to your computer and use it in GitHub Desktop.
Save justinvh/08c2e4c768d6dddc69d8 to your computer and use it in GitHub Desktop.
const uint8_t gamecube_pin = PD0;
const uint8_t gamecube_prefix = 25;
const uint8_t gamecube_bitcount = 64;
unsigned char data[gamecube_bitcount + gamecube_prefix];
#define PIN_READ(pin) (PIND & (1 << pin))
#define TWOMICROSECOND_NOPS "nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"
#define WAIT_FALLING_EDGE(pin) while(!PIN_READ(pin)); while(PIN_READ(pin));
void setup()
{
// Activate gamecube pin as an input
DDRD &= ~(1 << gamecube_pin);
Serial.begin(115200);
}
void loop()
{
uint8_t bits_left = gamecube_prefix + gamecube_bitcount;
unsigned char* ptr = data;
noInterrupts();
// Collect data
while (true) {
// Wait for the data line to go low
WAIT_FALLING_EDGE(gamecube_pin);
// Wait 2us between line reads
asm volatile(TWOMICROSECOND_NOPS);
// Read a bit and store in the header
*ptr = PIN_READ(gamecube_pin);
++ptr;
if (--bits_left == 0) {
break;
}
}
interrupts();
Serial.write(data + gamecube_prefix, gamecube_bitcount);
Serial.write('\n');
}
@bfinleyui
Copy link

Stumbled upon this code looking for ways to miniaturize a setup. Were you able to get this working on a 32u4? looking particularly at the beetle

@justinvh
Copy link
Author

Ah man, this has been a while. The point of this project wasn't for control. I used it to just read commands off the wire and interpret them with nintendospy. I ended up using a 328p and modified this for two controllers and it worked fine.

@bfinleyui
Copy link

bfinleyui commented Jan 16, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment