📄 i2saudio.cpp
字号:
*GPIO_PGDR = uiVal;
//
// Delay to meet the EE Interface timing specification.
//
DelayuS( EE_DELAY_USEC );
}
//
// Reconfigure the EE data line as an output.
//
uiDDR |= GPIOG_EEDAT;
*GPIO_PGDDR = uiDDR;
//
// Delay to meet the EE Interface timing specification.
//
DelayuS( EE_DELAY_USEC );
//
// Drive the EE data line low.
//
uiVal &= ~GPIOG_EEDAT;
*GPIO_PGDR = uiVal;
//
// Delay to meet the EE Interface timing specification.
//
DelayuS( EE_DELAY_USEC );
//
// Drive the EE clock line high.
//
uiVal |= GPIOG_EECLK;
*GPIO_PGDR = uiVal;
//
// Delay to meet the EE Interface timing specification.
//
DelayuS( EE_DELAY_USEC );
//
// Drive the EE data line high.
//
uiVal |= GPIOG_EEDAT;
*GPIO_PGDR = uiVal;
//
// Delay to meet the EE Interface timing specification.
//
DelayuS( EE_DELAY_USEC );
//
// Return the byte that we read.
//
*pucRegValue = ucData;
FUNC_I2S
(
(
L"ReadCodecReg: Reg = 0x%02x, Value = 0x%02x\n",
(ULONG)ucRegAddr,
(ULONG)ucData
)
);
return (MMSYSERR_NOERROR);
}
static volatile ULONG ulJunk;
//****************************************************************************
// I2SCodec::ProducePIOTone
//****************************************************************************
// For Debug only.
//
// Uses I2S to produce a PIO tone.
//
//
void I2SCodec::ProducePIOTone(void)
{
ULONG ulCount;
ULONG ulCount2;
volatile ULONG ulTemp;
//volatile ULONG ulCSR;
ULONG ulMax= 0x0007Fffff, ulMin=0x00800000;
//
// Enable the I2S transmitt channel 0.
//
*SAI_TX0_EN = 1;
Sleep(1);
ulCount2 = 0;
ulTemp = 0x800000;
for(ulCount = 0; ;ulCount ++)
{
if(ulCount& 0x40)
{
ulTemp = ulMax;
}
else
{
ulTemp = ulMin;
}
ulJunk = *SAI_TX0_LEFT;
ulJunk = *SAI_TX0_RIGHT;
while(!( *SAI_GSR & GSR_TX0_FIFO_HALF_EMPTY))
{
if(ulCount2++>10000000)
{
*SAI_GSR = 0;
Initialize();
*SAI_TX0_EN = 1;
Sleep(1);
break;
}
};
*SAI_TX0_LEFT = ulTemp;
*SAI_TX0_RIGHT = ulTemp;
}
}
//****************************************************************************
// I2SCodec::ReadAllCodecReg
//****************************************************************************
// For Debug only.
//
// Reads all of the I2C registers.
void I2SCodec::ReadAllCodecReg(void)
{
UCHAR ucCodecReg, ucValue;
for(ucCodecReg = 1; ucCodecReg < 0xE; ucCodecReg++)
{
ReadCodecReg(ucCodecReg, &ucValue);
}
}
//****************************************************************************
// DelayuS
//****************************************************************************
// Delays a certian number of microseconds.
//
//
void DelayuS(ULONG ulMicroSec)
{
LARGE_INTEGER liStart, liCurrent;
BOOL b;
b = QueryPerformanceCounter(&liStart);
ASSERT(b);
do
{
Sleep(0);
b = QueryPerformanceCounter(&liCurrent);
ASSERT(b);
} while((liStart.QuadPart + (LONGLONG)ulMicroSec) >=liCurrent.QuadPart);
}
//****************************************************************************
// I2SCodec::WriteCodecSPI
//****************************************************************************
// Writes a codec register using SPI.
//
//
MMRESULT I2SCodec::WriteCodecRegSPI(UCHAR ucRegAddr, UCHAR ucRegValue)
{
ULONG ulSPIStatus;
ULONG ulTimeOut;
// ulADR = *GPIO_PADR;
// *GPIO_PADR = ulADR | 0x80;
//
// Wait for the the fifo to be empty.
//
for(ulTimeOut = 0;;ulTimeOut++)
{
ulSPIStatus = *SPI_SR;
if(ulSPIStatus & SPISR_TFE)
break;
Sleep(2);
if(ulTimeOut >50)
{
ERRMSG
((
L"I2SCodec::WriteCodecSSP Write timeout on register 0x%02x\r\n",
(ULONG)ucRegAddr
));
}
}
//
// Write out the chip address for the CS4228.
//
*SPI_DR = 0x20;
*SPI_DR = (ULONG)ucRegAddr;
*SPI_DR = (ULONG)ucRegValue;
//
// Wait for the the fifo to be empty.
//
for(ulTimeOut = 0;;ulTimeOut++)
{
ulSPIStatus = *SPI_SR;
Sleep(2);
if(ulSPIStatus & SPISR_TFE)
break;
if(ulTimeOut >50)
{
ERRMSG
((
L"I2SCodec::WriteCodecSSP Write timeout on register 0x%02x\r\n",
(ULONG)ucRegAddr
));
}
}
// *GPIO_PADR = ulADR & ~0x80;
//Sleep(0);
return (MMSYSERR_NOERROR);
}
//****************************************************************************
// SetSPIToI2S
//****************************************************************************
// This is currently a hack to get audio working on the Videon Central
// board. I need to fix this later.
//
//
void SetSPIToI2S(unsigned long ulCodec)
{
ULONG ulTemp;
//
// Set GPIO pins 12 and 14 as outputs. They are used in the ps2 keyboard
// interface.
//
ulTemp = *GPIO_PBDDR;
*GPIO_PBDDR = 0x50 | ulTemp;
//
// Clear GPIO pins 12 and 14.
//
ulTemp = *GPIO_PBDR;
*GPIO_PBDR = 0x50 | ulTemp ;
if(ulCodec == 4228)
{
//
// Configure EGPIO7 as an output and set it. This selects
// I2S codec as the device on the SSP output instead of
// the serial flash (on an EP9312).
//
HalWriteCommonReg
(
GPIO_PADDR,
0x80,
0x80
);
HalWriteCommonReg
(
GPIO_PADR,
0x80,
0x80
);
//
// Configure EGPIO8 as an output and set it. This selects
// I2S codec as the device on the SSP output (on an EP9315 & EP9307).
//
HalWriteCommonReg
(
GPIO_PBDDR,
0x1,
0x1
);
HalWriteCommonReg
(
GPIO_PBDR,
0x1,
0x0
);
}
if(ulCodec == 4271)
{
//
// Configure EGPIO6 as an output and set it. This selects
// I2S codec as the device on the SSP (on an EP9301).
//
HalWriteCommonReg
(
GPIO_PADDR,
0x40,
0x40
);
HalWriteCommonReg
(
GPIO_PADR,
0x40,
0x40
);
}
//
// Sleep a couple Milliseconds. Hopefully the keyboard will get
// any characters in the fifo.
//
Sleep(2);
//
// SPICR0_SPO - SCLKOUT Polarity
// SPICR0_SPH - SCLKOUT Phase
// Motorola format, 10 bit, one start, 8 data, one bit for parity,
// one stop bit.
//
*SPI_CR0 = SPICR0_SPO| SPICR0_SPH |SPICR0_FRF_MOTOROLA |
(SPICR0_DSS_MASK & (8 -1));
//
// Configure the device as a slave, enable interrupts and
// reset the device.
//
*SPI_CR1 = 0;
*SPI_CR1 = SPICR1_SSE;
}
//****************************************************************************
// SetSPIToPS2
//****************************************************************************
// This is currently a hack to get audio working on the Videon Central
// board. I need to fix this later.
//
//
void SetSPIToPS2(unsigned long ulCodec)
{
ULONG ulTemp;
//
// Clear GPIO pins 12 and 14.
//
ulTemp = *GPIO_PBDR;
*GPIO_PBDR = (~0x50) & ulTemp ;
if(ulCodec == 4228)
{
//
// Clear EGPIO7. This de-selects
// I2S codec as the device on the SSP output (on an EP9312).
//
HalWriteCommonReg
(
GPIO_PADDR,
0x80,
0x00
);
HalWriteCommonReg
(
GPIO_PADR,
0x80,
0x00
);
//
// Set EGPIO8. This de-selects I2S codec as the device on the SSP
// output (on an EP9315 & EP9307).
//
HalWriteCommonReg
(
GPIO_PBDDR,
0x1,
0x1
);
HalWriteCommonReg
(
GPIO_PBDR,
0x1,
0x1
);
}
if(ulCodec == 4271)
{
//
// Clear EGPIO6. This de-selects I2S codec as the device on the SSP
// output (on an EP9301).
//
HalWriteCommonReg
(
GPIO_PADDR,
0x40,
0x00
);
HalWriteCommonReg
(
GPIO_PADR,
0x40,
0x00
);
}
//
// SPICR0_SPO - SCLKOUT Polarity
// SPICR0_SPH - SCLKOUT Phase
// Motorola format, 10 bit, one start, 8 data, one bit for parity,
// one stop bit.
//
*SPI_CR0 = SPICR0_SPO| SPICR0_SPH |SPICR0_FRF_MOTOROLA |
(SPICR0_DSS_MASK & (11 -1));
//
// Configure the device as a slave, enable interrupts and
// reset the device.
//
*SPI_CR1 = SPICR1_MS | SPICR1_RIE;
*SPI_CR1 = SPICR1_MS | SPICR1_RIE | SPICR1_SSE;
}
void I2SReset( void )
{
HalWriteCommonReg
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -