Example #1
0
File: main.c Project: gstroe/Arm
/**
 * Adjust codec for sync
 * \param adjust Sync case: default(0)/faster(>0)/slower(<0)
 */
static void _SyncAdjust(int32_t adjust)
{
	if (adjust > 0) {
		/* Fractional multiply for FLL_K, Fref = 0x8000 (1/2) */
		WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, WM8904_REG_FLL_CRTL3, 0xFF00);
		/* FLL_GAIN=0, FLL_N=187 */
		return;
	}

	if (adjust < 0) {
		/* Fractional multiply for FLL_K, Fref = 0x8000 (1/2) */
		WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, WM8904_REG_FLL_CRTL3, 0x5000);
		/* FLL_GAIN=0, FLL_N=187 */
		return;
	}

	/* Default: 32K -> 48K*256, FLL: 32768*187.5/16/8
	 */
	/* FLL_FRATIO=4 (/16), FLL_OUTDIV= 7 (/8) */
	/* Fractional multiply for FLL_K, Fref = 0x8000 (1/2) */
	WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, WM8904_REG_FLL_CRTL3,
				 0x8000 + 0x3000);
	/* FLL_GAIN=0, FLL_N=187 */
	return;
}
void WM8904_IN2R_IN1L(Twid *pTwid, uint32_t device)
{
    //{ 0x0005, 44},  /** R44  - Analogue Left Input 0 */
    //{ 0x0005, 45},  /** R45  - Analogue Right Input 0 */
    //{ 0x0000, 46},  /** R46  - Analogue Left Input 1 */
    //{ 0x0010, 47},  /** R47  - Analogue Right Input 1 */
    WM8904_Write(pTwid, device, 0x2C, 0x0008);
    WM8904_Write(pTwid, device, 0x2D, 0x0005);
    WM8904_Write(pTwid, device, 0x2E, 0x0000);
    WM8904_Write(pTwid, device, 0x2F, 0x0010);
}
uint8_t WM8904_Init(Twid *pTwid, uint32_t device,  uint32_t PCK)
{
    uint8_t count, size;
    uint16_t data = 0;

    // Reset (write Reg@0x0 to reset)
    WM8904_Write(pTwid, device, 0, 0xFFFF);

    for(data=0; data<1000; data++);
    //wait ready
    while(data!=0x8904)
        data=WM8904_Read(pTwid, device, 0);

    if (PMC_MCKR_CSS_SLOW_CLK == PCK) {
        size = sizeof(wm8904_access_slow) / 4 + 1;
        for(count=0; count<size; count++) {
            WM8904_Write(pTwid, device, wm8904_access_slow[count].address,
                         wm8904_access_slow[count].value);
            if(((wm8904_access_slow[count].address==0x05)
                    &&(wm8904_access_slow[count].value==0x0047))
                    ||((wm8904_access_slow[count].address==0x74)
                       &&(wm8904_access_slow[count].value==0x0005))
                    ||((wm8904_access_slow[count].address==0x12)
                       &&(wm8904_access_slow[count].value==0x000F))) {
                Wait(5);
            }
            if (((wm8904_access_slow[count].address==0x44)
                    &&(wm8904_access_slow[count].value==0x00F0))
                    ||((wm8904_access_slow[count].address==0x3A)
                       &&(wm8904_access_slow[count].value==0x00B9))) {
                Wait(100);
            }
        }
    }
    else if (PMC_MCKR_CSS_MAIN_CLK == PCK) {
        for(count = 0; count < 255; count++) {
            if(wm8904_access_main[count].address < 255) {
                WM8904_Write(pTwid, device, wm8904_access_main[count].address,
                             wm8904_access_main[count].value);
            } else {
                break;
            }
        }
    } else {
        printf("W: PCK not supported! \n\r");
        while(1);
    }
    return 0;
}
Example #4
0
/**
 * \brief Application entry point for ssc_dam_audio example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main( void )
{    
    uint16_t data = 0;
    /* Disable watchdog */
    WDT_Disable( WDT ) ;
 
    /* Enable I and D cache */
    SCB_EnableICache();
    SCB_EnableDCache();

    /* Output example information */
    printf("-- SSC DMA Audio Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* Configure systick for 1 ms. */
    printf( "Configure system tick to get 1ms tick period.\n\r" ) ;
    if ( TimeTick_Configure( ) )
    {
        printf("-F- Systick configuration error\n\r" ) ;
    }

    /* Configure all pins */
    PIO_Configure(pinsSsc, PIO_LISTSIZE(pinsSsc));

    /* Configure SSC */
    SSC_Configure(AUDIO_IF , 0 , SSC_MCK );
    SSC_ConfigureReceiver(AUDIO_IF,I2S_SLAVE_RX_SETTING,I2S_SLAVE_RX_FRM_SETTING);
    SSC_DisableReceiver(AUDIO_IF);
    SSC_ConfigureTransmitter(AUDIO_IF,I2S_SLAVE_TX_SETTING,I2S_SLAVE_TX_FRM_SETTING);
    SSC_DisableTransmitter(AUDIO_IF);

    /* Configure DMA */
    Dma_configure();

    /* Configure and enable the TWI (required for accessing the DAC) */
    PMC_EnablePeripheral(ID_TWIHS0);
    TWI_ConfigureMaster(TWIHS0, TWI_CLOCK, BOARD_MCK);
    TWID_Initialize(&twid, TWIHS0);
    /* Configure TWI interrupts */
    NVIC_ClearPendingIRQ(TWIHS0_IRQn);
    NVIC_EnableIRQ(TWIHS0_IRQn);

    /* check that WM8904 is present */
    WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, 22, 0);
    data=WM8904_Read(&twid, WM8904_SLAVE_ADDRESS, 0);
    if( data != 0x8904){
        printf("WM8904 not found!\n\r");
        while(1);
    }
    /* Initialize the audio DAC */
    WM8904_Init(&twid, WM8904_SLAVE_ADDRESS, PMC_MCKR_CSS_SLOW_CLK); 

    /* Enable the DAC master clock */
    PMC_ConfigurePCK2(PMC_MCKR_CSS_SLOW_CLK, PMC_MCKR_PRES_CLK_1 );
    printf("Insert Line-in cable with PC Headphone output\n\r");
    PlayRecording();
    while ( 1 );
}
Example #5
0
File: main.c Project: gstroe/Arm
/**
 * Configure the TWI and DACC for audio output.
 * \param sampleRate Audio sample rate.
 * \param mck        MCK frequency.
 */
static void _ConfigureAudioPlay(uint32_t sampleRate, uint32_t mck)
{
	/* -- Pins Configuration -- */
	PIO_Configure(pinsAudio, PIO_LISTSIZE(pinsAudio));

	/* -- SSC Configuration -- */
	sampleRate = sampleRate; /*dummy */
	SSC_Configure(SSC, 0, mck);
	SSC_DisableTransmitter(SSC);
	SSC_DisableReceiver(SSC);
	SSC_ConfigureTransmitter(SSC, I2S_SLAVE_TX_SETTING, I2S_SLAVE_TX_FRM_SETTING);
	SSC_DisableTransmitter(SSC);

	/* Enable TWI peripheral clock */
	PMC_EnablePeripheral(ID_TWIHS0);
	/* Configure and enable the TWI (required for accessing the DAC) */
	TWI_ConfigureMaster(TWIHS0, TWI_CLOCK, mck);
	TWID_Initialize(&twid, TWIHS0);

	/* Initialize the audio DAC
	 */
	WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, WM8904_REG_RESET, 0);
	Wait(100);

	/* WM8904 as master */
	if (WM8904_Read(&twid, WM8904_SLAVE_ADDRESS, 0) != 0x8904) {
		printf("WM8904 not found!\n\r");

		while (1);
	}

	WM8904_Init(&twid, WM8904_SLAVE_ADDRESS, PMC_MCKR_CSS_SLOW_CLK);
	_SyncAdjust(0);
	PMC_ConfigurePCK2(PMC_MCKR_CSS_SLOW_CLK, PMC_MCKR_PRES_CLK_1);
	/* Mute */
	AudioPlayEnable(0);
}