From 2e8f7d92a553aec9419190e985d88fbf512407a6 Mon Sep 17 00:00:00 2001 From: profi200 Date: Sun, 7 Jun 2020 19:50:26 +0200 Subject: [PATCH] Automatically enumerate IPC cmds. Actually power off bottom screen backlight instead of dimming it to basically off. --- include/hardware/gfx.h | 11 +++++++++++ include/ipc_handler.h | 24 +++++++++++++++--------- source/arm11/hardware/gfx.c | 30 +++++++++++++++++++++++++----- source/arm11/main.c | 2 +- 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/include/hardware/gfx.h b/include/hardware/gfx.h index a97e361..c91d6f0 100644 --- a/include/hardware/gfx.h +++ b/include/hardware/gfx.h @@ -67,6 +67,13 @@ typedef enum GFX_EVENT_P3D = 5u } GfxEvent; +typedef enum +{ + GFX_BLIGHT_BOT = 1u<<2, + GFX_BLIGHT_TOP = 1u<<4, + GFX_BLIGHT_BOTH = GFX_BLIGHT_TOP | GFX_BLIGHT_BOT +} GfxBlight; + void GFX_init(GfxFbFmt fmtTop, GfxFbFmt fmtBot); @@ -80,6 +87,10 @@ void GFX_deinit(void); void GFX_setFramebufFmt(GfxFbFmt fmtTop, GfxFbFmt fmtBot); +void GFX_powerOnBacklights(GfxBlight mask); + +void GFX_powerOffBacklights(GfxBlight mask); + void GFX_setBrightness(u8 top, u8 bot); void GFX_setForceBlack(bool top, bool bot); diff --git a/include/ipc_handler.h b/include/ipc_handler.h index 3d3cdff..c991385 100644 --- a/include/ipc_handler.h +++ b/include/ipc_handler.h @@ -29,24 +29,30 @@ #define IPC_CMD_PARAMS_MASK(cmd) ((cmd) & 15u) // Max 15 -#define MAKE_CMD(id, inBufs, outBufs, params) ((id)<<8 | (inBufs)<<6 | (outBufs)<<4 | params) +// https://stackoverflow.com/a/52770279 +// Note: __COUNTER__ is non standard. +#define MAKE_CMD9(inBufs, outBufs, params) ((__COUNTER__ - _CMD9_C_BASE)<<8 | (inBufs)<<6 | (outBufs)<<4 | params) +#define MAKE_CMD11(inBufs, outBufs, params) ((__COUNTER__ - _CMD11_C_BASE)<<8 | (inBufs)<<6 | (outBufs)<<4 | params) +enum {_CMD9_C_BASE = __COUNTER__ + 1}; // Start at 0. typedef enum { - IPC_CMD9_PREPARE_GBA = MAKE_CMD(0, 0, 0, 2), - IPC_CMD9_SET_GBA_RTC = MAKE_CMD(1, 0, 0, 2), - IPC_CMD9_GET_GBA_RTC = MAKE_CMD(2, 0, 1, 0), - IPC_CMD9_PREPARE_POWER = MAKE_CMD(3, 0, 0, 0) + IPC_CMD9_PREPARE_GBA = MAKE_CMD9(0, 0, 2), + IPC_CMD9_SET_GBA_RTC = MAKE_CMD9(0, 0, 2), + IPC_CMD9_GET_GBA_RTC = MAKE_CMD9(0, 1, 0), + IPC_CMD9_PREPARE_POWER = MAKE_CMD9(0, 0, 0) } IpcCmd9; +enum {_CMD11_C_BASE = __COUNTER__ + 1}; // Start at 0. typedef enum { - IPC_CMD11_PRINT_MSG = MAKE_CMD(0, 0, 0, 0), // Invalid on purpose. Will be decided later. - IPC_CMD11_PANIC = MAKE_CMD(1, 0, 0, 0), - IPC_CMD11_EXCEPTION = MAKE_CMD(2, 0, 0, 0) + IPC_CMD11_PRINT_MSG = MAKE_CMD11(0, 0, 0), // Invalid on purpose. Will be decided later. + IPC_CMD11_PANIC = MAKE_CMD11(0, 0, 0), + IPC_CMD11_EXCEPTION = MAKE_CMD11(0, 0, 0) } IpcCmd11; -#undef MAKE_CMD +#undef MAKE_CMD9 +#undef MAKE_CMD11 typedef struct diff --git a/source/arm11/hardware/gfx.c b/source/arm11/hardware/gfx.c index 94e96a4..5f30aeb 100644 --- a/source/arm11/hardware/gfx.c +++ b/source/arm11/hardware/gfx.c @@ -19,6 +19,7 @@ #include #include #include "types.h" +#include "fb_assert.h" #include "hardware/gfx.h" #include "arm11/hardware/lcd.h" #include "arm11/hardware/gx.h" @@ -163,7 +164,7 @@ void GFX_deinit(void) if(power & ~1u) // Poweroff backlights if on. { MCU_controlLCDPower(power & ~1u); - if(MCU_waitEvents(0x3Fu<<24) != (power & ~1u)<<24) panic(); + if(MCU_waitEvents(0x3Fu<<24) != (u32)(power & ~1u)<<24) panic(); } if(power & 1u) // Poweroff LCDs if on. { @@ -245,8 +246,8 @@ static void setupFramebufs(GfxFbFmt fmtTop, GfxFbFmt fmtBot) g_gfxState.strides[0] = 240u * topPixSize; // No gap. g_gfxState.strides[1] = 240u * botPixSize; // No gap. - const u32 topSize = 400 * 240 * topPixSize; - const u32 botSize = 320 * 240 * botPixSize; + const u32 topSize = 400u * 240 * topPixSize; + const u32 botSize = 320u * 240 * botPixSize; g_gfxState.framebufs[0][0] = vramAlloc(topSize); // Top A1 (3D left eye) void *botPtr = vramAlloc(botSize); g_gfxState.framebufs[1][0] = botPtr; // Bottom A1 @@ -398,6 +399,25 @@ static void waitLcdsReady(void) } } +void GFX_powerOnBacklights(GfxBlight mask) +{ + fb_assert((mask & ~GFX_BLIGHT_BOTH) == 0u); + g_gfxState.lcdPower |= mask; + + mask <<= 1; + MCU_controlLCDPower(mask); // Power on backlights. + if(MCU_waitEvents(0x3Fu<<24) != (u32)mask<<24) panic(); +} + +void GFX_powerOffBacklights(GfxBlight mask) +{ + fb_assert((mask & ~GFX_BLIGHT_BOTH) == 0u); + g_gfxState.lcdPower &= ~mask; + + MCU_controlLCDPower(mask); // Power off backlights. + if(MCU_waitEvents(0x3Fu<<24) != (u32)mask<<24) panic(); +} + void GFX_setBrightness(u8 top, u8 bot) { if(top > 64 || bot > 64) return; @@ -410,8 +430,8 @@ void GFX_setBrightness(u8 top, u8 bot) void GFX_setForceBlack(bool top, bool bot) { - REG_LCD_ABL0_FILL = top<<24; // Force blackscreen - REG_LCD_ABL1_FILL = bot<<24; // Force blackscreen + REG_LCD_ABL0_FILL = (u32)top<<24; // Force blackscreen + REG_LCD_ABL1_FILL = (u32)bot<<24; // Force blackscreen } void GFX_setDoubleBuffering(u8 screen, bool dBuf) diff --git a/source/arm11/main.c b/source/arm11/main.c index dd8d860..ae1add4 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -41,7 +41,7 @@ int main(void) { #ifdef NDEBUG GFX_setForceBlack(false, true); - GFX_setBrightness(DEFAULT_BRIGHTNESS, 0); + GFX_powerOffBacklights(GFX_BLIGHT_BOT); #endif // Sync LgyFb start with LCD VBlank. GFX_waitForVBlank0();