- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# 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 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)
void | sof_action ()
## Variables
volatile U8 | cpt_sof = 0
U8 | jump_bootloader
U8 | g_last_joy = 0

## Detailed Description

This file manages the generic HID IN/OUT task.

- Compiler: IAR EWAVR and GNU GCC for AVR
- Supported devices: AT90USB1287, AT90USB1286, AT90USB647, AT90USB646

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 93 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, start_boot(), Usb_ack_receive_out, Usb_detach, Usb_read_byte, and Usb_select_endpoint.

Referenced by hid_task().

    00094 {
    00095    Usb_select_endpoint(EP_HID_OUT);
    00096    if(Is_usb_receive_out())
    00097    {
    00098       //* Read report from HID Generic Demo
    00099       U8 led_state;
    00100       U8 led_number;
    00101       led_state      = Usb_read_byte()&0x0F; // RepportOUT[0] is LEDS value
    00102       led_number     = Usb_read_byte()&0x0F;
    00103       switch (led_number)
    00104       {
    00105          case 1:
    00106             if(led_state)
    00107             {  Led0_on();   }
    00108             else {Led0_off();}
    00109             break;
    00110          case 2:
    00111             if(led_state)
    00112             {  Led1_on();   }
    00113             else {Led1_off();}
    00114             break;
    00115          case 3:
    00116             if(led_state)
    00117             {  Led2_on();   }
    00118             else {Led2_off();}
    00119             break;
    00120          case 4:
    00121             if(led_state)
    00122             {  Led3_on();   }
    00123             else {Led3_off();}
    00124             break;
    00125       }
    00126       Usb_ack_receive_out();
    00127    }
    00128
    00129    //** Check if we received DFU mode command from host
    00130    if(jump_bootloader)
    00131    {
    00132       U32 volatile tempo;
    00133       Leds_off();
    00134       Usb_detach();                          // Detach actual generic HID application
    00135       for(tempo=0;tempo<70000;tempo++);      // Wait some time before
    00136       start_boot();                          // Jumping to booltoader
    00137    }
    00138 }

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

Check for UP event

Definition at line 143 of file hid_task.c.

References EP_HID_IN, g_last_joy, Is_joy_down, Is_joy_left, Is_joy_right, Is_joy_up, Is_usb_write_enabled, Usb_ack_in_ready, Usb_select_endpoint, and Usb_write_byte.

Referenced by hid_task().

    00144 {
    00145    U8 joy   =0;
    00146
    00147    Usb_select_endpoint(EP_HID_IN);
    00148    if(!Is_usb_write_enabled())
    00149       return;                                // Not ready to send report
    00150
    00151    // Build the Joytick report
    00152    if(Is_joy_up()|| Is_joy_down() || Is_joy_right() || Is_joy_left() )
    00153    {
    00154      joy=0x01;
    00155    }
    00156    if(joy==g_last_joy)
    00157       return;                                // Same report then no send report
    00158    g_last_joy=joy;
    00159
    00160    // Send report
    00161    Usb_write_byte(g_last_joy);               // Joystick
    00162    Usb_write_byte(GPIOR1);                   // Dummy (not used)
    00163    Usb_write_byte(GPIOR1);                   // Dummy (not used)
    00164    Usb_write_byte(GPIOR1);                   // Dummy (not used)
    00165    Usb_write_byte(GPIOR1);                   // Dummy (not used)
    00166    Usb_write_byte(GPIOR1);                   // Dummy (not used)
    00167    Usb_write_byte(GPIOR1);                   // Dummy (not used)
    00168    Usb_write_byte(GPIOR1);                   // Dummy (not used)
    00169    Usb_ack_in_ready();                       // Send data over the USB
    00170 }

Here is the caller graph for this function:

void hid_task_init | ( | void |  | ) |

This function initializes the target board ressources.

Definition at line 72 of file hid_task.c.

References Joy_init, and Leds_init.

    00073 {
    00074    Leds_init();
    00075    Joy_init();
    00076 }

void hid_task | ( | void |  | ) |

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

Definition at line 81 of file hid_task.c.

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

    00082 {
    00083    if(!Is_device_enumerated())          // Check USB HID is enumerated
    00084       return;
    00085
    00086    hid_report_out();
    00087    hid_report_in();
    00088 }

Here is the call graph for this function:

## Variable Documentation

volatile U8 cpt_sof = 0

Definition at line 62 of file hid_task.c.

Referenced by sof_action().

U8 jump_bootloader

Definition at line 66 of file usb_specific_request.c.

Referenced by hid_report_out(), and usb_hid_set_report_feature().

U8 g_last_joy = 0

Definition at line 64 of file hid_task.c.

Referenced by hid_report_in().