backlight

This commit is contained in:
CTurt 2015-09-06 18:50:21 +01:00
parent 800657cc2b
commit 6577488dc0
3 changed files with 38 additions and 15 deletions

View File

@ -1,5 +1,13 @@
#pragma once
#ifndef REG_LCDBACKLIGHTMAIN
#define REG_LCDBACKLIGHTMAIN (u32)(0x1ED02240 - 0x1EB00000)
#endif
#ifndef REG_LCDBACKLIGHTSUB
#define REG_LCDBACKLIGHTSUB (u32)(0x1ED02A40 - 0x1EB00000)
#endif
inline void clearScreen(void);
#define drawPixelRGB(x, y, r, g, b) drawPixelRGBFramebuffer(0, x, y, r, g, b)
@ -10,3 +18,6 @@ inline void drawBoxFramebuffer(u8 *fb, int x, int y, int width, int height, u8 r
#define drawString(sx, sy, text, ...) drawStringFramebuffer(0, sx, sy, text, ##__VA_ARGS__)
void drawStringFramebuffer(u8 *fb, int sx, int sy, char *text, ...);
void disableBacklight();
void enableBacklight();

View File

@ -155,3 +155,21 @@ void drawStringFramebuffer(u8 *fb, int sx, int sy, char *text, ...) {
sx += 8;
}
}
static u32 brightnessMain;
static u32 brightnessSub;
void disableBacklight() {
u32 off = 0;
GSPGPU_ReadHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &brightnessMain, 4);
GSPGPU_ReadHWRegs(NULL, REG_LCDBACKLIGHTSUB, &brightnessSub, 4);
GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &off, 4);
GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTSUB, &off, 4);
}
void enableBacklight() {
GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &brightnessMain, 4);
GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTSUB, &brightnessSub, 4);
}

View File

@ -34,7 +34,8 @@ int main(void) {
acInit();
gfxInitDefault();
//consoleInit(GFX_BOTTOM, NULL);
gfxSetDoubleBuffering(GFX_TOP, false);
gfxSetDoubleBuffering(GFX_BOTTOM, false);
if(setjmp(exitJmp)) goto exit;
@ -81,20 +82,17 @@ int main(void) {
gfxFlushBuffers();
gfxSwapBuffers();
clearScreen();
gfxFlushBuffers();
gfxSwapBuffers();
disableBacklight();
while(aptMainLoop()) {
hidScanInput();
irrstScanInput();
u32 kHeld = hidKeysHeld();
circlePosition circlePad;
circlePosition cStick;
hidCstickRead(&cStick);
hidCircleRead(&circlePad);
irrstCstickRead(&cStick);
touchPosition touch;
touchRead(&touch);
@ -104,6 +102,8 @@ int main(void) {
if(keyboardToggle) {
keyboardActive = !keyboardActive;
keyboardToggle = false;
if(keyboardActive) enableBacklight();
}
}
else keyboardToggle = true;
@ -137,15 +137,7 @@ int main(void) {
sendKeys(kHeld, circlePad, touch, cStick);
receiveBuffer(sizeof(struct packet));
/*u8 *frame = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
switch(rcvBuf.command) {
case SCREENSHOT:
//drawStringFramebuffer(frame, 10, 10, "R");
break;
}*/
//receiveBuffer(sizeof(struct packet));
if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);
@ -156,6 +148,8 @@ int main(void) {
exit:
enableBacklight();
SOC_Shutdown();
svcCloseHandle(fileHandle);