Created
February 22, 2016 02:22
-
-
Save justinvh/08c2e4c768d6dddc69d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
commented
Jan 16, 2020
via email
Yeah, that's what I was hoping to do with the smaller chip. Been doing it
with the 328p just fine, and got greedy for something smaller :) Thanks
…On Thu, Jan 16, 2020 at 10:46 AM Justin Bruce Van Horne < ***@***.***> wrote:
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.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/08c2e4c768d6dddc69d8?email_source=notifications&email_token=ABT6INSHNA5NTXYBUTJAI6DQ6CFNBA5CNFSM4KHW4AW2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF7V3A#gistcomment-3140528>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABT6INVNLF7WSKFZRGNXN7LQ6CFNBANCNFSM4KHW4AWQ>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment