📄 f3xx_usb0_reporthandler.c
字号:
/* Copyright (c) 2007 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of
* Nordic Semiconductor. The use, copying, transfer or disclosure
* of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*/
/** @file
*
* Functions for seding USB reports. This file is originally a template
* from a SiLabs Application Note. It has been adapted to satisfy the needs of
* this application. Documentation blocks for automatical generaion of
* documentation have not been added. However, the source code has useful
* comments.
*
* @author Runar Kjellhaug
* @author Eirik Midttun
*
* @addtogroup usb_code
* @{
*/
//-----------------------------------------------------------------------------
// F3xx_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: C8051F3xx
// Tool chain: Keil C51 7.50 / Keil EVAL C51
// Silicon Laboratories IDE version 2.6
// Command Line: See Readme.txt
// Project Name: F3xx_FirmwareTemplate
//
// Release 1.1
// - Minor changes to F3xx_USB0_Descriptor.c
// - 16 NOV 2006
// Release 1.0
// -Initial Revision (PD)
// -07 DEC 2005
//
// ----------------------------------------------------------------------------
// Header files
// ----------------------------------------------------------------------------
#include "f3xx_usb0_reporthandler.h"
// ----------------------------------------------------------------------------
// Local Function Prototypes
// ----------------------------------------------------------------------------
// ****************************************************************************
// Add custom Report Handler Prototypes Here
// ****************************************************************************
void OUT_Report(void);
void mouse_report(void);
void keyb_report(void);
void rc_report(void);
// ----------------------------------------------------------------------------
// Global Constant Declaration
// ----------------------------------------------------------------------------
// ****************************************************************************
// Link all Report Handler functions to corresponding Report IDs
// ****************************************************************************
const VectorTableEntry code IN_VECTORTABLE[IN_VECTORTABLESize] =
{
0, mouse_report,
1, keyb_report,
2, rc_report
};
// ****************************************************************************
// Link all Report Handler functions to corresponding Report IDs
// ****************************************************************************
const VectorTableEntry code OUT_VECTORTABLE[OUT_VECTORTABLESize] =
{
0, OUT_Report // FORMAT: Report ID, Report Handler
};
// ----------------------------------------------------------------------------
// Global Variable Declaration
// ----------------------------------------------------------------------------
BufferStructure xdata in_buffer, out_buffer;
usb_in_rep_mouse_t usb_in_packet_mouse;
usb_in_rep_keyb_t usb_in_packet_keyb;
usb_in_rep_rc_t usb_in_packet_rc;
uint8_t out_packet[10];
// ----------------------------------------------------------------------------
// 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 mouse_report(void)
{
in_buffer.Ptr = (uint8_t*)&usb_in_packet_mouse;
in_buffer.Length = sizeof(usb_in_packet_mouse);
}
void keyb_report(void)
{
in_buffer.Ptr = (uint8_t*)&usb_in_packet_keyb;
in_buffer.Length = sizeof(usb_in_packet_keyb);
}
void rc_report(void)
{
in_buffer.Ptr = (uint8_t*)&usb_in_packet_rc;
in_buffer.Length = sizeof(usb_in_packet_rc);
}
// ****************************************************************************
// 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)
{
out_buffer.Ptr = out_packet;
out_buffer.Length = 10;
}
// ----------------------------------------------------------------------------
// 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, since global interrupts are disabled
// by SendPacket before USB operation begins.
// ----------------------------------------------------------------------------
void ReportHandler_IN_ISR(uint8_t R_ID)
{
uint8_t 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;
}
index++; // if Report IDs didn't match, increment the index pointer
}
}
// ----------------------------------------------------------------------------
// 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(uint8_t R_ID){
uint8_t 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;
}
index++; // if Report IDs didn't match, increment the index pointer
}
}
/** @} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -