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

📄 app_led.c

📁 实现蓝牙无线 USB适配器功能
💻 C
字号:
/* Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006 */
/* Part of BlueLab 3.6.2-release */
#include "app_private.h"
#include "app_led.h"

#include <pio.h>

#define LED_PIO (7)

enum
{
    LED_INTERNAL_UPDATE
};

/*************************************************************************
NAME    
DESCRIPTION
RETURNS
*/
static void ledHandleInternalUpdate(ledTaskData *theLed)
{
    if (theLed->onPeriod < 0)
        theLed->state = (1 << LED_PIO);
    else if (theLed->offPeriod < 0)
        theLed->state = 0;
    else
        theLed->state ^= (1 << LED_PIO);
        
    PioSet(1 << LED_PIO, theLed->state);
    
    if (theLed->state)
    {
        if (theLed->onPeriod > 0)
            MessageSendLater(&theLed->task, LED_INTERNAL_UPDATE, 0, theLed->onPeriod);
    }
    else
    {
        if (theLed->offPeriod > 0)
            MessageSendLater(&theLed->task, LED_INTERNAL_UPDATE, 0, theLed->offPeriod);
    }            
}

/*************************************************************************
NAME    
DESCRIPTION
RETURNS
*/
static void ledHandler(Task task, MessageId id, Message message)
{
    if (id == LED_INTERNAL_UPDATE)
        ledHandleInternalUpdate((ledTaskData *)task);
}

/*************************************************************************
NAME    
DESCRIPTION
RETURNS
*/
void LedInit(ledTaskData *theLed, appDongleTaskData *theApp)
{
    theLed->task.handler = ledHandler;
    theLed->state = 0;
    theLed->priority = -1;   
    PioSetDir(1 << LED_PIO, 1 << LED_PIO);
    PioSet(1 << LED_PIO, 0);
}

/*************************************************************************
NAME    
DESCRIPTION
RETURNS
*/
void LedUpdate(ledTaskData *theLed, int onPeriod, int offPeriod, uint8 priority)
{
    theLed->onPeriodTable[priority] = onPeriod;
    theLed->offPeriodTable[priority] = offPeriod;
    
    LedSetPriority(theLed, priority);
}

/*************************************************************************
NAME    
DESCRIPTION
RETURNS
*/
void LedSetPriority(ledTaskData *theLed, uint8 priority)
{
    theLed->onPeriod = theLed->onPeriodTable[priority];
    theLed->offPeriod = theLed->offPeriodTable[priority];
    theLed->priority = priority;
        
    /* Cancel LED update message */
    MessageCancelAll(&theLed->task, LED_INTERNAL_UPDATE);
       
    /* Post update message to LED task */
    MessageSend(&theLed->task, LED_INTERNAL_UPDATE, 0);
}

⌨️ 快捷键说明

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