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

📄 headset_pio.c

📁 bluelab的一个很好的例程
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004

FILE NAME
    headset_LEDs.c
    
DESCRIPTION


*/

#include "headset_pio.h"

#include "headset_private.h"

#include <pio.h>



#ifdef DEBUG_PIO
#define PIO_DEBUG(x)  DEBUG (x)
#else
#define PIO_DEBUG(x) 
#endif

/****************************************************************************
NAME	
	LEDManagerSetPowerPin

DESCRIPTION
    controls the internal regulators to latch / remove the power on state
    
RETURNS
	void
*/
void PioSetPowerPin ( hsTaskData * pApp , PowerPin_t pEnable ) 
{

    bool lVal = (bool) pEnable ;
    

    if ( pApp->features.PowerOnSMPS)
    {
        /*this is the power regulator PIO*/
        PioSetPsuRegulator ( lVal ) ; 
        PIO_DEBUG(("PIO : PowerOnSMPS\n")) ;
    }
    
    if  ( pApp->features.PowerOnLDO)
    {
        PioSetInternalLDO ( lVal ) ;
        PIO_DEBUG(("PIO : PowerOn LDO\n")) ;
    }    
}

void PioSetLedPin ( LedTaskData * pLedTask , uint16 pPIO , bool pOnOrOff ) 
{
   /*special LED pins are special cases*/
    if ( pPIO == 14)        
    {
        PioSetLed0 ( pOnOrOff ) ;
        pLedTask->gLED_0_STATE = pOnOrOff ;
    }
    else if (pPIO == 15 )
    {
        PioSetLed1 ( pOnOrOff ) ;
        pLedTask->gLED_1_STATE = pOnOrOff ;
    }
    else
    {
        PioSetPin (pPIO , pOnOrOff) ;
    }
}


/****************************************************************************
NAME	
	LEDManagerUpdateLED

DESCRIPTION
    Fn to change an individual LED state 
    
RETURNS
	void
*/


void PioSetPin ( uint16 pPIO , bool pOnOrOff  ) 
{
    uint16 lPinVals = 0 ;
    
    uint16 lWhichPin  = 1 << pPIO ;
    

    PIO_DEBUG(("PIO : set[%d][%d] [%x]\n",pPIO, pOnOrOff ,lWhichPin)) ;
    
    if ( pOnOrOff == TRUE )    
    {
        lPinVals = lWhichPin  ;
    }
    else
    {
        lPinVals = 0x0000;
            /*clr the corresponding bit*/
    }
    
    PIO_DEBUG(("PIO : set[%x][%x]\n",lWhichPin , lPinVals)) ;
    
    PioSetPinAsOutput(pPIO) ;        
    PioSet (  lWhichPin , lPinVals ) ;     
}

bool PioGetLedPin ( LedTaskData * pLedTask , uint16 pPIO ) 
{
    bool lState = FALSE ;
        /*special LED pins are special cases*/
    if ( pPIO == 14)        
    {
        lState = pLedTask->gLED_0_STATE ;
    }
    else if (pPIO == 15 )
    {
        lState =    pLedTask->gLED_1_STATE ;
    }
    else
    {
        lState = PioGetPin( pPIO ) ;
    }
    
    return lState ;
}

/****************************************************************************
NAME	
	LEDManagerGetLEDState

DESCRIPTION
    Fn to get the state of an individual LED     
    
RETURNS
	bool On or OFF
*/
bool PioGetPin (  uint16 pPIO )
{
    bool lState = FALSE ;
    uint16 lMask  = 0;
    
    lMask = PioGet ( ) ;
    
    PIO_DEBUG(("PIO : g[%d] p[%d] [%d] ",lMask , pPIO , (lMask & (1<<pPIO)))) ;
    
    if ( lMask & (1<<pPIO) )
    {
        lState = TRUE ;
    }
    
    PIO_DEBUG(("PIO :get[%d]l[%d]\n" , pPIO,lState)) ;
        
    return lState ;
}


/****************************************************************************
NAME	
	PioSetPinAsOutput

DESCRIPTION
    Fn to set a PIO as an output pin ( DDR)    
    
RETURNS
	void
*/
void PioSetPinAsOutput ( uint16 pPIO )
{
        /*(mask,bits) setting bit to a '1' sets the corresponding port as an output*/
    uint16 lMask = (1<<pPIO) ;
    PioSetDir(lMask,lMask);   
}



/****************************************************************************
NAME	
	PioSetInternalLDO

DESCRIPTION
    Fn to set the internal LDO pin  
    
RETURNS
	void
*/
void PioSetInternalLDO ( bool pEnable)
{
    PioSetMicBias ( pEnable ) ;
    PIO_DEBUG(("PIO : InternalLDO[%c]\n", pEnable ? 'T' :'F')) ;    
}


⌨️ 快捷键说明

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