From c86ca860276766f4bea74f608bad1688118bab89 Mon Sep 17 00:00:00 2001 From: yutaka Date: Fri, 25 May 2007 00:20:08 +0000 Subject: [PATCH] sparate TWL additions to snd_i2s.c git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@82 4ee2a332-4b2b-5046-8439-1ba90f034370 --- build/libraries/snd/ARM7/Makefile | 19 +-- build/libraries/snd/ARM7/snd_global.c | 26 ++-- build/libraries/snd/ARM7/snd_i2s.c | 188 ++++++++++++++++++++++++++ include/twl/snd/ARM7/i2s.h | 57 ++++++++ 4 files changed, 264 insertions(+), 26 deletions(-) create mode 100644 build/libraries/snd/ARM7/snd_i2s.c create mode 100644 include/twl/snd/ARM7/i2s.h diff --git a/build/libraries/snd/ARM7/Makefile b/build/libraries/snd/ARM7/Makefile index 61e68a1..bc91a05 100644 --- a/build/libraries/snd/ARM7/Makefile +++ b/build/libraries/snd/ARM7/Makefile @@ -33,16 +33,17 @@ SRCS = \ snd_global.c \ snd_channel.c \ snd_util.c \ - snd_main.c \ + snd_main.c \ snd_capture.c \ - snd_exchannel.c \ - snd_seq.c \ - snd_midiplayer.c \ - snd_bank.c \ - snd_work.c \ - snd_alarm.c \ - snd_command.c \ - snd_data.c + snd_exchannel.c \ + snd_seq.c \ + snd_midiplayer.c \ + snd_bank.c \ + snd_work.c \ + snd_alarm.c \ + snd_command.c \ + snd_data.c \ + snd_i2s.c TARGET_LIB = libsnd_sp$(TWL_LIBSUFFIX).a diff --git a/build/libraries/snd/ARM7/snd_global.c b/build/libraries/snd/ARM7/snd_global.c index d535a2a..e09bf86 100644 --- a/build/libraries/snd/ARM7/snd_global.c +++ b/build/libraries/snd/ARM7/snd_global.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -54,21 +55,8 @@ extern void PMi_ResetControl(u8 sw); void SND_Enable(void) { OSIntrMode enabled = OS_DisableInterrupts(); - - reg_SND_POWCNT |= REG_SND_POWCNT_SPE_MASK; - reg_CFG_TWL_EX |= REG_CFG_TWL_EX_I2S_MASK; - - if ((reg_CFG_CLK & REG_CFG_CLK_SND_MASK) == 0) - { - CDC_Init(); - } - - reg_SND_I2SCNT |= REG_SND_I2SCNT_E_MASK - | REG_SND_I2SCNT_MIX_RATIO_MASK; - reg_SND_I2SCNT &= ~REG_SND_I2SCNT_MUTE_MASK; - + SND_I2SEnable(); reg_SND_SOUNDCNT_8 |= REG_SND_SOUNDCNT_8_E_MASK; - (void)OS_RestoreInterrupts(enabled); } @@ -84,10 +72,8 @@ void SND_Enable(void) void SND_Disable(void) { OSIntrMode enabled = OS_DisableInterrupts(); - - reg_SND_I2SCNT &= REG_SND_I2SCNT_E_MASK; + SND_I2SDisable(); reg_SND_SOUNDCNT_8 &= ~REG_SND_SOUNDCNT_8_E_MASK; - (void)OS_RestoreInterrupts(enabled); } @@ -125,6 +111,9 @@ void SND_Shutdown(void) *---------------------------------------------------------------------------*/ void SND_BeginSleep(void) { + // adding process for TWL + SND_I2SBeginSleep(); + // stop all sound SND_Disable(); @@ -164,6 +153,9 @@ void SND_EndSleep(void) // sound enable SND_Enable(); + + // adding process for TWL + SND_I2SEndSleep(); } /*---------------------------------------------------------------------------* diff --git a/build/libraries/snd/ARM7/snd_i2s.c b/build/libraries/snd/ARM7/snd_i2s.c new file mode 100644 index 0000000..a15bd4f --- /dev/null +++ b/build/libraries/snd/ARM7/snd_i2s.c @@ -0,0 +1,188 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - SND - libraries + File: snd_i2s.c + + Copyright 2004-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: snd_i2s.c,v $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include + +#include +#include +#include +#include + +/****************************************************************************** + static typedef declaration + ******************************************************************************/ + +/****************************************************************************** + static variables + ******************************************************************************/ + +static u8 state; +static BOOL isTwl = FALSE; + +/****************************************************************************** + static functions + ******************************************************************************/ + +static void SNDi_I2SInit(void) +{ + static BOOL isInitialized = FALSE; + if (isInitialized == FALSE) + { + isInitialized = TRUE; + reg_SND_POWCNT |= REG_SND_POWCNT_SPE_MASK; + reg_CFG_TWL_EX |= REG_CFG_TWL_EX_I2S_MASK; + if (reg_CFG_TWL_EX & REG_CFG_TWL_EX_I2S_MASK) + { + isTwl = TRUE; + reg_SND_I2SCNT |= REG_SND_I2SCNT_MIX_RATIO_MASK; + reg_SND_I2SCNT &= ~REG_SND_I2SCNT_MUTE_MASK; + } + } +} + +/****************************************************************************** + public functions + ******************************************************************************/ + +/*---------------------------------------------------------------------------* + Name: SND_I2SEnable + + Description: Enable sound master control + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void SND_I2SEnable(void) +{ + SNDi_I2SInit(); + + if (isTwl) + { + reg_SND_I2SCNT |= REG_SND_I2SCNT_E_MASK; + } +} + +/*---------------------------------------------------------------------------* + Name: SND_I2SDisable + + Description: Disable sound master control + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void SND_I2SDisable(void) +{ + if (isTwl) + { + reg_SND_I2SCNT &= ~REG_SND_I2SCNT_E_MASK; + } +} + +/*---------------------------------------------------------------------------* + Name: SND_I2SShutdown + + Description: shutdown sound system + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void SND_I2SShutdown(void) +{ +} + +/*---------------------------------------------------------------------------* + Name: SND_BeginSleep + + Description: Begin sleep + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void SND_I2SBeginSleep(void) +{ + if (isTwl) + { + state = reg_SND_I2SCNT; + } +} + +/*---------------------------------------------------------------------------* + Name: SND_EndSleep + + Description: End sleep + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void SND_I2SEndSleep(void) +{ + if (isTwl) + { + reg_SND_I2SCNT = state; + } +} + +/*---------------------------------------------------------------------------* + Name: SND_I2SMute + + Description: Set mute status + + Arguments: isMute : TRUE if mute + + Returns: None + *---------------------------------------------------------------------------*/ +void SND_I2SMute(BOOL isMute) +{ + if (isTwl) + { + if (isMute) + { + reg_SND_I2SCNT |= REG_SND_I2SCNT_MUTE_MASK; + } + else + { + reg_SND_I2SCNT &= ~REG_SND_I2SCNT_MUTE_MASK; + } + } +} + +/*---------------------------------------------------------------------------* + Name: SND_I2SSetMixingRatio + + Description: Set output selector + + Arguments: nitroRatio : NITRO / (NITRO + DSP) ratio. (0-8) + if 8, nitro sound is all. + + Returns: None + *---------------------------------------------------------------------------*/ +void SND_I2SSetMixingRatio(int nitroRatio) +{ + if (isTwl) + { + if (nitroRatio >= 0 && nitroRatio <= 8) + { + reg_SND_I2SCNT &= ~REG_SND_I2SCNT_MIX_RATIO_MASK; + reg_SND_I2SCNT = (u8)((reg_SND_I2SCNT & ~REG_SND_I2SCNT_MIX_RATIO_MASK) | nitroRatio); + } + } +} + +/*====== End of snd_i2s.c ======*/ diff --git a/include/twl/snd/ARM7/i2s.h b/include/twl/snd/ARM7/i2s.h new file mode 100644 index 0000000..a08e578 --- /dev/null +++ b/include/twl/snd/ARM7/i2s.h @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - SND - include + File: i2s.h + + Copyright 2004-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: i2s.h,v $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_SND_COMMON_I2S_H_ +#define TWL_SND_COMMON_I2S_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** + public macro variables + ******************************************************************************/ +#define SND_I2S_MIXING_NITRO_MAX 8 +#define SND_I2S_MIXING_NITRO_MIN 0 +#define SND_I2S_MIXING_DSP_MAX 0 +#define SND_I2S_MIXING_DSP_MIN 8 + +/****************************************************************************** + public function declaration + ******************************************************************************/ + +#ifdef SDK_ARM7 + +void SND_I2SEnable(void); +void SND_I2SDisable(void); + +void SND_I2SShutdown(void); + +void SND_I2SBeginSleep(void); +void SND_I2SEndSleep(void); + +void SND_I2SMute(BOOL isMute); + +void SND_I2SSetMixingRatio(int nitroRatio); + +#endif /* SDK_ARM7 */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* TWL_SND_COMMON_I2S_H_ */