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

📄 hid_task.c

📁 ATMEL at90usb128 usb HID source code for win-avr
💻 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.1 at90usb128-demo-hidgen-std-2_0_0 $Id: hid_task.c,v 1.1 2007/01/05 12:56:55 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_board/stk_525/stk_525.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"



//_____ 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;
volatile U8  cpt_sof=0;
extern U8 jump_bootloader;
U8 last_joy=0;

//! 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)
{
   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 joy;
   U32 volatile tempo;
   U8 led_state;
   U8 led_number;

    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())
      {
         led_state=Usb_read_byte()&0x0F;       //! RepportOUT[0] is LEDS value
         led_number=Usb_read_byte()&0x0F;
         switch (led_number)
         {
            case 1:
               if(led_state)
               {  Led0_on();   }
               else {Led0_off();}
               break;
            case 2:
               if(led_state)
               {  Led1_on();   }
               else {Led1_off();}
               break;
            case 3:
               if(led_state)
               {  Led2_on();   }
               else {Led2_off();}
               break;
            case 4:
               if(led_state)
               {  Led3_on();   }
               else {Led3_off();}
               break;
         }
         Usb_ack_receive_out();
      }

      if(jump_bootloader)     //! Check if we received DFU mode command from host
      {
         Leds_off();
         Usb_detach();                    //! Detach actual generic HID application
         for(tempo=0;tempo<70000;tempo++);//! Wait some time before
         (*start_bootloader)();           //! Jumping to booltoader
      }


      joy=0;                              //! Now we build the Joytick information
      if(Is_joy_up()|| Is_joy_down() || Is_joy_right() || Is_joy_left() )                     //! Check for UP event
      {
        joy=0x01;
      }
      Usb_select_endpoint(EP_HID_IN);     //! Ready to send these information to the host application
      if(Is_usb_write_enabled())
      {
         if(joy!=last_joy)
         {
            Usb_write_byte(joy);
            Usb_write_byte(GPIOR1);           //! Dummy (not used)
            Usb_write_byte(GPIOR1);           //! Dummy (not used)
            Usb_write_byte(GPIOR1);           //! Dummy (not used)
            Usb_write_byte(GPIOR1);           //! Dummy (not used)
            Usb_write_byte(GPIOR1);           //! Dummy (not used)
            Usb_write_byte(GPIOR1);           //! Dummy (not used)
            Usb_write_byte(GPIOR1);           //! Dummy (not used)
            Usb_ack_in_ready();               //! Send data over the USB
            last_joy=joy;
         }
      }
    }

}

//! @brief sof_action
//!
//! This function increments the cpt_sof counter each times
//! the USB Start Of Frame interrupt subroutine is executed (1ms)
//! Usefull to manage time delays
//!
//! @warning Code:?? bytes (function code length)
//!
//! @param none
//!
//! @return none
void sof_action()
{
   cpt_sof++;
}

⌨️ 快捷键说明

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