/******************************************************************************
 *
 *    @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;
}
Beispiel #2
0
void TestApp_Init(void)
{
   AUDIO_CONFIG_STRUCT       audio_config;
   USB_CLASS_AUDIO_ENDPOINT  * endPoint_ptr;

   /* Pointer to audio endpoint entry */  
   endPoint_ptr = USB_mem_alloc_zero(sizeof(USB_CLASS_AUDIO_ENDPOINT)*AUDIO_DESC_ENDPOINT_COUNT);
   /* USB descriptor endpoint */
   audio_config.usb_ep_data = &usb_desc_ep;
   /* USB audio unit */
   audio_config.usb_ut_data = &usb_audio_unit;
   /* Endpoint count */
   audio_config.desc_endpoint_cnt = AUDIO_DESC_ENDPOINT_COUNT;
   /* Application callback */
   audio_config.audio_class_callback.callback = USB_App_Callback;
   /* Application callback argurment */
   audio_config.audio_class_callback.arg = &g_app_handle;
   /* Vendor callback */
   audio_config.vendor_req_callback.callback = NULL;
   /* Vendor callback argurment */
   audio_config.vendor_req_callback.arg = NULL;
   /* Param callback function */
   audio_config.param_callback.callback = USB_Notif_Callback;
   /* Param callback argurment */
   audio_config.param_callback.arg = &g_app_handle;
   /* Memory param callback */
   audio_config.mem_param_callback.callback = NULL;
   /* Memory param callback argurment */
   audio_config.mem_param_callback.arg = &g_app_handle;
   /* Descriptor callback pointer */
   audio_config.desc_callback_ptr =  &desc_callback;
   /* Audio enpoint pointer */
   audio_config.ep = endPoint_ptr;

   /* Initialize timer module */
//   audio_timer_init();

//   _audio_timer_init_freq(AUDIO_TIMER, AUDIO_TIMER_CHANNEL, AUDIO_SPEAKER_FREQUENCY, AUDIO_TIMER_CLOCK, TRUE);

    if (MQX_OK != _usb_device_driver_install(USBCFG_DEFAULT_DEVICE_CONTROLLER)) {
        printf("Driver could not be installed\n");
        return;
    }

   /* Initialize the USB interface */
   g_app_handle = USB_Class_Audio_Init(&audio_config);

   if (MQX_OK != _lwevent_create(&app_event, LWEVENT_AUTO_CLEAR)) {
      printf("\n_lwevent_create app_event failed.\n");
      _task_block();
   }
   
   if (MQX_OK != _lwevent_wait_ticks(&app_event, USB_APP_ENUM_COMPLETE_EVENT_MASK, FALSE, 0)) {
      printf("\n_lwevent_wait_ticks app_event failed.\n");
      _task_block();
   }
   
   if (MQX_OK != _lwevent_clear(&app_event, USB_APP_ENUM_COMPLETE_EVENT_MASK)) {
      printf("\n_lwevent_clear app_event failed.\n");
      _task_block();
   }
   printf("Audio speaker is working ... \r\n");
   /* Prepare buffer for first isochronous input */
   USB_Class_Audio_Recv_Data(g_app_handle,AUDIO_ISOCHRONOUS_ENDPOINT,
                  audio_data_buff0, DATA_BUFF_SIZE);

   _task_block();   
}