From cc99734facce9689f140619fe78ab02d5406e7b8 Mon Sep 17 00:00:00 2001 From: Balint Kovacs Date: Tue, 30 Mar 2021 00:31:44 +0100 Subject: [PATCH] Fix IR card support This is based on the latest update of GBATEK. --- arm9/source/gamecart/card_spi.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arm9/source/gamecart/card_spi.c b/arm9/source/gamecart/card_spi.c index 964d83b..3d1fe62 100644 --- a/arm9/source/gamecart/card_spi.c +++ b/arm9/source/gamecart/card_spi.c @@ -18,6 +18,7 @@ * along with this program. If not, see */ +#include #include "card_spi.h" #include #include "timer.h" @@ -102,6 +103,8 @@ int CardSPIWriteRead(bool infrared, const void* cmd, u32 cmdSize, void* answer, if (infrared) { SPI_XferInfo irXfer = { &headerFooterVal, 1, false }; SPI_DoXfer(SPI_DEV_CART_IR, &irXfer, 1, false); + // Wait as specified by GBATEK (0x800 cycles at 33 MHz) + ARM_WaitCycles(0x800 * 4); } SPI_XferInfo transfers[3] = { @@ -113,6 +116,11 @@ int CardSPIWriteRead(bool infrared, const void* cmd, u32 cmdSize, void* answer, REG_CFG9_CARDCTL &= ~CARDCTL_SPICARD; + if (infrared) { + // Wait as specified by GBATEK (0x800 cycles at 33 MHz) + ARM_WaitCycles(0x800 * 4); + } + return 0; } @@ -167,7 +175,7 @@ int CardSPIReadJEDECIDAndStatusReg(bool infrared, u32* id, u8* statusReg) { u8 reg = 0; u8 idbuf[3] = { 0 }; u32 id_ = 0; - int res = CardSPIWaitWriteEnd(infrared, 0); + int res = CardSPIWaitWriteEnd(infrared, 10); if (res) return res; if ((res = CardSPIWriteRead(infrared, &cmd, 1, idbuf, 3, 0, 0))) return res; @@ -446,11 +454,6 @@ CardSPIType CardSPIGetCardSPIType(bool infrared) { CardSPIType t = {NO_CHIP, infrared}; int res; - if(infrared) { - // Infrared carts currently not supported, need additional handling! - return (CardSPIType) {NO_CHIP, true}; - } - res = CardSPIReadJEDECIDAndStatusReg(infrared, &jedec, &sr); if (res) return (CardSPIType) {NO_CHIP, false};