gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Turning off a backlight

#58575 - josath - Mon Oct 24, 2005 6:18 pm

I'm trying to turn off a backlight. But for some reason, both backlights, and the sound amp turn off when I do this. The only part I'm not sure about is 3, what is the 'register offset'?
From neimod's DSTek:
Quote:

Reading and writing powermanagement registers
1. Wait until the SPI busy flag is cleared
2. Enable SPICNT, with baudrate 1MHz, powermanagement device, 8 clocks, and continuous mode.
3. Set SPIDATA to the register offset
a)To read from the PM register, enable bit 7.
b)To write to the PM register, clear bit 7.
4. Wait until the SPI busy flag is cleared
5. Set SPICNT to single byte mode now
6. a)Set SPIDATA to 0
b)Set SPIDATA to the register value you want to write.
7. a)Wait until the SPI busy flag is cleared
8. a)the lower 8bits of SPIDATA now contain the contents of the PM register.


My code (numbers indicate which step it corresponds to):
Code:

        SerialWaitBusy(); //1
        REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz | SPI_DEVICE_POWER | SPI_8CLOCKS | SPI_CONTINUOUS; //2
        REG_SPIDATA = 0; //3 - is this right?
        SerialWaitBusy(); //4
        REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz | SPI_DEVICE_POWER | SPI_8CLOCKS | SPI_SINGLE_BYTE; //5
        REG_SPIDATA = 0; //6a

        // This line should keep everything on, execpt for the bottom backlight. However, both backlights, and the sound amp turn off
        REG_SPIDATA = PM_SOUND_PWR | PM_SOUND_VOL | PM_BACKLIGHT_TOP | PM_LED_CONTROL(0) | PM_SYSTEM_PWR; //6b

        SerialWaitBusy(); //7


FYI: SPI_8CLOCKS and SPI_SINGLE_BYTE are defined to 0, I just added them to be clear what I am doing.

Any suggestions where I went wrong? What exactly is "register offset"? My guess, is it means the 0 in the line "PM 0H - REG_PM_CONTROL - Powermanagement Control (Register 0h) (R/W)" which is why I'm currently setting it to 0.

#58576 - Mighty Max - Mon Oct 24, 2005 6:21 pm

You only do step 6a when reading and 6b when writing. So remove the 6a line.

Also, you don't have to wait again, it is again a "a)" step that you only need when reading.
_________________
GBAMP Multiboot

#58586 - josath - Mon Oct 24, 2005 7:05 pm

Ok, now I'm doing this:

Code:

        SerialWaitBusy(); //1
        REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz | SPI_DEVICE_POWER | SPI_8CLOCKS | SPI_CONTINUOUS; //2
        REG_SPIDATA = 0; //3 - is this right?
        SerialWaitBusy(); //4
        REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz | SPI_DEVICE_POWER | SPI_8CLOCKS | SPI_SINGLE_BYTE; //5

        // This line should keep everything on, execpt for the bottom backlight.
         REG_SPIDATA = PM_SOUND_PWR | PM_SOUND_VOL | PM_BACKLIGHT_TOP | PM_LED_CONTROL(0) | PM_SYSTEM_PWR; //6b


However, now the entire DS shuts down.

#58666 - Kir - Tue Oct 25, 2005 5:31 am

Try to look in the Moonshell code. It has "backlight off on touchscreen when fullscreen video is being played" feature.

#59122 - josath - Sat Oct 29, 2005 8:53 am

Got it to work...
I just copied a7sleep.cpp & a7sleep.h from moonshell (but the code was written by SaTa_JP) into my arm7 source folder, then run:
Code:
a7lcd_select(PM_BACKLIGHT_TOP);

and that turns off the bottom backlight.

Other stuff in a7sleep is useful as well...like going to sleep when the lid is closed. this stuff (or something similar) should be integrated into libnds. I think the default arm7 should sleep on lid close (if it doesn't already...i'm a bit behind the latest cvs code)