📄 f3xx_usb0_reporthandler.c
字号:
//-----------------------------------------------------------------------------
// USB0_ReportHandler.c
//-----------------------------------------------------------------------------
// Copyright 2005 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// Contains functions and variables dealing with Input and Output
// HID reports.
//
// How To Test: See Readme.txt
//
//
// FID:
// Target: C8051F340
// Tool chain: Keil C51 7.50 / Keil EVAL C51
// Silicon Laboratories IDE version 2.6
// Command Line: See Readme.txt
// Project Name: F3xx_MouseExample
//
// Release 1.1
// -Minor code comment changes
// -16 NOV 2006
// Release 1.0
// -Initial Revision (PD)
// -07 DEC 2005
//
// ----------------------------------------------------------------------------
// Header files
// ----------------------------------------------------------------------------
#include "F3xx_USB0_ReportHandler.h"
#include "F3xx_USB0_InterruptServiceRoutine.h"
#include "F3xx_USB0_Mouse.h"
// ----------------------------------------------------------------------------
// Local Function Prototypes
// ----------------------------------------------------------------------------
// ****************************************************************************
// Add custom Report Handler Prototypes Here
// ****************************************************************************
void IN_Report(void);
void OUT_Report(void);
// ----------------------------------------------------------------------------
// Local Definitions
// ----------------------------------------------------------------------------
// ****************************************************************************
// Set Definitions to sizes corresponding to the number of reports
// ****************************************************************************
#define IN_VECTORTABLESize 1
#define OUT_VECTORTABLESize 1
// ----------------------------------------------------------------------------
// Global Constant Declaration
// ----------------------------------------------------------------------------
// ****************************************************************************
// Link all Report Handler functions to corresponding Report IDs
// ****************************************************************************
const VectorTableEntry code IN_VECTORTABLE[IN_VECTORTABLESize] =
{
// FORMAT: Report ID, Report Handler
0, IN_Report
};
// ****************************************************************************
// Link all Report Handler functions to corresponding Report IDs
// ****************************************************************************
const VectorTableEntry code OUT_VECTORTABLE[OUT_VECTORTABLESize] =
{
// FORMAT: Report ID, Report Handler
0, OUT_Report
};
// ----------------------------------------------------------------------------
// Global Variable Declaration
// ----------------------------------------------------------------------------
BufferStructure IN_BUFFER, OUT_BUFFER;
// ----------------------------------------------------------------------------
// Local Functions
// ----------------------------------------------------------------------------
// ****************************************************************************
// Add all Report Handler routines here
// ****************************************************************************
// ****************************************************************************
// For Input Reports:
// Point IN_BUFFER.Ptr to the buffer containing the report
// Set IN_BUFFER.Length to the number of bytes that will be
// transmitted.
//
// REMINDER:
// Systems using more than one report must define Report IDs
// for each report. These Report IDs must be included as the first
// byte of an IN report.
// Systems with Report IDs should set the FIRST byte of their buffer
// to the value for the Report ID
// AND
// must transmit Report Size + 1 to include the full report PLUS
// the Report ID.
//
// ****************************************************************************
void IN_Report(void){
// save left mouse button stat to bit 0 of first data byte
IN_PACKET[0] = MOUSE_BUTTON;
// determine whether X-Axis or Y-Axis is active, then
// set MOUSE_VECTOR to active axis
if(MOUSE_AXIS == X_Axis) IN_PACKET[1] = MOUSE_VECTOR;
else IN_PACKET[1] = 0;
if(MOUSE_AXIS == Y_Axis) IN_PACKET[2] = MOUSE_VECTOR;
else IN_PACKET[2] = 0;
// point IN_BUFFER pointer to data packet and set
// IN_BUFFER length to transmit correct report size
IN_BUFFER.Ptr = IN_PACKET;
IN_BUFFER.Length = 3;
}
// ****************************************************************************
// For Output Reports:
// Data contained in the buffer OUT_BUFFER.Ptr will not be
// preserved after the Report Handler exits.
// Any data that needs to be preserved should be copyed from
// the OUT_BUFFER.Ptr and into other user-defined memory.
//
// ****************************************************************************
void OUT_Report(void)
{
}
// ----------------------------------------------------------------------------
// Global Functions
// ----------------------------------------------------------------------------
// ****************************************************************************
// Configure Setup_OUT_BUFFER
//
// Reminder:
// This function should set OUT_BUFFER.Ptr so that it
// points to an array in data space big enough to store
// any output report.
// It should also set OUT_BUFFER.Length to the size of
// this buffer.
//
// ****************************************************************************
void Setup_OUT_BUFFER(void)
{
}
// ----------------------------------------------------------------------------
// Vector Routines
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ReportHandler_IN...
// ----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - Report ID
//
// These functions match the Report ID passed as a parameter
// to an Input Report Handler.
// the ...FG function is called in the SendPacket foreground routine,
// while the ...ISR function is called inside the USB ISR. A lock
// is set whenever one function is called to prevent a call from the
// other from disrupting the routine.
// However, this should never occur, as interrupts are disabled by SendPacket
// before USB operation begins.
// ----------------------------------------------------------------------------
void ReportHandler_IN_ISR(unsigned char R_ID)
{
unsigned char index;
index = 0;
while(index <= IN_VECTORTABLESize)
{
// check to see if Report ID passed into function
// matches the Report ID for this entry in the Vector Table
if(IN_VECTORTABLE[index].ReportID == R_ID)
{
IN_VECTORTABLE[index].hdlr();
break;
}
// if Report IDs didn't match, increment the index pointer
index++;
}
}
void ReportHandler_IN_Foreground(unsigned char R_ID)
{
unsigned char index;
index = 0;
while(index <= IN_VECTORTABLESize)
{
// check to see if Report ID passed into function
// matches the Report ID for this entry in the Vector Table
if(IN_VECTORTABLE[index].ReportID == R_ID)
{
IN_VECTORTABLE[index].hdlr();
break;
}
// if Report IDs didn't match, increment the index pointer
index++;
}
}
// ----------------------------------------------------------------------------
// ReportHandler_OUT
// ----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// This function matches the Report ID passed as a parameter
// to an Output Report Handler.
//
// ----------------------------------------------------------------------------
void ReportHandler_OUT(unsigned char R_ID){
unsigned char index;
index = 0;
while(index <= OUT_VECTORTABLESize)
{
// check to see if Report ID passed into function
// matches the Report ID for this entry in the Vector Table
if(OUT_VECTORTABLE[index].ReportID == R_ID)
{
OUT_VECTORTABLE[index].hdlr();
break;
}
// if Report IDs didn't match, increment the index pointer
index++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -