Skip to content

Commit

Permalink
Support and detect Pi-Pico pinouts programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
nopjne committed Nov 2, 2024
1 parent 1b37868 commit 90b6938
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/n64cartinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ uint16_t gGameTitle[0x16];
uint16_t gGameCode[6];
uint32_t gChecksum;
const char* gCICName;
bool gGpioRemap = false;

void set_ad_input() {
for(uint32_t i = 0; i < 16; i++) {
Expand Down Expand Up @@ -174,7 +175,21 @@ void cartio_init()
// Read start address, assert that the retured value is something valid.
set_address(CART_ADDRESS_START);
uint32_t read = (((uint32_t)read16()) << 16) | (read16());
if (read != 0x80371240) {
gGpioRemap = true;
// Force setup.
gpio_init(N64_ALEL);
gpio_set_dir(N64_ALEL, true);
gpio_put(N64_ALEL, false);
gpio_set_pulls(N64_ALEL, true, false);
sleep_ms(300);
set_address(CART_ADDRESS_START);
read = (((uint32_t)read16()) << 16) | (read16());
}

assert(read == 0x80371240);

// Hang is coudn't header.
while(read != 0x80371240) {
gpio_put(PICO_DEFAULT_LED_PIN, true);
sleep_ms(100);
Expand Down
12 changes: 10 additions & 2 deletions src/n64cartinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@
#define N64_CIC_DCLK (20)
#define N64_CIC_DIO (21)
#define N64_COLD_RESET (22)
#define N64_ALEL (27)
#define N64_ALEH (28)
#define N64_ALEL_INIT (27)
#define N64_ALEH_INIT (28)
#define N64_ALEL_PI (26)
#define N64_ALEH_PI (27)


#define N64_ALEL ((gGpioRemap == false) ? N64_ALEL_INIT : N64_ALEL_PI)
#define N64_ALEH ((gGpioRemap == false) ? N64_ALEH_INIT : N64_ALEH_PI)

extern bool gGpioRemap;

#define READ_LOW_DELAY_NS (133 / 4) // 133 = 1us 1us / 5 = ~300ns

Expand Down

0 comments on commit 90b6938

Please sign in to comment.