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

📄 mouse.c

📁 基于STR711的PRCCU程序
💻 C
字号:
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name          : mouse.c
* Author             : MCD Application Team
* Date First Issued  : 27/10/2003
* Description        : USB Mouse demo main file
********************************************************************************/
#include "mouse.h"
#include "71x_lib.h"

#include "USB_lib.h"
#include "USB_conf.h"
#include "USB_prop.h"
#include "USB_pwr.h"

// directions of transfer for CopyBuffer
#define USR_TO_PMA 0
#define PMA_TO_USR 1

extern BOOL fCellSuspended;


/*******************************************************************************
* Function Name : gInit
* Description   : Hardware initialisation
* Input         : None
* Output        : None
* Return value  : None
*******************************************************************************/
void gInit(void)
{
  wInterrupt_Mask = IMR_MSK;

} /* gInit */


/*******************************************************************************
* Function Name : CopyBuffer
* Description   : Transfers a packet of data from/to PMA to/from user memory
* Input 1       : iTrDirection: USR_TO_PMA or PMA_TO_USR
* Input 2       : EpNum: endpoint number
* Input 3       : Usr_buffer: a pointer to user memory
* Input 4       : Nbytes: number of bytes to transfer
* Output        : None
* Return value  : None
*******************************************************************************/
void CopyBuffer(int iTrDirection, BYTE EpNum, BYTE *Usr_buffer, int Nbytes)
{
  DWORD *pTxBuff;
  WORD wTra;
  BYTE *pbTra;
  int i;

  if (iTrDirection == USR_TO_PMA)
  {
    pTxBuff = (DWORD *)(PMAAddr + (BYTE *)(GetEPTxAddr(EpNum)*2));
   	for(i = 0; i < Nbytes;)
   	{
	   	pbTra = (BYTE *)&wTra;
   		*pbTra++ = *Usr_buffer++;
   		i++;
   		if (i < Nbytes) /* check for ODD transfers */
	   		*pbTra = *Usr_buffer++;
	   	else
	   		*pbTra = 0;
   		*pTxBuff++ = wTra;
	   	i++;
	}
  }

} /* CopyBuffer */


/*******************************************************************************
* Function Name : Mouse_Send
* Description   : Decodes commands arriving from serial and
*                 prepares buffer to be sent containing mouse event infos
* Input 1       : deltaX: cursor delta X
* Input 2       : deltaY: cursor delta Y
* Input 3       : buttons: mouse buttons status
* Output        : None
* Return value  : None
*******************************************************************************/
void Mouse_Send(int deltaX, int deltaY, int buttons)
{
	BYTE Mouse_Buffer[3];

	/* prepare buffer to send */
	Mouse_Buffer[0] = buttons;
	Mouse_Buffer[1] = deltaX;
	Mouse_Buffer[2] = deltaY;
	CopyBuffer(USR_TO_PMA, ENDP1, Mouse_Buffer, 3);

	/* enable endpoint for transmission */
	SetEPTxAddr(ENDP1, ENDP1_TXADDR);
	SetEPTxCount(ENDP1, 4);
	SetEPTxValid(ENDP1);
} /* Mouse_Send */


/*******************************************************************************
* Function Name : Keys_Read
* Description   : Checks if a new character from terminal has arrived
* Input 1       : deltaX: cursor delta X
* Input 2       : deltaY: cursor delta Y
* Input 3       : buttons: mouse buttons status
* Output        : None
* Return value  : None
*******************************************************************************/
void Mouse_Action(int deltaX, int deltaY, int buttons)
{
	if (fCellSuspended)
		Resume(RESUME_INTERNAL);	// remote wake-up
	else
		Mouse_Send(deltaX, deltaY, buttons);
}

void Mouse_Init(void)
{
	XTI_Init();
	GPIO_Config(GPIO2, 1<<8, GPIO_INOUT_WP);
	XTI_LineModeConfig(XTI_Line2, XTI_FallingEdge);
	XTI_LineConfig(XTI_Line2, ENABLE);
	XTI_ModeConfig(XTI_Interrupt, ENABLE);
	EIC_IRQChannelPriorityConfig(XTI_IRQChannel, 1);
	EIC_IRQChannelConfig(XTI_IRQChannel, ENABLE);

	gInit();  /* init hardware */

	USB_Init();
}

⌨️ 快捷键说明

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