⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headset_configmanager.c

📁 bc5_stereo:bluetooth stereo Headset CODE 支持A2DP HSP 和 HSP 。可作为车载免提。BlueLab 2007环境下编译
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2007

FILE NAME
    headset_configmanager.c
    
DESCRIPTION
    Configuration manager for the headset - resoponsible for extracting user information out of the 
    PSKEYs and initialising the configurable nature of the headset components.
    
*/


#include "headset_amp.h"
#include "headset_buttonmanager.h"
#include "headset_configmanager.h"
#include "headset_config.h"
#include "headset_debug.h"
#include "headset_events.h"
#include "headset_LEDmanager.h"
#include "headset_statemanager.h"
#include "headset_private.h"
#include "headset_tones.h"

#include <csrtypes.h>
#include <ps.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <panic.h>

#ifdef DEBUG_CONFIG
#define CONF_DEBUG(x) DEBUG(x)
#else
#define CONF_DEBUG(x) 
#endif

#define HCI_PAGESCAN_INTERVAL_DEFAULT  (0x800)
#define HCI_PAGESCAN_WINDOW_DEFAULT   (0x12)
#define HCI_INQUIRYSCAN_INTERVAL_DEFAULT  (0x800)
#define HCI_INQUIRYSCAN_WINDOW_DEFAULT   (0x12)


#define DEFAULT_VOLUME_MUTE_REMINDER_TIME_SEC 10


/****************************************************************************
    LOCAL FUNCTIONS
*/
static void   	configManagerButtons                ( hsTaskData* theHeadset, const uint16 pio_debounce);
static void  	configManagerLEDS                   ( hsTaskData* theHeadset);
static uint16  	configManagerButtonDurations        ( hsTaskData* theHeadset);
static void     configManagerEventTones             ( hsTaskData* theHeadset);
static void     configManagerButtonPatterns         ( hsTaskData* theHeadset);
static void 	configManagerPower                  ( hsTaskData* theHeadset);
static void     configManagerTimeouts               ( hsTaskData* theHeadset);
static void     configManagerAmp	                ( hsTaskData* theHeadset);
static void     configManagerFeatures               ( hsTaskData* theHeadset);


/****************************************************************************
  FUNCTIONS
*/

/*****************************************************************************/
void configManagerInit(hsTaskData* theHeadset)  
{ 
  	    /* Read and configure the button durations */
  	const uint16 pio_debounce = configManagerButtonDurations(theHeadset);
    
  	    /* Read the system event configuration and configure the buttons */
    configManagerButtons(theHeadset, pio_debounce);

        /*configures the pattern button events*/
    configManagerButtonPatterns(theHeadset) ;

        /*Read and configure the event tones*/
    configManagerEventTones(theHeadset) ;

  	    /* Read and configure the LEDs */
    configManagerLEDS(theHeadset);
    
        /* Read and configure the power management system */
  	configManagerPower(theHeadset);
    
         /* Read and configure the timeouts */
    configManagerTimeouts(theHeadset);
	
		/* Read and configure the audio amp control */
    configManagerAmp(theHeadset);
	
		/* Read and configure the headset features */
    configManagerFeatures(theHeadset);
}


/*****************************************************************************/ 
uint16 configManagerGetMicBiasPio ( void )
{
    uint16 lResult = 0;
    
    PsFullRetrieve(441, &lResult, sizeof(uint16));

    CONF_DEBUG(("Co :MicPio[%x]\n", lResult)); 
    
    return lResult ;
}

/*****************************************************************************/ 
void configManagerSetupSupportedFeatures(hsTaskData* theHeadset)
{
	if(!ConfigRetrieve(PSKEY_HFP_SUPPORTED_FEATURES, &theHeadset->local_hfp_features, sizeof(uint16)))
    {
     	theHeadset->local_hfp_features = (HFP_NREC_FUNCTION | HFP_VOICE_RECOGNITION | HFP_REMOTE_VOL_CONTROL);
	}
}

/*****************************************************************************/ 
void configManagerSetupVolumeGains(uint16 *gains, uint16 size)
{
	/* ConfigRetrieve cannot fail since we have volume levels in the default config. */
	(void)ConfigRetrieve(PSKEY_VOLUME_GAINS, gains, size);
}

/*****************************************************************************/ 
void configManagerReset ( hsTaskData * pApp ) 
{
    CONF_DEBUG(("CO: Reset\n")) ;
        
    /* Reset the Last AG */
    (void)PsStore ( PSKEY_LAST_USED_AG , 0 , 0 ) ;
	
	/* Reset the Last A2DP source */
    (void)PsStore ( PSKEY_LAST_USED_AV_SOURCE , 0 , 0 ) ;
	
	/* Reset the Last A2DP source SEP */
    (void)PsStore ( PSKEY_LAST_USED_AV_SOURCE_SEP , 0 , 0 ) ;
	
	/* Reset the Last paired device */
    (void)PsStore ( PSKEY_LAST_PAIRED_DEVICE , 0 , 0 ) ;
	
	/* Reset the Volume Levels */
    (void)PsStore ( PSKEY_VOLUME_LEVELS , 0 , 0 ) ;
    
    /* Delete the Connection Libs Paired Device List */
    ConnectionSmDeleteAllAuthDevices ( 0 );
}
      

/****************************************************************************
NAME 
  	configManagerButtons

DESCRIPTION
 	Read the system event configuration from persistent store and configure
  	the buttons by mapping the associated events to them.
*/  
static void configManagerButtons(hsTaskData* theHeadset, const uint16 pio_debounce)
{ 
  	uint16 no_events = 20;
 
	/* Allocate enough memory to hold event configuration */
    event_config_type* config = (event_config_type*) PanicUnlessMalloc(no_events * sizeof(event_config_type));
    
        /*read in the events for the first PSKEY*/                
    if(ConfigRetrieve(PSKEY_EVENTS_A, config, no_events * sizeof(event_config_type)))
  	{
        uint16 n;
 
    		/* Now we have the event configuration, map required events to system events */
        for(n = 0; n < no_events; n++)
        { 
            CONF_DEBUG(("Co : AddMap Ev[%x] \n", config[n].event )) ;
                    
            if ( config[n].pio_mask_0_to_15 | config[n].pio_mask_16_to_31 )
            {
                    /* Map PIO button event to system events in specified states */
                buttonManagerAddMapping (((uint32)config[n].pio_mask_16_to_31 << 16) | config[n].pio_mask_0_to_15, 
                 						(config[n].event + EVENTS_EVENT_BASE) ,
                						 config[n].hfp_state_mask, 
                                         config[n].a2dp_state_mask, 
                						(ButtonsTime_t)config[n].type,
										pio_debounce); 
            }                                            
    	}
  	}
		else
		{
	   CONF_DEBUG(("Co: !EvLen\n")) ;
    }
    
        /*now do the same for the second PSKEY*/
    if(ConfigRetrieve(PSKEY_EVENTS_B, config, no_events * sizeof(event_config_type)))
  	{
        uint16 n;
 
    		/* Now we have the event configuration, map required events to system events */
        for(n = 0; n < no_events; n++)
        { 
            CONF_DEBUG(("Co : AddMap Ev[%x]\n", config[n].event )) ;
                    
            if ( config[n].pio_mask_0_to_15 | config[n].pio_mask_16_to_31 )
            {
                    /* Map PIO button event to system events in specified states */
                buttonManagerAddMapping (((uint32)config[n].pio_mask_16_to_31 << 16) | config[n].pio_mask_0_to_15, 
                 						(config[n].event + EVENTS_EVENT_BASE) ,
                						 config[n].hfp_state_mask, 
                                         config[n].a2dp_state_mask, 
                						(ButtonsTime_t)config[n].type,
										pio_debounce); 
            }          
    	}
  	}
		else
		{
	   CONF_DEBUG(("Co: !EvLen2\n")) ;
    }        

    	/* Free up memory */
  	free(config);
}


/****************************************************************************
NAME 
  	configManagerButtonPatterns

DESCRIPTION
  	Read and configure any buttonpattern matches that exist.
    
*/
static void configManagerButtonPatterns(hsTaskData * theHeadset) 
{  
      		/* Allocate enough memory to hold event configuration */
    button_pattern_config_type* config = (button_pattern_config_type*) PanicUnlessMalloc(BM_NUM_BUTTON_MATCH_PATTERNS * sizeof(button_pattern_config_type));
   
    CONF_DEBUG(("Co: No Button Patterns - %d\n", BM_NUM_BUTTON_MATCH_PATTERNS));
   
    /* Now read in event configuration */
    if(ConfigRetrieve(PSKEY_BUTTON_PATTERN_CONFIG, config, BM_NUM_BUTTON_MATCH_PATTERNS * sizeof(button_pattern_config_type)))
    {
        uint16 n;
 
       /* Now we have the event configuration, map required events to system events */
        for(n = 0; n < BM_NUM_BUTTON_MATCH_PATTERNS ; n++)
        {	 
 	      CONF_DEBUG(("Co : AddPattern Ev[%x]\n", config[n].event )) ;
                    
      			   /* Map PIO button event to system events in specified states */
      	    BMAddPatternMapping (config[n].event + EVENTS_EVENT_BASE, config[n].pattern ) ;
        }
    }
    else
	    {
	      CONF_DEBUG(("Co: !EvLen\n")) ;
    }
    free (config) ;
}


/****************************************************************************
NAME 
  	config

DESCRIPTION
  	Read the LED configuration from persistent store and configure the LEDS.
 
RETURNS
  	TRUE or FALSE
    
*/ 
static bool config(hsTaskData * theHeadset , configType type, uint16 pskey_no, uint16 pskey_config, uint16 max) 
{ 
  	bool success = FALSE;
  	uint16 no_events = 0;
 
  	/* First read the number of states/events configured */
  	if(ConfigRetrieve(pskey_no, &no_events, sizeof(uint16)))
  	{	  
		CONF_DEBUG(("Co: no_events:%d max:%d\n",no_events,max)) ;
    	/* Providing there are states to configure */
    	if((no_events > 0) && (no_events <= max))
    	{
      		/* Allocate enough memory to hold state/event configuration */
      		led_config_type* config = (led_config_type*) PanicUnlessMalloc(no_events * sizeof(led_config_type));
   
      		/* Now read in configuration */
   			if(ConfigRetrieve(pskey_config, config, no_events * sizeof(led_config_type)))
   			{
     			uint16    n;
     			LEDPattern_t  pattern;                   

     			/* Now we have the configuration, map to system states/events */
     			for(n = 0; n < no_events; n++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -