- Main Page
- Related Pages
- Files

# ssc_i2s_example.c

Go to the documentation of this file.

    00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
    00080 #include <avr32/io.h>
    00081 #include "board.h"
    00082 #include "pm_at32ap7000.h"
    00083 #include "gpio.h"
    00084 #include "ssc_i2s.h"
    00085
    00086
    00090 int main(void)
    00091 {
    00092 #if BOARD == STK1000
    00093   #define EXAMPLE_SSC (&AVR32_SSC0)
    00094   #define EXAMPLE_SSC_TX_CLOCK_PIN            AVR32_SSC0_TX_CLOCK_0_PIN
    00095   #define EXAMPLE_SSC_TX_CLOCK_FUNCTION       AVR32_SSC0_TX_CLOCK_0_FUNCTION
    00096   #define EXAMPLE_SSC_TX_DATA_PIN             AVR32_SSC0_TX_DATA_0_PIN
    00097   #define EXAMPLE_SSC_TX_DATA_FUNCTION        AVR32_SSC0_TX_DATA_0_FUNCTION
    00098   #define EXAMPLE_SSC_TX_FRAME_SYNC_PIN       AVR32_SSC0_TX_FRAME_SYNC_0_PIN
    00099   #define EXAMPLE_SSC_TX_FRAME_SYNC_FUNCTION  AVR32_SSC0_TX_FRAME_SYNC_0_FUNCTION
    00100 #elif BOARD == NGW100
    00101   #define EXAMPLE_SSC (&AVR32_SSC0)
    00102   #define EXAMPLE_SSC_TX_CLOCK_PIN            AVR32_SSC0_TX_CLOCK_0_PIN
    00103   #define EXAMPLE_SSC_TX_CLOCK_FUNCTION       AVR32_SSC0_TX_CLOCK_0_FUNCTION
    00104   #define EXAMPLE_SSC_TX_DATA_PIN             AVR32_SSC0_TX_DATA_0_PIN
    00105   #define EXAMPLE_SSC_TX_DATA_FUNCTION        AVR32_SSC0_TX_DATA_0_FUNCTION
    00106   #define EXAMPLE_SSC_TX_FRAME_SYNC_PIN       AVR32_SSC0_TX_FRAME_SYNC_0_PIN
    00107   #define EXAMPLE_SSC_TX_FRAME_SYNC_FUNCTION  AVR32_SSC0_TX_FRAME_SYNC_0_FUNCTION
    00108 #elif BOARD == EVK1100
    00109   #define EXAMPLE_SSC (&AVR32_SSC)
    00110   #define EXAMPLE_SSC_TX_CLOCK_PIN            AVR32_SSC_TX_CLOCK_0_PIN
    00111   #define EXAMPLE_SSC_TX_CLOCK_FUNCTION       AVR32_SSC_TX_CLOCK_0_FUNCTION
    00112   #define EXAMPLE_SSC_TX_DATA_PIN             AVR32_SSC_TX_DATA_0_PIN
    00113   #define EXAMPLE_SSC_TX_DATA_FUNCTION        AVR32_SSC_TX_DATA_0_FUNCTION
    00114   #define EXAMPLE_SSC_TX_FRAME_SYNC_PIN       AVR32_SSC_TX_FRAME_SYNC_0_PIN
    00115   #define EXAMPLE_SSC_TX_FRAME_SYNC_FUNCTION  AVR32_SSC_TX_FRAME_SYNC_0_FUNCTION
    00116 #endif
    00117
    00118   static const gpio_map_t SSC_GPIO_MAP =
    00119   {
    00120     {EXAMPLE_SSC_TX_CLOCK_PIN,      EXAMPLE_SSC_TX_CLOCK_FUNCTION     },
    00121     {EXAMPLE_SSC_TX_DATA_PIN,       EXAMPLE_SSC_TX_DATA_FUNCTION      },
    00122     {EXAMPLE_SSC_TX_FRAME_SYNC_PIN, EXAMPLE_SSC_TX_FRAME_SYNC_FUNCTION}
    00123   };
    00124
    00125   volatile avr32_ssc_t *ssc = EXAMPLE_SSC;
    00126
    00127   // Switch main clock to external oscillator 0 (crystal).
    00128   //pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
    00129
    00130   // Assign GPIO to SSC.
    00131   gpio_enable_module(SSC_GPIO_MAP, sizeof(SSC_GPIO_MAP) / sizeof(SSC_GPIO_MAP[0]));
    00132
    00133   // SSC init in I2S mode.
    00134     ssc_i2s_init(ssc, 11025, 8, 8, SSC_I2S_MODE_STEREO_OUT, FOSC0);
    00135
    00136     unsigned char leds = 0x00;
    00137
    00138     while (1)
    00139   {
    00140         leds <<= 1;
    00141         leds ^= (leds ^ 0x08) >> 3;
    00142     LED_Display_Field(LED_MONO0_GREEN |
    00143                       LED_MONO1_GREEN |
    00144                       LED_MONO2_GREEN |
    00145                       LED_MONO3_GREEN,
    00146                       leds);
    00147
    00148     while (!(ssc_i2s_get_status(ssc) & AVR32_SSC_SR_TXRDY_MASK));
    00149         ssc_i2s_transfer(ssc, 0xA3);
    00150     }
    00151 }