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/adc/adc_drv.h"
#include "lib_mcu/wdt/wdt_drv.h"
#include "lib_mcu/power/power_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_joy_left()
#define Is_mouse_right_event()   Is_joy_right()
#define Is_mouse_up_event()   Is_joy_up()
#define Is_mouse_down_event()   Is_joy_down()
#define SCROLL_STEP   10
#define Is_mouse_scroll_up_event()   ((g_u16_pos_scroll+SCROLL_STEP) < Get_adc_pot_val())
#define Is_mouse_scroll_down_event()   ((g_u16_pos_scroll-SCROLL_STEP) > Get_adc_pot_val())
#define Is_mouse_click_left_event()   Is_btn_left()
#define Is_mouse_click_middle_event()   FALSE
#define Is_mouse_click_right_event()   Is_btn_middle()

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.
U16 g_u16_pos_scroll
 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 214 of file mouse_task.c.

References FALSE, g_hid_mouse_report, g_u16_pos_scroll, 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, SCROLL_STEP, and TRUE.

Referenced by mouse_task().

00215 {
00216    Hid_mouse_report_reset();
00217    
00218    // Check Click events
00219    if(Is_mouse_click_left_event()) {
00220       Hid_mouse_report_click_left();
00221    }
00222    if(Is_mouse_click_middle_event()) {
00223       Hid_mouse_report_click_middle();
00224    }
00225    if(Is_mouse_click_right_event()) {
00226       Hid_mouse_report_click_right();
00227    }
00228 
00229    // Check Mouve events
00230    if (Is_mouse_left_event()) {
00231       Hid_mouse_report_left();
00232    }
00233    if (Is_mouse_right_event()) {
00234       Hid_mouse_report_right();
00235    }
00236    if (Is_mouse_up_event()) {
00237       Hid_mouse_report_up();
00238    }
00239    if (Is_mouse_down_event()) {
00240       Hid_mouse_report_down();
00241    }
00242 #if (TARGET_BOARD==STK525)
00243    if (Is_mouse_scroll_up_event()) {
00244       g_u16_pos_scroll+=SCROLL_STEP;
00245       Hid_mouse_report_scroll_up();
00246    }
00247    if (Is_mouse_scroll_down_event()) {
00248       g_u16_pos_scroll-=SCROLL_STEP;
00249       Hid_mouse_report_scroll_down();
00250    }
00251 #endif
00252 
00253    // Check report
00254    if((0==g_hid_mouse_report[0])
00255    && (0==g_hid_mouse_report[1])
00256    && (0==g_hid_mouse_report[2])
00257    && (0==g_hid_mouse_report[3]))
00258    {
00259       return FALSE;  // No event
00260    }
00261    return TRUE;      // Event(s) occurs
00262 }

Here is the caller graph for this function:

void mouse_task ( void   ) 

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

Definition at line 146 of file mouse_task.c.

00147 {
00148    if(Is_usb_vbus_low())
00149    {
00150       // Before power down the USB Stack must be call to manage the VBus low state
00151       usb_task();
00152       Usb_enable_vbus_interrupt();  // To exit of power down mode when VBus is plugged
00153       Setup_power_down_mode();
00154       Sleep_instruction();
00155       Usb_disable_vbus_interrupt();
00156    }
00157 
00158    if(!Is_device_enumerated())
00159       return;  // Device not ready
00160    
00161 #if (USB_LOW_SPEED_DEVICE==DISABLE)
00162    // The SOF is used to schedule the task at the same frequency that Endpoint Interrupt frequency
00163    // This check allow to win a CPU time
00164    if(g_u8_cpt_sof<NB_IDLE_POLLING_SOF)
00165       return;  // Wait a delay
00166    g_u8_cpt_sof=0;
00167 #endif
00168 
00169    if(!g_b_send_report)
00170    {
00171       // No report sending on going then check mouse event to eventualy fill a new report
00172       if(is_mouse_event())
00173       {
00174          // Enable sending of report
00175          g_b_send_report      = TRUE;
00176       }
00177    }
00178    
00179    if((!g_b_send_report)&&(!g_b_send_ack_report))
00180       return;  // No report and ack to send
00181    
00182    //** A report or ack must be send
00183    Usb_select_endpoint(EP_MOUSE_IN);
00184    if(!Is_usb_write_enabled())
00185       return;  // Endpoint no free
00186    
00187    Led0_on();      
00188    if( g_b_send_report )
00189    {
00190       g_b_send_report      = FALSE;
00191       // Send an ack after a "clic" report only
00192       g_b_send_ack_report = (0!=g_hid_mouse_report[0]);
00193    }
00194    else
00195    {
00196       Hid_mouse_report_reset();     // Reset report to have a ack report
00197       g_b_send_ack_report  = FALSE;
00198    }
00199    // Send report
00200    Usb_write_byte(g_hid_mouse_report[0]);
00201    Usb_write_byte(g_hid_mouse_report[1]);
00202    Usb_write_byte(g_hid_mouse_report[2]);
00203    Usb_write_byte(g_hid_mouse_report[3]);
00204    Usb_ack_in_ready();
00205    Led0_off();      
00206 }

__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 310 of file mouse_task.c.

References Switches_disable_it, and usb_generate_remote_wakeup().

00312 {
00313    Switches_disable_it();
00314    usb_generate_remote_wakeup();
00315 }

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 106 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 108 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 110 of file mouse_task.c.

Referenced by is_mouse_event(), and mouse_task().

U16 g_u16_pos_scroll

Used to store the HID mouse report.

Definition at line 113 of file mouse_task.c.

Referenced by is_mouse_event(), and mouse_task_init().

volatile U8 g_u8_cpt_sof

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

Definition at line 116 of file mouse_task.c.

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


Generated on Mon Sep 14 13:21:27 2009 for ATMEL by  doxygen 1.5.3