Skip to content
This repository has been archived by the owner on Oct 13, 2019. It is now read-only.

Commit

Permalink
backlight
Browse files Browse the repository at this point in the history
  • Loading branch information
CTurt committed Sep 6, 2015
1 parent 4512c5a commit dc7f9f4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
11 changes: 11 additions & 0 deletions 3DS/include/drawing.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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();
18 changes: 18 additions & 0 deletions 3DS/source/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
24 changes: 9 additions & 15 deletions 3DS/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -104,6 +102,8 @@ int main(void) {
if(keyboardToggle) {
keyboardActive = !keyboardActive;
keyboardToggle = false;

if(keyboardActive) enableBacklight();
}
}
else keyboardToggle = true;
Expand Down Expand Up @@ -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);

Expand All @@ -156,6 +148,8 @@ int main(void) {

exit:

enableBacklight();

SOC_Shutdown();

svcCloseHandle(fileHandle);
Expand Down

0 comments on commit dc7f9f4

Please sign in to comment.