⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 l3.c

📁 i2s usb audio demo lpc2138
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
 *   L3.c:  L3 interface module file for Philips LPC23xx/24xx Family Microprocessors
 *
 *   Copyright(C) 2006, Philips Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.09.20  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include <stdio.h>
#include "LPC23xx.h"                        /* LPC23xx/24xx definitions */
#include "type.h"
#include "irq.h"

#include "../fio/inc/fio.h"

#include "./inc/L3.h"

#define WAIT(x) while(x != 0x0)

extern void nextTone(void);
extern void nextTone1(void);

volatile DWORD L3_status0, L3_status1;
volatile DWORD L3_data0[5], L3_Edata0[7] , L3_data1_0;

/*  GLOBAL DATA  */
volatile DWORD L3AddressData = L3DATA0_MODE; 
volatile DWORD L3DataValue = 0; 
volatile DWORD L3Data1ReadValue = 0; 
volatile DWORD L3Cmd = 0; 	 /* 0 = device free; 1 = Send Address; 2 Send Data */

/* public functions in this file */
void L3_init_GPIO(void);
void L3_setMode(DWORD mode);
void L3_sendStatusData(DWORD command,DWORD value);
void L3_sendData0(DWORD command,DWORD value);
void L3_sendExtendedData0(DWORD command,DWORD value);
void L3_sendStatus(unsigned int status);
void L3_sendData(DWORD status);

void UDA1341_start_audio_in(void);
void UDA1341_stop_audio_in(void);
void UDA1341_start_audio_out (void);
void UDA1341_stop_audio_out (void);
int  UDA1341_is_dac_on(void);
int  UDA1341_is_adc_on(void);
void UDA1341_volume_up_one(void);
void UDA1341_volume_down_one(void);

DWORD L3_readData1(void);

/* private functions in this file */

void txL3Address(void);
void L3_txData(void);

/*******************************************************************************
* 
     Function: UDA1341_display    prints audio chip config data to output defined
    							  in retarget.c
        		 		  
*******************************************************************************/
void UDA1341_display(void)
 {
   DWORD temp;
/* Status 0 */
   printf("Stat0 ... ");
   temp =(L3_status0 & L3s0_DC(1))>>0;
   printf("DC filter = %d; ", temp );
   temp =(L3_status0 & L3s0_IF(7))>>1;
   printf("Serial Format = %d; ", temp );
   temp =(L3_status0 & L3s0_SCLK(3))>>4;
   printf("Sys Clk = %d; ", temp );
   temp =(L3_status0 & L3s0_RST(1))>>6;
   printf("Reset = %d; ", temp );
   printf("\n\r");

/* Status 1 */
   printf("Stat1 ... ");
   temp =(L3_status1 & L3s1_PC(3))>>0;
   printf("Pwr Cntl = %d; ", temp );
   temp =(L3_status1 & L3s1_DS(1))>>2;
   printf("2x Speed = %d; ", temp );
   temp =(L3_status1 & L3s1_PDA(1))>>3;
   printf("polarity of DAC = %d; ", temp );
   temp =(L3_status1 & L3s1_PAD(1))>>4;
   printf("polarity of ADC  = %d; ", temp );
   temp =(L3_status1 & L3s1_IGS(1))>>5;
   printf("Input Gain = %d; ", temp);
   temp =(L3_status1 & L3s1_OGS(1))>>6;
   printf("Output Gain = %d; ", temp);
   printf( "\n\n\r");

   printf("Data0\r\n");
/* Data 0 register 0 */
   printf(" reg 0 ... ");
   temp =(L3_data0[0] & L3d0_VC(0x3F))>>0;
   printf("Volume Level = %d; ", temp );
   printf("\n\r");

/* Data 0 register 1 */
   printf(" reg 1 ... ");
   temp =(L3_data0[1] & L3d1_TR(3))>>0;
   printf("Treble Level = %d; ", temp );
   temp =(L3_data0[1] & L3d1_BB(0xF))>>2;
   printf("Bass Boost Level = %d; ", temp );
   printf("\n\r");

/* Data 0 register 2 */
   printf(" reg 2 ... ");
   temp =(L3_data0[2] & L3d2_M(3))>>0;
   printf("Filter Mode = %d; ", temp );
   temp =(L3_data0[2] & L3d2_MT(1))>>2;
   printf("Mute = %d; ", temp );
   temp =(L3_data0[2] & L3d2_DE(3))>>3;
   printf("De-emphasis = %d; ", temp );
   temp =(L3_data0[2] & L3d2_PP(1))>>5;
   printf("Peak Detect Positon = %d; ", temp );
   printf("\n\n\r");

   printf("L3 Extended Data0\r\n");
/* Extended Data 0 register 0 */
   printf(" register 0   ... ");
   temp =(L3_Edata0[0] & L3ed0_MA(0x1F))>>0;
   printf("Ch1 Mixer Gain = %d; ", temp );
   printf("\n\r");

/* Extended Data 0 register 1 */
   printf(" register 1   ... ");
   temp =(L3_Edata0[1] & L3ed1_MB(0x1F))>>0;
   printf("Ch2 Mixer Gain = %d; ", temp );
   printf("\n\r");

/* Extended Data 0 register 2 */
   printf(" register 2   ... ");
   temp =(L3_Edata0[2] & L3ed2_MM(3))>>0;
   printf("Mic Mixer Mode = %d; ", temp );
   temp =(L3_Edata0[2] & L3ed2_MS(7))>>2;
   printf("Mic Sensitivity = %d; ", temp );
   printf("\n\r");

/* Extended Data 0 register 4 & 5 */
   printf(" register 4&5 ... ");
   temp =(L3_Edata0[4] & L3ed4_AG(0x1F))>>4;
   printf("AGC Control = %d; ", temp );

   temp =((L3_Edata0[5] & L3ed5_IG(0x1F))<<2);
   temp |=(L3_Edata0[4] & L3ed4_IG(3))>>0;
   printf("CH2 input amp gain = %d; ", temp );
   printf("\n\r");

/* Extended Data 0 register 6 */
   printf(" register 6   ... ");
   temp =(L3_Edata0[6] & L3ed6_AL(3))>>0;
   printf("AGC Output Level = %d; ", temp );
   temp =(L3_Edata0[6] & L3ed6_AT(7))>>2;
   printf("AGC Time Constant = %d; ", temp );
   printf("\n\r");

 }

/*******************************************************************************
* 
     Function: L3_init_GPIO    Init I/O pins used between the LPC2378 and UDA1341
    							  to control the L3 interface
        		 		  
*******************************************************************************/

void L3_init_GPIO(void)
{
    DWORD oldFIO1MASK;
	 /* pins 15,16,17 output; pin 18 input TX & Rx enable*/
	DWORD L3fioSelect = ~(P15_OUT|P16_OUT|P17_OUT|P18_OUT);
	DWORD L3fioPinDir =  (P15_OUT|P16_OUT|P17_OUT |P18_IN);	/*direction out */
	DWORD L3QMuteDir = (P20_OUT);	/* physical mute pin on 1341 */
	DWORD L3QMuteSelect = ~(P20_OUT);

      /* setup GPIO for L3 interface on 1341 */
    GPIOInit(0, FAST_PORT, L3fioPinDir, L3fioSelect);
 
      /* setup GPIO for quickmute on 1341 */
    GPIOInit(1, FAST_PORT, L3QMuteDir, L3QMuteSelect);

	oldFIO1MASK = FIO1MASK;
	FIO1MASK = ~(P20_OUT);
	FIO1PIN = 0;			/* 1341  mute off */
    FIO1MASK = oldFIO1MASK;

};

/*******************************************************************************
* 
     Function: UDA1341_reset    Reset the UDA1341 using the L3 interface
        		 		  
*******************************************************************************/

void UDA1341_reset(void)
 {
 	L3_setMode(L3STATUS_MODE);
    L3_status0 |= L3s0_RST(1);	   /* send reset */
    L3_sendStatusData(L3status0_CMD, L3_status0 ); 
    L3_status0 &= ~(L3s0_RST(1));	  /* send reset clear */
    L3_sendStatusData(L3status0_CMD, L3_status0 );   
    L3_sendStatusData(L3status0_CMD, 0x20 );   

 }


/*******************************************************************************
* 
     Function: UDA1341_init    Init the UDA1341 using the L3 interface from values
	 						stored in RAM
	     					       		 		  
*******************************************************************************/

void UDA1341_init(void)
 {

/* 1341 is a write mostly device so create a config table here */
/* Set Defaults */
    L3_status0 =  L3s0_RST(0x00) | L3s0_SCLK(0x00) | L3s0_IF(0x00) |(L3s0_DC(0x01) ); /* 22Mhz */
//    L3_status0 =  L3s0_RST(0x00) | L3s0_SCLK(0x02) | L3s0_IF(0x00) |(L3s0_DC(0x01) ); /* 11Mhz */
    L3_status1 =  L3s1_OGS(0x00) | L3s1_IGS(0x00) | L3s1_PAD(0x00) | L3s1_PDA(0x00) | L3s1_DS(0x00) | (L3s1_PC(0x03));
    L3_data0[0] =  L3d0_VC(0x06);
    L3_data0[1] =  L3d1_BB(0x00) | (L3d1_TR(0x00) );
    L3_data0[2] =  L3d2_PP(0x01) | L3d2_DE(0x02) | L3d2_MT(0x00) | (L3d2_M(0x00));
    L3_data0[3] =  L3d3_EA(0x00);
    L3_data0[4] =  L3d4_ED(0x00);
    L3_Edata0[0] = L3ed0_MA(0x00);
    L3_Edata0[1] = L3ed1_MB(0x00);
    L3_Edata0[2] = L3ed2_MS(0x00) | L3ed2_MM(0x03);
    L3_Edata0[4] = L3ed4_AG(0x01) | L3ed4_IG(0x02);
    L3_Edata0[5] = L3ed5_IG(0x00);
    L3_Edata0[6] = L3ed6_AT(0x00) | L3ed6_AL(0x03);		  

/* reset UDA1341, set format to a known state as defined above */

	L3_setMode(L3STATUS_MODE);
    L3_status0 |= L3s0_RST(1);	   /* send reset */
    L3_sendStatusData(L3status0_CMD, L3_status0); 
    L3_status0 &= ~(L3s0_RST(1));	  /* send reset clear */
    L3_sendStatusData(L3status0_CMD, L3_status0 );   

    L3_sendStatusData(L3status0_CMD, L3_status0);   /* send known config */
    L3_sendStatusData(L3status1_CMD, L3_status1); 

	L3_setMode(L3DATA0_MODE);
    L3_sendData0(L3data0_CMD, L3_data0[0] ); 	 /* send known config */
    L3_sendData0(L3data1_CMD, L3_data0[1] ); 	 /* send known config */
    L3_sendData0(L3data2_CMD, L3_data0[2] ); 	 /* send known config */

    L3_sendExtendedData0(L3edata0_CMD, L3_Edata0[0] ); 	 /* send known config */
	L3_sendExtendedData0(L3edata1_CMD, L3_Edata0[1] ); 	 /* send known config */
    L3_sendExtendedData0(L3edata2_CMD, L3_Edata0[2] ); 	 /* send known config */
    L3_sendExtendedData0(L3edata4_CMD, L3_Edata0[4] ); 	 /* send known config */
    L3_sendExtendedData0(L3edata5_CMD, L3_Edata0[5] ); 	 /* send known config */
    L3_sendExtendedData0(L3edata6_CMD, L3_Edata0[6] ); 	 /* send known config */
 };

/*******************************************************************************
* Function: UDA1341_start_audio_in
*
*******************************************************************************/
void UDA1341_start_audio_in(void)
{ 
	L3_setMode(L3STATUS_MODE);
    L3_status1 |= L3s1_PC(2); /* power on 1431 ADC */ 
    L3_sendStatusData(L3status1_CMD, L3_status1 );  
}

/*******************************************************************************
* Function: UDA1341_stop_audio_in
*
*******************************************************************************/
void UDA1341_stop_audio_in(void)
{ 
	L3_setMode(L3STATUS_MODE);
    L3_status1 &= ~(L3s1_PC(2)); /* power off 1431 ADC */ 
    L3_sendStatusData(L3status1_CMD, L3_status1 ); 
}

/*******************************************************************************
* Function: UDA1341_start_audio_out
*
*******************************************************************************/
void UDA1341_start_audio_out (void)
{ 
	L3_setMode(L3DATA0_MODE);
    L3_data0[2] &= ~(L3d2_MT(1)); /* Mute off 1431 */ 
    L3_sendData0(L3data2_CMD, L3_data0[2] ); 

	L3_setMode(L3STATUS_MODE);
    L3_status1 |= L3s1_PC(1); /* power on 1431 DAC */ 
    L3_sendStatusData(L3status1_CMD, L3_status1 ); 
}

/*******************************************************************************
* Function: UDA1341_stop_audio_out
*
*******************************************************************************/
void UDA1341_stop_audio_out (void)
{ 
// mute d02 dac/adc off status1PC=0

	L3_setMode(L3DATA0_MODE);
    L3_data0[2] |= L3d2_MT(1); /* Mute 1431 */ 
    L3_sendData0(L3data2_CMD, L3_data0[2] ); 

	L3_setMode(L3STATUS_MODE);
    L3_status1 &= ~(L3s1_PC(1)); /* power off 1431 DAC */ 
    L3_sendStatusData(L3status1_CMD, L3_status1 );               
}

/*******************************************************************************
* Function: UDA1341_is_dac_on
*
*******************************************************************************/
int UDA1341_is_dac_on(void)
{  
    return ((L3_status1 & L3s1_PC(1)==0)?0:1);
}

/*******************************************************************************
* Function: UDA1341_is_adc_on
*
*******************************************************************************/
int UDA1341_is_adc_on(void)
{  
    return ((L3_status1 & L3s1_PC(2)==0)?0:1);
}

/*******************************************************************************
* Function: UDA1341_stop
*
*******************************************************************************/
void UDA1341_stop(void)
{
  /*stop all playing back and recording activities*/
  if(UDA1341_is_dac_on())
  {
    UDA1341_stop_audio_out();
  }														
  else if(UDA1341_is_adc_on())
  {
    UDA1341_stop_audio_in();
  }
}

/*******************************************************************************
* Function: change_mic_source
*
*******************************************************************************/
int UDA1341_change_mic_source(void)
{
  static unsigned int micsource = 2;
  micsource++;
  if (micsource > 3) micsource = 1;
        L3_setMode(L3DATA0_MODE); /* change to data0 mode */
        L3_Edata0[2] &= ~L3ed2_MM(3); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -