Created
June 20, 2026 22:26
-
-
Save profi200/f144d81ad3a9ce848f0ed4f78d39bba9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Universal LCD reg dumper. | |
| #include <stdlib.h> | |
| #include "arm11/drivers/lcd.h" | |
| #include "fsutil.h" | |
| static void dumpLcdRegs(void) | |
| { | |
| u8 *const lcd0Buf = calloc(1, 5 * 256); | |
| u8 *const lcd1Buf = calloc(1, 5 * 256); | |
| // Do a normal dump without any modifications. | |
| for(u32 i = 0; i < 256; i++) | |
| { | |
| lcd0Buf[i] = LCDI2C_readReg(0, i); | |
| lcd1Buf[i] = LCDI2C_readReg(1, i); | |
| } | |
| // Skip old LCD controllers. | |
| if(lcd0Buf[255] != 0x01) | |
| { | |
| LCDI2C_writeReg(0, 0x03, 0); | |
| LCDI2C_writeReg(0, 0xAF, 0); | |
| u32 bufPos = 256; | |
| for(u32 i = bufPos; i < 256 + bufPos; i++) | |
| { | |
| lcd0Buf[i] = LCDI2C_readReg(0, i); | |
| } | |
| bufPos += 256; | |
| LCDI2C_writeReg(0, 0x03, 0xAA); | |
| //LCDI2C_writeReg(0, 0xAF, 0); | |
| for(u32 i = bufPos; i < 256 + bufPos; i++) | |
| { | |
| lcd0Buf[i] = LCDI2C_readReg(0, i); | |
| } | |
| bufPos += 256; | |
| LCDI2C_writeReg(0, 0x03, 0); | |
| LCDI2C_writeReg(0, 0xAF, 0xAA); | |
| for(u32 i = bufPos; i < 256 + bufPos; i++) | |
| { | |
| lcd0Buf[i] = LCDI2C_readReg(0, i); | |
| } | |
| bufPos += 256; | |
| LCDI2C_writeReg(0, 0x03, 0xAA); | |
| //LCDI2C_writeReg(0, 0xAF, 0xAA); | |
| for(u32 i = bufPos; i < 256 + bufPos; i++) | |
| { | |
| lcd0Buf[i] = LCDI2C_readReg(0, i); | |
| } | |
| } | |
| // Skip old LCD controllers. | |
| if(lcd1Buf[255] != 0x01) | |
| { | |
| LCDI2C_writeReg(1, 0x03, 0); | |
| LCDI2C_writeReg(1, 0xAF, 0); | |
| u32 bufPos = 256; | |
| for(u32 i = bufPos; i < 256 + bufPos; i++) | |
| { | |
| lcd1Buf[i] = LCDI2C_readReg(1, i); | |
| } | |
| bufPos += 256; | |
| LCDI2C_writeReg(1, 0x03, 0xAA); | |
| //LCDI2C_writeReg(1, 0xAF, 0); | |
| for(u32 i = bufPos; i < 256 + bufPos; i++) | |
| { | |
| lcd1Buf[i] = LCDI2C_readReg(1, i); | |
| } | |
| bufPos += 256; | |
| LCDI2C_writeReg(1, 0x03, 0); | |
| LCDI2C_writeReg(1, 0xAF, 0xAA); | |
| for(u32 i = bufPos; i < 256 + bufPos; i++) | |
| { | |
| lcd1Buf[i] = LCDI2C_readReg(1, i); | |
| } | |
| bufPos += 256; | |
| LCDI2C_writeReg(1, 0x03, 0xAA); | |
| //LCDI2C_writeReg(1, 0xAF, 0xAA); | |
| for(u32 i = bufPos; i < 256 + bufPos; i++) | |
| { | |
| lcd1Buf[i] = LCDI2C_readReg(1, i); | |
| } | |
| } | |
| const Result res = fsQuickWrite("sdmc:/I2C_LCD0_dump.bin", lcd0Buf, 5 * 256); | |
| const Result res2 = fsQuickWrite("sdmc:/I2C_LCD1_dump.bin", lcd1Buf, 5 * 256); | |
| ee_printf("Regs dumped. %" PRIu32 "/%" PRIu32 "\n", res, res2); | |
| free(lcd0Buf); | |
| free(lcd1Buf); | |
| } | |
| static void drawFilledRect(const u16 x, const u16 y, u16 w, const u16 h, const u16 c) | |
| { | |
| const u16 tarH = 240; | |
| u16 *buf = (u16*)GFX_getBuffer(GFX_LCD_TOP, GFX_SIDE_LEFT) + (tarH * x + y); | |
| while(w--) | |
| { | |
| for(unsigned height = 0; height < h; height++) | |
| buf[height] = c; | |
| buf += tarH; | |
| } | |
| } | |
| static void drawTestRects(void) | |
| { | |
| drawFilledRect(0, 0, 32, 32, RGB8_2_565(255, 0, 0)); | |
| drawFilledRect(32, 0, 32, 32, RGB8_2_565(0, 255, 0)); | |
| drawFilledRect(64, 0, 32, 32, RGB8_2_565(0, 0, 255)); | |
| drawFilledRect(96, 0, 32, 32, RGB8_2_565(255, 255, 255)); | |
| } | |
| #include "arm11/drivers/timer.h" | |
| int main(void) | |
| { | |
| GFX_init(GFX_BGR565, GFX_BGR565, GFX_TOP_2D); | |
| GFX_setLcdLuminance(20); | |
| consoleInit(GFX_LCD_BOT, NULL); | |
| GFX_setDoubleBuffering(GFX_LCD_TOP, false); | |
| //CODEC_init(); | |
| drawTestRects(); | |
| dumpLcdRegs(); | |
| while(1) | |
| { | |
| GFX_waitForVBlank0(); | |
| GFX_swapBuffers(); | |
| hidScanInput(); | |
| if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) break; | |
| } | |
| fUnmount(FS_DRIVE_SDMC); | |
| CODEC_deinit(); | |
| GFX_deinit(); | |
| power_off(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment