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

📄 zkbgetkey.c

📁 基于Jennic公司Zigbee芯片JN5139做的无线键盘项目源码
💻 C
字号:
/*****************************************************************************
 *
 * MODULE:              PS2 Keyboard Key Code Sequencer
 *
 * COMPONENT:           $RCSfile$
 *
 * VERSION:             $Name$
 *
 * REVISION:            $Revision$
 *
 * DATED:               $Date$
 *
 * STATUS:              $State$
 *
 * AUTHOR:              APV Ward
 *
 * DESCRIPTION:
 * handles the application interface to the PS2 socket service.
 *
 * LAST MODIFIED BY:    $Author$
 *                      $Modtime$
 *
 ****************************************************************************
 *
 * This software is owned by Jennic and/or its supplier and is protected
 * under applicable copyright laws. All rights are reserved. We grant You,
 * and any third parties, a license to use this software solely and
 * exclusively on Jennic products. You, and any third parties must reproduce
 * the copyright and warranty notice and any other legend of ownership on each
 * copy or partial copy of the software.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS". JENNIC MAKES NO WARRANTIES, WHETHER
 * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
 * ACCURACY OR LACK OF NEGLIGENCE. JENNIC SHALL NOT, IN ANY CIRCUMSTANCES,
 * BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, SPECIAL,
 * INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER.
 *
 * Copyright Jennic Ltd 2005, 2006. All rights reserved
 *
 ****************************************************************************/

/****************************************************************************/
/***        Include files                                                 ***/
/****************************************************************************/

#include "jendefs.h"

#include "ZKBgetKey.h"
#include "PS2keyCodes.h"
#include "PS2socket.h"

/****************************************************************************/
/***        Local Variables                                               ***/
/****************************************************************************/

/****************************************************************************/
/***        Local functions                                               ***/
/****************************************************************************/

/****************************************************************************
 *
 * NAME: u16ZKBgetKey
 *
 * DESCRIPTION:
 * Reads keycodes from PS2 keyboard using the PS2 socket service.
 * Reads one PS2 code at a time, so this function would need to be called at
 * least three times to build a (typical) three-byte code sequence.
 * Between bytes the bus is disabled, thereby allowing control to return
 * to the ZigBee stack.
 *
 * PARAMETERS:      none
 *
 * RETURNS:         uint16: either KBD_NO_KEY_PRESS or 8 bit key code
 *
 ****************************************************************************/

    /* key sequence consists of:                                */
    /*  KEY PRESS code                                          */
    /*  BREAK CODE (0xF0)                                       */
    /*  KEY PRESS code (again)                                  */
    /*                                                          */

PUBLIC uint16 u16ZKBgetKey(void)
{
    uint16 u16kbdstatus = KBD_NO_KEY_PRESS;

    /* enable the PS2 bus */
    vPS2socketBusEnable();

	if ( boPS2socketBusReady() )  /* if keyboard is not asserting RTS */
	{
		u16kbdstatus = u16PS2socketRead();    /* read key codes */

		if (u16kbdstatus & PS2_SOCKET_ERROR_MASK)
		{
			/* either no key press or PS2 bus error, errors are ignored */
			u16kbdstatus = KBD_NO_KEY_PRESS;
		}
		else
		{
			/* good PS2 scan, keycode is in lower byte */
			u16kbdstatus &= PS2_SOCKET_KEYCODE_MASK;
		}
	}

    /* inhibit the  PS2 bus */
    vPS2socketBusDisable();

    return u16kbdstatus;
}


/****************************************************************************/
/***        END OF FILE                                                   ***/
/****************************************************************************/

⌨️ 快捷键说明

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