//***************************************************************************** // //! Decreases the volume. //! //! \param ulPercent is the amount to decrease the volume, specified as a //! percentage between 0% (silence) and 100% (full volume), inclusive. //! //! This function adjusts the audio output down by the specified percentage. //! The adjusted volume will not go below 0% (silence). //! //! \return None. // //***************************************************************************** void SoundVolumeDown(unsigned long ulPercent) { // // Do not let the volume go below 0%. // if(g_ucVolume < ulPercent) { // // Set the volume to the minimum. // g_ucVolume = 0; } else { // // Decrease the volume by the specified amount. // g_ucVolume -= ulPercent; } // // Set the new volume. // SoundVolumeSet(g_ucVolume); }
/***************************************************************************** * FUNCTION IMPLEMENTATIONS *****************************************************************************/ int main(void) { /* One-time initialization of hardware */ vInit(); SchedulerInit(TICKS_PER_SECOND); char statusStr[96]; int sounddemo=0; // sound demo SoundVolumeSet(80); // less obnoxious during testing while (1) { SchedulerRun(); // to get measurements // currentMeasuredDistance // to play sound // soundStart(sounddemo) where soundemo is 0-9 // A DEMO OF SOUNDS /////////////////////////////////////////////////// if(GamepadButtons.buttonA && bWavPlaying==false) { usprintf(statusStr,"sound=%d\r",sounddemo); Display96x16x1StringDrawCentered(statusStr,0,false); sounddemo = soundStart(sounddemo); // returns the actual sound index used sounddemo++; } } /* This should never happen */ return 0; }
//***************************************************************************** // //! Increases the volume. //! //! \param ulPercent is the amount to increase the volume, specified as a //! percentage between 0% (silence) and 100% (full volume), inclusive. //! //! This function adjusts the audio output up by the specified percentage. The //! adjusted volume will not go above 100% (full volume). //! //! \return None. // //***************************************************************************** void SoundVolumeUp(unsigned long ulPercent) { // // Increase the volume by the specified amount. // g_ucVolume += ulPercent; // // Do not let the volume go above 100%. // if(g_ucVolume > 100) { // // Set the volume to the maximum. // g_ucVolume = 100; } // // Set the new volume. // SoundVolumeSet(g_ucVolume); }
//***************************************************************************** // //! Enables the sound output. //! //! This function enables the sound output, preparing it to play music or sound //! effects. //! //! \return None. // //***************************************************************************** void SoundEnable(void) { // // Set the timer to produce 40 kHz, which is well beyond the limits of // human hearing. // TimerLoadSet(TIMER2_BASE, TIMER_A, (g_ulSystemClock / 40000) - 1); // // Restore the output volume. // SoundVolumeSet(g_ucVolume); // // Enable the PWM output timer. // TimerEnable(TIMER2_BASE, TIMER_A); // // Configure the speaker GPIO pin as a timer PWM pin. // GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_7); }
/** * Performs one-time setup of peripherals */ static void vInit(void) { /* Sets Clock Speed to 50MHz */ ROM_SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* Initializes Bumpers with Interrupt */ BumpSensorsInit(); GPIOPinIntEnable(GPIO_PORTE_BASE, (1 << 0) | (1 << 1)); GPIOIntTypeSet(GPIO_PORTE_BASE, (1 << 0) | (1 << 1), GPIO_FALLING_EDGE); IntEnable(20); /* Initializes timer, required for scheduler */ SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER_UP); TimerEnable(TIMER0_BASE, TIMER_A); SoundInit(); SoundVolumeSet(95); IntMasterEnable(); /* Hardware initialization for Bouncy related peripherals */ vBouncyInit(); /* Hardware initialization for Gamepad related peripherals */ vGamepadInit(); initDriveControl(); // Init the rangefinder initRangeFinder(); return; }
//***************************************************************************** // // The program main function. It performs initialization, then handles wav // file playback. // //***************************************************************************** int main(void) { int nStatus; // // Set the system clock to run at 80MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Give bget some memory to work with. // bpool(g_pulHeap, sizeof(g_pulHeap)); // // Set the device pin out appropriately for this board. // PinoutSet(); // // Configure the relevant pins such that UART0 owns them. // ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Open the UART for I/O // UARTStdioInit(0); UARTprintf("i2s_speex_enc\n"); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Enable Interrupts // ROM_IntMasterEnable(); // // Configure the I2S peripheral. // SoundInit(1); // // Set the format of the play back in the sound driver. // SoundSetFormat(AUDIO_RATE, AUDIO_BITS, AUDIO_CHANNELS); // // Print out some header information to the serial console. // UARTprintf("\ni2s_speex_enc Stellaris Example\n"); UARTprintf("Streaming at %d %d bit ",SoundSampleRateGet(), AUDIO_BITS); if(AUDIO_CHANNELS == 2) { UARTprintf("Stereo\n"); } else { UARTprintf("Mono\n"); } // // Set the initial volume. // SoundVolumeSet(INITIAL_VOLUME_PERCENT); // // Initialize the Speex decoder. // SpeexDecodeInit(); // // Set the default quality to 2. // g_iQuality = 2; // // Initialize the Speex encoder to Complexity of 1 and Quality 2. // SpeexEncodeInit(AUDIO_RATE, 1, g_iQuality); // // Initialize the audio buffers. // InitBuffers(); // // Initialize the applications global state flags. // g_ulFlags = 0; // // Kick off a request for a buffer play back and advance the encoder // pointer. // SoundBufferRead(g_pucRecBuffer, RECORD_BUFFER_INC, RecordBufferCallback); g_pucEncode += RECORD_BUFFER_INC; // // Kick off a second request for a buffer play back and advance the encode // pointer. // SoundBufferRead(&g_pucRecBuffer[RECORD_BUFFER_INC], RECORD_BUFFER_INC, RecordBufferCallback); g_pucEncode += RECORD_BUFFER_INC; // // The rest of the handling occurs at interrupt time so the main loop will // simply stall here. // while(1) { // // Print a prompt to the console. Show the CWD. // UARTprintf("\n> "); // // Get a line of text from the user. // UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // nStatus = CmdLineProcess(g_cCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error // code if one was returned. // else if(nStatus != 0) { UARTprintf("Command returned error code \n"); } } }
//***************************************************************************** // // 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; } } }
//***************************************************************************** // // 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; } } }
//***************************************************************************** // // The following is the Main Application Thread. It will Initialize the // Bluetooth Stack and all used profiles. // //***************************************************************************** static void MainApp(void *pThreadParameter) { int iPressCount; int iTick; int iVolume; int iRetVal; tDeviceInfo sDeviceInfo; BTPS_Initialization_t sBTPSInitialization; // // Set the callback function the stack can use for printing to the // console. // #ifdef DEBUG_ENABLED sBTPSInitialization.MessageOutputCallback = MessageOutputCallback; #else sBTPSInitialization.MessageOutputCallback = NULL; #endif // // Initialize the Bluetooth stack, using no callback parameters (NULL). // iRetVal = InitializeBluetooth(BluetoothCallbackFunction, NULL, &sBTPSInitialization); // // Initialize the Graphics Module. // InitializeGraphics(ButtonPressCallback); // // Proceed with application if there was no Bluetooth init error. // if(!iRetVal) { // // Make the device Connectable and Discoverable and enabled Secured // Simple Pairing. // SetLocalDeviceMode(CONNECTABLE_MODE | DISCOVERABLE_MODE | PAIRABLE_SSP_MODE); // // Get information about our local device. // iRetVal = GetLocalDeviceInformation(&sDeviceInfo); if(!iRetVal) { // // Format the board address into a string, and display it on // the console. // BD_ADDRToStr(sDeviceInfo.ucBDAddr, g_cBoardAddress); Display(("Local BD_ADDR: %s\r\n", g_cBoardAddress)); // // Display additional info about the device to the console // Display(("HCI Version : %s\r\n", g_pcHCIVersionStrings[sDeviceInfo.ucHCIVersion])); Display(("Connectable : %s\r\n", ((sDeviceInfo.sMode & CONNECTABLE_MODE) ? "Yes" : "No"))); Display(("Discoverable : %s\r\n", ((sDeviceInfo.sMode & DISCOVERABLE_MODE) ? "Yes" : "No"))); if(sDeviceInfo.sMode & (PAIRABLE_NON_SSP_MODE | PAIRABLE_SSP_MODE)) { Display(("Pairable : Yes\r\n")); Display(("SSP Enabled : %s\r\n", ((sDeviceInfo.sMode & PAIRABLE_SSP_MODE) ? "Yes" : "No"))); } else { Display(("Pairable : No\r\n")); } // // Show message to user on the screen // UpdateStatusBox("Waiting for Connection..."); // // Bluetooth should be running now. Enter a forever loop to run // the user interface on the board screen display and process // button presses. // iTick = ONE_SEC_COUNT; iVolume = DEFAULT_POWERUP_VOLUME; iPressCount = 0; while(1) { // // Update the screen. // ProcessGraphics(); // // Wait 1/10 second. // BTPS_Delay(TENTH_SEC_COUNT); // // If one second has elapsed, toggle the LED // if(!(--iTick)) { iTick = ONE_SEC_COUNT; ToggleLED(LED_PIN); } // // Check to see if the User Switch was pressed. // if(UserSwitchPressed()) { // // Count the amount of time that the button has been // pressed. // iPressCount++; } // // Else the user switch is not pressed // else { // // If the button was just released, then adjust the volume. // Decrease the volume by 10% for each button press. At // zero, then reset it to 100%. // if(iPressCount) { iVolume = (iVolume == 0) ? 100 : iVolume - 10; // // Set the new volume, and display a message on the // console // SoundVolumeSet(iVolume); Display(("Press Count %d Volume %d\r\n", iPressCount, iVolume)); iPressCount = 0; } } } } } // // There was an error initializing Bluetooth // else { // // Print an error message to the console and show a message on // the screen // Display(("Bluetooth Failed to initialize: Error %d\r\n", iRetVal)); UpdateStatusBox("Failed to Initialize Bluetooth."); // // Enter a forever loop. Continue to update the screen, and rapidly // blink the LED as an indication of the error state. // while(1) { ProcessGraphics(); BTPS_Delay(500); ToggleLED(LED_PIN); } } }