diff --git a/include/gfx.h b/include/gfx.h index 372c5e1..85e8b29 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -42,7 +42,8 @@ void GX_memoryFill(u64 *buf0a, u32 buf0v, u32 buf0Sz, u32 val0, u64 *buf1a, u32 buf1v, u32 buf1Sz, u32 val1); void GX_displayTransfer(u64 *in, u32 indim, u64 *out, u32 outdim, u32 flags); void GX_textureCopy(u64 *in, u32 indim, u64 *out, u32 outdim, u32 size); -void gfx_swapFramebufs(void); -void gfx_init(); -void gfx_deinit(); +void GFX_setBrightness(u32 brightness); +void GFX_swapFramebufs(void); +void GFX_init(void); +void GFX_deinit(void); #endif diff --git a/include/pxi.h b/include/pxi.h index 410780f..08c48bb 100644 --- a/include/pxi.h +++ b/include/pxi.h @@ -58,17 +58,18 @@ #define PXI_ENABLE_SEND_RECV_FIFO (1u<<15) // Custom PXI Command/Reply Definitions -#define PXI_CMD_ENABLE_LCDS 0x4C434453 -#define PXI_CMD_POWER_OFF 0x504F4646 -#define PXI_CMD_REBOOT 0x48326482 -#define PXI_CMD_ALLOW_POWER_OFF 0x504F4F4B -#define PXI_CMD_FORBID_POWER_OFF 0x504F4E4F -#define PXI_CMD_FIRM_LAUNCH 0x544F4F42 -#define PXI_RPL_FIRM_LAUNCH_READY 0x4F4B6666 -#define PXI_RPL_OK 0x4F4B4F4B -#define PXI_RPL_HOME_PRESSED 0x484F4D45 -#define PXI_RPL_HOME_HELD 0x484F4D22 -#define PXI_RPL_POWER_PRESSED 0x504F5752 +#define PXI_CMD_ENABLE_LCDS (0x4C434453) +#define PXI_CMD_SET_BRIGHTNESS (0x78D28107) +#define PXI_CMD_POWER_OFF (0x504F4646) +#define PXI_CMD_REBOOT (0x48326482) +#define PXI_CMD_ALLOW_POWER_OFF (0x504F4F4B) +#define PXI_CMD_FORBID_POWER_OFF (0x504F4E4F) +#define PXI_CMD_FIRM_LAUNCH (0x544F4F42) +#define PXI_RPL_FIRM_LAUNCH_READY (0x4F4B6666) +#define PXI_RPL_OK (0x4F4B4F4B) +#define PXI_RPL_HOME_PRESSED (0x484F4D45) +#define PXI_RPL_HOME_HELD (0x484F4D22) +#define PXI_RPL_POWER_PRESSED (0x504F5752) void PXI_init(void); @@ -76,3 +77,4 @@ bool PXI_trySendWord(u32 val); u32 PXI_recvWord(void); u32 PXI_tryRecvWord(bool *success); +void PXI_sendBuf(const u32 *const buf, u32 size); diff --git a/source/arm11/gfx.c b/source/arm11/gfx.c index 160cf06..4f1f4d1 100644 --- a/source/arm11/gfx.c +++ b/source/arm11/gfx.c @@ -49,7 +49,7 @@ -static void gfx_setup_framebuf_top() +static void gfxSetupFramebufTop(void) { *((vu32*)(0x10400400+0x00)) = 0x000001C2; *((vu32*)(0x10400400+0x04)) = 0x000000D1; @@ -91,7 +91,7 @@ } } -static void gfx_setup_framebuf_low() +static void gfxSetupFramebufLow(void) { *((vu32*)(0x10400500+0x00)) = 0x000001C2; *((vu32*)(0x10400500+0x04)) = 0x000000D1; @@ -174,7 +174,13 @@ REGs_TE[6] = 1; } -void gfx_swapFramebufs(void) +void GFX_setBrightness(u32 brightness) +{ + REG_LCD_BACKLIGHT_MAIN = brightness; + REG_LCD_BACKLIGHT_SUB = brightness; +} + +void GFX_swapFramebufs(void) { static u8 activeFb = 0; activeFb ^= 1; @@ -188,7 +194,7 @@ GX_textureCopy((u64*)FRAMEBUF_TOP_A_1, 0, (u64*)FRAMEBUF_TOP_A_2, 0, SCREEN_SIZE_TOP + SCREEN_SIZE_SUB); } -void gfx_init(void) +void GFX_init(void) { REG_PDN_GPU_CNT = 0x1007F; *((vu32*)0x10202014) = 0x00000001; @@ -200,8 +206,8 @@ *((vu32*)0x10202244) = 0x1023E; *((vu32*)0x10202A44) = 0x1023E; - gfx_setup_framebuf_top(); - gfx_setup_framebuf_low(); + gfxSetupFramebufTop(); + gfxSetupFramebufLow(); // The GPU mem fill races against the console. //GX_memoryFill((u64*)FRAMEBUF_TOP_A_1, 1u<<9, SCREEN_SIZE_TOP + SCREEN_SIZE_SUB, 0, @@ -213,13 +219,13 @@ TIMER_sleepMs(3); IRQ_registerHandler(IRQ_PDC0, 14, 0, true, vblankIrqHandler); - gfx_swapFramebufs(); + GFX_swapFramebufs(); REG_LCD_COLORFILL_MAIN = 0; REG_LCD_COLORFILL_SUB = 0; } -void gfx_deinit() +void GFX_deinit(void) { /*i2cmcu_lcd_poweroff(); diff --git a/source/arm11/main.c b/source/arm11/main.c index 6df8d5c..470d0ac 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -65,7 +65,7 @@ PXI_trySendWord(PXI_RPL_HOME_HELD); } - gfx_deinit(); // TODO: Let ARM9 decide when to deinit gfx + GFX_deinit(); // TODO: Let ARM9 decide when to deinit gfx firm_launch(); diff --git a/source/arm11/pxi.c b/source/arm11/pxi.c index 9430a57..f58d0cc 100644 --- a/source/arm11/pxi.c +++ b/source/arm11/pxi.c @@ -45,9 +45,13 @@ switch(cmdCode) { case PXI_CMD_ENABLE_LCDS: - gfx_init(); + GFX_init(); PXI_sendWord(PXI_RPL_OK); break; + case PXI_CMD_SET_BRIGHTNESS: + cmdCode = PXI_recvWord(); + GFX_setBrightness(cmdCode); + break; case PXI_CMD_ALLOW_POWER_OFF: g_poweroffAllowed = true; break; @@ -100,3 +104,13 @@ *success = true; return REG_PXI_RECV11; } + +void PXI_sendBuf(const u32 *const buf, u32 size) +{ + while(REG_PXI_CNT11 & PXI_SEND_FIFO_FULL); + for(u32 i = 0; i < size / 4; i++) + { + REG_PXI_SEND11 = buf[i]; + } + REG_PXI_SYNC11 |= PXI_NOTIFY_9; +} diff --git a/source/arm9/pxi.c b/source/arm9/pxi.c index caf317c..0e4fc48 100644 --- a/source/arm9/pxi.c +++ b/source/arm9/pxi.c @@ -66,3 +66,13 @@ *success = true; return REG_PXI_RECV9; } + +void PXI_sendBuf(const u32 *const buf, u32 size) +{ + while(REG_PXI_CNT9 & PXI_SEND_FIFO_FULL); + for(u32 i = 0; i < size / 4; i++) + { + REG_PXI_SEND9 = buf[i]; + } + REG_PXI_SYNC9 |= PXI_NOTIFY_11; +}