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

- File List
- Globals

# mouse_task.c File Reference

,vThis file manages the Mouse task. More...

`#include "config.h"`
`#include "conf_usb.h"`
`#include "mouse_task.h"`
`#include "lib_mcu/usb/usb_drv.h"`
`#include "usb_descriptors.h"`
`#include "modules/usb/device_chap9/usb_standard_request.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/quickstart/at90usb162_quickstart_drv.h"`

Include dependency graph for mouse_task.c:

Go to the source code of this file.

## Defines
#define | Usb_mouse_up() (usb_mouse_report[2]-=MOUSE_SPEED)
#define | Usb_mouse_down() (usb_mouse_report[2]+=MOUSE_SPEED)
#define | Usb_mouse_left() (usb_mouse_report[1]-=MOUSE_SPEED)
#define | Usb_mouse_right() (usb_mouse_report[1]+=MOUSE_SPEED)
#define | Usb_mouse_click_left() (usb_mouse_report[0] |= 0x01)
#define | Usb_mouse_click_right() (usb_mouse_report[0] |= 0x02)
#define | Usb_mouse_click_middle() (usb_mouse_report[0] |= 0x04)
#define | Usb_mouse_release_left() (usb_mouse_report[0] &= ~0x01)
#define | Usb_mouse_release_right() (usb_mouse_report[0] &= ~0x02)
#define | Usb_mouse_release_middle() (usb_mouse_report[0] &= ~0x04)
#define | Usb_mouse_scroll_up() (usb_mouse_report[3]++)
#define | Usb_mouse_scroll_down() (usb_mouse_report[3]--)
#define | Usb_mouse_report_reset() (usb_mouse_report[0]=0,usb_mouse_report[1]=0,usb_mouse_report[2]=0,usb_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 | Is_mouse_click_left_event() Is_hwb()
#define | Is_mouse_release_left_event() !Is_hwb()
## Functions
void | mouse_task_init (void)
| This function initializes the hardware/software resources required for mouse task.
void | mouse_task (void)
| Entry point of the mouse management.
void | mouse_task_by_IT (void)
| Entry point of the mouse management.
bit | is_usb_mouse_event (void)
| Is_usb_mouse_event.
void | sof_action ()
| sof_action
## Variables
U8 | report_ready
volatile U8 | usb_mouse_report [4]
U16 | wheel
volatile U8 | cpt_sof
U8 | usb_configuration_nb

## Detailed Description

,vThis file manages the Mouse task.

Copyright (c) 2004 Atmel.

Please read file license.txt for copyright notice.

Version:
  1.4 at90usb162-2enum-mouse_ms-1_0_1
  Id
    mouse_task.c,v 1.4 2007/01/08 16:09:44 arobert Exp

Todo:

Bug:
  /

Definition in file mouse_task.c.

## Define Documentation

#define Usb_mouse_up | ( |  | ) | (usb_mouse_report[2]-=MOUSE_SPEED)

Definition at line 32 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Usb_mouse_down | ( |  | ) | (usb_mouse_report[2]+=MOUSE_SPEED)

Definition at line 33 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Usb_mouse_left | ( |  | ) | (usb_mouse_report[1]-=MOUSE_SPEED)

Definition at line 34 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Usb_mouse_right | ( |  | ) | (usb_mouse_report[1]+=MOUSE_SPEED)

Definition at line 35 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Usb_mouse_click_left | ( |  | ) | (usb_mouse_report[0] |= 0x01)

Definition at line 36 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Usb_mouse_click_right | ( |  | ) | (usb_mouse_report[0] |= 0x02)

Definition at line 37 of file mouse_task.c.

#define Usb_mouse_click_middle | ( |  | ) | (usb_mouse_report[0] |= 0x04)

Definition at line 38 of file mouse_task.c.

#define Usb_mouse_release_left | ( |  | ) | (usb_mouse_report[0] &= ~0x01)

Definition at line 39 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Usb_mouse_release_right | ( |  | ) | (usb_mouse_report[0] &= ~0x02)

Definition at line 40 of file mouse_task.c.

#define Usb_mouse_release_middle | ( |  | ) | (usb_mouse_report[0] &= ~0x04)

Definition at line 41 of file mouse_task.c.

#define Usb_mouse_scroll_up | ( |  | ) | (usb_mouse_report[3]++)

Definition at line 42 of file mouse_task.c.

#define Usb_mouse_scroll_down | ( |  | ) | (usb_mouse_report[3]--)

Definition at line 43 of file mouse_task.c.

#define Usb_mouse_report_reset | ( |  | ) | (usb_mouse_report[0]=0,usb_mouse_report[1]=0,usb_mouse_report[2]=0,usb_mouse_report[3]=0)

Definition at line 44 of file mouse_task.c.

Referenced by is_usb_mouse_event(), and mouse_task_init().

#define Is_mouse_left_event | ( |  | ) | Is_joy_left()

Definition at line 46 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Is_mouse_right_event | ( |  | ) | Is_joy_right()

Definition at line 47 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Is_mouse_up_event | ( |  | ) | Is_joy_up()

Definition at line 48 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Is_mouse_down_event | ( |  | ) | Is_joy_down()

Definition at line 49 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Is_mouse_click_left_event | ( |  | ) | Is_hwb()

Definition at line 50 of file mouse_task.c.

Referenced by is_usb_mouse_event().

#define Is_mouse_release_left_event | ( |  | ) | !Is_hwb()

Definition at line 51 of file mouse_task.c.

Referenced by is_usb_mouse_event().

## Function Documentation

void mouse_task_init | ( | void |  | ) |

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

Warning:
  Code:?? bytes (function code length)

Parameters:

  | none |

Returns:
  none

/

Definition at line 80 of file mouse_task.c.

References cpt_sof, Hwb_button_init, Joy_init, Leds_init, report_ready, TRUE, Usb_enable_sof_interrupt, Usb_mouse_report_reset, and wheel.

    00081 {
    00082    Usb_mouse_report_reset();
    00083    report_ready=TRUE;
    00084    wheel=0;
    00085    cpt_sof=0;
    00086    Usb_enable_sof_interrupt();
    00087    Joy_init();
    00088    Leds_init();
    00089    Hwb_button_init();
    00090 }

void mouse_task | ( | void |  | ) |

Entry point of the mouse management.

This function has no effect, but is called by scheduler. It is replaced by mouse_task_by_IT() that is interrupt handled

Parameters:

  | none |

Returns:
  none

Definition at line 101 of file mouse_task.c.

    00102 {
    00103 }

void mouse_task_by_IT | ( | void |  | ) |

Entry point of the mouse management.

This function links the mouse and the USB bus. This task is interrupt handled : the function is called periodically from the ISR of Start of Frame reception That makes possible moving the mouse while the mass storage is used (file copy for example)

Parameters:

  | none |

Returns:
  none

Definition at line 116 of file mouse_task.c.

References EP_MOUSE_IN, Is_device_enumerated, is_usb_mouse_event(), Is_usb_report_ready, Is_usb_write_enabled, report_ready, TRUE, Usb_ack_in_ready, usb_mouse_report, Usb_select_endpoint, Usb_set_report_not_ready, and Usb_write_byte.

Referenced by sof_action().

    00117 {
    00118    if(Is_device_enumerated() && !Is_usb_report_ready() && is_usb_mouse_event())
    00119    {
    00120       report_ready=TRUE;
    00121    }
    00122
    00123    if (Is_device_enumerated() && Is_usb_report_ready())
    00124    {
    00125       Usb_select_endpoint(EP_MOUSE_IN);
    00126       if (Is_usb_write_enabled())
    00127       {
    00128          Usb_set_report_not_ready();
    00129          Usb_write_byte(usb_mouse_report[0]);
    00130          Usb_write_byte(usb_mouse_report[1]);
    00131          Usb_write_byte(usb_mouse_report[2]);
    00132          Usb_write_byte(usb_mouse_report[3]);
    00133          Usb_ack_in_ready();
    00134       }
    00135    }
    00136 }

Here is the call graph for this function:

bit is_usb_mouse_event | ( | void |  | ) |

Is_usb_mouse_event.

This function returns TRUE if a event occurs on the mouse (FALSE if not). The mouse report is updated by this function

Parameters:

  | none |

Returns:
  none

Definition at line 146 of file mouse_task.c.

References FALSE, Is_device_enumerated, Is_mouse_click_left_event, Is_mouse_down_event, Is_mouse_left_event, Is_mouse_release_left_event, Is_mouse_right_event, Is_mouse_up_event, TRUE, Usb_mouse_click_left, Usb_mouse_down, Usb_mouse_left, Usb_mouse_release_left, Usb_mouse_report_reset, Usb_mouse_right, and Usb_mouse_up.

Referenced by mouse_task_by_IT().

    00147 {
    00148    bit usb_mouse_event_stored;
    00149
    00150 // Following must not be used if interrupt handled task
    00151 //   if(cpt_sof<NB_IDLE_POLLING_SOF) return FALSE;
    00152 //   cpt_sof=0;
    00153
    00154    Usb_mouse_report_reset();
    00155
    00156    if(Is_device_enumerated())
    00157    {
    00158            // Check left click report
    00159       if(Is_mouse_click_left_event())
    00160       {
    00161          Usb_mouse_click_left();
    00162          usb_mouse_event_stored = 1;
    00163       }
    00164
    00165       if(Is_mouse_release_left_event())
    00166       {
    00167          Usb_mouse_release_left();
    00168          usb_mouse_event_stored = 1;
    00169       }
    00170
    00171       if (Is_mouse_left_event())
    00172       {
    00173         Usb_mouse_left();
    00174          usb_mouse_event_stored = 1;
    00175       }
    00176
    00177       if (Is_mouse_right_event())
    00178       {
    00179          Usb_mouse_right();
    00180          usb_mouse_event_stored = 1;
    00181       }
    00182
    00183       if (Is_mouse_down_event())
    00184       {
    00185          Usb_mouse_down();
    00186          usb_mouse_event_stored = 1;
    00187       }
    00188
    00189      if (Is_mouse_up_event())
    00190      {
    00191         Usb_mouse_up();
    00192         usb_mouse_event_stored = 1;
    00193      }
    00194
    00195      if (usb_mouse_event_stored == 1)
    00196      {
    00197         usb_mouse_event_stored = 0;
    00198         return TRUE;
    00199      }
    00200        else {return FALSE;}
    00201    }
    00202    return FALSE;
    00203 }

## Variable Documentation

U8 report_ready

Definition at line 62 of file mouse_task.c.

Referenced by mouse_task_by_IT(), and mouse_task_init().

volatile U8 usb_mouse_report[4]

Definition at line 63 of file mouse_task.c.

Referenced by mouse_task_by_IT().

U16 wheel

Definition at line 64 of file mouse_task.c.

Referenced by mouse_task_init().

volatile U8 cpt_sof

Definition at line 65 of file mouse_task.c.

Referenced by mouse_task_init(), and sof_action().

U8 usb_configuration_nb

Definition at line 71 of file usb_standard_request.c.

Referenced by usb_device_task(), usb_get_configuration(), and usb_set_configuration().