Skip to content

Instantly share code, notes, and snippets.

@ardangelo
Last active May 18, 2016 18:02
Show Gist options
  • Save ardangelo/f420bf8b4b77fc13b7cb041256aa1ae2 to your computer and use it in GitHub Desktop.
Save ardangelo/f420bf8b4b77fc13b7cb041256aa1ae2 to your computer and use it in GitHub Desktop.
// view from front of CABLE
// annotated with colors of crappy $1 ebay link cable
// T
// 1 3 5 1 3v, xxx 3 SI, wht 5 SC, red
// 2 4 6 2 SO, blk 4 SD, grn 6 GN, xxx
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <wiringPi.h>
const int CHANNEL = 1;
const int SD = 3;
const int SI = 12;
const int SO = 13;
const int SC = 14;
uint8_t buffer[2] = {0};
uint8_t* pack_buffer(uint16_t write16) {
buffer[0] = (write16 & 0xff00) >> 8;
buffer[1] = write16 & 0x00ff;
return buffer;
}
uint16_t unpack_buffer() {
return (buffer[0] << 8) | buffer[1];
}
uint32_t writeSPI32bits(uint32_t write32) {
printf("writing 0x%08x\n", write32);
digitalWrite(SD, 0);
pack_buffer(write32 && 0xffff);
wiringPiSPIDataRW(CHANNEL, buffer, 2);
uint16_t short0 = unpack_buffer();
digitalWrite(SD, 1);
digitalWrite(SD, 0);
pack_buffer(write32 >> 16);
wiringPiSPIDataRW(CHANNEL, buffer, 2);
uint16_t short1 = unpack_buffer();
digitalWrite(SD, 1);
return (short1 << 16) | short0;
}
int main(int argc, char* argv[]) {
wiringPiSPISetupMode(CHANNEL, 100000, 3);
pinMode(SD, 1);
digitalWrite(SD, 1);
uint32_t read_from_gba = 0;
while (read_from_gba != 0x72026202) {
read_from_gba = writeSPI32bits(0x00006202);
printf("got 0x%08x\n\n", read_from_gba);
usleep(1000000);
}
printf("found gba\n");
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment