mouse.c
资源名称:str711USB.rar [点击查看]
上传用户:yyyd609
上传日期:2022-07-18
资源大小:183k
文件大小:4k
源码类别:
微处理器开发
开发平台:
C/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();
- }