av_headset_led.c

来自「csr 蓝牙芯片 无线蓝牙耳机的嵌入式程序」· C语言 代码 · 共 93 行

C
93
字号
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004

FILE NAME
    headset_led.c

DESCRIPTION
    Control of board LEDs depending on the current state

NOTES

*/


/****************************************************************************
    Header files
*/
#include "av_headset_private.h"
#include "av_headset_led.h"

#include <pio.h>
#include <message.h>


#define LED_PAIRING_TIME_ON             250
#define LED_STREAMING_TIME_ON           500
#define LED_IDLE_ON                     100

#define LED_PAIRING_TIME_OFF            250
#define LED_STREAMING_TIME_OFF          1000
#define LED_IDLE_OFF                    1000

/*
    Function call periodically to update the flashing
    LED and set the next callback time
*/

static uint32 ledCallback(ledState state)
{
    bool on = (PioGet() & LED?TRUE:FALSE);
            
    if (on)
    {
        PioSet(LED,0);

        if (state & led_pairing)				/*lint !e655 */
            return LED_PAIRING_TIME_OFF;
        if (state & led_streaming)				/*lint !e655 */
            return LED_STREAMING_TIME_OFF;
        
        return LED_IDLE_OFF;
    }
    else
    {
        PioSet(LED,LED);

        if (state & led_pairing)				/*lint !e655 */
            return LED_PAIRING_TIME_ON;	
        if (state & led_streaming)				/*lint !e655 */
            return LED_STREAMING_TIME_ON;
        
        return LED_IDLE_ON;
    }
}

/*
    Start the LED flashing
*/
void startLED(ledState state)
{
    PioSetDir(LED,LED);
    PioSet(LED,0);

    /* call timer function ASAP */
    MessageSendLater(getAppTask(), LED_UPDATE_REQUIRED, 0, ledCallback(state));
}

/*
    Force LED to pick up state change immediately.
*/
ledState updateLED(const avTaskData *app, ledState state)
{
    ledState s = state;
    
    if ((app->a2dp_state == avHeadsetA2dpStreaming))
        s |= led_streaming;				/*lint !e655 */
    
    MessageSendLater(getAppTask(), LED_UPDATE_REQUIRED, 0, ledCallback(s));
    
    return s;
}

⌨️ 快捷键说明

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