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 #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); inline void clearScreen(void);
#define drawPixelRGB(x, y, r, g, b) drawPixelRGBFramebuffer(0, x, y, r, g, b) #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__) #define drawString(sx, sy, text, ...) drawStringFramebuffer(0, sx, sy, text, ##__VA_ARGS__)
void drawStringFramebuffer(u8 *fb, int sx, int sy, char *text, ...); 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; 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(); acInit();
gfxInitDefault(); gfxInitDefault();
//consoleInit(GFX_BOTTOM, NULL); gfxSetDoubleBuffering(GFX_TOP, false);
gfxSetDoubleBuffering(GFX_BOTTOM, false);
if(setjmp(exitJmp)) goto exit; if(setjmp(exitJmp)) goto exit;
@ -81,20 +82,17 @@ int main(void) {
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
clearScreen(); disableBacklight();
gfxFlushBuffers();
gfxSwapBuffers();
while(aptMainLoop()) { while(aptMainLoop()) {
hidScanInput(); hidScanInput();
irrstScanInput(); irrstScanInput();
u32 kHeld = hidKeysHeld(); u32 kHeld = hidKeysHeld();
circlePosition circlePad; circlePosition circlePad;
circlePosition cStick; circlePosition cStick;
hidCstickRead(&cStick);
hidCircleRead(&circlePad); hidCircleRead(&circlePad);
irrstCstickRead(&cStick);
touchPosition touch; touchPosition touch;
touchRead(&touch); touchRead(&touch);
@ -104,6 +102,8 @@ int main(void) {
if(keyboardToggle) { if(keyboardToggle) {
keyboardActive = !keyboardActive; keyboardActive = !keyboardActive;
keyboardToggle = false; keyboardToggle = false;
if(keyboardActive) enableBacklight();
} }
} }
else keyboardToggle = true; else keyboardToggle = true;
@ -137,15 +137,7 @@ int main(void) {
sendKeys(kHeld, circlePad, touch, cStick); sendKeys(kHeld, circlePad, touch, cStick);
receiveBuffer(sizeof(struct packet)); //receiveBuffer(sizeof(struct packet));
/*u8 *frame = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
switch(rcvBuf.command) {
case SCREENSHOT:
//drawStringFramebuffer(frame, 10, 10, "R");
break;
}*/
if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1); if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);
@ -156,6 +148,8 @@ int main(void) {
exit: exit:
enableBacklight();
SOC_Shutdown(); SOC_Shutdown();
svcCloseHandle(fileHandle); svcCloseHandle(fileHandle);