📄 l3.c
字号:
L3_Edata0[2] |= L3ed2_MM(micsource); /* set microphone channel */
L3_sendExtendedData0(L3edata2_CMD, L3_Edata0[2] ); /* send known config */
return 1;
}
/*******************************************************************************
* Function: UDA1341_mute
*
*******************************************************************************/
void UDA1341_mute(DWORD flag)
{
L3_setMode(L3DATA0_MODE);
if (flag == 0)
L3_data0[2] &= ~(L3d2_MT(1)); /*not mute */
else
L3_data0[2] |= (L3d2_MT(1)); /* mute */
L3_sendData0(L3data2_CMD, L3_data0[2] );
};
/*******************************************************************************
* Function: UDA1341_mute
*
*******************************************************************************/
void UDA1341_volume_down_one(void)
{
L3_data0[0] += 1;
if (L3_data0[0] > 0x3F) L3_data0[0] = 0x3F ;
L3_setMode(L3DATA0_MODE);
L3_sendData0(L3data0_CMD, L3_data0[0] ); /* send volume = 8*/
};
/*******************************************************************************
* Function: UDA1341_mute
*
*******************************************************************************/
void UDA1341_volume_up_one(void)
{
L3_data0[0] -= 1;
if (L3_data0[0] > 0x3F) L3_data0[0] = 0 ;
L3_setMode(L3DATA0_MODE);
L3_sendData0(L3data0_CMD, L3_data0[0] ); /* send volume = 8*/
};
/*******************************************************************************
* Function: L3_setMode
*
*******************************************************************************/
void L3_setMode(DWORD mode)
{
mode &= 0x3; /* mask off unused bits */
switch(mode)
{
case 0x0: /* DATA 0 */
L3AddressData = L3DATA0_MODE;
txL3Address();
break;
case 0X1: /* DATA 1 */
L3AddressData = L3DATA1_MODE;
txL3Address();
break;
case 0x2: /* Status */
L3AddressData = L3STATUS_MODE;
txL3Address();
break;
case 0x3: /* Not Used do nothing */
break;
}
}
/*******************************************************************************
* Function: txL3Address Address must be sent first (subroutine of L3_setMode)
*
*******************************************************************************/
void txL3Address(void)
{
// while (L3Cmd != 0x0);
WAIT(L3Cmd); /* Make sure Last interrupt driven L3 Command is complete */
L3Cmd = 0x1;
// while (L3Cmd != 0x0);
WAIT(L3Cmd); /* Make sure Last interrupt driven L3 Command is complete */
}
/*******************************************************************************
* Function: L3_sendStatus
*
*******************************************************************************/
void L3_sendStatus(unsigned int status)
{
status &= 0xff; /* mask data value to 8-bits */
L3DataValue = status;
L3_txData();
}
/*******************************************************************************
* Function: L3_sendStatusData send Status command
*
*******************************************************************************/
void L3_sendStatusData(DWORD command,DWORD value)
{
command &= (0x1 << 7); /* mask off unused bits */
value &= 0x7f; /* mask data value to 7-bits */
switch(command>>7)
{
case 0x0: /* DATA 0 */
L3DataValue = value;
break;
case 0x1: /* DATA 1 */
L3DataValue = 0x80 | value;
break;
}
L3_txData();
}
/*******************************************************************************
* Function: L3_sendData0 send Data0 command
*
*******************************************************************************/
void L3_sendData0(DWORD command,DWORD value)
{
command &= (0x3 << 6); /* mask off unused bits */
value &= 0x3F; /* mask data value to 6-bits */
switch(command >> 6)
{
case 0x0: /* Volume Control 0 */
L3DataValue = value;
break;
case 0x1: /* Bass Boost & Treble 1 */
L3DataValue = 0x40 | value;
break;
case 0x2: /* peak detection; de-emphasis; mute; mode switch 2 */
L3DataValue = 0x80 | value;
break;
case 0x3: /* extended address value; address(bit5=0) or data(bit5=1)*/
value &= 0x07;
L3DataValue = 0xC0 | value;
break;
}
L3_txData();
}
/*******************************************************************************
* Function: L3_sendExtendedData0 semd Extemded Data 0
*
*******************************************************************************/
void L3_sendExtendedData0(DWORD command,DWORD value)
{
command &= 0x7; /* limit extended commands to 3-bits */
value &= 0x1F; /* limit extended data value to 5-bits */
L3DataValue = 0xC0 | command;
L3_txData();
L3DataValue = 0xE0 | value;
L3_txData();
}
/*******************************************************************************
* Function: L3_txData set flag that starts interrupt based bit bash command to L3 interface
*
*******************************************************************************/
void L3_txData(void)
{
// while (L3Cmd != 0x0);
WAIT(L3Cmd); /* Make sure Last interrupt driven L3 Command is complete */
L3Cmd = 0x2;
// while (L3Cmd != 0x0);
WAIT(L3Cmd); /* Make sure Last interrupt driven L3 Command is complete */
}
/*******************************************************************************
* Function: L3_readData1 Read data1 register in UDA1341
*
*******************************************************************************/
DWORD L3_readData1(void)
{
L3_setMode(L3DATA1_MODE);
// while (L3Cmd != 0x0);
WAIT(L3Cmd); /* Make sure Last interrupt driven L3 Command is complete */
L3Cmd = 0x3;
// while (L3Cmd != 0x0);
WAIT(L3Cmd); /* Make sure Last interrupt driven L3 Command is complete */
return L3Data1ReadValue;
}
/******************************************************************************
** Function name: IRQ_L3_Handler
**
** Descriptions: Timer/Counter 0 interrupt handler for L3 bitBash interface
** executes on rising edge of capture input
for this demo rate is set at 44100 interrupts per second
for the construction of the audio stream to the I2s interface
this limits the command rate to the L3 interface to
about (44100/40bits address ~19 clks data ~19 clks) ~= 1000commands/sec
(in other words each L3 command may stop audio for 1/1000 of second)
faster L3 clock will shorted down time. This is not that
important for this demo.
**
** parameters: None
** Returned value: None
**
******************************************************************************/
void IRQ_L3_Handler (void) __irq
{
int temp;
static DWORD bitLoc = 0x0;
static DWORD L3Clk;
static DWORD L3Mode;
static DWORD L3Data;
DWORD oldFIO0mask;
volatile DWORD bitBash;
static DWORD toggle=0;
T0IR = 1; /* clear interrupt flag Timer 0 */
/**************************
* L3 Command Service
*************************/
oldFIO0mask = FIO0MASK;
FIO0MASK = ~(P15_OUT | P17_OUT ); /* Set fgpio mask register */
L3Cmd &= 0x03; /* clear high bits */
switch(L3Cmd)
{
case 0x0: /* No Pending Command Do Nothing */
break;
case 0x1: /* Send Address and Mode. */
if (bitLoc == 0)
{
L3AddressData &= 0xFF; /* mask to safe 8-bits */
L3Clk = 0xEAAAB;
L3Data = 0x00000 | (L3AddressData << 1);
}
if (bitLoc == 1)
{
FIO0MASK = ~( P16_OUT ); /* Set fgpio mask register */
FIO0PIN = ( 0x0 );
FIO0MASK = ~( P15_OUT | P17_OUT ); /* Set fgpio mask register */
}
bitBash = (L3Clk & 0x01) << 15;
bitBash |= (L3Data &0x01) << 17;
FIO0PIN = bitBash;
if ((bitLoc & 0x1)) /* on odd value change data bit */
{
L3Data = L3Data >> 0x01;
}
L3Clk = L3Clk >> 0x01;
bitLoc++;
if (bitLoc == 18)
{
bitLoc =0;
L3Cmd = 0; /* command complete */
}
break;
case 0x2: /* Send Data */
if (bitLoc == 0)
{
FIO0MASK = ~( P16_OUT ); /* Set fgpio mask register */
FIO0PIN = ( 0 );
FIO0MASK = ~( P15_OUT | P17_OUT ); /* Set fgpio mask register */
L3DataValue &= 0xFF; /* mask to safe 8-bits */
L3Clk = 0x2AAAB;
L3Data = 0x00000 | (L3DataValue << 1);
}
if (bitLoc == 1)
{
FIO0MASK = ~( P16_OUT ); /* Set fgpio mask register */
FIO0PIN = ( P16_OUT );
FIO0MASK = ~( P15_OUT | P17_OUT ); /* Set fgpio mask register */
}
bitBash = (L3Clk & 0x01) << 15;
bitBash |= (L3Data &0x01) << 17;
FIO0PIN = bitBash; /* send to L3 interface */
if ((bitLoc & 0x1)) /* on even value change data bit */
{
L3Data = L3Data >> 0x01;
}
L3Clk = L3Clk >> 0x01;
bitLoc++;
if (bitLoc == 18)
{
bitLoc =0;
L3Cmd = 0; /* command complete */
}
break;
case 0x3: /* Read Data */
FIO0MASK = ~(P15_OUT ); /* Set fgpio mask register */
if (bitLoc == 0)
{
FIO0MASK = ~( P16_OUT ); /* Set fgpio mask register */
FIO0PIN = ( 0 );
FIO0MASK = ~( P15_OUT ); /* Set fgpio mask register */
L3DataValue &= 0xFF; /* mask to safe 8-bits */
L3Clk = 0x2AAAB;
L3Data1ReadValue = 0x0;
}
if (bitLoc == 1)
{
FIO0MASK = ~( P16_OUT ); /* Set fgpio mask register */
FIO0PIN = ( P16_OUT );
FIO0MASK = ~( P15_OUT ); /* Set fgpio mask register */
}
bitBash = (L3Clk & 0x01) << 15;
FIO0PIN = bitBash; /* send to L3 interface */
if ((bitLoc & 0x1)) /* on odd bit read data bit */
{
if ((bitLoc>3)&&(bitLoc <15)) /* bits 6:1 read bit value */
{
FIO1DIR &= ~(P18_OUT ); /* change pin to input for read */
FIO0MASK = ~(P18_OUT ); /* Set fgpio mask tor read GPIO register */
temp = FIO0PIN;
temp = temp >> 18;
L3Data1ReadValue |= (temp << (bitLoc >> 0x1)); /* adjust bit (bitLoc/2 - 2) */
FIO1DIR |= (P18_OUT );/* change pin to output for future writes */
}
}
L3Clk = L3Clk >> 0x01;
L3Mode = L3Mode >> 0x01;
bitLoc++;
if (bitLoc == 18)
{
bitLoc =0;
L3Data1ReadValue = (L3Data1ReadValue >> 1)& 0x3F; /* adjust for 6-bit data */
L3Cmd = 0; /* command complete */
}
break;
default:
break;
}
FIO0MASK = oldFIO0mask;
/**************************
* DDS Service
*************************/
toggle++;
if ((toggle & 0x01) == 0 )
{
nextTone(); /* next value */ /* interrupt occurs 88200/sec write to I2S every other time */
}
VICVectAddr = 0; /* Acknowledge Interrupt */
}
/********************************************************
* End of File
********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -