int main(int argc, char **argv) { REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR ; u32 old_reg = readPowerManagement(PM_CONTROL_REG); writePowerManagement(PM_CONTROL_REG, old_reg |PM_LED_ON); // enable fast // Reset the clock if needed rtcReset(); // Turn on Sound powerON(POWER_SOUND); // Set up sound defaults. SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F); IPC->soundData = 0; // Set up the interrupt handler irqInit(); irqSet(IRQ_VBLANK, VblankHandler); irqEnable(IRQ_VBLANK); // Setup FIFO irqSet(IRQ_FIFO_NOT_EMPTY,FifoInterruptHandler); irqEnable(IRQ_FIFO_NOT_EMPTY); REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR | IPC_FIFO_RECV_IRQ ; // Keep the ARM7 out of main RAM while (1) swiWaitForVBlank(); return 0; }
void InterruptHandler_IPC_SYNC(void) { u8 sync; sync = IPC_GetSync(); { int oldval, newval; newval = oldval = readPowerManagement(PM_CONTROL_REG); if(sync == IPC2_REQUEST_SET_BACKLIGHTS_OFF) newval = oldval & ~PM_BACKLIGHT_TOP & ~PM_BACKLIGHT_BOTTOM; else if(sync == IPC2_REQUEST_SET_BACKLIGHTS_ON) newval = oldval | PM_BACKLIGHT_TOP | PM_BACKLIGHT_BOTTOM; else if(sync == IPC2_REQUEST_LEDBLINK_OFF) newval = oldval & ~PM_LED_BLINK; else if(sync == IPC2_REQUEST_LEDBLINK_ON) newval = oldval | PM_LED_BLINK; writePowerManagement(PM_CONTROL_REG, newval); } }
static void neoBacklightOn() { u32 enabled = REG_IME; REG_IME = 0; u32 value = readPowerManagement(PM_CONTROL_REG); writePowerManagement(PM_CONTROL_REG, value | PM_BACKLIGHT_BOTTOM); REG_IME = enabled; }
static void neoLidClose() { u32 enabled = REG_IME; REG_IME = 0; const u32 powerValue = readPowerManagement(PM_CONTROL_REG); u32 value = powerValue; value &= ~(PM_BACKLIGHT_BOTTOM | PM_BACKLIGHT_TOP); value |= PM_LED_SLEEP; writePowerManagement(PM_CONTROL_REG, value); REG_IME = enabled; swiChangeSoundBias(0, 0x400); //speaker off neoAudioShutdown(); //ack LIDCLOSE command neoIPCAckCommand(); //wait for lid to open while(1) { swiWaitForVBlank(); u32 command = neoIPCRecvCommand(); if(command) { if(NEOIPC_GET_COMMAND(command) == NEOARM7_LIDOPEN) { break; } else { //ignore all commands (should not get any) neoIPCAckCommand(); } } } enabled = REG_IME; REG_IME = 0; writePowerManagement(PM_CONTROL_REG, powerValue); REG_IME = enabled; swiChangeSoundBias(1, 0x400); //speaker on neoAudioReset(); //ACK lid open command neoIPCAckCommand(); }
void SoundEngine::soundOn() { int pmReg; powerOn((PM_Bits) POWER_SOUND); pmReg = readPowerManagement(PM_CONTROL_REG); pmReg &= ~PM_SOUND_MUTE; pmReg |= PM_SOUND_AMP; writePowerManagement(PM_CONTROL_REG, pmReg); REG_SOUNDCNT = SOUND_ENABLE; REG_MASTER_VOLUME = 127; }
//--------------------------------------------------------------------------------- int main(int argc, char ** argv) { //--------------------------------------------------------------------------------- // read User Settings from firmware readUserSettings(); REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; // enable & prepare fifo asap rtcReset(); //enable sound powerON(POWER_SOUND); writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP ); SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F); irqInit(); // Start the RTC tracking IRQ initClockIRQ(); SetYtrigger(80); irqSet(IRQ_VCOUNT, VcountHandler); irqSet(IRQ_VBLANK, VblankHandler); irqSet(IRQ_WIFI, Wifi_Interrupt); // set up wifi interrupt irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_WIFI); { // sync with arm9 and init wifi u32 fifo_temp; while(1) { // wait for magic number while(REG_IPC_FIFO_CR&IPC_FIFO_RECV_EMPTY) swiWaitForVBlank(); fifo_temp=REG_IPC_FIFO_RX; if(fifo_temp==0x12345678) break; } while(REG_IPC_FIFO_CR&IPC_FIFO_RECV_EMPTY) swiWaitForVBlank(); fifo_temp=REG_IPC_FIFO_RX; // give next value to wifi_init Wifi_Init(fifo_temp); irqSet(IRQ_FIFO_NOT_EMPTY,arm7_fifo); // set up fifo irq irqEnable(IRQ_FIFO_NOT_EMPTY); REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; Wifi_SetSyncHandler(arm7_synctoarm9); // allow wifi lib to notify arm9 } // arm7 wifi init complete // Keep the ARM7 mostly idle while (1) swiWaitForVBlank(); }
//--------------------------------------------------------------------------------- void i2cIRQHandler() { //--------------------------------------------------------------------------------- int cause = (i2cReadRegister(I2C_PM, I2CREGPM_PWRIF) & 0x3) | (i2cReadRegister(I2C_GPIO, 0x02)<<2); switch (cause & 3) { case 1: if (__powerbuttonCB) { __powerbuttonCB(); } else { i2cWriteRegister(I2C_PM, I2CREGPM_RESETFLAG, 1); i2cWriteRegister(I2C_PM, I2CREGPM_PWRCNT, 1); } break; case 2: writePowerManagement(PM_CONTROL_REG,PM_SYSTEM_PWR); break; } }
//--------------------------------------------------------------------------------- int main() { //--------------------------------------------------------------------------------- // clear sound registers dmaFillWords(0, (void*)0x04000400, 0x100); REG_SOUNDCNT |= SOUND_ENABLE; writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP ); powerOn(POWER_SOUND); readUserSettings(); ledBlink(0); irqInit(); // Start the RTC tracking IRQ initClockIRQ(); fifoInit(); mmInstall(FIFO_MAXMOD); SetYtrigger(80); installWifiFIFO(); installSoundFIFO(); installSystemFIFO(); irqSet(IRQ_VCOUNT, VcountHandler); irqSet(IRQ_VBLANK, VblankHandler); irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); setPowerButtonCB(powerButtonCB); // Keep the ARM7 mostly idle while (!exitflag) { if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) { exitflag = true; } swiWaitForVBlank(); } return 0; }
void PA_SetDSLiteBrightness(u8 level){ if (level > 3) level = 3; writePowerManagement(PM_DSLITE_REG, level); }