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

- File List
- Globals

# mouse_task.c

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007
    00008
    00009
    00010
    00011
    00012
    00013
    00014
    00015
    00016 //_____  I N C L U D E S ___________________________________________________
    00017
    00018 #include "config.h"
    00019 #include "conf_usb.h"
    00020 #include "mouse_task.h"
    00021 #include "lib_mcu/usb/usb_drv.h"
    00022 #include "usb_descriptors.h"
    00023 #include "modules/usb/device_chap9/usb_standard_request.h"
    00024 #include "lib_mcu/wdt/wdt_drv.h"
    00025 #include "lib_mcu/power/power_drv.h"
    00026 #include "lib_mcu/pll/pll_drv.h"
    00027 #include "lib_mcu/quickstart/at90usb162_quickstart_drv.h"
    00028
    00029
    00030 //_____ M A C R O S ________________________________________________________
    00031
    00032 #define Usb_mouse_up()                  (usb_mouse_report[2]-=MOUSE_SPEED)
    00033 #define Usb_mouse_down()                (usb_mouse_report[2]+=MOUSE_SPEED)
    00034 #define Usb_mouse_left()                (usb_mouse_report[1]-=MOUSE_SPEED)
    00035 #define Usb_mouse_right()               (usb_mouse_report[1]+=MOUSE_SPEED)
    00036 #define Usb_mouse_click_left()          (usb_mouse_report[0] |= 0x01)
    00037 #define Usb_mouse_click_right()         (usb_mouse_report[0] |= 0x02)
    00038 #define Usb_mouse_click_middle()        (usb_mouse_report[0] |= 0x04)
    00039 #define Usb_mouse_release_left()        (usb_mouse_report[0] &= ~0x01)
    00040 #define Usb_mouse_release_right()       (usb_mouse_report[0] &= ~0x02)
    00041 #define Usb_mouse_release_middle()      (usb_mouse_report[0] &= ~0x04)
    00042 #define Usb_mouse_scroll_up()           (usb_mouse_report[3]++)
    00043 #define Usb_mouse_scroll_down()         (usb_mouse_report[3]--)
    00044 #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)
    00045
    00046 #define Is_mouse_left_event()           Is_joy_left()
    00047 #define Is_mouse_right_event()          Is_joy_right()
    00048 #define Is_mouse_up_event()             Is_joy_up()
    00049 #define Is_mouse_down_event()           Is_joy_down()
    00050 #define Is_mouse_click_left_event()   Is_hwb()
    00051 #define Is_mouse_release_left_event() !Is_hwb()
    00052
    00053
    00054
    00055
    00056 //_____ D E F I N I T I O N S ______________________________________________
    00057
    00058
    00059
    00060 //_____ D E C L A R A T I O N S ____________________________________________
    00061
    00062 U8 report_ready;
    00063 volatile U8 usb_mouse_report[4];
    00064 U16 wheel;
    00065 volatile U8 cpt_sof;
    00066 extern  U8   usb_configuration_nb;
    00067
    00068
    00080 void mouse_task_init(void)
    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 }
    00091
    00092
    00093
    00101 void mouse_task(void)
    00102 {
    00103 }
    00104
    00105
    00106
    00116 void mouse_task_by_IT(void)
    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 }
    00137
    00146 bit is_usb_mouse_event(void)
    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 }
    00204
    00205
    00217 void sof_action()
    00218 {
    00219    U8 ep_selected;
    00220    cpt_sof++;
    00221    if (cpt_sof == NB_IDLE_POLLING_SOF)
    00222    {
    00223      ep_selected = Usb_get_selected_endpoint();   // the currently selected endpoint must be saved to avoid
    00224                                                   // problems when interrupt happens during mass storage endpoint reading/writing
    00225      mouse_task_by_IT();
    00226      cpt_sof = 0;
    00227      Usb_select_endpoint(ep_selected);            // restore current selected endpoint
    00228    }
    00229 }
    00230