Skip to content

Commit

Permalink
Revert "Fix a few MCU-related bugs, gm9 should boot properly now"
Browse files Browse the repository at this point in the history
This reverts commit 36ea48b.
  • Loading branch information
TuxSH committed Jan 26, 2021
1 parent 36ea48b commit 18f3783
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 497 deletions.
4 changes: 2 additions & 2 deletions arm11/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ static void initScreens(u32 brightnessLevel, struct fb *fbs)
for(u32 i = 0; i < 256; i++)
*(vu32 *)0x10400584 = 0x10101 * i;

//*(vu32 *)0x10202204 = 0x00000000; //unset LCD fill
//*(vu32 *)0x10202A04 = 0x00000000;
*(vu32 *)0x10202204 = 0x00000000; //unset LCD fill
*(vu32 *)0x10202A04 = 0x00000000;
}

static void setupFramebuffers(struct fb *fbs)
Expand Down
4 changes: 0 additions & 4 deletions arm9/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,16 @@ SECTIONS

chainloader.o(.text*)
i2c.o(.text*)
mcu.o(.text*)
arm9_exception_handlers.o(.text*)

*(.arm9_exception_handlers.rodata*)
chainloader.o(.rodata*)
i2c.o(.rodata*)
mcu.o(.rodata*)
arm9_exception_handlers.o(.rodata*)

*(.arm9_exception_handlers.data*)
chainloader.o(.data*)
i2c.o(.data*)
mcu.o(.data*)
arm9_exception_handlers.o(.data*)
. = ALIGN(32);
} >itcm AT>main :itcm
Expand All @@ -70,7 +67,6 @@ SECTIONS
*(.arm9_exception_handlers.bss*)
chainloader.o(.bss* COMMON)
i2c.o(.bss* COMMON)
mcu.o(.bss* COMMON)
arm9_exception_handlers.o(.bss* COMMON)
. = ALIGN(32);
PROVIDE (__itcm_end__ = ABSOLUTE(.));
Expand Down
8 changes: 5 additions & 3 deletions arm9/source/arm9_exception_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
*/

#include "arm9_exception_handlers.h"
#include "mcu.h"
#include "i2c.h"
#include "screen.h"

#define FINAL_BUFFER 0x25000000

Expand Down Expand Up @@ -102,9 +103,10 @@ void __attribute__((noreturn)) arm9ExceptionHandlerMain(u32 *registerDump, u32 t
//Copy header (actually optimized by the compiler)
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;

mcuPowerBacklightsOff();
if(ARESCREENSINITIALIZED) I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); //Shutdown LCD

((void (*)())0xFFFF0830)(); //Ensure that all memory transfers have completed and that the data cache has been flushed

mcuReboot();
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot
while(true);
}
2 changes: 1 addition & 1 deletion arm9/source/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,5 @@ void detectAndProcessExceptionDumps(void)

exit:
memset((void *)dumpHeader, 0, dumpHeader->totalSize);
powerOff();
mcuPowerOff();
}
2 changes: 0 additions & 2 deletions arm9/source/firm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "screen.h"
#include "fmt.h"
#include "chainloader.h"
#include "mcu.h"

static Firm *firm = (Firm *)0x20001000;

Expand Down Expand Up @@ -565,7 +564,6 @@ u32 patch1x2xNativeAndSafeFirm(void)

void launchFirm(int argc, char **argv)
{
mcuFinalize();
prepareArm11ForFirmlaunch();
chainload(argc, argv, firm);
}
225 changes: 0 additions & 225 deletions arm9/source/gpio.h

This file was deleted.

18 changes: 7 additions & 11 deletions arm9/source/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// Modified 2021 TuxSH

#include <stdbool.h>
#include <string.h>
#include "types.h"
#include "i2c.h"
#include "utils.h"
Expand Down Expand Up @@ -161,40 +158,39 @@ static bool i2cStartTransfer(I2cDevice devId, u8 regAddr, bool read, I2cRegs *co
else return false;
}

bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, void *out, u32 size)
bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size)
{
const u8 busId = i2cDevTable[devId].busId;
I2cRegs *const regs = i2cGetBusRegsBase(busId);
u8 *out8 = (u8 *)out;


if(!i2cStartTransfer(devId, regAddr, true, regs)) return false;

while(--size)
{
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_ACK;
i2cWaitBusy(regs);
*out8++ = regs->REG_I2C_DATA;
*out++ = regs->REG_I2C_DATA;
}

regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_STOP;
i2cWaitBusy(regs);
*out8 = regs->REG_I2C_DATA; // Last byte
*out = regs->REG_I2C_DATA; // Last byte

return true;
}

bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const void *in, u32 size)
bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const u8 *in, u32 size)
{
const u8 busId = i2cDevTable[devId].busId;
I2cRegs *const regs = i2cGetBusRegsBase(busId);
const u8 *in8 = (const u8 *)in;


if(!i2cStartTransfer(devId, regAddr, false, regs)) return false;

while(--size)
{
regs->REG_I2C_DATA = *in8++;
regs->REG_I2C_DATA = *in++;
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
i2cWaitBusy(regs);
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
Expand All @@ -204,7 +200,7 @@ bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const void *in, u32 size)
}
}

regs->REG_I2C_DATA = *in8;
regs->REG_I2C_DATA = *in;
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE | I2C_STOP;
i2cWaitBusy(regs);
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
Expand Down
4 changes: 2 additions & 2 deletions arm9/source/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void I2C_init(void);
*
* @return Returns true on success and false on failure.
*/
bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, void *out, u32 size);
bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size);

/**
* @brief Writes a buffer to a I2C register.
Expand All @@ -78,7 +78,7 @@ bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, void *out, u32 size);
*
* @return Returns true on success and false on failure.
*/
bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const void *in, u32 size);
bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const u8 *in, u32 size);

/**
* @brief Reads a byte from a I2C register.
Expand Down
Loading

0 comments on commit 18f3783

Please sign in to comment.