📄 hid_task.c
字号:
//!
//! @file hid_task.c,v
//!
//! Copyright (c) 2004 Atmel.
//!
//! Please read file license.txt for copyright notice.
//!
//! @brief This file manages the generic HID IN/OUT task.
//!
//!
//! @version 1.4 at90usb128-usbkey-demo-3enum-host-mouse-1_0_4 $Id: hid_task.c,v 1.4 2006/07/12 15:17:29 rletendu Exp $
//!
//! @todo
//! @bug
//!/
//_____ I N C L U D E S ___________________________________________________
#include "config.h"
#include "conf_usb.h"
#include "hid_task.h"
#include "lib_mcu\usb\usb_drv.h"
#include "usb_descriptors.h"
#include "modules\usb\device_chap9\usb_standard_request.h"
#include "usb_specific_request.h"
#include "lib_mcu\adc\adc_drv.h"
//_____ M A C R O S ________________________________________________________
//_____ D E F I N I T I O N S ______________________________________________
//_____ D E C L A R A T I O N S ____________________________________________
extern bit usb_connected;
extern U8 usb_configuration_nb;
extern volatile U8 joy_for_mouse;
extern volatile U16 cpt_sof_tempe;
U8 volatile tempe;
//! Declare function pointer to USB bootloader entry point
void (*start_bootloader) (void)=(void (*)(void))0xf000;
//!
//! @brief This function initializes the target board ressources.
//!
//! @warning Code:?? bytes (function code length)
//!
//! @param none
//!
//! @return none
//!
//!/
void hid_task_init(void)
{
init_adc();
Leds_init();
Joy_init();
}
//! @brief Entry point of the HID generic communication task
//!
//! This function manages IN/OUT repport management.
//!
//! @warning Code:?? bytes (function code length)
//!
//! @param none
//!
//! @return none
void hid_task(void)
{
U8 dummy;
U8 dummy2;
U8 volatile pot=0;
U8 joy;
U32 volatile tempo;
if(Is_device_enumerated() ) //! Check USB HID is enumerated
{
Usb_select_endpoint(EP_HID_OUT); //! Get Data repport from Host
if(Is_usb_receive_out())
{
Leds_set_val(Usb_read_byte()); //! RepportOUT[0] is LEDS value
GPIOR1=Usb_read_byte(); //! not used
GPIOR1=Usb_read_byte(); //! not used
dummy=Usb_read_byte(); //! In combinaisoon with nex byte allows
dummy2=Usb_read_byte(); //! the host to send an enter DFU mode event
Usb_ack_receive_out();
}
if(dummy==0x55 && dummy2==0xAA) //! Check if we received DFU mode command from host
{
Usb_detach(); //! Detach actual generic HID application
for(tempo=0;tempo<70000;tempo++);//! Wait some time before
(*start_bootloader)(); //! Jumping to booltoader
}
if (cpt_sof_tempe>=500)
{
tempe=(S8)Read_temperature(); //! Get temperature value from ADC converter
cpt_sof_tempe=0;
}
joy=0;
//! Now we build the Joytick information
if(Is_joy_up()) //! Check for UP event
{
joy+=0x01;
}
if(Is_joy_down()) //! Check for DOWN event
{
joy+=0x02;
}
if(Is_joy_right()) //! Check for RIGHT event
{
joy+=0x04;
}
if(Is_joy_left()) //! Check for LEFT event
{
joy+=0x08;
}
Usb_select_endpoint(EP_HID_IN); //! Ready to send these information to the host application
if(Is_usb_in_ready())
{
Usb_write_byte(Leds_get_val()); //! Leds
Usb_write_byte(joy); //! Joystick
Usb_write_byte(pot); //! Potentiometer
Usb_write_byte(tempe); //! Temperature
Usb_write_byte(GPIOR1); //! Dummy (not used)
Usb_write_byte(~PINE); //! Dummy (not used)
Usb_write_byte(~PINE); //! Dummy (not used)
Usb_write_byte(~PINE); //! Dummy (not used)
Usb_ack_fifocon(); //! Send data over the USB
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -