mouse_task.c File Reference

#include "config.h"
#include "conf_usb.h"
#include "mouse_task.h"
#include "usb_descriptors.h"
#include "lib_mcu/usb/usb_drv.h"
#include "lib_mcu/wdt/wdt_drv.h"
#include "lib_mcu/power/power_drv.h"
#include "lib_mcu/pll/pll_drv.h"
#include "lib_mcu/util/start_boot.h"
#include "lib_mcu/flash/flash_drv.h"
#include "modules/usb/device_chap9/usb_standard_request.h"

Include dependency graph for mouse_task.c:

Go to the source code of this file.

Defines

#define Hid_mouse_report_up()   (g_hid_mouse_report[2]-=MOUSE_SPEED)
#define Hid_mouse_report_down()   (g_hid_mouse_report[2]+=MOUSE_SPEED)
#define Hid_mouse_report_left()   (g_hid_mouse_report[1]-=MOUSE_SPEED)
#define Hid_mouse_report_right()   (g_hid_mouse_report[1]+=MOUSE_SPEED)
#define Hid_mouse_report_scroll_up()   (g_hid_mouse_report[3]+=MOUSE_SPEED)
#define Hid_mouse_report_scroll_down()   (g_hid_mouse_report[3]-=MOUSE_SPEED)
#define Hid_mouse_report_click_left()   (g_hid_mouse_report[0] |= 0x01)
#define Hid_mouse_report_click_right()   (g_hid_mouse_report[0] |= 0x02)
#define Hid_mouse_report_click_middle()   (g_hid_mouse_report[0] |= 0x04)
#define Hid_mouse_report_reset()   (g_hid_mouse_report[0]=0,g_hid_mouse_report[1]=0,g_hid_mouse_report[2]=0,g_hid_mouse_report[3]=0)
#define Is_mouse_left_event()   Is_switch_3()
#define Is_mouse_right_event()   Is_switch_2()
#define Is_mouse_up_event()   Is_switch_1()
#define Is_mouse_down_event()   Is_switch_0()
#define Is_mouse_scroll_up_event()   FALSE
#define Is_mouse_scroll_down_event()   FALSE
#define Is_mouse_click_left_event()   Is_switch_6()
#define Is_mouse_click_middle_event()   Is_switch_5()
#define Is_mouse_click_right_event()   Is_switch_4()

Functions

bit is_mouse_event (void)
 This function checks the board interface and fill the HID mouse report.
void mouse_task_init (void)
 This function initializes the hardware/software resources required for mouse task.
void mouse_task (void)
 Task which links mouse events with the USB HID mouse device.
void sof_action ()
 This function increments the SOF counter each times.
void suspend_action (void)
 This function enables switches interruptions and enters the CPU in power down mode.
__interrupt void switch_event_int ()
 This function exits the CPU of the power down mode and disables switches interruptions.

Variables

Bool g_b_send_report
 Used to flag a report ready to send.
Bool g_b_send_ack_report
 Used to flag a ack report ready to send.
U8 g_hid_mouse_report [4]
 Used to store the HID mouse report.
volatile U8 g_u8_cpt_sof
 Used to count the number of SOF and create a timer counter.


Detailed Description

This file manages the Mouse task.

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

Definition in file mouse_task.c.


Function Documentation

bit is_mouse_event ( void   ) 

This function checks the board interface and fill the HID mouse report.

Returns:
TRUE if an event occurs. In this case, the HID mouse report is filled

FALSE if not event

Definition at line 192 of file mouse_task.c.

References FALSE, g_hid_mouse_report, Hid_mouse_report_click_left, Hid_mouse_report_click_middle, Hid_mouse_report_click_right, Hid_mouse_report_down, Hid_mouse_report_left, Hid_mouse_report_reset, Hid_mouse_report_right, Hid_mouse_report_scroll_down, Hid_mouse_report_scroll_up, Hid_mouse_report_up, Is_mouse_click_left_event, Is_mouse_click_middle_event, Is_mouse_click_right_event, Is_mouse_down_event, Is_mouse_left_event, Is_mouse_right_event, Is_mouse_scroll_down_event, Is_mouse_scroll_up_event, Is_mouse_up_event, and TRUE.

Referenced by mouse_task().

00193 {
00194    Hid_mouse_report_reset();
00195    
00196    // Check Click events
00197    if(Is_mouse_click_left_event()) {
00198       Hid_mouse_report_click_left();
00199    }
00200    if(Is_mouse_click_middle_event()) {
00201       Hid_mouse_report_click_middle();
00202    }
00203    if(Is_mouse_click_right_event()) {
00204       Hid_mouse_report_click_right();
00205    }
00206 
00207    // Check Mouve events
00208    if (Is_mouse_left_event()) {
00209       Hid_mouse_report_left();
00210    }
00211    if (Is_mouse_right_event()) {
00212       Hid_mouse_report_right();
00213    }
00214    if (Is_mouse_up_event()) {
00215       Hid_mouse_report_up();
00216    }
00217    if (Is_mouse_down_event()) {
00218       Hid_mouse_report_down();
00219    }
00220    if (Is_mouse_scroll_up_event()) {
00221       Hid_mouse_report_scroll_up();
00222    }
00223    if (Is_mouse_scroll_down_event()) {
00224       Hid_mouse_report_scroll_down();
00225    }
00226 
00227    // Check report
00228    if((0==g_hid_mouse_report[0])
00229    && (0==g_hid_mouse_report[1])
00230    && (0==g_hid_mouse_report[2])
00231    && (0==g_hid_mouse_report[3]))
00232    {
00233       return FALSE;  // No event
00234    }
00235    return TRUE;      // Event(s) occurs
00236 }

Here is the caller graph for this function:

void mouse_task_init ( void   ) 

This function initializes the hardware/software resources required for mouse task.

Definition at line 114 of file mouse_task.c.

00115 {
00116    // Init SOF
00117    g_u8_cpt_sof=0;
00118    Usb_enable_sof_interrupt();
00119 
00120    // Init interface board
00121    Switches_init();
00122    Leds_init();
00123    Led7_on();
00124    Led6_off();
00125    
00126    // Send a ack report at startup
00127    g_b_send_report      = FALSE;
00128    g_b_send_ack_report  = TRUE;
00129 }

void mouse_task ( void   ) 

Task which links mouse events with the USB HID mouse device.

Definition at line 134 of file mouse_task.c.

00135 {
00136    if(!Is_device_enumerated())
00137       return;  // Device not ready
00138    
00139 #if (USB_LOW_SPEED_DEVICE==DISABLE)
00140    // The SOF is used to schedule the task at the same frequency that Endpoint Interrupt frequency
00141    // This check allow to win a CPU time
00142    if(g_u8_cpt_sof<NB_IDLE_POLLING_SOF)
00143       return;  // Wait a delay
00144    g_u8_cpt_sof=0;
00145 #endif
00146 
00147    if(!g_b_send_report)
00148    {
00149       // No report sending on going then check mouse event to eventualy fill a new report
00150       if(is_mouse_event())
00151       {
00152          // Enable sending of report
00153          g_b_send_report      = TRUE;
00154       }
00155    }
00156    
00157    if((!g_b_send_report)&&(!g_b_send_ack_report))
00158       return;  // No report and ack to send
00159    
00160    //** A report or ack must be send
00161    Usb_select_endpoint(EP_MOUSE_IN);
00162    if(!Is_usb_write_enabled())
00163       return;  // Endpoint no free
00164    
00165    Led6_on();      
00166    if( g_b_send_report )
00167    {
00168       g_b_send_report      = FALSE;
00169       // Send an ack after a "clic" report only
00170       g_b_send_ack_report = (0!=g_hid_mouse_report[0]);
00171    }
00172    else
00173    {
00174       Hid_mouse_report_reset();     // Reset report to have a ack report
00175       g_b_send_ack_report  = FALSE;
00176    }
00177    // Send report
00178    Usb_write_byte(g_hid_mouse_report[0]);
00179    Usb_write_byte(g_hid_mouse_report[1]);
00180    Usb_write_byte(g_hid_mouse_report[2]);
00181    Usb_write_byte(g_hid_mouse_report[3]);
00182    Usb_ack_in_ready();
00183    Led6_off();      
00184 }

__interrupt void switch_event_int (  ) 

This function exits the CPU of the power down mode and disables switches interruptions.

//! This function is executed when a switche interruption is received
//! 

Definition at line 284 of file mouse_task.c.

References Switches_disable_it, and usb_generate_remote_wakeup().

00286 {
00287    Switches_disable_it();
00288    usb_generate_remote_wakeup();
00289 }

Here is the call graph for this function:


Variable Documentation

Bool g_b_send_report

Used to flag a report ready to send.

Definition at line 103 of file mouse_task.c.

Referenced by mouse_task(), and mouse_task_init().

Bool g_b_send_ack_report

Used to flag a ack report ready to send.

Definition at line 105 of file mouse_task.c.

Referenced by mouse_task(), and mouse_task_init().

U8 g_hid_mouse_report[4]

Used to store the HID mouse report.

Definition at line 107 of file mouse_task.c.

Referenced by is_mouse_event(), and mouse_task().

volatile U8 g_u8_cpt_sof

Used to count the number of SOF and create a timer counter.

Definition at line 109 of file mouse_task.c.

Referenced by mouse_task(), mouse_task_init(), and sof_action().


Generated on Fri Sep 11 15:04:25 2009 for ATMEL by  doxygen 1.5.3