static bool usbEnumerateHidKeyboard(bool consumer_active)
{
    device->usb_interface[usb_interface_hid_keyboard] = UsbAddInterface(&usb_codes_hid_no_boot, B_DESCRIPTOR_TYPE_HID, interface_descriptor_hid_keybd, sizeof(interface_descriptor_hid_keybd));
    if (device->usb_interface[usb_interface_hid_keyboard] == usb_interface_error)
        return FALSE;

    /* Register HID Keyboard report descriptor with the interface */
    if (UsbAddDescriptor(device->usb_interface[usb_interface_hid_keyboard], B_DESCRIPTOR_TYPE_HID_REPORT, report_descriptor_hid_keybd, sizeof(report_descriptor_hid_keybd)) == FALSE)
        return FALSE;
    /* Add required endpoints to the interface */
    if (consumer_active)
    {
        if (UsbAddEndPoints(device->usb_interface[usb_interface_hid_keyboard], 1, epinfo_hid_keybd_with_consumer) == FALSE)
            return FALSE;
    }
    else
    {
        if (UsbAddEndPoints(device->usb_interface[usb_interface_hid_keyboard], 1, epinfo_hid_keybd_no_consumer) == FALSE)
            return FALSE;
    }

    device->usb_task[usb_task_hid_keyboard].handler = hidKeyboardHandler;
    (void) MessageSinkTask(StreamUsbClassSink(device->usb_interface[usb_interface_hid_keyboard]), &device->usb_task[usb_task_hid_keyboard]);
    
    return TRUE;
}
/**
 	Switch On the wind noise filter
 */
void Filter_On(void) 
{
	DEBUG_FILTER(("[FILTER] ON\n"));
	
	MessageSinkTask(theHeadset.sco_sink, &theHeadset.task);
	voice_activity = VOICE_ACTIVITY_OFF;
	set_filter();
}
/****************************************************************************
DESCRIPTION
    Stop prompt where DSP has not been loaded by the plugin, e.g. (adpcm or pcm) 
    Prompt is either mixing in an existing DSP app or not using the DSP.
*/
static void CsrVoicePresencesPluginStopPhraseMixable ( void ) 
{
    Sink lSink=NULL;
    Task taskdata = NULL;
    
    /* Check for DSP mixing */
    if(GetCurrentDspStatus())
    {
        lSink = StreamKalimbaSink(PRESENT_DSP_PORT);
        /* reset the volume levels of the dsp plugin */
        if(GetAudioPlugin())           	    
            MessageSend( GetAudioPlugin(), AUDIO_PLUGIN_RESET_VOLUME_MSG, 0 ) ;
    }
    else    /* Must be ADPCM not mixing */
    {
        switch(koovox_phrase_data->features.audio_output_type)
        {
            /* is the I2S required? */
            case OUTPUT_INTERFACE_TYPE_I2S:
            {               
                CsrI2SAudioOutputDisconnect( koovox_phrase_data->features.stereo);  
            }
            break;
            
            /* spdif output? */
            case OUTPUT_INTERFACE_TYPE_SPDIF:
            {
                Sink rSink = NULL;
                                
                /* obtain source to SPDIF hardware and disconnect it */
                lSink = StreamAudioSink(AUDIO_HARDWARE_SPDIF, AUDIO_INSTANCE_0, SPDIF_CHANNEL_A );
                rSink = StreamAudioSink(AUDIO_HARDWARE_SPDIF, AUDIO_INSTANCE_0, SPDIF_CHANNEL_B );
                StreamDisconnect(0, lSink);
                StreamDisconnect(0, rSink);
                SinkClose(lSink);
                SinkClose(rSink);
            }
            break;
            
            /* use built in codec */
            default:
            {
                lSink = StreamAudioSink(AUDIO_HARDWARE_CODEC,AUDIO_INSTANCE_0, (koovox_phrase_data->features.stereo ? AUDIO_CHANNEL_A_AND_B : AUDIO_CHANNEL_A));
                /* Disconnect PCM source/sink */
                StreamDisconnect(StreamSourceFromSink(lSink), lSink); 
            }
        }
    }    
    /* close sink and cancel any messages if valid */
    if(lSink)
    {
        /* Cancel all the messages relating to VP that have been sent */
        taskdata = MessageSinkTask(lSink, NULL);
        SinkClose(lSink);
    }
    PRINT(("PRESENT: SinkTask now NULL was %x\n",(uint16)taskdata));
    MessageCancelAll((TaskData*) &csr_voice_presences_plugin, MESSAGE_STREAM_DISCONNECT);
}
Source avrcpSourceFromData(AVRCP *avrcp, uint8 *data, uint16 length)
{
    /* Create a source from the data */
    Source src = StreamRegionSource(data, length);

    /* Register a task for freeing the data and store a ptr to it */
    avrcp->dataFreeTask.sent_data = data;
    MessageSinkTask(StreamSinkFromSource(src), &avrcp->dataFreeTask.cleanUpTask);

    return src;
}
static bool usbEnumerateAudioControl(usb_device_class_descriptor descriptor)
{
    /* Add an Audio Control Interface */
    device->usb_interface[usb_interface_audio_control] = UsbAddInterface(&usb_codes_ac, B_DESCRIPTOR_TYPE_CS_INTERFACE, descriptor.descriptor, descriptor.size_descriptor);
    if (device->usb_interface[usb_interface_audio_control] == usb_interface_error)
        return FALSE;
        
    device->usb_task[usb_task_audio_control].handler = audioControlHandler;
    (void) MessageSinkTask(StreamUsbClassSink(device->usb_interface[usb_interface_audio_control]), &device->usb_task[usb_task_audio_control]);
    
    return TRUE;
}
示例#6
0
static void scanner_off_state_enter(void) {
	
	DEBUG(( "scanner, off state enter... \n" ));
	update_indication();
#if 0	
	disable_scanner();
#endif
	trigger_pull_up();
	
	if (StreamUartSource()) {
		
		StreamUartConfigure(VM_UART_RATE_9K6, VM_UART_STOP_ONE, VM_UART_PARITY_NONE);
		
		MessageSinkTask(StreamUartSink(), &scanner.task);
		
		scanner.uart_initialized = TRUE;
	}
}
static bool usbEnumerateAudioMic(usb_device_class_descriptor descriptor)
{
    /* Add the microphone Audio Streaming Interface */
    device->usb_interface[usb_interface_audio_streaming_mic] = UsbAddInterface(&usb_codes_as, B_DESCRIPTOR_TYPE_CS_INTERFACE, descriptor.descriptor, descriptor.size_descriptor);
    
    if (device->usb_interface[usb_interface_audio_streaming_mic] == usb_interface_error)
        return FALSE;

    /* Add the microphone endpoint */
    if (UsbAddEndPoints(device->usb_interface[usb_interface_audio_streaming_mic], 1, descriptor.end_point_info) == FALSE)
        return FALSE;
    
    device->usb_task[usb_task_audio_streaming].handler = audioStreamingHandler;
    (void) MessageSinkTask(StreamUsbClassSink(device->usb_interface[usb_interface_audio_streaming_mic]), &device->usb_task[usb_task_audio_streaming]);
    
    /* set mic default volume */
    device->audio.in_vol = usb_audio_volume->mic_default;
    
    return TRUE;
}
/****************************************************************************
DESCRIPTION
    plays a tone using the audio plugin
*/
void CsrA2dpDecoderPluginPlayTone ( A2dpPluginTaskdata *task, audio_note * tone, Task codec_task, uint16 tone_volume , bool stereo)
{
    Source lSource ;
    Sink lSink ;

    if (!DECODER)
        Panic() ;

    PRINT(("DECODER: Tone Start\n")) ;

    lSink = StreamKalimbaSink(3) ;

    /*request an indication that the tone has completed / been disconnected*/
    MessageSinkTask ( lSink , (TaskData*) task ) ;

    /*connect the tone*/
    lSource = StreamAudioSource ( (const audio_note *) (tone) ) ;
    
    /*mix the tone to the SBC*/
    StreamConnectAndDispose( lSource , lSink ) ;

}
void connectionHandleRfcommControlInd(const RFC_CONTROL_IND_T *ind)
{
    /* Get the connection instance data keyed by server channel and mux id */
    conn_instance *conn = getRfcommConnection(NULL, ind->mux_id, ind->server_chan);
	
    if(conn)
    {
		/* Get the connection sink */
		Sink sink = StreamRfcommSink(ind->mux_id, ind->server_chan);

        /* Cancel the connection timeout */
	    (void) MessageCancelFirst(connectionGetCmTask(), CL_INTERNAL_RFCOMM_CONNECT_TIMEOUT_IND);		

        /* Connection establishment complete, let the client application know */     
        sendRfcommConnectionCfm(conn->config.rfcomm.app_task, rfcomm_connect_success, ind->server_chan, conn->config.rfcomm.maxMtu, sink);

		/* Associate the task with its sink */
		(void) MessageSinkTask(sink, conn->config.rfcomm.app_task);
		
        /* No longer require connection instance data */
        (void) deleteRfcommConnection(NULL, ind->mux_id, ind->server_chan);
    }
    else
    {
        /* 
            This indicates that the connection is already established and
            as we throw away connection state on successful connection 
            establishment, we wouldn't expect to find a connection instance 
        */
        Task task;
        Sink sink = StreamRfcommSink(ind->mux_id, ind->server_chan);
        task = MessageSinkGetTask(sink);

        /* Send modem status indication */
        if(task)
            sendRfcommControlInd(task, sink, ind->control_pars.break_signal, ind->control_pars.modem_signal);
    }
}
示例#10
0
static bool usbEnumerateHidConsumerTransportControl(void)
{
    if (!usb_hid_consumer_config)
    {
        usb_hid_consumer_config = &usb_hid_config_consumer_transport;        
        PRINT(("USB: HID consumer default descriptors\n"));
    }
    
    device->usb_interface[usb_interface_hid_consumer_transport] = UsbAddInterface(&usb_codes_hid_no_boot, B_DESCRIPTOR_TYPE_HID, usb_hid_consumer_config->interface.descriptor, usb_hid_consumer_config->interface.size_descriptor);
    if (device->usb_interface[usb_interface_hid_consumer_transport] == usb_interface_error)
        return FALSE;

    /* Register HID Consumer Control Device report descriptor with the interface */
    if (UsbAddDescriptor(device->usb_interface[usb_interface_hid_consumer_transport], B_DESCRIPTOR_TYPE_HID_REPORT, usb_hid_consumer_config->report.descriptor, usb_hid_consumer_config->report.size_descriptor) == FALSE)
        return FALSE;
    /* Add required endpoints to the interface */
    if (UsbAddEndPoints(device->usb_interface[usb_interface_hid_consumer_transport], 1, usb_hid_consumer_config->interface.end_point_info) == FALSE)
        return FALSE;
    
    device->usb_task[usb_task_hid_consumer].handler = hidConsumerHandler;
    (void) MessageSinkTask(StreamUsbClassSink(device->usb_interface[usb_interface_hid_consumer_transport]), &device->usb_task[usb_task_hid_consumer]);
    
    return TRUE;
}
static void CsrVoicePresencesPluginPlayDigit(void) 
{
    Source lSource ;
    voice_prompt prompt;
    
    /* Get the prompt data*/
    lSource = csrVoicePresencesGetPrompt(&prompt, koovox_phrase_data);
    if(!lSource) Panic();
    
    SetAudioBusy((TaskData*) &csr_voice_presences_plugin);

    /* Stash the source */
    koovox_phrase_data->source = lSource;
    koovox_phrase_data->decompression = prompt.decompression;
    koovox_phrase_data->stereo = prompt.stereo;
    koovox_phrase_data->playback_rate =  (prompt.playback_rate ? prompt.playback_rate : 8000);
    koovox_phrase_data->mixing = FALSE;    /* overridden later if this prompt is mixed */
    
    SetVpPlaying(TRUE);

	PRINT(("==decompression:%d===\n", prompt.decompression));

    /* Connect the stream to the DAC */
    switch(prompt.decompression)
    {
        case voice_prompts_codec_ima_adpcm:
        case voice_prompts_codec_none:     
        case voice_prompts_codec_tone:  
        {
            Sink lSink = NULL;
            Task taskdata = NULL;
            
            /* if DSP is already running, the voice prompt can be mixed with the dsp
               audio via the kalimba mixing port (3), either the CVC plugin or
               the music plugin will have already determined the output source and connected the 
               appropriate ports to the hardware, the volume will already have been set, it is not
               necessary to do it again */
            if(GetCurrentDspStatus())
            {            
                /* Configure tone or prompt playback */    
                if(prompt.decompression == voice_prompts_codec_tone)
                {
                    PRINT(("PRESENT: play tone\n"));
                    KalimbaSendMessage(MESSAGE_SET_TONE_RATE_MESSAGE_ID, koovox_phrase_data->playback_rate , 0/*Mono Bit 0 =0, TONE BIT 1 = 0*/, 0, 0); 
                }                    
                else
                {
                    PRINT(("PRESENT: play adpcm\n"));
                    KalimbaSendMessage(MESSAGE_SET_TONE_RATE_MESSAGE_ID, koovox_phrase_data->playback_rate , /*PROMPT_MONO*/PROMPT_ISPROMPT, 0, 0);                                  
                }
                /* stream voice prompt data to the DSP tone mixing port */                
                koovox_phrase_data->mixing = TRUE;
                lSink = StreamKalimbaSink(PRESENT_DSP_PORT);
                PRINT(("PRESENT: play dsp mix lSink = %x lSource = %x\n",(uint16)lSink,(uint16)lSource));
                SinkConfigure(lSink, STREAM_CODEC_OUTPUT_RATE, koovox_phrase_data->playback_rate);
                
                /* Get messages when source has finished */
                taskdata = MessageSinkTask( lSink , (TaskData*) &csr_voice_presences_plugin);

                /* connect the kalimba port to the audio_prompt */
                if(prompt.decompression == voice_prompts_codec_ima_adpcm)
                {   
                    PanicFalse(TransformStart(TransformAdpcmDecode(lSource, lSink)));
                }
                else
                {                      
                    PanicFalse(StreamConnect(lSource, lSink)); 
                }   
                
            }
			else
			{
				CsrVoicePresencesPluginStopPhrase();
			}
        }
        break;
        
        case voice_prompts_codec_pcm:        
        {    
            Sink lSink = NULL;
            Task taskdata = NULL;
            
            /* determine whether the prompt is being played as a mixed with audio via the dsp, if the dsp is being
               used for audio mixing there is no need to set the volume as this will already have been performed 
               plugin used to load the dsp for audio processing */            
            if(GetCurrentDspStatus())
            {
                /* store that this PCM prompt is mixing */
                koovox_phrase_data->mixing = TRUE;
                
                /* stream voice prompt data to the DSP tone mixing port */                
                lSink = StreamKalimbaSink(PRESENT_DSP_PORT);
                PRINT(("PRESENT: play dsp mix lSink = %x lSource = %x\n",(uint16)lSink,(uint16)lSource));
                SinkConfigure(lSink, STREAM_CODEC_OUTPUT_RATE, koovox_phrase_data->playback_rate);                               
                
                /* Get messages when source has finished */
                taskdata = MessageSinkTask( lSink , (TaskData*) &csr_voice_presences_plugin);

				PRINT(("PRESENT: sink task now %x was %x.\n",(uint16)&csr_voice_presences_plugin,(uint16)taskdata));
                /* Configure PCM prompt playback */    
                KalimbaSendMessage(MESSAGE_SET_TONE_RATE_MESSAGE_ID, koovox_phrase_data->playback_rate , (koovox_phrase_data->stereo?PROMPT_STEREO:0)|PROMPT_ISPROMPT, 0, 0);        
                
                /* Connect source to PCM */
                PanicFalse(StreamConnect(lSource, lSink));
            }
        }
        break;

        default:
            PRINT(("PRESENT: Codec Invalid\n"));
            Panic();
        break;
    }

}
/****************************************************************************
DESCRIPTION
	Reconnects the audio after a tone has completed
*/
void CsrA2dpDecoderPluginToneComplete ( void )
{
    /*we no longer want to receive stream indications*/
    MessageSinkTask ( StreamKalimbaSink(3) , NULL) ;
}