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

📄 host_mouse_task.c

📁 ATMEL 90usb128 USB source,include USB protocol stack.
💻 C
字号:
/**
 * @file host_mouse_task.c,v
 *
 * Copyright (c) 2004 Atmel.
 *
 * Please read file license.txt for copyright notice.
 *
 * @brief This file manages the USB Host mouse control application.
 *
 * @version 1.4 at90usb128-usbkey-demo-3enum-host-mouse-1_0_4 $Id: host_mouse_task.c,v 1.4 2006/08/02 14:52:08 rletendu Exp $
 *
 * @todo
 * @bug
 */

//_____  I N C L U D E S ___________________________________________________

#include "config.h"
#include "conf_usb.h"
#include "host_mouse_task.h"
#include "modules/usb/host_chap9/usb_host_task.h"
#include "modules/usb/host_chap9/usb_host_enum.h"
#include "lib_mcu/usb/usb_drv.h"

//_____ M A C R O S ________________________________________________________

#ifndef LOG_STR_CODE
#define LOG_STR_CODE(str)
#else
U8 code log_mouse_connect[]="Mouse Connected";
#endif

//_____ D E F I N I T I O N S ______________________________________________



U8  mouse_connected=0;

U8  pipe_mouse_in;



//_____ D E C L A R A T I O N S ____________________________________________
/**
 * @brief This function initializes the Host USB mouse application
 *
 *
 *
 * @warning Code:?? bytes (function code length)
 *
 * @param none
 *
 * @return none
 *
 */
void host_mouse_task_init(void)
{
   Leds_init();
}

//!
//! @brief This function manages the HOST mouse application
//!
//!
//! @warning Code:?? bytes (function code length)
//!
//! @param none
//!
//! @return none
//!
//!

void host_mouse_task(void)
{
U8 i;
S8 new_x,new_y;

   //Test HID device connection
   if(Is_host_ready())
   {
      if(Is_new_device_connection_event())   //Device connection
      {
            mouse_connected=0;
            for(i=0;i<Get_nb_supported_interface();i++)
            {
               if(Get_class(i)==HID_CLASS && Get_protocol(i)==MOUSE_PROTOCOL)
               {
                  mouse_connected=1;
                  LOG_STR_CODE(log_mouse_connect);
                  PIPE_MOUSE_IN=host_get_hwd_pipe_nb(Get_ep_addr(i,0));
                  Host_select_pipe(PIPE_MOUSE_IN);
                  Host_continuous_in_mode();
                  Host_unfreeze_pipe();
                  break;
               }
            }
      }
      if(mouse_connected)
      {
         Host_select_pipe(PIPE_MOUSE_IN);
         if(Is_host_in_received())
         {
            if(Is_host_stall()==FALSE)
            {
               i=Host_read_byte();
               new_x=(S8)Host_read_byte();
               new_y=(S8)Host_read_byte();
   
               if(new_x==0)
               { Led0_off(); Led1_off();}
               else if(new_x>0)
               {Led0_on(); Led1_off();}
               else
               { Led0_off(); Led1_on();}
   
               if(new_y==0)
               { Led2_off(); Led3_off();}
               else if(new_y>0)
               { Led2_on(); Led3_off();}
               else
               { Led2_off(); Led3_on();}
   
            }
            Host_ack_in_received(); Host_send_in();
         }
         if(Is_host_nak_received())
         {
            Host_ack_nak_received();
            Led0_off(); Led1_off();
            Led2_off(); Led3_off();
         }
      }
   }
   //Device disconnection...
   if(Is_device_disconnection_event())
   {
      Leds_off();
      mouse_connected=0;
   }
}

⌨️ 快捷键说明

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