host_hid_task.c

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * 1. Redistributions of source code must retain the above copyright notice,
00020  * this list of conditions and the following disclaimer.
00021  *
00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
00023  * this list of conditions and the following disclaimer in the documentation
00024  * and/or other materials provided with the distribution.
00025  *
00026  * 3. The name of Atmel may not be used to endorse or promote products derived
00027  * from this software without specific prior written permission.
00028  *
00029  * 4. This software may only be redistributed and used in connection with an Atmel
00030  * AVR product.
00031  *
00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00042  */
00043 
00044 //_____  I N C L U D E S ___________________________________________________
00045 
00046 #include "config.h"
00047 #include "conf_usb.h"
00048 #include "host_hid_task.h"
00049 #include "modules/usb/host_chap9/usb_host_task.h"
00050 #include "modules/usb/host_chap9/usb_host_enum.h"
00051 #include "lib_mcu/usb/usb_drv.h"
00052 
00053 //_____ M A C R O S ________________________________________________________
00054 
00055 
00056 //_____ D E F I N I T I O N S ______________________________________________
00057 
00058 
00059 #ifndef LOG_STR_CODE
00060 #define LOG_STR_CODE(str)
00061 #else
00062 U8 code log_enter_boot[]="Entering bootloader";
00063 U8 code log_hid_connect[]="Generic HID connected";
00064 #endif
00065 
00066 //_____ D E C L A R A T I O N S ____________________________________________
00067 
00068 U8 hid_connected;
00069 #if( HID_GENERIC_DEMO_FULL == ENABLE )         
00070 S8 hid_temperature=0;
00071 U8 hid_potentiometer=0;
00072 #endif
00073 U8 hid_enter_dfu;
00074 static U8 pipe_hid_in;
00075 static U8 pipe_hid_out;
00076 
00077 
00084 void host_hid_task_init(void)
00085 {
00086    hid_enter_dfu=0;
00087    hid_connected=0;
00088 }
00089 
00095 void host_hid_task(void)
00096 {
00097    U8 i;
00098    U8 buf_hid[8];
00099    
00100    // Test HID device connection
00101    if(Is_host_ready())
00102    {
00103       if(Is_new_device_connection_event())   //Device connection
00104       {
00105             hid_connected=0;
00106             hid_enter_dfu=0;
00107             for(i=0;i<Get_nb_supported_interface();i++)
00108             {
00109                if(Get_class(i)==HID_CLASS && Get_subclass(i)==NO_SUBCLASS && Get_protocol(i)==NO_PROTOCOL)
00110                {
00111                   LOG_STR_CODE(log_hid_connect);
00112                   hid_connected=1;
00113                   if(Is_ep_addr_in(Get_ep_addr(i,0)))
00114                   {
00115                      PIPE_HID_IN=host_get_hwd_pipe_nb(Get_ep_addr(i,0));
00116                      PIPE_HID_OUT=host_get_hwd_pipe_nb(Get_ep_addr(i,1));
00117                   }
00118                   else
00119                   {
00120                      PIPE_HID_IN=host_get_hwd_pipe_nb(Get_ep_addr(i,1));
00121                      PIPE_HID_OUT=host_get_hwd_pipe_nb(Get_ep_addr(i,0));
00122                   }
00123                   Host_select_pipe(PIPE_HID_IN);
00124                   Host_continuous_in_mode();
00125                   Host_unfreeze_pipe();
00126                   break;
00127                }
00128             }
00129       }
00130       if(hid_connected)
00131       {
00132          Host_select_pipe(PIPE_HID_IN);
00133          if(Is_host_in_received())
00134          {
00135             if(Is_host_stall()==FALSE)
00136             {
00137 #if( HID_GENERIC_DEMO_FULL == ENABLE )         
00138                i=Usb_read_byte();                     // Leds
00139                i=Usb_read_byte();                     // Joystick
00140                hid_potentiometer=Usb_read_byte();     // Potentiometer
00141                hid_temperature=Usb_read_byte();       // Temperature
00142 #else
00143                i=Usb_read_byte();                     // Joystick
00144 #endif
00145             }
00146             Host_ack_in_received(); Host_send_in();
00147          }
00148          if(hid_enter_dfu==TRUE)
00149          {
00150             LOG_STR_CODE(log_enter_boot);
00151 #if( HID_GENERIC_DEMO_FULL == ENABLE )         
00152             buf_hid[3]=0x55;
00153             buf_hid[4]=0xAA;
00154             host_send_data(PIPE_HID_OUT, 8, buf_hid);
00155 #else
00156             buf_hid[0]=0x55;
00157             buf_hid[1]=0xAA;
00158             buf_hid[2]=0x55;
00159             buf_hid[3]=0xAA;
00160             usb_request.bmRequestType = USB_SETUP_SET_CLASS_INTER;
00161             usb_request.bRequest      = SETUP_HID_SET_REPORT;
00162             usb_request.wValue        = (REPORT_TYPE_FEATURE<<8);
00163             usb_request.wIndex        = 0;
00164             usb_request.wLength       = 4;
00165             usb_request.uncomplete_read = FALSE;
00166             host_send_control(buf_hid);
00167 #endif
00168          }
00169       }
00170    }
00171    //Device disconnection...
00172    if(Is_device_disconnection_event())
00173    {
00174       Leds_off();
00175       hid_connected=0;
00176       hid_enter_dfu=0;
00177    }
00178 }

Generated on Wed Sep 23 09:33:17 2009 for ATMEL by  doxygen 1.5.3