diff --git a/Makefile b/Makefile
index c5035a8..1078a89 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ ARCH := -DARM9 -march=armv5te -mthumb -mthumb-interwork -flto
ASFLAGS := $(ARCH) -g -x assembler-with-cpp $(INCLUDE)
CFLAGS := $(ARCH) -g -Wall -Wextra -Wpedantic -Wcast-align -Wno-main -O2 \
-mtune=arm946e-s -fomit-frame-pointer -ffast-math -std=gnu11 \
- $(INCLUDE)
+ $(INCLUDE) -Wno-unused-function
CFLAGS += -DBUILD_NAME="\"$(TARGET) (`date +'%Y/%m/%d'`)\""
diff --git a/source/common/i2c.c b/common/i2c.h
similarity index 82%
rename from source/common/i2c.c
rename to common/i2c.h
index 0c027d8..0ee4537 100644
--- a/source/common/i2c.c
+++ b/common/i2c.h
@@ -16,9 +16,38 @@
* along with this program. If not, see .
*/
-#include
-#include "i2c.h"
+#pragma once
+#include
+#include
+
+
+#define I2C_STOP (1u)
+#define I2C_START (1u<<1)
+#define I2C_ERROR (1u<<2)
+#define I2C_ACK (1u<<4)
+#define I2C_DIRE_WRITE (0u)
+#define I2C_DIRE_READ (1u<<5)
+#define I2C_IRQ_ENABLE (1u<<6)
+#define I2C_ENABLE (1u<<7)
+
+#define I2C_GET_ACK(reg) ((bool)((reg)>>4 & 1u))
+
+
+typedef enum
+{
+ I2C_DEV_POWER = 0, // Unconfirmed
+ I2C_DEV_CAMERA = 1, // Unconfirmed
+ I2C_DEV_CAMERA2 = 2, // Unconfirmed
+ I2C_DEV_MCU = 3,
+ I2C_DEV_GYRO = 10,
+ I2C_DEV_DEBUG_PAD = 12,
+ I2C_DEV_IR = 13,
+ I2C_DEV_EEPROM = 14, // Unconfirmed
+ I2C_DEV_NFC = 15,
+ I2C_DEV_QTM = 16,
+ I2C_DEV_N3DS_HID = 17
+} I2cDevice;
#define I2C1_REGS_BASE (0x10161000)
#define REG_I2C1_DATA *((vu8* )(I2C1_REGS_BASE + 0x00))
@@ -65,14 +94,12 @@ static const struct
{2, 0x54}
};
-
-
-static void i2cWaitBusy(vu8 *cntReg)
+static inline void i2cWaitBusy(vu8 *cntReg)
{
while(*cntReg & I2C_ENABLE);
}
-static vu8* i2cGetBusRegsBase(u8 busId)
+static inline vu8* i2cGetBusRegsBase(u8 busId)
{
vu8 *base;
if(!busId) base = (vu8*)I2C1_REGS_BASE;
@@ -134,7 +161,7 @@ static bool i2cStartTransfer(I2cDevice devId, u8 regAddr, bool read, vu8 *regsBa
else return false;
}
-void I2C_init(void)
+static void I2C_init(void)
{
i2cWaitBusy(i2cGetBusRegsBase(0));
REG_I2C1_CNTEX = 2; // ?
@@ -149,7 +176,7 @@ void I2C_init(void)
REG_I2C3_SCL = 1280; // ?
}
-bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size)
+static bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size)
{
const u8 busId = i2cDevTable[devId].busId;
vu8 *const i2cData = i2cGetBusRegsBase(busId);
@@ -172,7 +199,7 @@ bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size)
return true;
}
-bool I2C_writeReg(I2cDevice devId, u8 regAddr, u8 data)
+static bool I2C_writeReg(I2cDevice devId, u8 regAddr, u8 data)
{
const u8 busId = i2cDevTable[devId].busId;
vu8 *const i2cData = i2cGetBusRegsBase(busId);
diff --git a/common/pxi.h b/common/pxi.h
index f307104..f3c4ab4 100644
--- a/common/pxi.h
+++ b/common/pxi.h
@@ -46,32 +46,32 @@ enum {
#define PXI_SYNC_TRIGGER_OLDARM (BIT(6))
#define PXI_SYNC_ENABLE_IRQ (BIT(7))
-void PXI_SetRemote(u8 msg)
+static inline void PXI_SetRemote(u8 msg)
{
*PXI_SYNC_SEND = msg;
}
-u8 PXI_GetRemote(void)
+static inline u8 PXI_GetRemote(void)
{
return *PXI_SYNC_RECV;
}
-void PXI_WaitRemote(u8 msg)
+static inline void PXI_WaitRemote(u8 msg)
{
while(*PXI_SYNC_RECV != msg);
}
-void PXI_EnableIRQ(void)
+static inline void PXI_EnableIRQ(void)
{
*PXI_SYNC_IRQ = PXI_SYNC_ENABLE_IRQ;
}
-void PXI_DisableIRQ(void)
+static inline void PXI_DisableIRQ(void)
{
*PXI_SYNC_IRQ = 0;
}
-void PXI_Sync(void)
+static inline void PXI_Sync(void)
{
#ifdef ARM9
*PXI_SYNC_IRQ |= PXI_SYNC_TRIGGER_MPCORE;
@@ -80,7 +80,7 @@ void PXI_Sync(void)
#endif
}
-void PXI_Reset(void)
+static void PXI_Reset(void)
{
*PXI_SYNC = 0;
*PXI_CNT = PXI_CNT_SEND_FIFO_FLUSH;
@@ -92,7 +92,7 @@ void PXI_Reset(void)
return;
}
-void PXI_Send(u32 w)
+static void PXI_Send(u32 w)
{
while(*PXI_CNT & PXI_CNT_SEND_FIFO_FULL);
do {
@@ -101,7 +101,7 @@ void PXI_Send(u32 w)
return;
}
-u32 PXI_Recv(void)
+static u32 PXI_Recv(void)
{
u32 ret;
while(*PXI_CNT & PXI_CNT_RECV_FIFO_EMPTY);
@@ -111,7 +111,7 @@ u32 PXI_Recv(void)
return ret;
}
-void PXI_SendArray(const u32 *w, u32 c)
+static void PXI_SendArray(const u32 *w, u32 c)
{
if (c>PXI_FIFO_LEN) c=PXI_FIFO_LEN;
for (u32 i=0; iPXI_FIFO_LEN) c=PXI_FIFO_LEN;
for (u32 i=0; i
#include
-void LCD_SetBrightness(u32 screen, u32 brightness)
+void LCD_SetBrightness(u32 screen, u8 brightness)
{
vu32 *lcd_reg;
if (screen & 1) {
@@ -10,20 +10,19 @@ void LCD_SetBrightness(u32 screen, u32 brightness)
} else {
lcd_reg = LCD_CFG(0x240);
}
- *lcd_reg = brightness & 0xFF;
+ *lcd_reg = brightness;
return;
}
-void LCD_Initialize(u32 brightness)
+void LCD_Initialize(u8 brightness)
{
- brightness &= 0xFF;
-
*LCD_CFG(0x014) = 0x00000001;
*LCD_CFG(0x00C) &= 0xFFFEFFFE;
*LCD_CFG(0x240) = brightness;
*LCD_CFG(0xA40) = brightness;
*LCD_CFG(0x244) = 0x1023E;
*LCD_CFG(0xA44) = 0x1023E;
+ return;
}
void LCD_Deinitialize(void)
@@ -38,9 +37,8 @@ void LCD_Deinitialize(void)
void GPU_PSCFill(u32 start, u32 end, u32 fv)
{
u32 mp;
- if (start > end) {
+ if (start > end)
return;
- }
start = GPU_ADDR(start);
end = GPU_ADDR(end);
@@ -74,7 +72,7 @@ void GPU_SetFramebuffers(const u32 *framebuffers)
return;
}
-void GPU_SetFramebufferMode(u32 screen, u32 mode)
+void GPU_SetFramebufferMode(u32 screen, u8 mode)
{
u32 stride, cfg;
vu32 *fbcfg_reg, *fbstr_reg;
@@ -140,6 +138,7 @@ void GPU_Init(void)
*GPU_PDC0(0x6C) = VRAM_START;
*GPU_PDC0(0x70) = 0x00080340;
*GPU_PDC0(0x74) = 0x00010501;
+ *GPU_PDC0(0x78) = 0x00000000;
*GPU_PDC0(0x90) = 0x000003C0;
*GPU_PDC0(0x94) = VRAM_START;
*GPU_PDC0(0x98) = VRAM_START;
@@ -174,6 +173,7 @@ void GPU_Init(void)
*GPU_PDC1(0x6C) = VRAM_START;
*GPU_PDC1(0x70) = 0x00080300;
*GPU_PDC1(0x74) = 0x00010501;
+ *GPU_PDC1(0x78) = 0x00000000;
*GPU_PDC1(0x90) = 0x000003C0;
*GPU_PDC1(0x9C) = 0x00000000;
diff --git a/screeninit/source/gpulcd.h b/screeninit/source/gpulcd.h
index 36a0b39..6b933d0 100644
--- a/screeninit/source/gpulcd.h
+++ b/screeninit/source/gpulcd.h
@@ -8,7 +8,7 @@
#define LCD_CFG(x) ((vu32*)(0x10202000 + (x)))
-void LCD_SetBrightness(u32 screen, u32 brightness);
+void LCD_SetBrightness(u32 screen, u8 brightness);
void LCD_Deinitialize(void);
#define GPU_PSC0(x) ((vu32*)(0x10400010 + (x)))
@@ -43,5 +43,5 @@ void GPU_PSCFill(u32 start, u32 end, u32 fv);
#define PDC_FIXSTRIP (BIT(7))
void GPU_SetFramebuffers(const u32 *framebuffers);
-void GPU_SetFramebufferMode(u32 screen, u32 mode);
+void GPU_SetFramebufferMode(u32 screen, u8 mode);
void GPU_Init();
diff --git a/screeninit/source/main.c b/screeninit/source/main.c
index 2f8e56d..4f49a53 100644
--- a/screeninit/source/main.c
+++ b/screeninit/source/main.c
@@ -1,6 +1,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -46,7 +47,7 @@ void PXI_IRQHandler(void)
void main(void)
{
- u32 entry=0;
+ u32 entry;
PXI_Reset();
GPU_Init();
@@ -58,6 +59,8 @@ void main(void)
GPU_SetFramebufferMode(0, PDC_RGB24);
GPU_SetFramebufferMode(1, PDC_RGB24);
+ I2C_writeReg(I2C_DEV_MCU, 0x22, 0x2A);
+
GIC_Reset();
GIC_SetIRQ(IRQ_PXI_SYNC, PXI_IRQHandler);
PXI_EnableIRQ();
diff --git a/source/common/i2c.h b/source/common/i2c.h
deleted file mode 100644
index 8229e3f..0000000
--- a/source/common/i2c.h
+++ /dev/null
@@ -1,56 +0,0 @@
-#pragma once
-
-/*
- * This file is part of fastboot 3DS
- * Copyright (C) 2017 derrek, profi200
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include
-#include "common.h"
-
-
-#define I2C_STOP (1u)
-#define I2C_START (1u<<1)
-#define I2C_ERROR (1u<<2)
-#define I2C_ACK (1u<<4)
-#define I2C_DIRE_WRITE (0u)
-#define I2C_DIRE_READ (1u<<5)
-#define I2C_IRQ_ENABLE (1u<<6)
-#define I2C_ENABLE (1u<<7)
-
-#define I2C_GET_ACK(reg) ((bool)((reg)>>4 & 1u))
-
-
-typedef enum
-{
- I2C_DEV_POWER = 0, // Unconfirmed
- I2C_DEV_CAMERA = 1, // Unconfirmed
- I2C_DEV_CAMERA2 = 2, // Unconfirmed
- I2C_DEV_MCU = 3,
- I2C_DEV_GYRO = 10,
- I2C_DEV_DEBUG_PAD = 12,
- I2C_DEV_IR = 13,
- I2C_DEV_EEPROM = 14, // Unconfirmed
- I2C_DEV_NFC = 15,
- I2C_DEV_QTM = 16,
- I2C_DEV_N3DS_HID = 17
-} I2cDevice;
-
-
-
-void I2C_init(void);
-bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size);
-bool I2C_writeReg(I2cDevice devId, u8 regAddr, u8 data);
diff --git a/source/common/power.c b/source/common/power.c
index d3219c0..9e6d57c 100644
--- a/source/common/power.c
+++ b/source/common/power.c
@@ -18,11 +18,6 @@ void CheckBrightness() {
return;
}
-void ScreenOn() {
- wait_msec(3); // wait 3ms (cause profi200 said so)
- I2C_writeReg(I2C_DEV_MCU, 0x22, 0x2A); // poweron LCD
-}
-
void Reboot() {
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
flushEntireDCache();
diff --git a/source/main.c b/source/main.c
index 79f11de..cea260f 100644
--- a/source/main.c
+++ b/source/main.c
@@ -1,12 +1,13 @@
#include "godmode.h"
#include "power.h"
+#include "pxi.h"
void main(int argc, char** argv)
{
(void) argv; // unused for now
- // Screen on
- ScreenOn();
+ // Wait for ARM11
+ PXI_WaitRemote(PXI_READY);
// Run the main program
if (GodMode(argc) == GODMODE_EXIT_REBOOT) Reboot();
diff --git a/source/start.s b/source/start.s
index 5871917..381869e 100644
--- a/source/start.s
+++ b/source/start.s
@@ -116,13 +116,6 @@ _start_gm:
strlt r3, [r2], #4
blt .LXRQ_Install
- @ Wait for the ARM11 to do its thing
- mov r0, #0x20000000
- .LWaitMPC:
- ldr r1, [r0, #-4]
- cmp r1, #0
- bne .LWaitMPC
-
@ Enable caches / select low exception vectors
ldr r1, =(CR_ALT_VECTORS | CR_DISABLE_TBIT)
ldr r2, =(CR_ENABLE_MPU | CR_ENABLE_DCACHE | CR_ENABLE_ICACHE | \