/****************************************************************************** * * @name USB_App_Callback * * @brief This function handles Class callback * * @param controller_ID : Controller ID * @param event_type : Value of the event * @param val : gives the configuration value * * @return None * ***************************************************************************** * This function is called from the class layer whenever reset occurs or enum * is completed. After the enum is completed this function sets a variable so * that the application can start. * This function also receives DATA Send and RECEIVED Events *****************************************************************************/ static void USB_App_Callback ( uint_8 controller_ID, /* [IN] Controller ID */ uint_8 event_type, /* [IN] value of the event */ void* val /* [IN] gives the configuration value */ ) { static APP_DATA_STRUCT* data_receive; if(event_type == USB_APP_BUS_RESET) { start_app=FALSE; } else if(event_type == USB_APP_ENUM_COMPLETE) { start_app=TRUE; #if (!(defined _MC9S08JS16_H)) (void)printf("Audio Speaker is working ... \r\n"); #endif #ifdef USE_FEEDBACK_ENDPOINT // Send initial rate control feedback (48Khz) USB_Class_Audio_Send_Data(controller_ID, AUDIO_FEEDBACK_ENDPOINT, (uint_8_ptr)&feedback_data, AUDIO_FEEDBACK_ENDPOINT_PACKET_SIZE); #endif // USE_FEEDBACK_ENDPOINT #if HIGH_SPEED_DEVICE // Start by receiving data to audio buffer USB_Class_Audio_Recv_Data(controller_ID, AUDIO_ENDPOINT, (uint_8_ptr) g_curr_recv_buf, AUDIO_ENDPOINT_PACKET_SIZE); #endif } else if ((event_type == USB_APP_DATA_RECEIVED) && (TRUE == start_app)) { (void)USB_Class_Audio_Recv_Data(controller_ID, AUDIO_ENDPOINT, (uint_8_ptr)g_curr_recv_buf, AUDIO_ENDPOINT_PACKET_SIZE); audio_event = USB_APP_DATA_RECEIVED; data_receive = (APP_DATA_STRUCT*)val; (void)memcpy(audio_data_recv, data_receive->data_ptr, data_receive->data_size); /*for(i=0;i<data_receive->data_size;i++){ audio_data_recv[i] = data_receive->data_ptr[i]; }*/ } #ifdef USE_FEEDBACK_ENDPOINT else if((event_type == USB_APP_SEND_COMPLETE) && (TRUE == start_app)) { feedback_data <<= 14; // 10.14 format (void)USB_Class_Audio_Send_Data(controller_ID, AUDIO_FEEDBACK_ENDPOINT, (uint_8_ptr)&feedback_data, AUDIO_FEEDBACK_ENDPOINT_PACKET_SIZE); } #endif return; }
/****************************************************************************** * * @name TestApp_Task * * @brief Application task function. It is called from the main loop * * @param None * * @return None * ***************************************************************************** * Application task function. It is called from the main loop *****************************************************************************/ void TestApp_Task(void) { #ifdef USE_FEEDBACK_ENDPOINT if((start_app == TRUE) && (start_send == TRUE)) { start_send = FALSE; feedback_data = 8<<14; // 10.14 format (8 bytes/frame) (void)USB_Class_Audio_Send_Data(CONTROLLER_ID, 2, (uint_8_ptr)&feedback_data, 3); } #endif }
/***************************************************************************** * * @name TestApp_Init * * @brief This function is the entry for Audio generator * * @param None * * @return None ** *****************************************************************************/ void Audio_TestApp_Init(void) { #if (OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_MQX) wav_buff = OS_Mem_alloc_uncached_align(AUDIO_ENDPOINT_PACKET_SIZE, 32); if(wav_buff == NULL) { printf("OS_Mem_alloc_uncached_align fail in audio composite example \r\n"); return ; } #endif while(TRUE) { while(!start_app) { OS_Time_delay(1); ; } start_app = FALSE; printf("USB_Prepare_Data \r\n"); USB_Prepare_Data(); USB_Class_Audio_Send_Data(g_audio_handle, AUDIO_ENDPOINT, wav_buff, AUDIO_ENDPOINT_PACKET_SIZE); } }