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

📄 usbio.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      All Rights Reserved.                                                */
/*                                                                          */
/*  Property of Texas Instruments Incorporated. Restricted Rights -         */
/*  Use, duplication, or disclosure is subject to restrictions set          */
/*  forth in TI's program license agreement and associated documentation.   */
/****************************************************************************/

/****************************************************************************/
/* usbIO.c                                                                  */
/*                                                                          */
/* Projector to host USB interface. Three interface modes are provided:     */
/*                                                                          */
/*      User mode: The following endpoints are included:                    */
/*                  [0] - USB control endpoint                              */
/*                  [1] - Emulated mouse                                    */
/*                  [2] - Emulated keyboard                                 */
/*                                                                          */
/*   Factory mode: Provided if the symbol __NO_FACTORYMODE_USB is not de-   */
/*                 fined at compile time. When defined, the following end   */
/*                 points are provided:                                     */
/*                  [0] - USB control endpoint                              */
/*                  [1] - Host projector control                            */
/*                  [2] - Host RFC (remote function call)                   */
/*                  [3] - Emulated mouse                                    */
/*                  [4] - emulated keyboard                                 */
/*                                                                          */
/*                 The RFC endpoint is used for TI qualification testing.   */
/****************************************************************************/

#include <string.h>

#include "ddp2230_rtos_include.h"

#include "common.h"
#include "tmr.h"
#include "usb.h"

#include "global.h"
#include "sysmon.h"
#include "taskParm.h"
#include "usbIO.h"
#include "usb_descriptor.h"
#include "dbmessage.h"
#include "iox.h"

#define USBMAIN_EVT_MASK    0x0003FFFF               /* USB task event mask */

                                /********************************************/
                                /* Flags and state indications              */
                                /********************************************/

volatile uint08 USB_Mode;                              /* user/factory mode */
volatile BOOL   USB_Mode_Changed;                   /*mode-has-changed flag */
uint32          ID_USBEvent;                                /* USB event ID */
uint32          usbTaskID;                                   /* USB task ID */
uint32          USB_MouseEP;                       /* mouse endpoint number */
uint32          USB_KeyBoardEP;                 /* keyboard endpoint number */

BOOL USBMAIN_Ep1DataRequested;             /* ep1 pending data request flag */
BOOL USBMAIN_Ep2DataRequested;             /* ep2 pending data request flag */
BOOL USBMAIN_Ep3DataRequested;             /* ep3 pending data request flag */
BOOL USBMAIN_Ep4DataRequested;             /* ep4 pending data request flag */

                                /********************************************/
                                /* Mouse/key control blocks and buffers.    */
                                /* The buffers are 4-byte aligned per USB   */
                                /* driver requirements.                     */
                                /********************************************/

USBMAIN_MOUSE_DATA    Ep_MouseData;           /* mouse buffer control block */
USBMAIN_KEYBOARD_DATA Ep_KeyboardData;     /* keyboard buffer control block */

__align(4) uint08 mouseDataBuffer[8];                  /* mouse data buffer */
__align(4) uint08 keyboardDataBuffer[8];            /* keyboard data buffer */

                                /********************************************/
                                /* Data comm control blocks and buffers.    */
                                /* The buffers are 4-byte aligned per USB   */
                                /* driver requirements.                     */
                                /*                                          */
                                /* The control endpoint uses fixed tx/rx    */
                                /* buffers for all configurations.          */
                                /*                                          */
                                /* The projector control interface and the  */
                                /* RFC interface (when configured) read     */
                                /* one block at a time and assemble com-    */
                                /* plete messages at the application level. */
                                /* Thus only a FIFO-sized receive buffer is */
                                /* needed. Transmit buffers are allocated   */
                                /* in the application and pointers are      */
                                /* passed to the USB driver.                */
                                /*                                          */
                                /* Three USBMAIN_EP_DATA structures are al- */
                                /* ways allocated, but may not all be used, */
                                /* depending on the build mode. Only those  */
                                /* data buffers needed by the selected      */
                                /* build mode are allocated.                */
                                /********************************************/

USBMAIN_EP_DATA Ep_Data[3];

__align(4) uint08 EP_Ctrl_send[64];              /* control EP send to host */
__align(4) uint08 EP_Ctrl_recv[64];         /* control EP receive from host */

#ifndef __NO_FACTORYMODE_USB
    __align(4) uint08 EP_PCtl_recv[64];   /* projector control host receive */
    __align(4) uint08 EP_RFC_recv [64];                 /* RFC host receive */
#endif

                                /********************************************/
                                /* Polled HID data rates, in milliseconds.  */
                                /* Set by host Set_Idle request. Defines    */
                                /* the rate at which updates are sent if no */
                                /* change in HID parameters.                */
                                /********************************************/

uint16 MOUSE_HID_Idle_Rate;
uint16 KEYBOARD_HID_Idle_Rate;

uint08 MOUSE_HID_Timer_Id    = NULL;     /* timer ID when polling mouse HID */
uint08 KEYBOARD_HID_Timer_Id = NULL;  /* timer ID when polling keyboard HID */


/****************************************************************************/
/* The following events and semaphores are used to transfer messages from   */
/* the host to the projector communication tasks:                           */
/*                                                                          */
/*   - The projector task receiving messages blocks waiting for the event   */
/*     to be set. The event is set by the USB receiver to indicate that     */
/*     message data are available.                                          */
/*                                                                          */
/*   - When the USB receiver task is signalled that a packet is available,  */
/*     it blocks until it obtains the semaphore before copying received     */
/*     data from the USB FIFO to the application buffer space. The sema-    */
/*     phore is released by the comm task when it has parsed the buffer.    */
/****************************************************************************/

uint32 ID_USBCmd_Event;                                /* projector control */
uint32 ID_USBCmd_Sem;

uint32 ID_USBPeer_Event;                       /* peer remote function call */
uint32 ID_USBPeer_Sem;



static const char usbIOTaskName[] = "usbIOTask";               /* Task name */



/****************************************************************************/
/* Forward function declarations.                                           */
/****************************************************************************/

void  USBMAIN_Task( void );
void  USBMAIN_FactoryModeProcessEvent(void );
void  USBMAIN_UserModeProcessEvent( void );
int08 USBMAIN_HidGetIdleRecv( uint08 Ep, uint16 interface );
int08 USBMAIN_SetEpDataRequested( uint08 Ep, BOOL Data_Request_Pending );
BOOL  USBMAIN_GetEpDataRequested( uint08 Ep );
int08 USBMAIN_SetConfiguration( void );

void  USBMAIN_MouseIdleISR( void );
void  USBMAIN_KeyboardIdleISR( void );



/****************************************************************************/
/* Initialize and create USB tak.                                           */
/****************************************************************************/

EXEC_CC_ENUM usbIO_init( void )
{
    iox_cfgSet( IOX_PINCFG( IOX_D1_RED, IOX_OUT, IOX_FALSE ));/* config LED */

    USBMAIN_Ep1DataRequested = FALSE;  /* Set FALSE to ensure clean restart */
    USBMAIN_Ep2DataRequested = FALSE;
    USBMAIN_Ep3DataRequested = FALSE;
    USBMAIN_Ep4DataRequested = FALSE;

    /* Create events used to pass USB packets to command and peer processor */

    if( RTA_SUCCESS  != RTA_EventCreate( &ID_USBCmd_Event,"ucev" ))
        return TRUE;

    if( RTA_SUCCESS  != RTA_EventCreate( &ID_USBPeer_Event,"upev" ))
        return TRUE;

    if( RTA_SUCCESS  != RTA_SemCreate( &ID_USBCmd_Sem,"ucsm" ))
        return TRUE;

    if( RTA_SUCCESS  != RTA_SemCreate( &ID_USBPeer_Sem,"upsm" ))
        return TRUE;

    RTA_EventClear( ID_USBCmd_Event );             /* ensure event is clear */
    RTA_EventClear( ID_USBPeer_Event );            /* ensure event is clear */

    if( RTA_SUCCESS != RTA_TaskCreate( USBMAIN_Task, &usbTaskID,
        PRIORITY_USB, STACK_USB, "usb ", 0 ))
            return TRUE;

    return FALSE;
}



/****************************************************************************/
/* Return task information.                                                 */
/****************************************************************************/

void usbIO_info( TASKINFO_STRUCT *info )
{
    info -> taskID    = usbTaskID;
    info -> stackSize = STACK_USB;
    info -> taskName  = usbIOTaskName;
}



/****************************************************************************/
/* IR mouse/keyboard activity report.                                       */
/*                                                                          */
/* called by the GUI when IR remote control mouse activity is detected.     */
/****************************************************************************/

void usbIO_IRReport( UIREP *pRep )
{
    uint08         kd;                              /* button/key data byte */
    BOOL           isMouse     = TRUE;     /* assume this is a mouse report */
    USB_DEV_STATES deviceState = USB_GetDeviceState();
    
    switch( pRep -> key )
    {
                                /********************************************/
                                /* Keycode report.                          */
                                /********************************************/

        case KCODE_IR_LEFT_ARROW:
            kd = 0x4B;                                     /* 0x4B = PageUp */
            isMouse = FALSE;
            break;

        case KCODE_IR_RIGHT_ARROW:
            kd = 0x4E;                                   /* 0x4E = PageDown */
            isMouse = FALSE;
            break;
                                /********************************************/
                                /* Mouse report.                            */
                                /********************************************/

        case KCODE_IR_LEFTCLICK:
            kd = 0x01;                                  /* left button down */
            break;

        case KCODE_IR_RIGHTCLICK:
            kd = 0x02;                                 /* right button down */
            break;

        case KCODE_IR_LEFTRIGHT:
            kd = 0x03;                                 /* both buttons down */
            break;

        case KCODE_IR_NOBUTTON:
            kd = 0x00;                                   /* no buttons down */
            break;

                                /********************************************/
                                /* Unexpected.                              */
                                /********************************************/
        default:
            return;
    }

                                /********************************************/
                                /* Initiate wakeup if bus is suspended.     */
                                /********************************************/

    if( deviceState == USB_SUSPEND )
    {
        USB_ResumeSignalling(TRUE);
        TMR_Delay(5000);                                       /* 5000 usec */
        USB_ResumeSignalling(FALSE);
    }

                                /********************************************/
                                /* Format and send response if requested.   */
                                /*                                          */
                                /* Restart the idle timer, if idle reports  */

⌨️ 快捷键说明

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