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

📄 hid_keyboard_events.c

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

FILE NAME
    hid_keyboard_events.c        
DESCRIPTION
    This file contains the functions to handle HID events.
NOTES

*/

/****************************************************************************
    Header files
*/
#include "hid_keyboard.h"
#include "hid_keyboard_sm.h"
#include "hid_keyboard_events.h"

/*************************************************************************
NAME    
    appHandleHidSetReportInd   
DESCRIPTION
    Handles HID_SET_REPORT packets.  Updates status LEDs
RETURNS
    void     
*/
void appHandleHidSetReportInd(appTaskData *theApp, HID_SET_REPORT_IND_T *ind, bool respond)
{
	MAIN_PRINT(("appHandleHidSetReportInd\n"));
    
    /* Check it's the correct report type and correct length (Note that the host
       can append random data to the end of a packet) */
	if ((ind->report_type == hid_report_output) && (ind->report_length >= 2))
	{
		/* Check for our report ID */
		if (ind->report_data[0] == 1)
		{
			uint16 leds = 0;

			/* Store the passed state for later */
			theApp->keyboard_led_state = ind->report_data[1] & 7;			

#ifdef LED_AUX_DAC
            /* Check NUM LOCK status */
			PioSetAuxDac(TRUE, ind->report_data[1] & 0x01 ? 0xFF : 0x00);
#else
            /* Check NUM LOCK status */
			if (ind->report_data[1] & 0x01)
				leds |= LED_MASK_NUM_LOCK;
#endif                
            /* Check CAPS LOCK status */
			if (ind->report_data[1] & 0x02)
				leds |= LED_MASK_CAPS_LOCK;
                
            /* Check SCROLL LOCK status */
			if (ind->report_data[1] & 0x04)
				leds |= LED_MASK_SCROLL_LOCK;

            /* Update LEDs */
			PioSet(LED_MASK_NUM_LOCK | LED_MASK_CAPS_LOCK | LED_MASK_SCROLL_LOCK, leds);

            /* Send response */
            if (respond)
                HidSetReportResponse(theApp->hid, hid_success);
		}
		else
        {
			/* Invalid report ID */
            if (respond)
    			HidSetReportResponse(theApp->hid, hid_invalid_id);
        }
	}
	else
    {
		/* Unexpected */
        if (respond)
    		HidSetReportResponse(theApp->hid, hid_invalid_param);
    }
}

/*************************************************************************
NAME    
    appHandleHidGetReportInd   
DESCRIPTION
    Handles HID_GET_REPORT packets.
RETURNS
    void     
*/
void appHandleHidGetReportInd(appTaskData *theApp, HID_GET_REPORT_IND_T *ind)
{
	MAIN_PRINT(("appHandleHidGetReportInd\n"));
    
	/* Check if it is an input report */
	if (ind->report_type == hid_report_input)
	{
		/*
			We only support one report which has an ID of 1.
			This will also be the case in boot mode.

			Note that we deliberately don't respond to requests
			for the PIN entry report because it is only active for
			a very short time.
		*/
		if (ind->report_id == 1)
		{
            uint8 data[9];
            uint16 length;
            
            /* We don't know the current state, so we send an "empty report" */
			data[0] = 1;
            
			/* Clip length to only send what fits in Host's buffer */
			length = (ind->report_length < 9) ? ind->report_length : 9;
            
            /* Send response */
            HidGetReportResponse(theApp->hid, hid_success, hid_report_input, length, data);
		}
		else
        {
			/* This is not a valid report ID */
            HidGetReportResponse(theApp->hid, hid_invalid_id, hid_report_input, 0, NULL);
        }
	}
	/* Check if it is an output report? */
	else if (ind->report_type == hid_report_output)
	{
		/* Check if LED report */
		if (ind->report_id == 1)
		{
            uint8 data[1];
            uint16 length;

    		/* Copy current LED state */
            data[0] = theApp->keyboard_led_state;
            
			/* Clip length to only send what fits in Host's buffer */
			length = (ind->report_length < 1) ? ind->report_length : 1;
            
            /* Send response */
            HidGetReportResponse(theApp->hid, hid_success, hid_report_output, length, data);
		}
		else
        {
			/* This is not a valid report ID */
            HidGetReportResponse(theApp->hid, hid_invalid_id, hid_report_output, 0, NULL);
        }
	}
	else
	{
		/* Return invalid param for any other report type */
        HidGetReportResponse(theApp->hid, hid_invalid_param, hid_report_output, 0, NULL);
	}
}

/*************************************************************************
NAME    
    appHandleHidSetIdleInd   
DESCRIPTION
    Handles HID_SET_IDLE packets.
RETURNS
    void     
*/
void appHandleHidSetIdleInd(appTaskData *theApp, HID_SET_IDLE_IND_T *ind)
{
	MAIN_PRINT(("appHandleHidSetIdleInd\n"));
    
    /* We don't want to enter an idle mode which could cause us to run at a
       very high rate.  We therefore only allow a zero value or one greater
       than 5 (>20ms) */
    if ((ind->idle_rate == 0) || (ind->idle_rate >= 5))
	{
        /* Update the accepted idle rate */
    	theApp->keyboard_idle_rate = ind->idle_rate;
        
        /* Configure HID source with new idle rate */
    	SourceConfigure(StreamHidSource(), VM_SOURCE_HID_IDLE_MODE, theApp->keyboard_idle_rate);                
        
#ifdef HW_CASIRA_UART
		/* If we are in IDLE mode (non-zero value), we need to signal this
           to the external procesor.  The processor should see this and send
           the current keystate every poll from the UART interface */
		if (ind->idle_rate != 0)
			PioSet(HID_MASK_IDLE_MODE, HID_MASK_IDLE_MODE);
		else
			PioSet(HID_MASK_IDLE_MODE, 0);
#endif

        /* Send response */
        HidSetIdleResponse(theApp->hid, hid_success);
    }
    else
    {
        /* Invalid parameter */
        HidSetIdleResponse(theApp->hid, hid_invalid_param);
    }    
}

/*************************************************************************
NAME    
    appHandleHidGetIdleInd   
DESCRIPTION
    Handles HID_GET_IDLE packets.
RETURNS
    void     
*/
void appHandleHidGetIdleInd(appTaskData *theApp, HID_GET_IDLE_IND_T *ind)
{
	MAIN_PRINT(("appHandleHidGetIdleInd\n"));
    
    /* Send response */
    HidGetIdleResponse(theApp->hid, hid_success, theApp->keyboard_idle_rate);
}

/*************************************************************************
NAME    
    appHandleHidSetProtocolInd   
DESCRIPTION
    Handles HID_SET_PROTOCOL packets.
RETURNS
    void     
*/
void appHandleHidSetProtocolInd(appTaskData *theApp, HID_SET_PROTOCOL_IND_T *ind)
{
	MAIN_PRINT(("appHandleHidSetProtocolInd\n"));
    
	/* Store the protocol */
	theApp->keyboard_protocol = ind->protocol;
    
    /* Send response */
    HidSetProtocolResponse(theApp->hid, hid_success);    
}

/*************************************************************************
NAME    
    appHandleHidGetProtocolInd   
DESCRIPTION
    Handles HID_GET_PROTOCOL packets.
RETURNS
    void     
*/
void appHandleHidGetProtocolInd(appTaskData *theApp, HID_GET_PROTOCOL_IND_T *ind)
{
	MAIN_PRINT(("appHandleHidGetReportInd\n"));
    
    /* Send response */
    HidGetProtocolResponse(theApp->hid, hid_success, theApp->keyboard_protocol);
}

/*************************************************************************
NAME    
    appHandleHidControlInd   
DESCRIPTION
    Handles HID_CONTROL packets.
RETURNS
    void     
*/
extern void appHandleHidControlInd(appTaskData *theApp, HID_CONTROL_IND_T *ind)
{
	MAIN_PRINT(("appHandleHidControlInd\n"));

    switch (ind->operation)
    {
        case hid_control_op_hard_reset:
        case hid_control_op_soft_reset:
        {
            /* Panic VM, this should cause a reset */
            Panic();
        }
        break;

        case hid_control_op_suspend:
        {
            /* We should just disconnect */
            appSetState(theApp, appCabledDisconnecting);
        }
        break;

        default:
            break;
    }
}

⌨️ 快捷键说明

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