hid_task.c File Reference

#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/util/start_boot.h"
#include "lib_mcu/adc/adc_drv.h"

Include dependency graph for hid_task.c:

Go to the source code of this file.

Functions

void hid_report_out (void)
void hid_report_in (void)
void hid_task_init (void)
void hid_task (void)

Variables

volatile U16 g_u16_cpt2_sof
U8 jump_bootloader
U8 g_temperature = 0
U8 g_potentiometer = 0


Detailed Description

This file manages the generic HID IN/OUT task.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file hid_task.c.


Function Documentation

void hid_report_out ( void   ) 

Get data report from Host

Definition at line 104 of file hid_task.c.

References EP_HID_OUT, Is_usb_receive_out, jump_bootloader, Led0_off, Led0_on, Led1_off, Led1_on, Led2_off, Led2_on, Led3_off, Led3_on, Leds_off, Leds_set_val, start_boot(), TRUE, Usb_ack_receive_out, Usb_detach, Usb_read_byte, and Usb_select_endpoint.

Referenced by hid_task().

00105 {
00106    Usb_select_endpoint(EP_HID_OUT);
00107    if(Is_usb_receive_out())
00108    {
00109 #if( HID_GENERIC_DEMO_FULL == ENABLE )         
00110       //* Read report from HID Generic Demo Full
00111       U8 report_byte_4;
00112       U8 report_byte_5;
00113       Leds_set_val(    Usb_read_byte());     // RepportOUT[0] is LEDS value
00114       GPIOR1         = Usb_read_byte();      // not used
00115       GPIOR1         = Usb_read_byte();      // not used
00116       report_byte_4  = Usb_read_byte();
00117       report_byte_5  = Usb_read_byte();
00118       // Check if we received DFU mode command from host
00119       if( (report_byte_4==0x55) && (report_byte_5==0xAA) )
00120          jump_bootloader = TRUE;
00121 #else
00122       //* Read report from HID Generic Demo
00123       U8 led_state;
00124       U8 led_number;
00125       led_state      = Usb_read_byte()&0x0F; // RepportOUT[0] is LEDS value
00126       led_number     = Usb_read_byte()&0x0F;
00127       switch (led_number)
00128       {
00129          case 1:
00130             if(led_state)
00131             {  Led0_on();   }
00132             else {Led0_off();}
00133             break;
00134          case 2:
00135             if(led_state)
00136             {  Led1_on();   }
00137             else {Led1_off();}
00138             break;
00139          case 3:
00140             if(led_state)
00141             {  Led2_on();   }
00142             else {Led2_off();}
00143             break;
00144          case 4:
00145             if(led_state)
00146             {  Led3_on();   }
00147             else {Led3_off();}
00148             break;
00149       }         
00150 #endif
00151       Usb_ack_receive_out();
00152    }
00153 
00154    //** Check if we received DFU mode command from host
00155    if(jump_bootloader)
00156    {
00157       U32 volatile tempo;
00158       Leds_off();
00159       Usb_detach();                          // Detach actual generic HID application
00160       for(tempo=0;tempo<70000;tempo++);      // Wait some time before
00161       start_boot();                          // Jumping to booltoader
00162    }
00163 }

Here is the call graph for this function:

Here is the caller graph for this function:

void hid_report_in ( void   ) 

Send data report to Host

Definition at line 168 of file hid_task.c.

References EP_HID_IN, g_potentiometer, g_temperature, g_u16_cpt2_sof, Is_joy_down, Is_joy_left, Is_joy_right, Is_joy_up, Is_usb_write_enabled, Leds_get_val, Usb_ack_in_ready, Usb_select_endpoint, and Usb_write_byte.

Referenced by hid_task().

00169 {
00170    U8 joy   =0;
00171 
00172    Usb_select_endpoint(EP_HID_IN);
00173    if(!Is_usb_write_enabled())
00174       return;                                // Not ready to send report
00175 
00176 #if( HID_GENERIC_DEMO_FULL == ENABLE )         
00177 #  if (TARGET_BOARD!=USBKEY)
00178    if (g_u16_cpt2_sof%100==0)
00179    {
00180       g_potentiometer=Get_adc_pot_val()>>2;
00181    }
00182 #  endif
00183    if (g_u16_cpt2_sof>=600)
00184    {
00185       g_temperature=(S8)Read_temperature();
00186       g_temperature=(S8)Read_temperature();
00187       g_u16_cpt2_sof=0;
00188    }
00189    // Build the Joytick report
00190    if(Is_joy_up())                           // Check for UP event
00191    {
00192       joy+=0x01;
00193    }
00194    if(Is_joy_down())                         // Check for DOWN event
00195    {
00196       joy+=0x02;
00197    }
00198    if(Is_joy_right())                        // Check for RIGHT event
00199    {
00200       joy+=0x04;
00201    }
00202    if(Is_joy_left())                         // Check for LEFT event
00203    {
00204       joy+=0x08;
00205    }
00206 #else
00207    // Build the Joytick report
00208    if(Is_joy_up()|| Is_joy_down() || Is_joy_right() || Is_joy_left() )                     
00209    {
00210      joy=0x01;
00211    }
00212    if(joy==g_last_joy)
00213       return;                                // Same report then no send report
00214    g_last_joy=joy;
00215 #endif
00216 
00217    // Send report
00218 #if( HID_GENERIC_DEMO_FULL == ENABLE )         
00219    Usb_write_byte(Leds_get_val());           // Leds
00220    Usb_write_byte(joy);                      // Joystick
00221    Usb_write_byte(g_potentiometer);          // Potentiometer
00222    Usb_write_byte(g_temperature);            // temperature
00223 #else
00224    Usb_write_byte(g_last_joy);               // Joystick
00225    Usb_write_byte(GPIOR1);                   // Dummy (not used)
00226    Usb_write_byte(GPIOR1);                   // Dummy (not used)
00227    Usb_write_byte(GPIOR1);                   // Dummy (not used)
00228 #endif
00229    Usb_write_byte(GPIOR1);                   // Dummy (not used)
00230    Usb_write_byte(GPIOR1);                   // Dummy (not used)
00231    Usb_write_byte(GPIOR1);                   // Dummy (not used)
00232    Usb_write_byte(GPIOR1);                   // Dummy (not used)
00233    Usb_ack_in_ready();                       // Send data over the USB
00234 }

Here is the caller graph for this function:

void hid_task_init ( void   ) 

This function initializes the target board ressources.

Definition at line 80 of file hid_task.c.

References init_adc(), Joy_init, and Leds_init.

00081 {
00082 #if( HID_GENERIC_DEMO_FULL == ENABLE )         
00083    init_adc();
00084 #endif
00085    Leds_init();
00086    Joy_init();
00087 }

Here is the call graph for this function:

void hid_task ( void   ) 

Entry point of the HID generic communication task This function manages IN/OUT repport management.

Definition at line 92 of file hid_task.c.

References hid_report_in(), hid_report_out(), and Is_device_enumerated.

00093 {
00094    if(!Is_device_enumerated())               // Check USB HID is enumerated
00095       return;
00096 
00097    hid_report_out();
00098    hid_report_in();
00099 }

Here is the call graph for this function:


Variable Documentation

volatile U16 g_u16_cpt2_sof

Definition at line 109 of file device_mouse_task.c.

U8 jump_bootloader

Definition at line 73 of file usb_specific_request.c.

Referenced by hid_report_out(), and usb_hid_set_report_feature().

U8 g_temperature = 0

Definition at line 69 of file hid_task.c.

Referenced by hid_report_in().

U8 g_potentiometer = 0

Definition at line 70 of file hid_task.c.

Referenced by hid_report_in().


Generated on Wed Sep 23 09:49:38 2009 for ATMEL by  doxygen 1.5.3