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

📄 hid_keyboard_led.c

📁 CSR蓝牙无线键盘源码,实现无线键盘功能
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006
Part of BlueLab 3.5.2-release

FILE NAME
    hid_led.c        
DESCRIPTION
    This file contains the LED control task.
NOTES

*/

/****************************************************************************
    Header files
*/
#include "hid_keyboard.h"
#include <pio.h>

/* Defines which PIOs are used for status LED */
#define LED_PIO_MASK (LED_MASK_NUM_LOCK | LED_MASK_CAPS_LOCK | LED_MASK_SCROLL_LOCK)

/* Internal messages */
enum
{
    LED_INTERNAL_UPDATE
};


static void appLedHandleInternalUpdate(appLedTaskData *theLed)
{
    if (theLed->onPeriod < 0)
        theLed->state = (LED_PIO_MASK);
    else if (theLed->offPeriod < 0)
        theLed->state = 0;
    else
        theLed->state ^= (LED_PIO_MASK);
        
    PioSet(LED_PIO_MASK, theLed->state);
#ifdef LED_AUX_DAC
	PioSetAuxDac(TRUE, theLed->state ? 0xFF : 0x00);
#endif

    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);
    }            
}

static void appLedHandler(Task task, MessageId id, Message message)
{
    if (id == LED_INTERNAL_UPDATE)
        appLedHandleInternalUpdate((appLedTaskData *)task);
}

void appLedInit(appLedTaskData *theLed)
{
    theLed->task.handler = appLedHandler;
    theLed->state = 0;
    theLed->priority = -1;   
    PioSetDir(LED_PIO_MASK, LED_PIO_MASK);
    PioSet(LED_PIO_MASK, 0);
#ifdef LED_AUX_DAC
	PioSetAuxDac(TRUE, 0);
#endif
}

void appLedUpdate(appLedTaskData *theLed, int onPeriod, int offPeriod, uint8 priority)
{
    theLed->onPeriodTable[priority] = onPeriod;
    theLed->offPeriodTable[priority] = offPeriod;
    
    appLedSetPriority(theLed, priority);
}

void appLedSetPriority(appLedTaskData *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 + -