コード例 #1
0
ファイル: synth.c プロジェクト: PhamVanNhi/ECE5770
//*****************************************************************************
//
// This application performs simple audio synthesis and playback based on the
// keys pressed on the touch screen virtual piano keyboard.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32SysClock, ui32OldKey, ui32NewKey;
    tContext sContext;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                       SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_PLL |
                                       SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "synth");

    //
    // Draw the keys on the virtual piano keyboard.
    //
    DrawWhiteKeys(&sContext);
    DrawBlackKeys(&sContext);

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit(ui32SysClock);
    TouchScreenCallbackSet(TouchCallback);

    //
    // Initialize the sound driver.
    //
    SoundInit(ui32SysClock);
    SoundVolumeSet(128);
    SoundStart(g_pi16AudioBuffer, AUDIO_SIZE, 64000, SoundCallback);

    //
    // Default the old and new key to not pressed so that the first key press
    // will be properly drawn on the keyboard.
    //
    ui32OldKey = NUM_WHITE_KEYS + NUM_BLACK_KEYS;
    ui32NewKey = NUM_WHITE_KEYS + NUM_BLACK_KEYS;

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // See if the first half of the sound buffer needs to be filled.
        //
        if(HWREGBITW(&g_ui32Flags, FLAG_PING) == 1)
        {
            //
            // Synthesize new audio into the first half of the sound buffer.
            //
            ui32NewKey = GenerateAudio(g_pi16AudioBuffer, AUDIO_SIZE / 2);

            //
            // Clear the flag for the first half of the sound buffer.
            //
            HWREGBITW(&g_ui32Flags, FLAG_PING) = 0;
        }

        //
        // See if the second half of the sound buffer needs to be filled.
        //
        if(HWREGBITW(&g_ui32Flags, FLAG_PONG) == 1)
        {
            //
            // Synthesize new audio into the second half of the sound buffer.
            //
            ui32NewKey = GenerateAudio(g_pi16AudioBuffer + (AUDIO_SIZE / 2),
                                       AUDIO_SIZE / 2);

            //
            // Clear the flag for the second half of the sound buffer.
            //
            HWREGBITW(&g_ui32Flags, FLAG_PONG) = 0;
        }

        //
        // See if a different key has been pressed.
        //
        if(ui32OldKey != ui32NewKey)
        {
            //
            // See if the old key was a white key.
            //
            if(ui32OldKey < NUM_WHITE_KEYS)
            {
                //
                // Redraw the face of the white key so that it no longer shows
                // as being pressed.
                //
                FillWhiteKey(&sContext, ui32OldKey, ClrWhiteKey);
            }

            //
            // See if the old key was a black key.
            //
            else if(ui32OldKey < (NUM_WHITE_KEYS + NUM_BLACK_KEYS))
            {
                //
                // Redraw the face of the black key so that it no longer shows
                // as being pressed.
                //
                FillBlackKey(&sContext, ui32OldKey - NUM_WHITE_KEYS,
                             ClrBlackKey);
            }

            //
            // See if the new key is a white key.
            //
            if(ui32NewKey < NUM_WHITE_KEYS)
            {
                //
                // Redraw the face of the white key so that it is shown as
                // being pressed.
                //
                FillWhiteKey(&sContext, ui32NewKey, ClrPressed);
            }

            //
            // See if the new key is a black key.
            //
            else if(ui32NewKey < (NUM_WHITE_KEYS + NUM_BLACK_KEYS))
            {
                //
                // Redraw the face of the black key so that it is shown as
                // being pressed.
                //
                FillBlackKey(&sContext, ui32NewKey - NUM_WHITE_KEYS,
                             ClrPressed);
            }

            //
            // Save the new key as the old key.
            //
            ui32OldKey = ui32NewKey;
        }
    }
}
コード例 #2
0
ファイル: grlib_demo.c プロジェクト: bli19/unesp_mdt
//*****************************************************************************
//
// A simple demonstration of the features of the TivaWare Graphics Library.
//
//*****************************************************************************
int
main(void)
{
    tContext sContext;
    uint32_t ui32SysClock;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                       SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_PLL |
                                       SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "grlib-demo");

    //
    // Configure and enable uDMA
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    SysCtlDelay(10);
    ROM_uDMAControlBaseSet(&psDMAControlTable[0]);
    ROM_uDMAEnable();

    //
    // Initialize the sound driver.
    //
    SoundInit(ui32SysClock);
    SoundVolumeSet(128);
    SoundStart(g_pi16AudioBuffer, AUDIO_SIZE, 64000, SoundCallback);

    //
    // Initialize the touch screen driver and have it route its messages to the
    // widget tree.
    //
    TouchScreenInit(ui32SysClock);
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the title block and the previous and next buttons to the widget
    // tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext);

    //
    // Add the first panel to the widget tree.
    //
    g_ui32Panel = 0;
    WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels);
    CanvasTextSet(&g_sTitle, g_pcPanelNames[0]);

    //
    // Issue the initial paint request to the widgets.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Loop forever handling widget messages.
    //
    while(1)
    {
        //
        // Process any messages in the widget message queue.
        //
        WidgetMessageQueueProcess();

        //
        // See if the first half of the sound buffer needs to be filled.
        //
        if(HWREGBITW(&g_ui32Flags, FLAG_PING) == 1)
        {
            //
            // generate new audio into the first half of the sound buffer.
            //
            GenerateAudio(g_pi16AudioBuffer, AUDIO_SIZE / 2);

            //
            // Clear the flag for the first half of the sound buffer.
            //
            HWREGBITW(&g_ui32Flags, FLAG_PING) = 0;
        }

        //
        // See if the second half of the sound buffer needs to be filled.
        //
        if(HWREGBITW(&g_ui32Flags, FLAG_PONG) == 1)
        {
            //
            // generate new audio into the second half of the sound buffer.
            //
            GenerateAudio(g_pi16AudioBuffer + (AUDIO_SIZE / 2),
                                       AUDIO_SIZE / 2);

            //
            // Clear the flag for the second half of the sound buffer.
            //
            HWREGBITW(&g_ui32Flags, FLAG_PONG) = 0;
        }
    }
}