mirror of
https://github.com/rvtr/twl_wrapsdk.git
synced 2025-10-31 06:11:10 -04:00
add SND, a part of CODEC, and I2C libraries
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@81 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
parent
21d7a66b00
commit
e342d61547
@ -173,6 +173,9 @@ TWL_LIBS_BASE ?= \
|
||||
libvlink_sp \
|
||||
libnvram_sp \
|
||||
libaes_sp \
|
||||
libi2c_sp \
|
||||
libcdc_sp \
|
||||
libsnd_sp \
|
||||
|
||||
ifdef TWL_PROFILE_TYPE
|
||||
TWL_LIBS_BASE += libos_sp.$(TWL_PROFILE_TYPE)
|
||||
|
||||
@ -29,6 +29,9 @@ SUBDIRS = \
|
||||
spi \
|
||||
ctrdg \
|
||||
aes \
|
||||
i2c \
|
||||
cdc \
|
||||
snd \
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
55
build/libraries/cdc/ARM7/Makefile
Normal file
55
build/libraries/cdc/ARM7/Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - CDC - libraries
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: Makefile,v $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
TWL_CODEGEN_ALL ?= True
|
||||
|
||||
# Codegen for sub processer
|
||||
TWL_PROC = ARM7
|
||||
|
||||
SRCS = cdc.c \
|
||||
cdc_api.c \
|
||||
cdc_filter_coefficient.c
|
||||
|
||||
|
||||
TARGET_LIB = libcdc_sp$(TWL_LIBSUFFIX).a
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# DEBUG版ビルドの場合、RELEASE版でビルドして
|
||||
# DEBUG版のライブラリを装います。
|
||||
|
||||
ifdef TWL_DEBUG
|
||||
TWL_BUILD_TYPE = RELEASE
|
||||
endif
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(TWL_INSTALL_LIBDIR)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
268
build/libraries/cdc/ARM7/src/cdc.c
Normal file
268
build/libraries/cdc/ARM7/src/cdc.c
Normal file
@ -0,0 +1,268 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - libraties - CDC_
|
||||
File: CDC_.c
|
||||
|
||||
Copyright 2006-2007 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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <twl.h>
|
||||
#include <twl/i2c/ARM7/i2c.h>
|
||||
#include <twl/cdc/ARM7/cdc_reg.h>
|
||||
#include <twl/cdc/ARM7/cdc.h>
|
||||
|
||||
|
||||
void CDCi_PreInitAudio( void );
|
||||
void CDCi_PostInitAudio( void );
|
||||
void CDCi_PreInitMic( void );
|
||||
void CDCi_PostInitMic( void );
|
||||
void CDCi_InitTouchPanel( void );
|
||||
void CDCi_InitCoefTable( void );
|
||||
|
||||
|
||||
SPIBaudRate cdcSPIBaudRate = CDC_SPI_BAUDRATE_DEFAULT;
|
||||
BOOL cdcIsTwlMode = TRUE;
|
||||
int cdcCurrentPage = 0;
|
||||
|
||||
int cdcRevisionID = 0;
|
||||
|
||||
#define CDC_SPI_MODE_SETTING_REVISION_A ((u16)((1 << REG_SPI_SPICNT_E_SHIFT) | \
|
||||
(0 << REG_SPI_SPICNT_I_SHIFT) | \
|
||||
(SPI_SLAVE_RESERVED << REG_SPI_SPICNT_SEL_SHIFT) | \
|
||||
(CDC_SPI_BAUDRATE_DEFAULT << REG_SPI_SPICNT_BAUDRATE_SHIFT)))
|
||||
#define CDC_SPI_MODE_SETTING_REVISION_B ((u16)((1 << REG_SPI_SPICNT_E_SHIFT) | \
|
||||
(0 << REG_SPI_SPICNT_I_SHIFT) | \
|
||||
(SPI_SLAVE_CODEC_TP << REG_SPI_SPICNT_SEL_SHIFT) | \
|
||||
(CDC_SPI_BAUDRATE_DEFAULT << REG_SPI_SPICNT_BAUDRATE_SHIFT)))
|
||||
#define CDC_SPI_MODE_SETTING_REVISION_C CDC_SPI_MODE_SETTING_REVISION_B
|
||||
|
||||
#if 0
|
||||
u16 cdcSpiMode = CDC_SPI_MODE_SETTING_REVISION_B;
|
||||
|
||||
//================================================================================
|
||||
static inline void CDCi_ChangeSpiMode( SPITransMode continuous )
|
||||
{
|
||||
reg_SPI_SPICNT = (u16)((continuous << REG_SPI_SPICNT_MODE_SHIFT) | CDC_SpiMode );
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// SPI BIT CONTROL
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetSpiParams
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
maskBits : bits to mask
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_SetSpiParams( u8 reg, u8 setBits, u8 maskBits )
|
||||
{
|
||||
u8 tmp;
|
||||
tmp = CDCi_ReadSpiRegister( reg );
|
||||
tmp &= ~maskBits;
|
||||
setBits &= maskBits;
|
||||
tmp |= setBits;
|
||||
CDCi_WriteSpiRegister( reg, tmp );
|
||||
}
|
||||
void CDC_SetSpiParams( u8 reg, u8 setBits, u8 maskBits )
|
||||
{
|
||||
(void)spiLock();
|
||||
CDCi_SetSpiParams( reg, setBits, maskBits );
|
||||
(void)spiUnlock();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_SetSpiFlags
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_SetSpiFlags( u8 reg, u8 setBits )
|
||||
{
|
||||
CDCi_SetSpiParams( reg, setBits, setBits );
|
||||
}
|
||||
void CDC_SetSpiFlags( u8 reg, u8 setBits )
|
||||
{
|
||||
CDC_SetSpiParams( reg, setBits, setBits );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_ClearSpiFlags
|
||||
|
||||
Description: clear control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
clrBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_ClearSpiFlags( u8 reg, u8 clrBits )
|
||||
{
|
||||
CDCi_SetSpiParams( reg, 0, clrBits );
|
||||
}
|
||||
void CDC_ClearSpiFlags( u8 reg, u8 clrBits )
|
||||
{
|
||||
CDC_SetSpiParams( reg, 0, clrBits );
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// SPI ACCESS
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_WriteSpiRegister
|
||||
|
||||
Description: set value to PMIC register
|
||||
|
||||
Arguments: reg : PMIC register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_WriteSpiRegister( u8 reg, u8 data )
|
||||
{
|
||||
i_spiWait();
|
||||
|
||||
CDCi_ChangeSpiMode( SPI_TRANSMODE_CONTINUOUS );
|
||||
i_spiSendWait( reg << 1 );
|
||||
|
||||
CDCi_ChangeSpiMode( SPI_TRANSMODE_1BYTE );
|
||||
i_spiSend( data );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_ReadSpiRegister
|
||||
|
||||
Description: get value from PMIC register
|
||||
|
||||
Arguments: reg : PMIC register
|
||||
|
||||
Returns: value which is read from specified PMIC register
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 CDCi_ReadSpiRegister( u8 reg )
|
||||
{
|
||||
u8 data;
|
||||
|
||||
i_spiWait();
|
||||
|
||||
CDCi_ChangeSpiMode( SPI_TRANSMODE_CONTINUOUS );
|
||||
i_spiSendWait( reg << 1 );
|
||||
|
||||
CDCi_ChangeSpiMode( SPI_TRANSMODE_1BYTE );
|
||||
data = i_spiDummyWaitReceive();
|
||||
return data;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_WriteSpiRegisters
|
||||
|
||||
Description: set value to decive registers through SPI.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_WriteSpiRegisters( u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
int i;
|
||||
|
||||
i_spiWait();
|
||||
|
||||
CDCi_ChangeSpiMode( SPI_TRANSMODE_CONTINUOUS );
|
||||
i_spiSendWait( reg << 1 );
|
||||
|
||||
for ( i=0; i<(size-1); i++ )
|
||||
{
|
||||
i_spiWait();
|
||||
i_spiSend( *bufp++ );
|
||||
}
|
||||
i_spiWait();
|
||||
CDCi_ChangeSpiMode( SPI_TRANSMODE_1BYTE );
|
||||
i_spiSend( *bufp++ );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_ReadSpiRegisters
|
||||
|
||||
Description: get value from decive registers through SPI.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_ReadSpiRegisters( u8 reg, u8 *bufp, size_t size )
|
||||
{
|
||||
int i;
|
||||
|
||||
i_spiWait();
|
||||
|
||||
CDCi_ChangeSpiMode( SPI_TRANSMODE_CONTINUOUS );
|
||||
i_spiSendWait( reg << 1 );
|
||||
|
||||
for ( i=0; i<(size-1); i++ )
|
||||
{
|
||||
i_spiWait();
|
||||
*bufp++ = i_spiDummyWaitReceive();
|
||||
}
|
||||
CDCi_ChangeSpiMode( SPI_TRANSMODE_1BYTE );
|
||||
*bufp++ = i_spiDummyWaitReceive();
|
||||
}
|
||||
#endif
|
||||
|
||||
//================================================================================
|
||||
// Utility Functions
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_ChangePage
|
||||
|
||||
Description: change register page
|
||||
|
||||
Arguments: page_no : next page number
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_ChangePage( int page_no )
|
||||
{
|
||||
SDK_ASSERT( (page_no == 0) || (page_no == 1) || (page_no == 3) || (page_no == 4) ||
|
||||
(page_no == 8) || (page_no == 9) || (page_no == 252) || (page_no == 255) );
|
||||
|
||||
// 既にそのページにいる
|
||||
if (cdcCurrentPage == page_no)
|
||||
return;
|
||||
|
||||
// 255 だけ別扱い
|
||||
if (cdcCurrentPage == 255)
|
||||
{
|
||||
CDCi_WriteI2cRegister( REG_CDC255_PAGE_CTL_ADDR, (u8)page_no );
|
||||
}
|
||||
else
|
||||
{
|
||||
CDCi_WriteI2cRegister( REG_CDC_PAGE_CTL_ADDR, (u8)page_no );
|
||||
}
|
||||
|
||||
cdcCurrentPage = page_no;
|
||||
}
|
||||
// maybe change i2c to spi
|
||||
void CDC_ChangePage( int page_no )
|
||||
{
|
||||
(void)I2C_Lock();
|
||||
CDCi_ChangePage( page_no );
|
||||
(void)I2C_Unlock();
|
||||
}
|
||||
|
||||
|
||||
760
build/libraries/cdc/ARM7/src/cdc_api.c
Normal file
760
build/libraries/cdc/ARM7/src/cdc_api.c
Normal file
@ -0,0 +1,760 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - libraties - CDC_
|
||||
File: CDC__api.c
|
||||
|
||||
Copyright 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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <twl.h>
|
||||
#include <twl/cdc.h>
|
||||
|
||||
//#define MEASUREMENT_BY_TICK
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
#include <twl/vlink.h>
|
||||
|
||||
u64 tick_cdcInit_head = 0;
|
||||
u64 tick_cdcPowerUpPLL_head = 0;
|
||||
u64 tick_cdcInitSound_head = 0;
|
||||
u64 tick_cdcPowerUpDAC_head = 0;
|
||||
u64 tick_cdcSetupDAC_head = 0;
|
||||
u64 tick_cdcEnableHeadphoneDriver_head = 0;
|
||||
u64 tick_cdcEnableSpeakerDriver_head = 0;
|
||||
u64 tick_cdcUnmuteDAC_head = 0;
|
||||
u64 tick_cdcInit_tail = 0;
|
||||
#endif
|
||||
|
||||
BOOL isADCOn = FALSE;
|
||||
BOOL isDACOn = FALSE;
|
||||
#define CDC_PLL_STABLE_WAIT_TIME 18
|
||||
|
||||
void CDCi_PowerUpPLL( void );
|
||||
void CDCi_PowerDownPLL( void );
|
||||
|
||||
//================================================================================
|
||||
// INIT APIs
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_Init
|
||||
|
||||
Description: initialize codec
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_Init( void )
|
||||
{
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
OS_InitTimer();
|
||||
OS_InitTick();
|
||||
// tick_cdcInit_head =OS_GetTick();
|
||||
#endif
|
||||
|
||||
reg_CFG_CLK |= REG_CFG_CLK_SND_MASK;
|
||||
|
||||
CDC_Reset();
|
||||
|
||||
cdcRevisionID = CDC_GetRevisionId();
|
||||
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
tick_cdcPowerUpPLL_head =OS_GetTick();
|
||||
#endif
|
||||
CDCi_PowerUpPLL();
|
||||
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
tick_cdcInitSound_head =OS_GetTick();
|
||||
#endif
|
||||
CDC_InitSound();
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
tick_cdcInit_tail =OS_GetTick();
|
||||
|
||||
OS_TPrintf("cdcInit = %llu, %6d\n", tick_cdcInit_head,
|
||||
OS_TICK_TO_USEC(tick_cdcInit_head));
|
||||
OS_TPrintf("cdcPowerUpPLL = %llu, %6d\n", tick_cdcPowerUpPLL_head,
|
||||
OS_TICK_TO_USEC(tick_cdcPowerUpPLL_head));
|
||||
OS_TPrintf("cdcInitSound = %llu, %6d\n", tick_cdcInitSound_head,
|
||||
OS_TICK_TO_USEC(tick_cdcInitSound_head));
|
||||
OS_TPrintf("cdcPowerUpDAC = %llu, %6d\n", tick_cdcPowerUpDAC_head,
|
||||
OS_TICK_TO_USEC(tick_cdcPowerUpDAC_head));
|
||||
OS_TPrintf("cdcSetupDAC = %llu, %6d\n", tick_cdcSetupDAC_head,
|
||||
OS_TICK_TO_USEC(tick_cdcSetupDAC_head));
|
||||
OS_TPrintf("cdcEnableHeadphoneDriver = %llu, %6d\n", tick_cdcEnableHeadphoneDriver_head,
|
||||
OS_TICK_TO_USEC(tick_cdcEnableHeadphoneDriver_head));
|
||||
OS_TPrintf("cdcEnableSpeakerDriver = %llu, %6d\n", tick_cdcEnableSpeakerDriver_head,
|
||||
OS_TICK_TO_USEC(tick_cdcEnableSpeakerDriver_head));
|
||||
OS_TPrintf("cdcUnmuteDAC = %llu, %6d\n", tick_cdcUnmuteDAC_head,
|
||||
OS_TICK_TO_USEC(tick_cdcUnmuteDAC_head));
|
||||
OS_TPrintf("cdcInit tail = %llu, %6d\n", tick_cdcInit_tail,
|
||||
OS_TICK_TO_USEC(tick_cdcInit_tail));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_Reset
|
||||
|
||||
Description: codec SW reset
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_Reset( void )
|
||||
{
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_RST_ADDR, CDC0_RST_E );
|
||||
CDC_SetInputPinControl( TRUE, TRUE, TRUE ); // enable VCNT5,SP#HP,PMOFF pin
|
||||
OS_Sleep(1);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_InitSound
|
||||
|
||||
Description: initialize output sound(speaker/headphone) logic
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_InitSound( void )
|
||||
{
|
||||
#if 1 // このコードは本来、cdcInitSound呼び出しルーチンが記述すべきコード。
|
||||
// Enable I2S
|
||||
reg_SND_I2SCNT |= REG_SND_I2SCNT_E_MASK;
|
||||
#endif
|
||||
|
||||
// setup High Pass Filter of 9.26Hz cutoff freq.
|
||||
CDC_Init1stOrderFilter( cdc1stCoef_HPF_9_26Hz,
|
||||
CDC_FILTER_1ST_IIR_LDAC | CDC_FILTER_1ST_IIR_RDAC );
|
||||
|
||||
// default, DACs are muted.
|
||||
// CDC_MuteDAC();
|
||||
|
||||
// Setup DAC, Speaker Driver, Headphone Driver
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
tick_cdcPowerUpDAC_head =OS_GetTick();
|
||||
#endif
|
||||
CDC_PowerUpDAC();
|
||||
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
tick_cdcSetupDAC_head =OS_GetTick();
|
||||
#endif
|
||||
CDC_SetupDAC( CDC_HP_DRV_PWON_TM_DEFAULT,
|
||||
CDC_HP_DRV_RAMPUP_TM_DEFAULT,
|
||||
CDC_HPSP_DRV_RAMPDWN_TM_DEFAULT );
|
||||
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
tick_cdcEnableHeadphoneDriver_head =OS_GetTick();
|
||||
#endif
|
||||
CDC_EnableHeadphoneDriver(); // enable headphone driver
|
||||
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
tick_cdcEnableSpeakerDriver_head =OS_GetTick();
|
||||
#endif
|
||||
CDC_EnableSpeakerDriver(); // enable speaker driver
|
||||
|
||||
#ifdef MEASUREMENT_BY_TICK
|
||||
tick_cdcUnmuteDAC_head =OS_GetTick();
|
||||
#endif
|
||||
CDC_UnmuteDAC();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_InitMic
|
||||
|
||||
Description: initialize microphone logic
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_InitMic( void )
|
||||
{
|
||||
// setup Mic Bias
|
||||
CDC_ChangePage( 1 );
|
||||
CDC_WriteI2cRegister( REG_CDC1_MIC_BIAS_ADDR, CDC1_MIC_BIAS_2_5V );
|
||||
|
||||
#if 1 // このコードは本来、cdcInitSound呼び出しルーチンが記述すべきコード。
|
||||
// Enable I2S
|
||||
reg_SND_I2SCNT |= REG_SND_I2SCNT_E_MASK;
|
||||
#endif
|
||||
|
||||
// setup High Pass Filter of 9.26Hz cutoff freq.
|
||||
CDC_Init1stOrderFilter( cdc1stCoef_HPF_9_26Hz, CDC_FILTER_1ST_IIR_ADC );
|
||||
|
||||
// Setup ADC
|
||||
CDC_PowerUpADC();
|
||||
CDC_UnmuteADC();
|
||||
|
||||
CDC_EnableAGC( CDC0_AGC_CTL1_DEFAULT_GAIN );
|
||||
}
|
||||
|
||||
|
||||
//================================================================================
|
||||
// Query APIs
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_IsTwlMode
|
||||
|
||||
Description: check CTR-mode (True) or DS-mode (False)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE : CTR-mode, FALSE : DS-mode
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline BOOL CDC_IsTwlMode( void )
|
||||
{
|
||||
return cdcIsTwlMode;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_GetVendorId
|
||||
|
||||
Description: get Vendor ID
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: u8 Vendor ID
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 CDC_GetVendorId( void )
|
||||
{
|
||||
CDC_ChangePage( 0 );
|
||||
return CDC_ReadI2cRegister( REG_CDC0_VEND_ID_ADDR );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_GetRevisionId
|
||||
|
||||
Description: get Revision ID
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: u8 Revision ID (3-bit value)
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 CDC_GetRevisionId( void )
|
||||
{
|
||||
CDC_ChangePage( 0 );
|
||||
return (u8)(( CDC_ReadI2cRegister( REG_CDC0_REV_ID_ADDR ) & CDC0_REV_ID_MASK ) >> CDC0_REV_ID_SHIFT);
|
||||
}
|
||||
#if 0
|
||||
//================================================================================
|
||||
// State Transition APIs
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_GoDsMode
|
||||
|
||||
Description: transit from CTR-mode to DS-mode
|
||||
(never come back to CTR-mode without HW Reset)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_GoDsMode( void )
|
||||
{
|
||||
CDC_ChangePage( 0 );
|
||||
|
||||
//#ifdef CDC_REVISION_A
|
||||
|
||||
// CODEC-IC bug workaround
|
||||
CDC_WriteI2cRegister( REG_CDC0_ADC_PWR_STEP_ADDR, CDC0_ADC_PWR_STEP_PWRUP );
|
||||
CDC_WriteI2cRegister( REG_CDC0_ADC_MUTE_ADDR, CDC0_ADC_MUTE_D );
|
||||
|
||||
//#endif // CDC_REVISION_A
|
||||
|
||||
// マイクバイアスを設定しておく必要がある。DSモードに入ってからは
|
||||
// この設定を行う手段がない。
|
||||
CDC_ChangePage( 1 );
|
||||
CDC_WriteI2cRegister( REG_CDC1_MIC_BIAS_ADDR, CDC1_MIC_BIAS_2_5V );
|
||||
|
||||
// PLL 設定を DS 用に変更
|
||||
CDC_WriteI2cRegister( REG_CDC0_PLL_J_ADDR, 21 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_NDAC_DIV_ADDR, CDC0_NDAC_DIV_PWR | 7 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_NADC_DIV_ADDR, CDC0_NADC_DIV_PWR | 7 );
|
||||
|
||||
CDC_ChangePage( 3 );
|
||||
|
||||
// READREADY 端子属性を TSC2046-PENINTERRUPT に変更
|
||||
CDC_WriteI2cRegister( REG_CDC3_TP_CONV_MODE_ADDR, 0 );
|
||||
|
||||
CDC_ChangePage( 255 );
|
||||
|
||||
// enable DS-Mode (via reg5 : current page=255)
|
||||
//
|
||||
// DS-mode default
|
||||
// Master Sound Power OFF, MicBias OFF, MicPGA x40 times
|
||||
CDC_WriteI2cRegister( REG_CDC255_BKCMPT_MODE_ADDR, CDC255_BKCMPT_MODE_DS );
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// !! from now on, I2C cannot be used. Only DS-type PCSN,TCSN SPI can work.
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
if (cdcRevisionID < CDC_REVISION_C)
|
||||
{
|
||||
// MicBias powered up
|
||||
// In Rev-A, MicBias must be powered up before enabling Master Sound Power
|
||||
dsmodeSetSpiFlags( REG_CDC255_DS_MIC_CTL_ADDR, CDC255_DS_MIC_CTL_BIAS_PWR );
|
||||
|
||||
// enable Master Sound Power (via reg0 : current page=255)
|
||||
//
|
||||
// note: In Rev-A, if Master Sound Power is off, touch-panel logic does
|
||||
// not work.
|
||||
//
|
||||
// CODEC PCSN is connected to IO-board Analog Key CS.
|
||||
// CODEC PCSN is associated with TouchPanel now (for revision A).
|
||||
//
|
||||
dsmodeSetSpiFlags( REG_CDC255_AUD_CTL_ADDR, CDC255_AUD_CTL_PWR );
|
||||
}
|
||||
else
|
||||
{
|
||||
// MicBias powered up
|
||||
pmSetFlags( REG_CDC255_DS_MIC_CTL_ADDR, CDC255_DS_MIC_CTL_BIAS_PWR );
|
||||
}
|
||||
|
||||
// change CODEC status variable
|
||||
CDCi_IsTwlMode = FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetInputPinControl
|
||||
|
||||
Description: set if input pin control enabled or not.
|
||||
Usually, PMOFF should not be disabled.
|
||||
|
||||
Arguments: BOOL enable_vcnt5 : set TRUE to enable VCNT5(LCD backlight) pin
|
||||
BOOL enable_sphp : set TRUE to enable SP#HP switching pin
|
||||
BOOL enable_pmoff : set TRUE to enable PMOFF pin
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_SetInputPinControl( BOOL enable_vcnt5, BOOL enable_sphp, BOOL enable_pmoff )
|
||||
{
|
||||
u8 work = 0;
|
||||
|
||||
CDC_ChangePage( 0 );
|
||||
|
||||
if (enable_vcnt5) work = CDC0_PIN_CTL1_VCNT5_E;
|
||||
if (enable_sphp) work |= CDC0_PIN_CTL1_SPHP_E;
|
||||
CDC_WriteI2cRegister( REG_CDC0_PIN_CTL1_ADDR, work );
|
||||
|
||||
work = 0;
|
||||
if (enable_pmoff) work = CDC0_PIN_CTL2_PMOFF_E;
|
||||
CDC_WriteI2cRegister( REG_CDC0_PIN_CTL2_ADDR, work );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_GetInputPinControl
|
||||
|
||||
Description: get if input pin control enabled or not.
|
||||
|
||||
Arguments: BOOL *enable_vcnt5 : get TRUE if VCNT5(LCD backlight) pin is enabled
|
||||
BOOL *enable_sphp : get TRUE if SP#HP switching pin is enabled
|
||||
BOOL *enable_pmoff : get TRUE if PMOFF pin is enabled
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_GetInputPinControl( BOOL *enable_vcnt5, BOOL *enable_sphp, BOOL *enable_pmoff )
|
||||
{
|
||||
u8 work;
|
||||
|
||||
*enable_vcnt5 = FALSE;
|
||||
*enable_sphp = FALSE;
|
||||
*enable_pmoff = FALSE;
|
||||
|
||||
CDC_ChangePage( 0 );
|
||||
|
||||
work = CDC_ReadI2cRegister( REG_CDC0_PIN_CTL1_ADDR );
|
||||
if ((work & CDC0_PIN_CTL1_VCNT5_MASK) == CDC0_PIN_CTL1_VCNT5_E)
|
||||
*enable_vcnt5 = TRUE;
|
||||
if ((work & CDC0_PIN_CTL1_SPHP_MASK) == CDC0_PIN_CTL1_SPHP_E)
|
||||
*enable_sphp = TRUE;
|
||||
|
||||
work = CDC_ReadI2cRegister( REG_CDC0_PIN_CTL2_ADDR );
|
||||
if ((work & CDC0_PIN_CTL2_PMOFF_MASK) == CDC0_PIN_CTL2_PMOFF_E)
|
||||
*enable_pmoff = TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_PowerUpPLL
|
||||
|
||||
Description: power up Internal PLL of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_PowerUpPLL( void )
|
||||
{
|
||||
// IOP からの MCLK を check / enable
|
||||
|
||||
// page 0, reg 5 で P=2,R=1,PLL on 設定
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_PLL_P_R_ADDR,
|
||||
CDC0_PLL_P_R_PWR | (2 << CDC0_PLL_P_R_DIV_SHIFT) |
|
||||
(1 << CDC0_PLL_P_R_MUL_SHIFT) );
|
||||
// ADC / DAC のパワーアップ時が問題?
|
||||
// dly_tsk( 15 );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_PowerDownPLL
|
||||
|
||||
Description: power down Internal PLL of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_PowerDownPLL( void )
|
||||
{
|
||||
// page 0, reg 5 で PLL off 設定
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_PLL_P_R_ADDR, 0 );
|
||||
// dly_tsk( 15 );
|
||||
|
||||
// IOP からの MCLK を check / disable
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_PowerUpDAC
|
||||
|
||||
Description: power up (both Left,Right channel of the) DAC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_PowerUpDAC( void )
|
||||
{
|
||||
// page 0, reg 63 で Left/Right DAC On, datapath is straght-forward setting.
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_DIG_PATH_ADDR,
|
||||
CDC0_DIG_PATH_CH_PWR_L | (1 << CDC0_DIG_PATH_L_SHIFT) |
|
||||
CDC0_DIG_PATH_CH_PWR_R | (1 << CDC0_DIG_PATH_R_SHIFT) );
|
||||
|
||||
// PLL は ADC, DAC が起動したときに動き出すらしいので、ここに PLL 安定のためのウェイトが必要
|
||||
if ((!isADCOn) && (!isDACOn))
|
||||
OS_Sleep( CDC_PLL_STABLE_WAIT_TIME );
|
||||
|
||||
isDACOn = TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_PowerDownDAC
|
||||
|
||||
Description: power down (both Left,Right channel of the) DAC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_PowerDownDAC( void )
|
||||
{
|
||||
// page 0, reg 63 で Left/Right DAC Off
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_DIG_PATH_ADDR, 0 );
|
||||
|
||||
isDACOn = FALSE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetupDAC
|
||||
|
||||
Description: setup DAC depop value of the CODEC
|
||||
|
||||
Arguments: int hp_pwon_tm : Headphone Power-on time
|
||||
int hp_rmpup_tm : Headphone Ramp-up step time
|
||||
int sphp_rmpdn_tm : Speaker/Headphonw Ramp-down step time
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_SetupDAC( int hp_pwon_tm, int hp_rmpup_tm, int sphp_rmpdn_tm )
|
||||
{
|
||||
// page 1, reg 33--35
|
||||
CDC_ChangePage( 1 );
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_DRV_TM_ADDR, (u8)(hp_pwon_tm | hp_rmpup_tm) );
|
||||
CDC_WriteI2cRegister( REG_CDC1_HPSP_RAMPDWN_ADDR, (u8)sphp_rmpdn_tm );
|
||||
CDC_WriteI2cRegister( REG_CDC1_DAC_OUTPUT_ADDR, CDC1_DAC_OUTPUT_E_R | CDC1_DAC_OUTPUT_E_L );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_EnableHeadphoneDriver
|
||||
|
||||
Description: enable Headphone Driver (HP Driver On)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_EnableHeadphoneDriver( void )
|
||||
{
|
||||
// page 1, reg 36--41
|
||||
CDC_ChangePage( 1 );
|
||||
|
||||
// Mute Analog Volume
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_ANGVOL_L_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MUTE );
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_ANGVOL_R_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MUTE );
|
||||
|
||||
// Power Up Headphone Driver, with short-circuit protection
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_DRV_ADDR, CDC1_HP_DRV_PWR_L | CDC1_HP_DRV_PWR_R |
|
||||
CDC1_HP_CMN_MODE_VOL_1_65V | CDC1_HP_DRV_SHTC_PROTECT_E );
|
||||
|
||||
// Un-mute Headphone
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_DRV_L_ADDR, CDC1_HP_DRV_PDN_TRISTATE | CDC1_HP_DRV_MUTEN );
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_DRV_R_ADDR, CDC1_HP_DRV_PDN_TRISTATE | CDC1_HP_DRV_MUTEN );
|
||||
|
||||
// Un-mute Analog Volume
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_ANGVOL_L_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MAX );
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_ANGVOL_R_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MAX );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_DisableHeadphoneDriver
|
||||
|
||||
Description: disable Headphone Driver (HP Driver Off)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_DisableHeadphoneDriver( void )
|
||||
{
|
||||
// page 1, reg 36--37,31
|
||||
CDC_ChangePage( 1 );
|
||||
|
||||
// Mute Analog Volume
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_ANGVOL_L_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MUTE );
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_ANGVOL_R_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MUTE );
|
||||
|
||||
// Power Down Headphone Driver, with short-circuit protection
|
||||
CDC_WriteI2cRegister( REG_CDC1_HP_DRV_ADDR, CDC1_HP_DRV_SHTC_PROTECT_E );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_EnableSpeakerDriver
|
||||
|
||||
Description: enable Speaker Driver (SP Driver On)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_EnableSpeakerDriver( void )
|
||||
{
|
||||
// page 1, reg 38-39,32,42-43
|
||||
CDC_ChangePage( 1 );
|
||||
|
||||
// Mute Analog Volume
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_ANGVOL_L_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MUTE );
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_ANGVOL_R_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MUTE );
|
||||
|
||||
// Power Up Speaker Driver, with short-circuit protection
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_DRV_ADDR, CDC1_SP_DRV_PWR_L | CDC1_SP_DRV_PWR_R |
|
||||
CDC1_SP_DRV_SHTC_PROTECT_E );
|
||||
|
||||
// Un-mute Speaker
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_DRV_L_ADDR, CDC1_SP_DRV_MUTEN | CDC1_SP_DRV_GAIN_0DB );
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_DRV_R_ADDR, CDC1_SP_DRV_MUTEN | CDC1_SP_DRV_GAIN_0DB );
|
||||
|
||||
// Un-mute Analog Volume
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_ANGVOL_L_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MAX );
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_ANGVOL_R_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MAX );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_DisableSpeakerDriver
|
||||
|
||||
Description: disable Speaker Driver (SP Driver Off)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_DisableSpeakerDriver( void )
|
||||
{
|
||||
// page 1, reg 38-39,32
|
||||
CDC_ChangePage( 1 );
|
||||
|
||||
// Mute Analog Volume
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_ANGVOL_L_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MUTE );
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_ANGVOL_R_ADDR, CDC1_ANGVOL_E | CDC1_ANGVOL_GAIN_MUTE );
|
||||
|
||||
// Power Down Speaker Driver, with short-circuit protection
|
||||
CDC_WriteI2cRegister( REG_CDC1_SP_DRV_ADDR, CDC1_SP_DRV_SHTC_PROTECT_E );
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_UnmuteDAC
|
||||
|
||||
Description: Un-mute DAC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_UnmuteDAC( void )
|
||||
{
|
||||
// page 0, reg 64 で Un-mute
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_DIG_VOL_M_ADDR, 0 );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_MuteDAC
|
||||
|
||||
Description: Mute DAC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_MuteDAC( void )
|
||||
{
|
||||
// page 0, reg 64 で Mute
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_DIG_VOL_M_ADDR, CDC0_DIG_VOL_M_MUTE_L | CDC0_DIG_VOL_M_MUTE_R );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_PowerUpADC
|
||||
|
||||
Description: power up ADC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_PowerUpADC( void )
|
||||
{
|
||||
// page 0, reg 81 で Power Up
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_ADC_PWR_STEP_ADDR, CDC0_ADC_PWR_STEP_PWRUP );
|
||||
|
||||
// PLL は ADC, DAC が起動したときに動き出すらしいので、ここに PLL 安定のためのウェイトが必要
|
||||
if ((!isADCOn) && (!isDACOn))
|
||||
OS_Sleep( CDC_PLL_STABLE_WAIT_TIME );
|
||||
|
||||
isADCOn = TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_PowerDownADC
|
||||
|
||||
Description: power down ADC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_PowerDownADC( void )
|
||||
{
|
||||
// page 0, reg 81 で Power Down
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_ADC_PWR_STEP_ADDR, CDC0_ADC_PWR_STEP_PWRDN );
|
||||
|
||||
isADCOn = FALSE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_UnmuteADC
|
||||
|
||||
Description: Un-mute ADC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_UnmuteADC( void )
|
||||
{
|
||||
// page 0, reg 82 で Un-mute
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_ADC_MUTE_ADDR, CDC0_ADC_MUTE_D );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_MuteADC
|
||||
|
||||
Description: Mute ADC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_MuteADC( void )
|
||||
{
|
||||
// page 0, reg 82 で Mute
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_ADC_MUTE_ADDR, CDC0_ADC_MUTE_E );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_EnableAGC
|
||||
|
||||
Description: Enable AGC of the CODEC
|
||||
|
||||
Arguments: int target_gain : AGC Target Gain
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_EnableAGC( int target_gain )
|
||||
{
|
||||
// page 0, reg 86 で Enable
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_AGC_CTL1_ADDR, (u8)(CDC0_AGC_CTL1_E | target_gain) );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_DisableAGC
|
||||
|
||||
Description: Disable AGC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_DisableAGC( void )
|
||||
{
|
||||
// page 0, reg 86 で Disable
|
||||
CDC_ChangePage( 0 );
|
||||
CDC_WriteI2cRegister( REG_CDC0_AGC_CTL1_ADDR, CDC0_AGC_CTL1_D );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_Init1stOrderFilter
|
||||
|
||||
Description: initialize 1st order filter coeffient
|
||||
|
||||
Arguments: u8 *coef : 1st order coefficient (6 bytes)
|
||||
int filter_target : target filter to be setup
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_Init1stOrderFilter( u8 *coef, int filter_target )
|
||||
{
|
||||
if (filter_target & CDC_FILTER_1ST_IIR_ADC)
|
||||
{
|
||||
CDC_ChangePage( 4 );
|
||||
CDC_WriteI2cRegisters( REG_CDC4_ADC_C4_MSB_ADDR, coef, 6 );
|
||||
}
|
||||
if (filter_target & CDC_FILTER_1ST_IIR_LDAC)
|
||||
{
|
||||
CDC_ChangePage( 9 );
|
||||
CDC_WriteI2cRegisters( REG_CDC9_DAC_C65_MSB_ADDR, coef, 6 );
|
||||
}
|
||||
if (filter_target & CDC_FILTER_1ST_IIR_RDAC)
|
||||
{
|
||||
CDC_ChangePage( 9 );
|
||||
CDC_WriteI2cRegisters( REG_CDC9_DAC_C68_MSB_ADDR, coef, 6 );
|
||||
}
|
||||
}
|
||||
|
||||
28
build/libraries/cdc/ARM7/src/cdc_filter_coefficient.c
Normal file
28
build/libraries/cdc/ARM7/src/cdc_filter_coefficient.c
Normal file
@ -0,0 +1,28 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - libraties - cdc
|
||||
File: cdc_filter_coefficient.c
|
||||
|
||||
Copyright 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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <twl.h>
|
||||
#include <twl/cdc.h>
|
||||
|
||||
|
||||
//================================================================================
|
||||
// Typical Filter Coefficients (1st order)
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
HPF, cut-off(-3dB) point = 0x00021*Fs = 9.26Hz (@Fs = 44.1kHz)
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 cdc1stCoef_HPF_9_26Hz[6] = { 0x7F, 0xEA, 0x80, 0x16, 0x7F, 0xD5 };
|
||||
|
||||
|
||||
34
build/libraries/cdc/Makefile
Normal file
34
build/libraries/cdc/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - CDC - libraries
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: Makefile,v $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
ifdef TWL_WITH_ARM7
|
||||
SUBDIRS += ARM7
|
||||
endif
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
51
build/libraries/i2c/ARM7/Makefile
Normal file
51
build/libraries/i2c/ARM7/Makefile
Normal file
@ -0,0 +1,51 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - libraries - spi
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = #camera
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
TWL_CODEGEN_ALL ?= True
|
||||
|
||||
TWL_PROC = ARM7
|
||||
|
||||
SRCS = i2c_instruction.c
|
||||
|
||||
TARGET_LIB = libi2c_sp$(TWL_LIBSUFFIX).a
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# DEBUG版ビルドの場合、RELEASE版でビルドして
|
||||
# DEBUG版のライブラリを装います。
|
||||
|
||||
ifdef NITRO_DEBUG
|
||||
NITRO_BUILD_TYPE = RELEASE
|
||||
endif
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(TWL_INSTALL_LIBDIR)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
650
build/libraries/i2c/ARM7/src/i2c_instruction.c
Normal file
650
build/libraries/i2c/ARM7/src/i2c_instruction.c
Normal file
@ -0,0 +1,650 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - libraties - I2C_
|
||||
File: I2C__instruction.c
|
||||
|
||||
Copyright 2006-2007 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: I2C_.c,v $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <twl.h>
|
||||
#include <twl/i2c/ARM7/i2c.h>
|
||||
|
||||
#define RETRY_COUNT 8
|
||||
|
||||
static u8 I2C_DeviceAddrTable[I2C_SLAVE_NUM] = { I2C_ADDR_CODEC,
|
||||
I2C_ADDR_CAMERA,
|
||||
};
|
||||
|
||||
static OSMutex mutex;
|
||||
static BOOL isInitialized = FALSE;
|
||||
|
||||
static inline void I2Ci_Start( void )
|
||||
{
|
||||
reg_EXI_I2CCNT = (u8)((1 << REG_EXI_I2CCNT_E_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_I_SHIFT) | // 割り込み禁止は IE にて行うことで仕様統一
|
||||
(I2C_WRITE << REG_EXI_I2CCNT_RW_SHIFT) |
|
||||
(0 << REG_EXI_I2CCNT_ACK_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_START_SHIFT));
|
||||
}
|
||||
|
||||
static inline void I2Ci_Continue( I2CReadWrite rw )
|
||||
{
|
||||
reg_EXI_I2CCNT = (u8)((1 << REG_EXI_I2CCNT_E_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_I_SHIFT) |
|
||||
(rw << REG_EXI_I2CCNT_RW_SHIFT) |
|
||||
(rw << REG_EXI_I2CCNT_ACK_SHIFT));
|
||||
}
|
||||
|
||||
static inline void I2Ci_Stop( I2CReadWrite rw )
|
||||
{
|
||||
reg_EXI_I2CCNT = (u8)((1 << REG_EXI_I2CCNT_E_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_I_SHIFT) |
|
||||
(rw << REG_EXI_I2CCNT_RW_SHIFT) |
|
||||
(0 << REG_EXI_I2CCNT_ACK_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_STOP_SHIFT));
|
||||
}
|
||||
|
||||
static inline void I2Ci_StopPhase1( I2CReadWrite rw )
|
||||
{
|
||||
reg_EXI_I2CCNT = (u8)((1 << REG_EXI_I2CCNT_E_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_I_SHIFT) |
|
||||
(rw << REG_EXI_I2CCNT_RW_SHIFT) |
|
||||
(0 << REG_EXI_I2CCNT_ACK_SHIFT));
|
||||
}
|
||||
static inline void I2Ci_StopPhase2( void )
|
||||
{
|
||||
reg_EXI_I2CCNT = (u8)((1 << REG_EXI_I2CCNT_E_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_I_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_STOP_SHIFT) |
|
||||
(1 << REG_EXI_I2CCNT_NT_SHIFT));
|
||||
}
|
||||
|
||||
|
||||
static inline void I2Ci_SetData( u8 data )
|
||||
{
|
||||
reg_EXI_I2CD = data;
|
||||
}
|
||||
|
||||
|
||||
static inline u8 I2Ci_GetData( void )
|
||||
{
|
||||
return reg_EXI_I2CD;
|
||||
}
|
||||
|
||||
static inline BOOL I2Ci_GetResult( void )
|
||||
{
|
||||
I2Ci_Wait();
|
||||
return (BOOL)((reg_EXI_I2CCNT & REG_EXI_I2CCNT_ACK_MASK) >> REG_EXI_I2CCNT_ACK_SHIFT);
|
||||
}
|
||||
|
||||
static inline BOOL I2Ci_SendStart( I2CSlave id )
|
||||
{
|
||||
I2Ci_Wait();
|
||||
I2Ci_SetData( (u8)(I2C_DeviceAddrTable[id] | (u8)I2C_WRITE) );
|
||||
I2Ci_Start();
|
||||
return I2Ci_GetResult();
|
||||
}
|
||||
|
||||
static inline BOOL I2Ci_SendMiddle( u8 data )
|
||||
{
|
||||
I2Ci_Wait();
|
||||
I2Ci_SetData( data );
|
||||
I2Ci_Continue( I2C_WRITE );
|
||||
return I2Ci_GetResult();
|
||||
}
|
||||
|
||||
static inline BOOL I2Ci_SendLast( u8 data )
|
||||
{
|
||||
I2Ci_Wait();
|
||||
I2Ci_SetData( data );
|
||||
I2Ci_Stop( I2C_WRITE );
|
||||
return I2Ci_GetResult();
|
||||
}
|
||||
|
||||
static inline BOOL I2Ci_ReceiveStart( I2CSlave id )
|
||||
{
|
||||
I2Ci_Wait();
|
||||
I2Ci_SetData( (u8)(I2C_DeviceAddrTable[id] | I2C_READ) );
|
||||
I2Ci_Start();
|
||||
return I2Ci_GetResult();
|
||||
}
|
||||
|
||||
static inline void I2Ci_ReceiveMiddle( void )
|
||||
{
|
||||
I2Ci_Wait();
|
||||
I2Ci_Continue( I2C_READ );
|
||||
}
|
||||
|
||||
static inline void I2Ci_ReceiveLast( void )
|
||||
{
|
||||
I2Ci_Wait();
|
||||
I2Ci_Stop( I2C_READ );
|
||||
}
|
||||
|
||||
static inline u8 I2Ci_WaitReceiveMiddle( void )
|
||||
{
|
||||
I2Ci_ReceiveMiddle();
|
||||
I2Ci_Wait();
|
||||
return I2Ci_GetData();
|
||||
}
|
||||
|
||||
static inline u8 I2Ci_WaitReceiveLast( void )
|
||||
{
|
||||
I2Ci_ReceiveLast();
|
||||
I2Ci_Wait();
|
||||
return I2Ci_GetData();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_Init
|
||||
|
||||
Description: initialize I2C
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2C_Init( void )
|
||||
{
|
||||
if (isInitialized == FALSE)
|
||||
{
|
||||
OS_InitMutex(&mutex);
|
||||
I2Ci_Init();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_Lock
|
||||
|
||||
Description: Lock I2C device
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2C_Lock( void ) // 外部スレッドから呼ばれ、I2Cデバイスの操作権利を取得する
|
||||
{
|
||||
if( isInitialized == FALSE ) {
|
||||
if( FALSE == I2C_Init() ) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
OS_LockMutex( &mutex );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_Unlock
|
||||
|
||||
Description: Unlock I2C device
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2C_Unlock( void ) // 外部スレッドから呼ばれ、I2Cデバイスの操作権利を解放する
|
||||
{
|
||||
if( isInitialized == FALSE ) {
|
||||
if( FALSE == I2C_Init() ) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
OS_UnlockMutex( &mutex );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_Init
|
||||
|
||||
Description: initialize I2C
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void I2Ci_Init( void )
|
||||
{
|
||||
#if 0 // TODO
|
||||
I2C_DeviceAddrTable[I2C_SLAVE_CODEC_TP] = ?; // from NorFlash
|
||||
I2C_DeviceAddrTable[I2C_SLAVE_LCDDAC] = ?; // from NorFlash
|
||||
I2C_DeviceAddrTable[I2C_SLAVE_CAMERA] = ?; // from NorFlash
|
||||
#endif
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// DEVICE BIT CONTROL
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_SetParams
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_SetParams( I2CSlave id, u8 reg, u8 setBits, u8 maskBits )
|
||||
{
|
||||
u8 tmp;
|
||||
tmp = I2Ci_ReadRegister( id, reg );
|
||||
tmp &= ~maskBits;
|
||||
setBits &= maskBits;
|
||||
tmp |= setBits;
|
||||
return I2Ci_WriteRegister( id, reg, tmp );
|
||||
}
|
||||
BOOL I2C_SetParams( I2CSlave id, u8 reg, u8 setBits, u8 maskBits )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_SetParams( id, reg, setBits, maskBits );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_SetFlags
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_SetFlags( I2CSlave id, u8 reg, u8 setBits )
|
||||
{
|
||||
return I2Ci_SetParams( id, reg, setBits, setBits );
|
||||
}
|
||||
BOOL I2C_SetFlags( I2CSlave id, u8 reg, u8 setBits )
|
||||
{
|
||||
return I2C_SetParams( id, reg, setBits, setBits );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_ClearFlags
|
||||
|
||||
Description: clear control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
clrBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_ClearFlags( I2CSlave id, u8 reg, u8 clrBits )
|
||||
{
|
||||
return I2Ci_SetParams( id, reg, 0, clrBits );
|
||||
}
|
||||
BOOL I2C_ClearFlags( I2CSlave id, u8 reg, u8 clrBits )
|
||||
{
|
||||
return I2C_SetParams( id, reg, 0, clrBits );
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// DEVICE ACCESS
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_WriteRegister
|
||||
|
||||
Description: set value to decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_WriteRegister( I2CSlave id, u8 reg, u8 data )
|
||||
{
|
||||
int r;
|
||||
int error;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendMiddle( reg ) == FALSE) error++;
|
||||
if (I2Ci_SendLast( data ) == FALSE) error++;
|
||||
if (error == 0) break;
|
||||
}
|
||||
return error ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_ReadRegister
|
||||
|
||||
Description: get value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 I2Ci_ReadRegister( I2CSlave id, u8 reg )
|
||||
{
|
||||
int r;
|
||||
u8 data;
|
||||
int error;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendMiddle( reg ) == FALSE) error++;
|
||||
if (I2Ci_ReceiveStart( id ) == FALSE) error++;
|
||||
data = I2Ci_WaitReceiveLast();
|
||||
if (error == 0) break;
|
||||
}
|
||||
return error ? (u8)0xee : data;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_ReadRegisterSC
|
||||
|
||||
Description: get value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 I2Ci_ReadRegisterSC( I2CSlave id, u8 reg )
|
||||
{
|
||||
int r;
|
||||
u8 data;
|
||||
int error;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendLast( reg ) == FALSE) error++;
|
||||
if (I2Ci_ReceiveStart( id ) == FALSE) error++;
|
||||
data = I2Ci_WaitReceiveLast();
|
||||
if (error == 0) break;
|
||||
}
|
||||
return error ? (u8)0xee : data;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_VerifyRegister
|
||||
|
||||
Description: get and verify value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_VerifyRegister( I2CSlave id, u8 reg, u8 data )
|
||||
{
|
||||
int r;
|
||||
int error;
|
||||
BOOL result;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
result = TRUE;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendMiddle( reg ) == FALSE) error++;
|
||||
if (I2Ci_ReceiveStart( id ) == FALSE) error++;
|
||||
if (data != I2Ci_WaitReceiveLast())
|
||||
{
|
||||
result = FALSE;
|
||||
}
|
||||
if (error == 0) break;
|
||||
}
|
||||
return error ? FALSE : (result ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_VerifyRegisterSC
|
||||
|
||||
Description: get and verify value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_VerifyRegisterSC( I2CSlave id, u8 reg, u8 data )
|
||||
{
|
||||
int r;
|
||||
int error;
|
||||
BOOL result;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
result = TRUE;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendLast( reg ) == FALSE) error++;
|
||||
if (I2Ci_ReceiveStart( id ) == FALSE) error++;
|
||||
if (data != I2Ci_WaitReceiveLast())
|
||||
{
|
||||
result = FALSE;
|
||||
}
|
||||
if (error == 0) break;
|
||||
}
|
||||
return error ? FALSE : (result ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_WriteRegisters
|
||||
|
||||
Description: set value to decive registers through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_WriteRegisters( I2CSlave id, u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
int error;
|
||||
const u8 *ptr;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
ptr = bufp;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendMiddle( reg ) == FALSE) error++;
|
||||
for ( i=0; error==0 && i<(size-1); i++ )
|
||||
{
|
||||
if (I2Ci_SendMiddle( *ptr++ ) == FALSE) error++;
|
||||
}
|
||||
if (I2Ci_SendLast( *ptr++ ) == FALSE) error++;
|
||||
if (error == 0) break;
|
||||
}
|
||||
return error ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_ReadRegisters
|
||||
|
||||
Description: get value from decive registers through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_ReadRegisters( I2CSlave id, u8 reg, u8 *bufp, size_t size )
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
int error;
|
||||
u8 *ptr;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
ptr = bufp;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendMiddle( reg ) == FALSE) error++;
|
||||
if (I2Ci_ReceiveStart( id ) == FALSE) error++;
|
||||
for ( i=0; error==0 && i<(size-1); i++ )
|
||||
{
|
||||
*ptr++ = I2Ci_WaitReceiveMiddle();
|
||||
}
|
||||
if (error == 0)
|
||||
{
|
||||
*ptr++ = I2Ci_WaitReceiveLast();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)I2Ci_WaitReceiveLast();
|
||||
}
|
||||
}
|
||||
return error ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_ReadRegistersSC
|
||||
|
||||
Description: get value from decive registers through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_ReadRegistersSC( I2CSlave id, u8 reg, u8 *bufp, size_t size )
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
int error;
|
||||
u8 *ptr;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
ptr = bufp;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendLast( reg ) == FALSE) error++;
|
||||
if (I2Ci_ReceiveStart( id ) == FALSE) error++;
|
||||
for ( i=0; error==0 && i<(size-1); i++ )
|
||||
{
|
||||
*ptr++ = I2Ci_WaitReceiveMiddle();
|
||||
}
|
||||
if (error == 0)
|
||||
{
|
||||
*ptr++ = I2Ci_WaitReceiveLast();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)I2Ci_WaitReceiveLast();
|
||||
}
|
||||
}
|
||||
return error ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_VerifyRegisters
|
||||
|
||||
Description: get and verify value from decive registers through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_VerifyRegisters( I2CSlave id, u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
int error;
|
||||
const u8 *ptr;
|
||||
BOOL result;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
ptr = bufp;
|
||||
result = TRUE;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendMiddle( reg ) == FALSE) error++;
|
||||
if (I2Ci_ReceiveStart( id ) == FALSE) error++;
|
||||
for ( i=0; error==0 && result!=FALSE && i<(size-1); i++ )
|
||||
{
|
||||
if (*ptr++ != I2Ci_WaitReceiveMiddle()) {
|
||||
result = FALSE;
|
||||
}
|
||||
}
|
||||
if (*ptr++ != I2Ci_WaitReceiveLast())
|
||||
{
|
||||
result = FALSE;
|
||||
}
|
||||
if (error == 0) break;
|
||||
}
|
||||
return error ? FALSE : (result ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_VerifyRegistersSC
|
||||
|
||||
Description: get and verify value from decive registers through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_VerifyRegistersSC( I2CSlave id, u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
int error;
|
||||
const u8 *ptr;
|
||||
BOOL result;
|
||||
for (r = 0; r < RETRY_COUNT; r++)
|
||||
{
|
||||
error = 0;
|
||||
ptr = bufp;
|
||||
result = TRUE;
|
||||
if (I2Ci_SendStart( id ) == FALSE) error++;
|
||||
if (I2Ci_SendLast( reg ) == FALSE) error++;
|
||||
if (I2Ci_ReceiveStart( id ) == FALSE) error++;
|
||||
for ( i=0; error==0 && result!=FALSE && i<(size-1); i++ )
|
||||
{
|
||||
if (*ptr++ != I2Ci_WaitReceiveMiddle()) {
|
||||
result = FALSE;
|
||||
}
|
||||
}
|
||||
if (*ptr++ != I2Ci_WaitReceiveLast())
|
||||
{
|
||||
result = FALSE;
|
||||
}
|
||||
if (error == 0) break;
|
||||
}
|
||||
return error ? FALSE : (result ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
//================================================================================
|
||||
// INTERRUPT
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_EnableInterrupt
|
||||
|
||||
Description: enable I2C interrupt for each device.
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void I2Ci_EnableInterrupt( void )
|
||||
{
|
||||
OS_EnableIrqMask( OS_IE_I2C );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_DisableInterrupt
|
||||
|
||||
Description: disable I2C interrupt for each device.
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void I2Ci_DisableInterrupt( void )
|
||||
{
|
||||
OS_DisableIrqMask( OS_IE_I2C );
|
||||
}
|
||||
#endif
|
||||
|
||||
34
build/libraries/i2c/Makefile
Normal file
34
build/libraries/i2c/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - libraries - i2c
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# SUBDIRS = ARM9
|
||||
|
||||
ifdef TWL_WITH_ARM7
|
||||
SUBDIRS += ARM7
|
||||
endif
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
70
build/libraries/snd/ARM7/Makefile
Normal file
70
build/libraries/snd/ARM7/Makefile
Normal file
@ -0,0 +1,70 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - SND - libraries
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2004,2005 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: Makefile,v $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
TWL_CODEGEN_ALL ?= True
|
||||
|
||||
# Codegen for sub processer
|
||||
TWL_PROC = ARM7
|
||||
|
||||
SRCDIR = ../common .
|
||||
SRCDIR += $(TWL_NITROSDK_ROOT)/build/libraries/snd/common/src \
|
||||
$(TWL_NITROSDK_ROOT)/build/libraries/snd/ARM7/src \
|
||||
|
||||
SRCS = \
|
||||
snd_global.c \
|
||||
snd_channel.c \
|
||||
snd_util.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
|
||||
|
||||
|
||||
TARGET_LIB = libsnd_sp$(TWL_LIBSUFFIX).a
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# DEBUG版ビルドの場合、RELEASE版でビルドして
|
||||
# DEBUG版のライブラリを装います。
|
||||
|
||||
ifdef TWL_DEBUG
|
||||
TWL_BUILD_TYPE = RELEASE
|
||||
endif
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(TWL_INSTALL_LIBDIR)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
205
build/libraries/snd/ARM7/snd_global.c
Normal file
205
build/libraries/snd/ARM7/snd_global.c
Normal file
@ -0,0 +1,205 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - SND - libraries
|
||||
File: snd_global.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_global.c,v $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include <nitro/snd/common/global.h>
|
||||
|
||||
#include <twl/os.h>
|
||||
#include <twl/misc.h>
|
||||
#include <twl/cdc.h>
|
||||
#include <nitro/hw/ARM7/ioreg_SND.h>
|
||||
#include <nitro/spi/common/pm_common.h>
|
||||
#include <nitro/snd/common/channel.h>
|
||||
#include <nitro/snd/common/capture.h>
|
||||
|
||||
/******************************************************************************
|
||||
macro definition
|
||||
******************************************************************************/
|
||||
|
||||
#define SOUND_BIAS_WAIT_COUNT 128
|
||||
#define SOUND_BIAS_LEVEL 0x200
|
||||
#define SOUND_BIAS_CYCLE_PER_LOOP 4
|
||||
|
||||
/******************************************************************************
|
||||
external function declaration
|
||||
******************************************************************************/
|
||||
|
||||
extern void PMi_SetControl(u8 sw);
|
||||
extern void PMi_ResetControl(u8 sw);
|
||||
|
||||
/******************************************************************************
|
||||
public functions
|
||||
******************************************************************************/
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SND_Enable
|
||||
|
||||
Description: Enable sound master control
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
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;
|
||||
|
||||
reg_SND_SOUNDCNT_8 |= REG_SND_SOUNDCNT_8_E_MASK;
|
||||
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SND_Disable
|
||||
|
||||
Description: Disable sound master control
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void SND_Disable(void)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
|
||||
reg_SND_I2SCNT &= REG_SND_I2SCNT_E_MASK;
|
||||
reg_SND_SOUNDCNT_8 &= ~REG_SND_SOUNDCNT_8_E_MASK;
|
||||
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SND_Shutdown
|
||||
|
||||
Description: shutdown sound system
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void SND_Shutdown(void)
|
||||
{
|
||||
int ch;
|
||||
|
||||
SND_Disable();
|
||||
|
||||
for (ch = 0; ch < SND_CHANNEL_NUM; ch++)
|
||||
{
|
||||
SND_StopChannel(ch, SND_CHANNEL_STOP_HOLD);
|
||||
}
|
||||
SND_StopCapture(SND_CAPTURE_0);
|
||||
SND_StopCapture(SND_CAPTURE_1);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SND_BeginSleep
|
||||
|
||||
Description: Begin sleep
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void SND_BeginSleep(void)
|
||||
{
|
||||
// stop all sound
|
||||
SND_Disable();
|
||||
|
||||
// bias level down
|
||||
SVC_ResetSoundBias(SOUND_BIAS_WAIT_COUNT);
|
||||
OS_SpinWait(SOUND_BIAS_CYCLE_PER_LOOP * SOUND_BIAS_WAIT_COUNT * SOUND_BIAS_LEVEL);
|
||||
|
||||
// sound power off
|
||||
PMi_ResetControl(PMIC_CTL_SND_PWR);
|
||||
|
||||
// sound clock stop
|
||||
reg_SND_POWCNT &= ~REG_SND_POWCNT_SPE_MASK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SND_EndSleep
|
||||
|
||||
Description: End sleep
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void SND_EndSleep(void)
|
||||
{
|
||||
// sound clock start
|
||||
reg_SND_POWCNT |= REG_SND_POWCNT_SPE_MASK;
|
||||
|
||||
// sound power on
|
||||
PMi_SetControl(PMIC_CTL_SND_PWR);
|
||||
|
||||
// bias level recover
|
||||
SVC_SetSoundBias(SOUND_BIAS_WAIT_COUNT * 2);
|
||||
|
||||
// wait 15msec
|
||||
OS_SpinWait(OS_MilliSecondsToTicks(15) * 64);
|
||||
|
||||
// sound enable
|
||||
SND_Enable();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SND_SetMasterVolume
|
||||
|
||||
Description: Set master volume
|
||||
|
||||
Arguments: volume : master volume
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void SND_SetMasterVolume(int volume)
|
||||
{
|
||||
SDK_MINMAX_ASSERT(volume, 0, SND_MASTER_VOLUME_MAX);
|
||||
|
||||
reg_SND_SOUNDCNT_VOL = (u8)volume;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SND_SetOutputSelector
|
||||
|
||||
Description: Set output selector
|
||||
|
||||
Arguments: left : L-OUT selector
|
||||
right : R-OUT selector
|
||||
channel1 : channel1 output setting
|
||||
channel3 : channel3 output setting
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void SND_SetOutputSelector(SNDOutput left,
|
||||
SNDOutput right, SNDChannelOut channel1, SNDChannelOut channel3)
|
||||
{
|
||||
BOOL enable = (reg_SND_SOUNDCNT_8 & REG_SND_SOUNDCNT_8_E_MASK) ? TRUE : FALSE;
|
||||
|
||||
reg_SND_SOUNDCNT_8 = REG_SND_SOUNDCNT_8_FIELD(enable, channel3, channel1, right, left);
|
||||
}
|
||||
|
||||
/*====== End of snd_global.c ======*/
|
||||
34
build/libraries/snd/Makefile
Normal file
34
build/libraries/snd/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - SND - libraries
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2004,2005 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: Makefile,v $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
ifdef TWL_WITH_ARM7
|
||||
SUBDIRS += ARM7
|
||||
endif
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
@ -20,8 +20,10 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = os mi \
|
||||
aes
|
||||
SUBDIRS = os \
|
||||
mi \
|
||||
aes \
|
||||
snd
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
32
build/tests/snd/Makefile
Normal file
32
build/tests/snd/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - tests - snd
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = channel \
|
||||
capture \
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
44
build/tests/snd/capture/ARM7/Makefile
Normal file
44
build/tests/snd/capture/ARM7/Makefile
Normal file
@ -0,0 +1,44 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - SND - demos - channel
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
#TWL_CODEGEN = THUMB
|
||||
TWL_PROC = ARM7
|
||||
|
||||
TARGET_BIN = main.axf
|
||||
|
||||
SRCS = main.c
|
||||
|
||||
#SRCDIR = # using default
|
||||
#LCFILE = # using default
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
170
build/tests/snd/capture/ARM7/src/main.c
Normal file
170
build/tests/snd/capture/ARM7/src/main.c
Normal file
@ -0,0 +1,170 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - tests - snd - channel
|
||||
File: main.c
|
||||
|
||||
Copyright 2007 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: main.c,v $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <twl_sp.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
定数定義
|
||||
*---------------------------------------------------------------------------*/
|
||||
// ===== スレッド優先度 =====
|
||||
|
||||
#define THREAD_PRIO_SPI 2
|
||||
#define THREAD_PRIO_SND 6
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
内部関数定義
|
||||
*---------------------------------------------------------------------------*/
|
||||
static OSHeapHandle InitializeAllocateSystem(void);
|
||||
static void VBlankIntr(void);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: TwlSpMain
|
||||
|
||||
Description: Initialize and do main
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void TwlSpMain(void)
|
||||
{
|
||||
OSHeapHandle heapHandle;
|
||||
|
||||
// OS初期化
|
||||
OS_Init();
|
||||
OS_InitThread();
|
||||
|
||||
// PXI初期化、ARM9と同期
|
||||
PXI_Init();
|
||||
|
||||
// ヒープ領域設定
|
||||
heapHandle = InitializeAllocateSystem();
|
||||
|
||||
// サウンド初期化
|
||||
SND_Init(THREAD_PRIO_SND);
|
||||
|
||||
// reg_CFG_DS_MDFY |= REG_CFG_DS_MDFY_SND_MASK; // SOUND回路バグ修正 (default: off)
|
||||
// reg_CFG_DS_MDFY |= REG_CFG_DS_MDFY_SDMA_MASK; // SOUND-DMAバグ修正 (default: off)
|
||||
// reg_CFG_DS_EX &= ~REG_CFG_DS_EX_SDMA2_MASK; // SOUND-DMA新回路 (default: on)
|
||||
|
||||
// ボタン入力サーチ初期化
|
||||
(void)PAD_InitXYButton();
|
||||
|
||||
// 割込み許可
|
||||
(void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
|
||||
(void)OS_EnableIrqMask(OS_IE_V_BLANK);
|
||||
(void)GX_VBlankIntr(TRUE);
|
||||
(void)OS_EnableIrq();
|
||||
(void)OS_EnableInterrupts();
|
||||
|
||||
// SPI初期化
|
||||
SPI_Init(THREAD_PRIO_SPI);
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
OS_Halt();
|
||||
|
||||
//---- check reset
|
||||
if (OS_IsResetOccurred())
|
||||
{
|
||||
OS_ResetSystem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: InitializeAllocateSystem
|
||||
|
||||
Description: メモリ割当てシステムを初期化する。
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static OSHeapHandle InitializeAllocateSystem(void)
|
||||
{
|
||||
void *tempLo;
|
||||
OSHeapHandle hh;
|
||||
|
||||
OS_TPrintf("OS_GetWramSubPrivArenaLo() = %p\n", OS_GetWramSubPrivArenaLo());
|
||||
OS_TPrintf("OS_GetWramSubPrivArenaHi() = %p\n", OS_GetWramSubPrivArenaHi());
|
||||
OS_TPrintf("OS_GetWramSubArenaLo() = %p\n", OS_GetWramSubArenaLo());
|
||||
OS_TPrintf("OS_GetWramSubArenaHi() = %p\n", OS_GetWramSubArenaHi());
|
||||
OS_TPrintf("OS_GetSubPrivArenaLo() = %p\n", OS_GetSubPrivArenaLo());
|
||||
OS_TPrintf("OS_GetSubPrivArenaHi() = %p\n", OS_GetSubPrivArenaHi());
|
||||
|
||||
OS_TPrintf("call OS_SetWramSubPrivArenaHi(0x0380f980); to fix arena.\n");
|
||||
OS_SetWramSubPrivArenaHi((void*)0x0380f980);
|
||||
|
||||
// メモリ割当て初期化
|
||||
tempLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV,
|
||||
OS_GetWramSubPrivArenaLo(), OS_GetWramSubPrivArenaHi(), 1);
|
||||
|
||||
// アリーナを0クリア
|
||||
MI_CpuClear8(tempLo, (u32)OS_GetWramSubPrivArenaHi() - (u32)tempLo);
|
||||
|
||||
// アリーナ下位アドレスを設定
|
||||
OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, tempLo);
|
||||
|
||||
// ヒープ作成
|
||||
hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV,
|
||||
OS_GetWramSubPrivArenaLo(), OS_GetWramSubPrivArenaHi());
|
||||
|
||||
if (hh < 0)
|
||||
{
|
||||
OS_Panic("ARM7: Fail to create heap.\n");
|
||||
}
|
||||
|
||||
// カレントヒープに設定
|
||||
(void)OS_SetCurrentHeap(OS_ARENA_WRAM_SUBPRIV, hh);
|
||||
|
||||
return hh;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: VBlankIntr
|
||||
|
||||
Description: VBlank interrupt handler
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef SDK_TEG
|
||||
|
||||
extern BOOL PMi_Initialized;
|
||||
void PM_SelfBlinkProc(void);
|
||||
|
||||
static void VBlankIntr(void)
|
||||
{
|
||||
//---- LED blink system
|
||||
if (PMi_Initialized)
|
||||
{
|
||||
PM_SelfBlinkProc();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void VBlankIntr(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
End of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
41
build/tests/snd/capture/ARM9/Makefile
Normal file
41
build/tests/snd/capture/ARM9/Makefile
Normal file
@ -0,0 +1,41 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - SND - demos - capture
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2005 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: Makefile,v $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
#TWL_CODEGEN = THUMB
|
||||
|
||||
TARGET_BIN = main.axf
|
||||
|
||||
SRCS = main.c fanfare.32.c
|
||||
|
||||
#SRCDIR = # using default
|
||||
#LCFILE = # using default
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
51
build/tests/snd/capture/ARM9/include/fanfare.32.h
Normal file
51
build/tests/snd/capture/ARM9/include/fanfare.32.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: NitroSDK - SND - demos - capture
|
||||
File: fanfare.32.h
|
||||
|
||||
Copyright 2005,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: fanfare.32.h,v $
|
||||
Revision 1.2 2006/01/18 02:11:20 kitase_hirotake
|
||||
do-indent
|
||||
|
||||
Revision 1.1 2005/04/13 03:29:35 ida
|
||||
SNDをNITRO-SDKへ移設
|
||||
|
||||
Revision 1.3 2005/04/13 01:15:26 kyuma_koichi
|
||||
波形ファイルフォーマットの変更
|
||||
|
||||
Revision 1.2 2005/03/08 07:45:24 kyuma_koichi
|
||||
初版
|
||||
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FANFARE_32_H_
|
||||
#define FANFARE_32_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <nitro.h>
|
||||
|
||||
#define FANFARE_32_FORMAT SND_WAVE_FORMAT_PCM16
|
||||
#define FANFARE_32_LOOPFLAG 0
|
||||
#define FANFARE_32_RATE 32000
|
||||
#define FANFARE_32_TIMER 523
|
||||
#define FANFARE_32_LOOPSTART 0
|
||||
#define FANFARE_32_LOOPLEN 56926
|
||||
|
||||
const s16 fanfare_32[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // FANFARE_32_H_
|
||||
14262
build/tests/snd/capture/ARM9/src/fanfare.32.c
Normal file
14262
build/tests/snd/capture/ARM9/src/fanfare.32.c
Normal file
File diff suppressed because it is too large
Load Diff
377
build/tests/snd/capture/ARM9/src/main.c
Normal file
377
build/tests/snd/capture/ARM9/src/main.c
Normal file
@ -0,0 +1,377 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - SND - demos - capture
|
||||
File: main.c
|
||||
|
||||
Copyright 2005,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: main.c,v $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// USAGE:
|
||||
// A : Start Bgm
|
||||
// B : Stop Bgm
|
||||
// X : Start Capture
|
||||
// Y : Stop Capture
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <nitro.h>
|
||||
#include "fanfare.32.h"
|
||||
|
||||
#define CAPTURE_BUF_PAGESIZE 64*32
|
||||
#define CAPTURE_BUF_SIZE CAPTURE_BUF_PAGESIZE*2
|
||||
#define CAPTURE_SAMPLE_RATE 44100
|
||||
#define CAPTURE_FIFO_SIZE 32
|
||||
#define THREAD_STACK_SIZE 1024
|
||||
|
||||
#define CHANNEL_NUM 4
|
||||
#define ALARM_NUM 0
|
||||
#define CAPTURE_THREAD_PRIO 12
|
||||
#define MAX_VOLUME 127
|
||||
#define CENTER_PAN 64
|
||||
#define FILTER_SIZE 12
|
||||
|
||||
typedef s16 smp_t;
|
||||
|
||||
typedef struct EffectCallbackInfo
|
||||
{
|
||||
smp_t sample[FILTER_SIZE - 1][2];
|
||||
}
|
||||
EffectCallbackInfo;
|
||||
|
||||
typedef struct CaptureInfo
|
||||
{
|
||||
u32 bufPage;
|
||||
EffectCallbackInfo callbackInfo;
|
||||
}
|
||||
CaptureInfo;
|
||||
|
||||
static void SoundAlarmHandler(void *arg);
|
||||
static void CaptureThread(void *arg);
|
||||
static void CaptureFunc(CaptureInfo * cap);
|
||||
static void VBlankIntr(void);
|
||||
void EffectCallback(void *bufferL_p, void *bufferR_p, u32 len, SNDCaptureFormat format,
|
||||
void *arg);
|
||||
|
||||
u16 Cont;
|
||||
u16 Trg;
|
||||
|
||||
static u64 captureThreadStack[THREAD_STACK_SIZE / sizeof(u64)];
|
||||
static OSThread captureThread;
|
||||
static OSMessageQueue msgQ;
|
||||
static OSMessage msgBuf[1];
|
||||
|
||||
static u8 captureBufL[CAPTURE_BUF_SIZE] ATTRIBUTE_ALIGN(32);
|
||||
static u8 captureBufR[CAPTURE_BUF_SIZE] ATTRIBUTE_ALIGN(32);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: TwlMain
|
||||
|
||||
Description: main
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void TwlMain()
|
||||
{
|
||||
CaptureInfo cap;
|
||||
|
||||
// 初期化
|
||||
OS_Init();
|
||||
GX_Init();
|
||||
SND_Init();
|
||||
|
||||
// Vブランク割り込み設定
|
||||
OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
|
||||
(void)OS_EnableIrqMask(OS_IE_V_BLANK);
|
||||
(void)OS_EnableIrq();
|
||||
(void)GX_VBlankIntr(TRUE);
|
||||
|
||||
// print usage
|
||||
OS_Printf("=================================\n");
|
||||
OS_Printf("USAGE:\n");
|
||||
OS_Printf(" A : start sound\n");
|
||||
OS_Printf(" B : stop sound\n");
|
||||
OS_Printf(" X : start capture(effect)\n");
|
||||
OS_Printf(" Y : stop capture(effect)\n");
|
||||
OS_Printf("=================================\n");
|
||||
|
||||
// チャンネルをロックする
|
||||
SND_LockChannel((1 << CHANNEL_NUM) | (1 << 1) | (1 << 3), 0);
|
||||
|
||||
/* ストリームスレッドの起動 */
|
||||
OS_CreateThread(&captureThread,
|
||||
CaptureThread,
|
||||
NULL,
|
||||
captureThreadStack + THREAD_STACK_SIZE / sizeof(u64),
|
||||
THREAD_STACK_SIZE, CAPTURE_THREAD_PRIO);
|
||||
OS_WakeupThreadDirect(&captureThread);
|
||||
|
||||
while (1)
|
||||
{
|
||||
u16 ReadData;
|
||||
|
||||
OS_WaitVBlankIntr();
|
||||
|
||||
// ARM7コマンド応答受信
|
||||
while (SND_RecvCommandReply(SND_COMMAND_NOBLOCK) != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ReadData = PAD_Read();
|
||||
Trg = (u16)(ReadData & (ReadData ^ Cont));
|
||||
Cont = ReadData;
|
||||
|
||||
// PCM再生
|
||||
if (Trg & PAD_BUTTON_A)
|
||||
{
|
||||
SND_SetupChannelPcm(CHANNEL_NUM,
|
||||
FANFARE_32_FORMAT,
|
||||
fanfare_32,
|
||||
FANFARE_32_LOOPFLAG ? SND_CHANNEL_LOOP_REPEAT :
|
||||
SND_CHANNEL_LOOP_1SHOT, FANFARE_32_LOOPSTART, FANFARE_32_LOOPLEN,
|
||||
MAX_VOLUME, SND_CHANNEL_DATASHIFT_NONE, FANFARE_32_TIMER,
|
||||
CENTER_PAN);
|
||||
SND_StartTimer(1 << CHANNEL_NUM, 0, 0, 0);
|
||||
}
|
||||
|
||||
// PCM停止
|
||||
if (Trg & PAD_BUTTON_B)
|
||||
{
|
||||
SND_StopTimer(1 << CHANNEL_NUM, 0, 0, 0);
|
||||
}
|
||||
|
||||
// キャプチャ開始
|
||||
if (Trg & PAD_BUTTON_X)
|
||||
{
|
||||
int timerValue;
|
||||
u32 alarmPeriod;
|
||||
u32 alarmFirst;
|
||||
|
||||
timerValue = SND_TIMER_CLOCK / CAPTURE_SAMPLE_RATE;
|
||||
alarmPeriod = timerValue * (CAPTURE_BUF_PAGESIZE / sizeof(s16)) / 32;
|
||||
alarmFirst =
|
||||
timerValue * ((CAPTURE_BUF_PAGESIZE + CAPTURE_FIFO_SIZE) / sizeof(s16)) / 32;
|
||||
cap.bufPage = 0;
|
||||
|
||||
// セレクタ変更:チャンネル1・3のみを出力
|
||||
SND_SetOutputSelector(SND_OUTPUT_CHANNEL1,
|
||||
SND_OUTPUT_CHANNEL3,
|
||||
SND_CHANNEL_OUT_BYPASS, SND_CHANNEL_OUT_BYPASS);
|
||||
// キャプチャ0のバッファの音を再生
|
||||
SND_SetupChannelPcm(1,
|
||||
SND_WAVE_FORMAT_PCM16,
|
||||
captureBufL,
|
||||
SND_CHANNEL_LOOP_REPEAT,
|
||||
0,
|
||||
CAPTURE_BUF_SIZE / sizeof(u32),
|
||||
MAX_VOLUME, SND_CHANNEL_DATASHIFT_NONE, timerValue, 0);
|
||||
// キャプチャ1のバッファの音を再生
|
||||
SND_SetupChannelPcm(3,
|
||||
SND_WAVE_FORMAT_PCM16,
|
||||
captureBufR,
|
||||
SND_CHANNEL_LOOP_REPEAT,
|
||||
0,
|
||||
CAPTURE_BUF_SIZE / sizeof(u32),
|
||||
MAX_VOLUME, SND_CHANNEL_DATASHIFT_NONE, timerValue, 127);
|
||||
// キャプチャ0設定
|
||||
SND_SetupCapture(SND_CAPTURE_0,
|
||||
SND_CAPTURE_FORMAT_PCM16,
|
||||
captureBufL,
|
||||
CAPTURE_BUF_SIZE / sizeof(u32),
|
||||
TRUE, SND_CAPTURE_IN_MIXER, SND_CAPTURE_OUT_NORMAL);
|
||||
// キャプチャ1設定
|
||||
SND_SetupCapture(SND_CAPTURE_1,
|
||||
SND_CAPTURE_FORMAT_PCM16,
|
||||
captureBufR,
|
||||
CAPTURE_BUF_SIZE / sizeof(u32),
|
||||
TRUE, SND_CAPTURE_IN_MIXER, SND_CAPTURE_OUT_NORMAL);
|
||||
// アラーム設定
|
||||
SND_SetupAlarm(ALARM_NUM, alarmFirst, // 初回はFIFOバッファのサイズ分を考慮
|
||||
alarmPeriod, SoundAlarmHandler, &cap);
|
||||
SND_StartTimer((1 << 1) | (1 << 3),
|
||||
(1 << SND_CAPTURE_0) | (1 << SND_CAPTURE_1), 1 << ALARM_NUM, 0);
|
||||
OS_Printf("capture start\n");
|
||||
}
|
||||
|
||||
// キャプチャ停止
|
||||
if (Trg & PAD_BUTTON_Y)
|
||||
{
|
||||
SND_StopTimer((1 << 1) | (1 << 3),
|
||||
(1 << SND_CAPTURE_0) | (1 << SND_CAPTURE_1), 1 << ALARM_NUM, 0);
|
||||
// セレクタ変更:ミキサーから出力
|
||||
SND_SetOutputSelector(SND_OUTPUT_MIXER,
|
||||
SND_OUTPUT_MIXER, SND_CHANNEL_OUT_MIXER, SND_CHANNEL_OUT_MIXER);
|
||||
|
||||
OS_Printf("capture stop\n");
|
||||
}
|
||||
// コマンドフラッシュ
|
||||
(void)SND_FlushCommand(SND_COMMAND_NOBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Vブランク割り込み処理
|
||||
//
|
||||
void VBlankIntr(void)
|
||||
{
|
||||
OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CaptureThread
|
||||
|
||||
Description: ストリームスレッド
|
||||
|
||||
Arguments: arg - ユーザーデータ(未使用)
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void CaptureThread(void * /*arg */ )
|
||||
{
|
||||
OSMessage message;
|
||||
|
||||
OS_InitMessageQueue(&msgQ, msgBuf, 1);
|
||||
|
||||
while (1)
|
||||
{
|
||||
(void)OS_ReceiveMessage(&msgQ, &message, OS_MESSAGE_BLOCK);
|
||||
(void)CaptureFunc((CaptureInfo *) message);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SoundAlarmHandler
|
||||
|
||||
Description: アラームコールバック関数
|
||||
|
||||
Arguments: arg - ストリームオブジェクト
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void SoundAlarmHandler(void *arg)
|
||||
{
|
||||
if (!OS_SendMessage(&msgQ, (OSMessage)arg, OS_MESSAGE_NOBLOCK))
|
||||
OS_Printf("faild to send message\n");
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CaptureFunc
|
||||
|
||||
Description: ストリームデータを生成
|
||||
|
||||
Arguments: strm - ストリームオブジェクト
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void CaptureFunc(CaptureInfo * cap)
|
||||
{
|
||||
u8 *bufL, *bufR;
|
||||
|
||||
// バッファのページ設定
|
||||
if (cap->bufPage == 0)
|
||||
{
|
||||
bufL = captureBufL;
|
||||
bufR = captureBufR;
|
||||
cap->bufPage = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bufL = captureBufL + CAPTURE_BUF_PAGESIZE;
|
||||
bufR = captureBufR + CAPTURE_BUF_PAGESIZE;
|
||||
cap->bufPage = 0;
|
||||
}
|
||||
|
||||
EffectCallback(bufL, bufR, CAPTURE_BUF_PAGESIZE, SND_CAPTURE_FORMAT_PCM16, &cap->callbackInfo);
|
||||
}
|
||||
|
||||
|
||||
static inline smp_t GetSample(smp_t * p, int x, int n, const EffectCallbackInfo * info)
|
||||
{
|
||||
if (x >= 0)
|
||||
return p[x];
|
||||
x += FILTER_SIZE - 1;
|
||||
return info->sample[x][n];
|
||||
}
|
||||
|
||||
void EffectCallback(void *bufferL_p, void *bufferR_p, u32 len, SNDCaptureFormat format, void *arg)
|
||||
{
|
||||
smp_t *lp = (smp_t *) bufferL_p;
|
||||
smp_t *rp = (smp_t *) bufferR_p;
|
||||
EffectCallbackInfo *info = (EffectCallbackInfo *) arg;
|
||||
smp_t org[FILTER_SIZE - 1][2];
|
||||
u32 samples;
|
||||
int x;
|
||||
long i, j;
|
||||
|
||||
samples = (format == SND_CAPTURE_FORMAT_PCM8) ? len : (len >> 1);
|
||||
|
||||
// store original sample data
|
||||
for (i = 0; i < FILTER_SIZE - 1; i++)
|
||||
{
|
||||
org[i][0] = lp[i + samples - FILTER_SIZE + 1];
|
||||
org[i][1] = rp[i + samples - FILTER_SIZE + 1];
|
||||
}
|
||||
|
||||
// filtering
|
||||
for (i = (long)(samples - 1); i >= FILTER_SIZE - 1; i--)
|
||||
{
|
||||
x = 0;
|
||||
for (j = 0; j < FILTER_SIZE; j++)
|
||||
{
|
||||
x += lp[i - j];
|
||||
}
|
||||
x /= FILTER_SIZE;
|
||||
lp[i] = (smp_t) x;
|
||||
|
||||
x = 0;
|
||||
for (j = 0; j < FILTER_SIZE; j++)
|
||||
{
|
||||
x += rp[i - j];
|
||||
}
|
||||
x /= FILTER_SIZE;
|
||||
rp[i] = (smp_t) x;
|
||||
}
|
||||
|
||||
#if FILTER_SIZE >= 2
|
||||
for (i = FILTER_SIZE - 2; i >= 0; i--)
|
||||
{
|
||||
x = lp[i];
|
||||
for (j = 1; j < FILTER_SIZE; j++)
|
||||
{
|
||||
x += GetSample(lp, i - j, 0, info);
|
||||
}
|
||||
x /= FILTER_SIZE;
|
||||
lp[i] = (smp_t) x;
|
||||
|
||||
x = rp[i];
|
||||
for (j = 1; j < FILTER_SIZE; j++)
|
||||
{
|
||||
x += GetSample(rp, i - j, 1, info);
|
||||
}
|
||||
x /= FILTER_SIZE;
|
||||
rp[i] = (smp_t) x;
|
||||
}
|
||||
#endif
|
||||
|
||||
// store last samples for next callback
|
||||
for (i = 0; i < FILTER_SIZE - 1; i++)
|
||||
{
|
||||
info->sample[i][0] = org[i][0];
|
||||
info->sample[i][1] = org[i][1];
|
||||
}
|
||||
|
||||
DC_FlushRange(bufferL_p, len);
|
||||
DC_FlushRange(bufferR_p, len);
|
||||
DC_WaitWriteBufferEmpty();
|
||||
|
||||
}
|
||||
32
build/tests/snd/capture/Makefile
Normal file
32
build/tests/snd/capture/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - build
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = \
|
||||
ARM7 \
|
||||
ARM9 \
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
44
build/tests/snd/channel/ARM7/Makefile
Normal file
44
build/tests/snd/channel/ARM7/Makefile
Normal file
@ -0,0 +1,44 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - SND - demos - channel
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
#TWL_CODEGEN = THUMB
|
||||
TWL_PROC = ARM7
|
||||
|
||||
TARGET_BIN = main.axf
|
||||
|
||||
SRCS = main.c
|
||||
|
||||
#SRCDIR = # using default
|
||||
#LCFILE = # using default
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
170
build/tests/snd/channel/ARM7/src/main.c
Normal file
170
build/tests/snd/channel/ARM7/src/main.c
Normal file
@ -0,0 +1,170 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - tests - snd - channel
|
||||
File: main.c
|
||||
|
||||
Copyright 2007 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: main.c,v $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <twl_sp.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
定数定義
|
||||
*---------------------------------------------------------------------------*/
|
||||
// ===== スレッド優先度 =====
|
||||
|
||||
#define THREAD_PRIO_SPI 2
|
||||
#define THREAD_PRIO_SND 6
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
内部関数定義
|
||||
*---------------------------------------------------------------------------*/
|
||||
static OSHeapHandle InitializeAllocateSystem(void);
|
||||
static void VBlankIntr(void);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: TwlSpMain
|
||||
|
||||
Description: Initialize and do main
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void TwlSpMain(void)
|
||||
{
|
||||
OSHeapHandle heapHandle;
|
||||
|
||||
// OS初期化
|
||||
OS_Init();
|
||||
OS_InitThread();
|
||||
|
||||
// PXI初期化、ARM9と同期
|
||||
PXI_Init();
|
||||
|
||||
// ヒープ領域設定
|
||||
heapHandle = InitializeAllocateSystem();
|
||||
|
||||
// サウンド初期化
|
||||
SND_Init(THREAD_PRIO_SND);
|
||||
|
||||
// reg_CFG_DS_MDFY |= REG_CFG_DS_MDFY_SND_MASK; // SOUND回路バグ修正 (default: off)
|
||||
// reg_CFG_DS_MDFY |= REG_CFG_DS_MDFY_SDMA_MASK; // SOUND-DMAバグ修正 (default: off)
|
||||
// reg_CFG_DS_EX &= ~REG_CFG_DS_EX_SDMA2_MASK; // SOUND-DMA新回路 (default: on)
|
||||
|
||||
// ボタン入力サーチ初期化
|
||||
(void)PAD_InitXYButton();
|
||||
|
||||
// 割込み許可
|
||||
(void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
|
||||
(void)OS_EnableIrqMask(OS_IE_V_BLANK);
|
||||
(void)GX_VBlankIntr(TRUE);
|
||||
(void)OS_EnableIrq();
|
||||
(void)OS_EnableInterrupts();
|
||||
|
||||
// SPI初期化
|
||||
SPI_Init(THREAD_PRIO_SPI);
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
OS_Halt();
|
||||
|
||||
//---- check reset
|
||||
if (OS_IsResetOccurred())
|
||||
{
|
||||
OS_ResetSystem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: InitializeAllocateSystem
|
||||
|
||||
Description: メモリ割当てシステムを初期化する。
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static OSHeapHandle InitializeAllocateSystem(void)
|
||||
{
|
||||
void *tempLo;
|
||||
OSHeapHandle hh;
|
||||
|
||||
OS_TPrintf("OS_GetWramSubPrivArenaLo() = %p\n", OS_GetWramSubPrivArenaLo());
|
||||
OS_TPrintf("OS_GetWramSubPrivArenaHi() = %p\n", OS_GetWramSubPrivArenaHi());
|
||||
OS_TPrintf("OS_GetWramSubArenaLo() = %p\n", OS_GetWramSubArenaLo());
|
||||
OS_TPrintf("OS_GetWramSubArenaHi() = %p\n", OS_GetWramSubArenaHi());
|
||||
OS_TPrintf("OS_GetSubPrivArenaLo() = %p\n", OS_GetSubPrivArenaLo());
|
||||
OS_TPrintf("OS_GetSubPrivArenaHi() = %p\n", OS_GetSubPrivArenaHi());
|
||||
|
||||
OS_TPrintf("call OS_SetWramSubPrivArenaHi(0x0380f980); to fix arena.\n");
|
||||
OS_SetWramSubPrivArenaHi((void*)0x0380f980);
|
||||
|
||||
// メモリ割当て初期化
|
||||
tempLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV,
|
||||
OS_GetWramSubPrivArenaLo(), OS_GetWramSubPrivArenaHi(), 1);
|
||||
|
||||
// アリーナを0クリア
|
||||
MI_CpuClear8(tempLo, (u32)OS_GetWramSubPrivArenaHi() - (u32)tempLo);
|
||||
|
||||
// アリーナ下位アドレスを設定
|
||||
OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, tempLo);
|
||||
|
||||
// ヒープ作成
|
||||
hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV,
|
||||
OS_GetWramSubPrivArenaLo(), OS_GetWramSubPrivArenaHi());
|
||||
|
||||
if (hh < 0)
|
||||
{
|
||||
OS_Panic("ARM7: Fail to create heap.\n");
|
||||
}
|
||||
|
||||
// カレントヒープに設定
|
||||
(void)OS_SetCurrentHeap(OS_ARENA_WRAM_SUBPRIV, hh);
|
||||
|
||||
return hh;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: VBlankIntr
|
||||
|
||||
Description: VBlank interrupt handler
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef SDK_TEG
|
||||
|
||||
extern BOOL PMi_Initialized;
|
||||
void PM_SelfBlinkProc(void);
|
||||
|
||||
static void VBlankIntr(void)
|
||||
{
|
||||
//---- LED blink system
|
||||
if (PMi_Initialized)
|
||||
{
|
||||
PM_SelfBlinkProc();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void VBlankIntr(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
End of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
43
build/tests/snd/channel/ARM9/Makefile
Normal file
43
build/tests/snd/channel/ARM9/Makefile
Normal file
@ -0,0 +1,43 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - SND - demos - channel
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
#TWL_CODEGEN = THUMB
|
||||
|
||||
TARGET_BIN = main.axf
|
||||
|
||||
SRCS = main.c organ_det.g3.pcm16.c wihaho.pcm16.c
|
||||
|
||||
#SRCDIR = # using default
|
||||
#LCFILE = # using default
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
48
build/tests/snd/channel/ARM9/include/organ_det.g3.pcm16.h
Normal file
48
build/tests/snd/channel/ARM9/include/organ_det.g3.pcm16.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: NitroSDK - SND - demos - channel
|
||||
File: organ_det.g3.pcm16.h
|
||||
|
||||
Copyright 2005,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: organ_det.g3.pcm16.h,v $
|
||||
Revision 1.2 2006/01/18 02:11:30 kitase_hirotake
|
||||
do-indent
|
||||
|
||||
Revision 1.1 2005/04/13 03:29:19 ida
|
||||
SND‚ðNITRO-SDK‚ÖˆÚ<EFBFBD>Ý
|
||||
|
||||
Revision 1.1 2005/04/13 01:14:54 kyuma_koichi
|
||||
<EFBFBD>‰”Å
|
||||
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef ORGAN_DET_G3_PCM16_H_
|
||||
#define ORGAN_DET_G3_PCM16_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <nitro.h>
|
||||
|
||||
#define ORGAN_DET_G3_PCM16_FORMAT SND_WAVE_FORMAT_PCM16
|
||||
#define ORGAN_DET_G3_PCM16_LOOPFLAG 1
|
||||
#define ORGAN_DET_G3_PCM16_RATE 32000
|
||||
#define ORGAN_DET_G3_PCM16_TIMER 523
|
||||
#define ORGAN_DET_G3_PCM16_LOOPSTART 1995
|
||||
#define ORGAN_DET_G3_PCM16_LOOPLEN 11959
|
||||
|
||||
const s16 organ_det_g3_pcm16[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ORGAN_DET_G3_PCM16_H_
|
||||
48
build/tests/snd/channel/ARM9/include/wihaho.pcm16.h
Normal file
48
build/tests/snd/channel/ARM9/include/wihaho.pcm16.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: NitroSDK - SND - demos - channel
|
||||
File: wihaho.pcm16.h
|
||||
|
||||
Copyright 2005,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: wihaho.pcm16.h,v $
|
||||
Revision 1.2 2006/01/18 02:12:39 kitase_hirotake
|
||||
do-indent
|
||||
|
||||
Revision 1.1 2005/04/13 03:29:19 ida
|
||||
SND‚ðNITRO-SDK‚ÖˆÚ<EFBFBD>Ý
|
||||
|
||||
Revision 1.1 2005/04/13 01:14:54 kyuma_koichi
|
||||
<EFBFBD>‰”Å
|
||||
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef WIHAHO_PCM16_H_
|
||||
#define WIHAHO_PCM16_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <nitro.h>
|
||||
|
||||
#define WIHAHO_PCM16_FORMAT SND_WAVE_FORMAT_PCM16
|
||||
#define WIHAHO_PCM16_LOOPFLAG 0
|
||||
#define WIHAHO_PCM16_RATE 44100
|
||||
#define WIHAHO_PCM16_TIMER 379
|
||||
#define WIHAHO_PCM16_LOOPSTART 0
|
||||
#define WIHAHO_PCM16_LOOPLEN 27016
|
||||
|
||||
const s16 wihaho_pcm16[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // WIHAHO_PCM16_H_
|
||||
173
build/tests/snd/channel/ARM9/src/main.c
Normal file
173
build/tests/snd/channel/ARM9/src/main.c
Normal file
@ -0,0 +1,173 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - SND - tests - channel
|
||||
File: main.c
|
||||
|
||||
Copyright 2007 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: main.c,v $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <twl.h>
|
||||
#include "organ_det.g3.pcm16.h"
|
||||
#include "wihaho.pcm16.h"
|
||||
|
||||
// PSGの周波数を計算するマクロ
|
||||
#define FreqToTimer(freq) (SND_TIMER_CLOCK / ( 8 * (freq) ))
|
||||
#define KeyToTimer(key) (SND_CalcTimer(FreqToTimer(440), ((key)-69)*64))
|
||||
|
||||
#define PCM_PLAY_CHANNEL1 4
|
||||
#define PCM_PLAY_CHANNEL2 5
|
||||
#define PSG_PLAY_CHANNEL 8
|
||||
#define NOISE_PLAY_CHANNEL 14
|
||||
|
||||
#define CENTER_PAN 64
|
||||
|
||||
u16 Cont;
|
||||
u16 Trg;
|
||||
u8 key = 60;
|
||||
|
||||
void VBlankIntr(void);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: TwlMain
|
||||
|
||||
Description: main
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void TwlMain()
|
||||
{
|
||||
// 初期化
|
||||
OS_Init();
|
||||
GX_Init();
|
||||
SND_Init();
|
||||
|
||||
// Vブランク割り込み設定
|
||||
OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
|
||||
(void)OS_EnableIrqMask(OS_IE_V_BLANK);
|
||||
(void)OS_EnableIrq();
|
||||
(void)GX_VBlankIntr(TRUE);
|
||||
|
||||
// print usage
|
||||
OS_Printf("=================================\n");
|
||||
OS_Printf("USAGE:\n");
|
||||
OS_Printf(" A, B, X, Y : start sound\n");
|
||||
OS_Printf(" START : stop sound\n");
|
||||
OS_Printf("=================================\n");
|
||||
|
||||
// チャンネルをロックする
|
||||
SND_LockChannel((1 << PCM_PLAY_CHANNEL1) | (1 << PCM_PLAY_CHANNEL2) | (1 << PSG_PLAY_CHANNEL) |
|
||||
(1 << NOISE_PLAY_CHANNEL), 0);
|
||||
|
||||
while (1)
|
||||
{
|
||||
u16 ReadData;
|
||||
|
||||
OS_WaitVBlankIntr();
|
||||
|
||||
// ARM7コマンド応答受信
|
||||
while (SND_RecvCommandReply(SND_COMMAND_NOBLOCK) != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ReadData = PAD_Read();
|
||||
Trg = (u16)(ReadData & (ReadData ^ Cont));
|
||||
Cont = ReadData;
|
||||
|
||||
// PCM再生
|
||||
if (Trg & PAD_BUTTON_A)
|
||||
{
|
||||
OS_Printf("A\n");
|
||||
SND_SetupChannelPcm(PCM_PLAY_CHANNEL1,
|
||||
ORGAN_DET_G3_PCM16_FORMAT,
|
||||
organ_det_g3_pcm16,
|
||||
ORGAN_DET_G3_PCM16_LOOPFLAG ? SND_CHANNEL_LOOP_REPEAT :
|
||||
SND_CHANNEL_LOOP_1SHOT, ORGAN_DET_G3_PCM16_LOOPSTART,
|
||||
ORGAN_DET_G3_PCM16_LOOPLEN, 127, SND_CHANNEL_DATASHIFT_NONE,
|
||||
SND_CalcTimer(ORGAN_DET_G3_PCM16_TIMER, ((key) - 67) * 64),
|
||||
CENTER_PAN);
|
||||
SND_StartTimer(1 << PCM_PLAY_CHANNEL1, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (Trg & PAD_BUTTON_B)
|
||||
{
|
||||
OS_Printf("B\n");
|
||||
SND_SetupChannelPcm(PCM_PLAY_CHANNEL2,
|
||||
WIHAHO_PCM16_FORMAT,
|
||||
wihaho_pcm16,
|
||||
WIHAHO_PCM16_LOOPFLAG ? SND_CHANNEL_LOOP_REPEAT :
|
||||
SND_CHANNEL_LOOP_1SHOT, WIHAHO_PCM16_LOOPSTART,
|
||||
WIHAHO_PCM16_LOOPLEN, 127, SND_CHANNEL_DATASHIFT_NONE,
|
||||
WIHAHO_PCM16_TIMER, CENTER_PAN);
|
||||
SND_StartTimer(1 << PCM_PLAY_CHANNEL2, 0, 0, 0);
|
||||
}
|
||||
|
||||
// PSG矩形波を再生
|
||||
if (Trg & PAD_BUTTON_X)
|
||||
{
|
||||
OS_Printf("X\n");
|
||||
SND_SetupChannelPsg(PSG_PLAY_CHANNEL,
|
||||
SND_DUTY_4_8,
|
||||
64, SND_CHANNEL_DATASHIFT_NONE, KeyToTimer(key), CENTER_PAN);
|
||||
SND_StartTimer(1 << PSG_PLAY_CHANNEL, 0, 0, 0);
|
||||
}
|
||||
|
||||
// ノイズの再生
|
||||
if (Trg & PAD_BUTTON_Y)
|
||||
{
|
||||
OS_Printf("Y\n");
|
||||
SND_SetupChannelNoise(NOISE_PLAY_CHANNEL,
|
||||
64, SND_CHANNEL_DATASHIFT_NONE, KeyToTimer(key), CENTER_PAN);
|
||||
SND_StartTimer(1 << NOISE_PLAY_CHANNEL, 0, 0, 0);
|
||||
}
|
||||
|
||||
// 停止
|
||||
if (Trg & PAD_BUTTON_START)
|
||||
{
|
||||
SND_StopTimer((1 << PCM_PLAY_CHANNEL1) | (1 << PCM_PLAY_CHANNEL2) |
|
||||
(1 << PSG_PLAY_CHANNEL) | (1 << NOISE_PLAY_CHANNEL), 0, 0, 0);
|
||||
}
|
||||
|
||||
// 再生のキーを半音上げる
|
||||
if (Trg & PAD_KEY_UP)
|
||||
{
|
||||
key++;
|
||||
SND_SetChannelTimer(1 << PCM_PLAY_CHANNEL1,
|
||||
SND_CalcTimer(ORGAN_DET_G3_PCM16_TIMER, ((key) - 67) * 64));
|
||||
SND_SetChannelTimer((1 << PSG_PLAY_CHANNEL) | (1 << NOISE_PLAY_CHANNEL),
|
||||
KeyToTimer(key));
|
||||
OS_Printf("key: %d\n", key);
|
||||
}
|
||||
|
||||
// 再生のキーを半音下げる
|
||||
if (Trg & PAD_KEY_DOWN)
|
||||
{
|
||||
key--;
|
||||
SND_SetChannelTimer(1 << PCM_PLAY_CHANNEL1,
|
||||
SND_CalcTimer(ORGAN_DET_G3_PCM16_TIMER, ((key) - 67) * 64));
|
||||
SND_SetChannelTimer((1 << PSG_PLAY_CHANNEL) | (1 << NOISE_PLAY_CHANNEL),
|
||||
KeyToTimer(key));
|
||||
OS_Printf("key: %d\n", key);
|
||||
}
|
||||
|
||||
// コマンドフラッシュ
|
||||
(void)SND_FlushCommand(SND_COMMAND_NOBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Vブランク割り込み処理
|
||||
//
|
||||
void VBlankIntr(void)
|
||||
{
|
||||
OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
|
||||
}
|
||||
3516
build/tests/snd/channel/ARM9/src/organ_det.g3.pcm16.c
Normal file
3516
build/tests/snd/channel/ARM9/src/organ_det.g3.pcm16.c
Normal file
File diff suppressed because it is too large
Load Diff
6781
build/tests/snd/channel/ARM9/src/wihaho.pcm16.c
Normal file
6781
build/tests/snd/channel/ARM9/src/wihaho.pcm16.c
Normal file
File diff suppressed because it is too large
Load Diff
32
build/tests/snd/channel/Makefile
Normal file
32
build/tests/snd/channel/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - build
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2007 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: $
|
||||
# $NoKeywords: $
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = \
|
||||
ARM7 \
|
||||
ARM9 \
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
27
include/twl/cdc.h
Normal file
27
include/twl/cdc.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - CDC - include
|
||||
File: cdc.h
|
||||
|
||||
Copyright 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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TWL_CDC_H_
|
||||
#define TWL_CDC_H_
|
||||
|
||||
#include <twl/cdc/ARM7/cdc_reg.h>
|
||||
#include <twl/cdc/ARM7/cdc.h>
|
||||
#include <twl/cdc/ARM7/cdc_api.h>
|
||||
#include <twl/cdc/ARM7/cdc_filter_coefficient.h>
|
||||
//#include <twl/cdc/ARM7/cdc_dsmode_access.h>
|
||||
|
||||
/* TWL_CDC_H_ */
|
||||
#endif
|
||||
354
include/twl/cdc/ARM7/cdc.h
Normal file
354
include/twl/cdc/ARM7/cdc.h
Normal file
@ -0,0 +1,354 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - CDC - include
|
||||
File: CDC_.h
|
||||
|
||||
Copyright 2006-2007 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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef TWL_CDC_CDC_H_
|
||||
#define TWL_CDC_CDC_H_
|
||||
|
||||
#include <twl/misc.h>
|
||||
#include <twl/types.h>
|
||||
#include <twl/cdc/ARM7/cdc_reg.h>
|
||||
#include <nitro/spi/ARM7/spi.h>
|
||||
#include <twl/i2c/ARM7/i2c.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//================================================================
|
||||
// CODEC status variables
|
||||
//================================================================
|
||||
extern SPIBaudRate cdcSPIBaudRate;
|
||||
extern BOOL cdcIsTwlMode;
|
||||
extern int cdcCurrentPage;
|
||||
|
||||
#define CDC_REVISION_A 0
|
||||
#define CDC_REVISION_B 1
|
||||
#define CDC_REVISION_C 2
|
||||
extern int cdcRevisionID;
|
||||
|
||||
extern u16 cdcSpiMode;
|
||||
|
||||
//================================================================
|
||||
// BAUDRATE parameter
|
||||
//================================================================
|
||||
|
||||
#define CDC_SPI_BAUDRATE_DEFAULT SPI_BAUDRATE_1MHZ // SPI_BAUDRATE_4MHZ
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_SetSPIBaudRate
|
||||
|
||||
Description: set SPI baud rate.
|
||||
|
||||
Arguments: baud rate.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void CDCi_SetSPIBaudRate( SPIBaudRate rate )
|
||||
{
|
||||
cdcSPIBaudRate = rate;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDCi_GetSPIBaudRate
|
||||
|
||||
Description: get SPI baud rate.
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: baud rate.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline SPIBaudRate CDCi_GetSPIBaudRate( void )
|
||||
{
|
||||
return cdcSPIBaudRate;
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// I2C BIT CONTROL
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetI2cParams
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
maskBits : bits to mask
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void CDCi_SetI2cParams( u8 reg, u8 setBits, u8 maskBits )
|
||||
{
|
||||
I2Ci_SetParams( I2C_SLAVE_CODEC_TP, reg, setBits, maskBits );
|
||||
}
|
||||
static inline void CDC_SetI2cParams( u8 reg, u8 setBits, u8 maskBits )
|
||||
{
|
||||
I2C_SetParams( I2C_SLAVE_CODEC_TP, reg, setBits, maskBits );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetI2cFlags
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void CDCi_SetI2cFlags( u8 reg, u8 setBits )
|
||||
{
|
||||
I2Ci_SetFlags( I2C_SLAVE_CODEC_TP, reg, setBits );
|
||||
}
|
||||
static inline void CDC_SetI2cFlags( u8 reg, u8 setBits )
|
||||
{
|
||||
I2C_SetFlags( I2C_SLAVE_CODEC_TP, reg, setBits );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_ClearI2cFlags
|
||||
|
||||
Description: clear control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void CDCi_ClearI2cFlags( u8 reg, u8 clrBits )
|
||||
{
|
||||
I2Ci_ClearFlags( I2C_SLAVE_CODEC_TP, reg, clrBits );
|
||||
}
|
||||
static inline void CDC_ClearI2cFlags( u8 reg, u8 clrBits )
|
||||
{
|
||||
I2C_ClearFlags( I2C_SLAVE_CODEC_TP, reg, clrBits );
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// I2C ACCESS
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_WriteI2cRegister
|
||||
|
||||
Description: set value to decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void CDCi_WriteI2cRegister( u8 reg, u8 data )
|
||||
{
|
||||
I2Ci_WriteRegister( I2C_SLAVE_CODEC_TP, reg, data );
|
||||
}
|
||||
static inline void CDC_WriteI2cRegister( u8 reg, u8 data )
|
||||
{
|
||||
I2C_WriteRegister( I2C_SLAVE_CODEC_TP, reg, data );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_ReadI2cRegister
|
||||
|
||||
Description: get value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline u8 CDCi_ReadI2cRegister( u8 reg )
|
||||
{
|
||||
return I2Ci_ReadRegister( I2C_SLAVE_CODEC_TP, reg );
|
||||
}
|
||||
static inline u8 CDC_ReadI2cRegister( u8 reg )
|
||||
{
|
||||
return I2C_ReadRegister( I2C_SLAVE_CODEC_TP, reg );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_WriteI2cRegisters
|
||||
|
||||
Description: set value to decive registers through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void CDCi_WriteI2cRegisters( u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
I2Ci_WriteRegisters( I2C_SLAVE_CODEC_TP, reg, bufp, size );
|
||||
}
|
||||
static inline void CDC_WriteI2cRegisters( u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
I2C_WriteRegisters( I2C_SLAVE_CODEC_TP, reg, bufp, size );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_ReadI2cRegisters
|
||||
|
||||
Description: get value from decive registers through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void CDCi_ReadI2cRegisters( u8 reg, u8 *bufp, size_t size )
|
||||
{
|
||||
I2Ci_ReadRegisters( I2C_SLAVE_CODEC_TP, reg, bufp, size );
|
||||
}
|
||||
static inline void CDC_ReadI2cRegisters( u8 reg, u8 *bufp, size_t size )
|
||||
{
|
||||
I2C_ReadRegisters( I2C_SLAVE_CODEC_TP, reg, bufp, size );
|
||||
}
|
||||
|
||||
#if 0
|
||||
//================================================================================
|
||||
// SPI BIT CONTROL
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetSpiParams
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
maskBits : bits to mask
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_SetSpiParams( u8 reg, u8 setBits, u8 maskBits );
|
||||
void CDC_SetSpiParams( u8 reg, u8 setBits, u8 maskBits );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetSpiFlags
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_SetSpiFlags( u8 reg, u8 setBits );
|
||||
void CDC_SetSpiFlags( u8 reg, u8 setBits );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_ClearSpiFlags
|
||||
|
||||
Description: clear control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_ClearSpiFlags( u8 reg, u8 clrBits );
|
||||
void CDC_ClearSpiFlags( u8 reg, u8 clrBits );
|
||||
|
||||
//================================================================================
|
||||
// SPI ACCESS
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_WriteSpiRegister
|
||||
|
||||
Description: set value to decive register through SPI.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_WriteSpiRegister( u8 reg, u8 data );
|
||||
static inline void CDC_WriteSpiRegister( u8 reg, u8 data )
|
||||
{
|
||||
(void)spiLock();
|
||||
CDCi_WriteSpiRegister( reg, data );
|
||||
(void)spiUnlock();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_ReadSpiRegister
|
||||
|
||||
Description: get value from decive register through SPI.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 CDCi_ReadSpiRegister( u8 reg );
|
||||
static inline void CDC_ReadSpiRegister( u8 reg )
|
||||
{
|
||||
(void)spiLock();
|
||||
CDCi_ReadSpiRegister( reg );
|
||||
(void)spiUnlock();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_WriteSpiRegisters
|
||||
|
||||
Description: set value to decive registers through SPI.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_WriteSpiRegisters( u8 reg, const u8 *bufp, size_t size );
|
||||
static inline void CDC_WriteSpiRegisters( u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
(void)spiLock();
|
||||
CDCi_WriteSpiRegisters( reg, bufp, size );
|
||||
(void)spiUnlock();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_ReadSpiRegisters
|
||||
|
||||
Description: get value from decive registers through SPI.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_ReadSpiRegisters( u8 reg, u8 *bufp, size_t size );
|
||||
static inline void CDC_ReadSpiRegisters( u8 reg, u8 *bufp, size_t size )
|
||||
{
|
||||
(void)spiLock();
|
||||
CDCi_ReadSpiRegisters( reg, bufp, size );
|
||||
(void)spiUnlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
//================================================================================
|
||||
// Utility Functions
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_ChangePage
|
||||
|
||||
Description: change register page
|
||||
|
||||
Arguments: page_no : next page number
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDCi_ChangePage( int page_no );
|
||||
void CDC_ChangePage( int page_no );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* TWL_CDC_CDC_H_ */
|
||||
#endif
|
||||
360
include/twl/cdc/ARM7/cdc_api.h
Normal file
360
include/twl/cdc/ARM7/cdc_api.h
Normal file
@ -0,0 +1,360 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - CDC - include
|
||||
File: CDC__api.h
|
||||
|
||||
Copyright 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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef TWL_CDC_CDC_API_H_
|
||||
#define TWL_CDC_CDC_API_H_
|
||||
|
||||
#include <twl/cdc/ARM7/cdc.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//================================================================================
|
||||
// INIT APIs
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_Init
|
||||
|
||||
Description: initialize codec
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_Init( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_Reset
|
||||
|
||||
Description: codec SW reset
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_Reset( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_InitSound
|
||||
|
||||
Description: initialize output sound(speaker/headphone) logic
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_InitSound( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_InitMic
|
||||
|
||||
Description: initialize microphone logic
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_InitMic( void );
|
||||
|
||||
|
||||
//================================================================================
|
||||
// Query/Check APIs
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_IsTwlMode
|
||||
|
||||
Description: check TWL-mode (True) or DS-mode (False)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: TRUE : TWL-mode, FALSE : DS-mode
|
||||
*---------------------------------------------------------------------------*/
|
||||
inline BOOL CDC_IsTwlMode( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_GetVendorId
|
||||
|
||||
Description: get Vendor ID
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: u8 Vendor ID
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 CDC_GetVendorId( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_GetRevisionId
|
||||
|
||||
Description: get Revision ID
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: u8 Revision ID (3-bit value)
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 CDC_GetRevisionId( void );
|
||||
|
||||
|
||||
//================================================================================
|
||||
// State Transition/Check APIs
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_GoDsMode
|
||||
|
||||
Description: transit from TWL-mode to DS-mode
|
||||
(never come back to TWL-mode without HW Reset)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_GoDsMode( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetInputPinControl
|
||||
|
||||
Description: set if input pin control enabled or not.
|
||||
Usually, PMOFF should not be disabled.
|
||||
|
||||
Arguments: BOOL enable_vcnt5 : set TRUE to enable VCNT5(LCD backlight) pin
|
||||
BOOL enable_sphp : set TRUE to enable SP#HP switching pin
|
||||
BOOL enable_pmoff : set TRUE to enable PMOFF pin
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_SetInputPinControl( BOOL enable_vcnt5, BOOL enable_sphp, BOOL enable_pmoff );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_GetInputPinControl
|
||||
|
||||
Description: get if input pin control enabled or not.
|
||||
|
||||
Arguments: BOOL *enable_vcnt5 : get TRUE if VCNT5(LCD backlight) pin is enabled
|
||||
BOOL *enable_sphp : get TRUE if SP#HP switching pin is enabled
|
||||
BOOL *enable_pmoff : get TRUE if PMOFF pin is enabled
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_GetInputPinControl( BOOL *enable_vcnt5, BOOL *enable_sphp, BOOL *enable_pmoff );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_cdcPowerUpPLL
|
||||
|
||||
Description: power up Internal PLL of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_cdcPowerUpPLL( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_cdcPowerDownPLL
|
||||
|
||||
Description: power down Internal PLL of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_cdcPowerDownPLL( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_PowerUpDAC
|
||||
|
||||
Description: power up (both Left,Right channel of the) DAC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_PowerUpDAC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_PowerDownDAC
|
||||
|
||||
Description: power down (both Left,Right channel of the) DAC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_PowerDownDAC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_SetupDAC
|
||||
|
||||
Description: setup DAC depop value of the CODEC
|
||||
|
||||
Arguments: int hp_pwon_tm : Headphone Power-on time
|
||||
int hp_rmpup_tm : Headphone Ramp-up step time
|
||||
int sphp_rmpdn_tm : Speaker/Headphonw Ramp-down step time
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_SetupDAC( int hp_pwon_tm, int hp_rmpup_tm, int sphp_rmpdn_tm );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_EnableHeadphoneDriver
|
||||
|
||||
Description: enable Headphone Driver (HP Driver On)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_EnableHeadphoneDriver( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_DisableHeadphoneDriver
|
||||
|
||||
Description: disable Headphone Driver (HP Driver Off)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_DisableHeadphoneDriver( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_EnableSpeakerDriver
|
||||
|
||||
Description: enable Speaker Driver (SP Driver On)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_EnableSpeakerDriver( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_DisableSpeakerDriver
|
||||
|
||||
Description: disable Speaker Driver (SP Driver Off)
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_DisableSpeakerDriver( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_UnmuteDAC
|
||||
|
||||
Description: Un-mute DAC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_UnmuteDAC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_MuteDAC
|
||||
|
||||
Description: Mute DAC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_MuteDAC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_PowerUpADC
|
||||
|
||||
Description: power up ADC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_PowerUpADC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_PowerDownADC
|
||||
|
||||
Description: power down ADC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_PowerDownADC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_UnmuteADC
|
||||
|
||||
Description: Un-mute ADC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_UnmuteADC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_MuteADC
|
||||
|
||||
Description: Mute ADC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_MuteADC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_EnableAGC
|
||||
|
||||
Description: Enable AGC of the CODEC
|
||||
|
||||
Arguments: int target_gain : AGC Target Gain
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_EnableAGC( int target_gain );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_DisableAGC
|
||||
|
||||
Description: Disable AGC of the CODEC
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_DisableAGC( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: CDC_Init1stOrderFilter
|
||||
|
||||
Description: initialize 1st order filter coeffient
|
||||
|
||||
Arguments: u8 *coef : 1st order coefficient (6 bytes)
|
||||
int filter_target : target filter to be setup
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void CDC_Init1stOrderFilter( u8 *coef, int filter_target );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* TWL_CDC_CDC_API_H_ */
|
||||
#endif
|
||||
76
include/twl/cdc/ARM7/cdc_filter_coefficient.h
Normal file
76
include/twl/cdc/ARM7/cdc_filter_coefficient.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - CDC - include
|
||||
File: cdc_filter_coefficient.h
|
||||
|
||||
Copyright 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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef TWL_CDC_CDC_FILTER_COEFFICIENT_H_
|
||||
#define TWL_CDC_CDC_FILTER_COEFFICIENT_H_
|
||||
|
||||
#include <twl/misc.h>
|
||||
#include <twl/types.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//================================================================================
|
||||
// Typical Filter Coefficients (1st order)
|
||||
//================================================================================
|
||||
// ADC Filters for Microphone
|
||||
#define CDC_FILTER_1ST_IIR_ADC 0x00000001 // page4 reg8 -- 13
|
||||
#define CDC_FILTER_BIQUAD_ADC_A 0x00000002 // reg14 -- 23
|
||||
#define CDC_FILTER_BIQUAD_ADC_B 0x00000004 // reg24 -- 33
|
||||
#define CDC_FILTER_BIQUAD_ADC_C 0x00000008 // reg34 -- 43
|
||||
#define CDC_FILTER_BIQUAD_ADC_D 0x00000010 // reg44 -- 53
|
||||
#define CDC_FILTER_BIQUAD_ADC_E 0x00000020 // reg54 -- 63
|
||||
|
||||
// DAC Filters for SP#HP (left)
|
||||
#define CDC_FILTER_1ST_IIR_LDAC 0x00000100 // page9 reg2 -- 7
|
||||
#define CDC_FILTER_BIQUAD_LDAC_B 0x00000200 // page8 reg12 -- 21
|
||||
#define CDC_FILTER_BIQUAD_LDAC_C 0x00000400 // reg22 -- 31
|
||||
#define CDC_FILTER_BIQUAD_LDAC_D 0x00000800 // reg32 -- 41
|
||||
#define CDC_FILTER_BIQUAD_LDAC_E 0x00001000 // reg42 -- 51
|
||||
#define CDC_FILTER_BIQUAD_LDAC_F 0x00002000 // reg52 -- 61
|
||||
|
||||
// DAC Filters for SP#HP (right)
|
||||
#define CDC_FILTER_1ST_IIR_RDAC 0x00010000 // page9 reg8 -- 13
|
||||
#define CDC_FILTER_BIQUAD_RDAC_B 0x00020000 // page8 reg76 -- 85
|
||||
#define CDC_FILTER_BIQUAD_RDAC_C 0x00040000 // reg86 -- 95
|
||||
#define CDC_FILTER_BIQUAD_RDAC_D 0x00080000 // reg96 -- 105
|
||||
#define CDC_FILTER_BIQUAD_RDAC_E 0x00100000 // reg106-- 115
|
||||
#define CDC_FILTER_BIQUAD_RDAC_F 0x00200000 // reg116-- 125
|
||||
|
||||
#define CDC_FILTER_ADC 0x0000003F
|
||||
#define CDC_FILTER_LDAC 0x00003F00
|
||||
#define CDC_FILTER_RDAC 0x003F0000
|
||||
|
||||
|
||||
//================================================================================
|
||||
// Typical Filter Coefficients (1st order)
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
HPF, cut-off(-3dB) point = 0x00021*Fs = 9.26Hz (@Fs = 44.1kHz)
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern u8 cdc1stCoef_HPF_9_26Hz[6];
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* TWL_CDC_CDC_FILTER_COEFFICIENT_H_ */
|
||||
#endif
|
||||
1560
include/twl/cdc/ARM7/cdc_reg.h
Normal file
1560
include/twl/cdc/ARM7/cdc_reg.h
Normal file
File diff suppressed because it is too large
Load Diff
367
include/twl/i2c/ARM7/i2c.h
Normal file
367
include/twl/i2c/ARM7/i2c.h
Normal file
@ -0,0 +1,367 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlSDK - I2C
|
||||
File: i2c.h
|
||||
|
||||
Copyright 2007 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: $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TWL_I2C_I2C_H_
|
||||
#define TWL_I2C_I2C_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <twl/ioreg.h>
|
||||
#include <nitro/hw/ARM7/ioreg_EXI.h>
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// enums
|
||||
//
|
||||
//---- I2C device ID
|
||||
typedef enum
|
||||
{
|
||||
I2C_SLAVE_CODEC_TP = 0,
|
||||
I2C_SLAVE_CAMERA = 2,
|
||||
I2C_SLAVE_NUM
|
||||
}
|
||||
I2CSlave;
|
||||
|
||||
|
||||
//---- I2C read/write
|
||||
typedef enum
|
||||
{
|
||||
I2C_WRITE = 0,
|
||||
I2C_READ = 1
|
||||
}
|
||||
I2CReadWrite;
|
||||
|
||||
|
||||
#define I2C_ADDR_CODEC (0x18 << 1)
|
||||
//#define I2C_ADDR_CAMERA 0x5a // SAMSUNG 1/8
|
||||
#define I2C_ADDR_CAMERA (0x62 << 1) // SAMSUNG 1/10
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// subroutine definition
|
||||
//
|
||||
BOOL I2C_Init( void );
|
||||
BOOL I2C_Lock( void ); // 外部スレッドから呼ばれ、I2Cデバイスの操作権利を取得する
|
||||
BOOL I2C_Unlock( void ); // 外部スレッドから呼ばれ、I2Cデバイスの操作権利を解放する
|
||||
|
||||
//----------------------------------------------------------------
|
||||
//---- check I2C is busy
|
||||
static inline BOOL I2C_IsBusy(void)
|
||||
{
|
||||
return (BOOL)((reg_EXI_I2CCNT & REG_EXI_I2CCNT_E_MASK) >> REG_EXI_I2CCNT_E_SHIFT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_Wait
|
||||
|
||||
Description: I2Cを用いたデータ転送を実行中の場合、1バイト転送が完了するまで
|
||||
待機する。
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
static inline void I2Ci_Wait(void)
|
||||
{
|
||||
while (reg_EXI_I2CCNT & REG_EXI_I2CCNT_E_MASK)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_Init
|
||||
|
||||
Description: initialize I2C
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void I2Ci_Init( void );
|
||||
|
||||
|
||||
//================================================================================
|
||||
// DEVICE BIT CONTROL
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_SetParams
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_SetParams( I2CSlave id, u8 reg, u8 setBits, u8 maskBits );
|
||||
BOOL I2C_SetParams( I2CSlave id, u8 reg, u8 setBits, u8 maskBits );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_SetFlags
|
||||
|
||||
Description: set control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_SetFlags( I2CSlave id, u8 reg, u8 setBits );
|
||||
BOOL I2C_SetFlags( I2CSlave id, u8 reg, u8 setBits );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_ClearFlags
|
||||
|
||||
Description: clear control bit to device register
|
||||
|
||||
Arguments: reg : device register
|
||||
setBits : bits to set
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_ClearFlags( I2CSlave id, u8 reg, u8 clrBits );
|
||||
BOOL I2C_ClearFlags( I2CSlave id, u8 reg, u8 clrBits );
|
||||
|
||||
//================================================================================
|
||||
// DEVICE ACCESS
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_WriteRegister
|
||||
|
||||
Description: set value to decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_WriteRegister( I2CSlave id, u8 reg, u8 data );
|
||||
static inline BOOL I2C_WriteRegister( I2CSlave id, u8 reg, u8 data )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_WriteRegister( id, reg, data );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_ReadRegister
|
||||
|
||||
Description: get value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 I2Ci_ReadRegister( I2CSlave id, u8 reg );
|
||||
static inline u8 I2C_ReadRegister( I2CSlave id, u8 reg )
|
||||
{
|
||||
u8 result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_ReadRegister( id, reg );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_ReadRegisterSC
|
||||
|
||||
Description: get value from decive register through I2C.
|
||||
this version sends second byte with stop condition
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
u8 I2Ci_ReadRegisterSC( I2CSlave id, u8 reg );
|
||||
static inline u8 I2C_ReadRegisterSC( I2CSlave id, u8 reg )
|
||||
{
|
||||
u8 result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_ReadRegisterSC( id, reg );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_VerifyRegister
|
||||
|
||||
Description: get and verify value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_VerifyRegister( I2CSlave id, u8 reg, u8 data );
|
||||
static inline BOOL I2C_VerifyRegister( I2CSlave id, u8 reg, u8 data )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_VerifyRegister( id, reg, data );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_VerifyRegisterSC
|
||||
|
||||
Description: get and verify value from decive register through I2C.
|
||||
this version sends second byte with stop condition
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_VerifyRegisterSC( I2CSlave id, u8 reg, u8 data );
|
||||
static inline BOOL I2C_VerifyRegisterSC( I2CSlave id, u8 reg, u8 data )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_VerifyRegisterSC( id, reg, data );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_WriteRegisters
|
||||
|
||||
Description: set value to decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
data : value to be written
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_WriteRegisters( I2CSlave id, u8 reg, const u8 *bufp, size_t size );
|
||||
static inline BOOL I2C_WriteRegisters( I2CSlave id, u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_WriteRegisters( id, reg, bufp, size );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_ReadRegisters
|
||||
|
||||
Description: get value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_ReadRegisters( I2CSlave id, u8 reg, u8 *bufp, size_t size );
|
||||
static inline BOOL I2C_ReadRegisters( I2CSlave id, u8 reg, u8 *bufp, size_t size )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_ReadRegisters( id, reg, bufp, size );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_ReadRegistersSC
|
||||
|
||||
Description: get value from decive register through I2C.
|
||||
this version sends second byte with stop condition
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_ReadRegistersSC( I2CSlave id, u8 reg, u8 *bufp, size_t size );
|
||||
static inline BOOL I2C_ReadRegistersSC( I2CSlave id, u8 reg, u8 *bufp, size_t size )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_ReadRegistersSC( id, reg, bufp, size );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_VerifyRegisters
|
||||
|
||||
Description: get and verify value from decive register through I2C.
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_VerifyRegisters( I2CSlave id, u8 reg, const u8 *bufp, size_t size );
|
||||
static inline BOOL I2C_VerifyRegisters( I2CSlave id, u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_VerifyRegisters( id, reg, bufp, size );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2C_VerifyRegistersSC
|
||||
|
||||
Description: get and verify value from decive register through I2C.
|
||||
this version sends second byte with stop condition
|
||||
|
||||
Arguments: reg : decive register
|
||||
|
||||
Returns: value which is read from specified decive register
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL I2Ci_VerifyRegistersSC( I2CSlave id, u8 reg, const u8 *bufp, size_t size );
|
||||
static inline BOOL I2C_VerifyRegistersSC( I2CSlave id, u8 reg, const u8 *bufp, size_t size )
|
||||
{
|
||||
BOOL result;
|
||||
(void)I2C_Lock();
|
||||
result = I2Ci_VerifyRegistersSC( id, reg, bufp, size );
|
||||
(void)I2C_Unlock();
|
||||
return result;
|
||||
}
|
||||
#if 0
|
||||
//================================================================================
|
||||
// INTERRUPT
|
||||
//================================================================================
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_EnableInterrupt
|
||||
|
||||
Description: enable I2C interrupt for each device.
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void I2Ci_EnableInterrupt( void );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: I2Ci_DisableInterrupt
|
||||
|
||||
Description: disable I2C interrupt for each device.
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void I2Ci_DisableInterrupt( void );
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* TWL_I2C_I2C_H_ */
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user