/** * \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 ); }
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; }
/** * 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); }