This file manages the Mouse task. More...
#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 "lib_mcu/cal_inter_rc/cal_inter_rc.h"#include "modules/usb/device_chap9/usb_standard_request.h"
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 | update_osc_cal_task () |
| This function update the OSCCAL value each 30s. | |
| 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. | |
| volatile int | g_int_cpt_cal_update |
This file manages the Mouse task.
Definition in file mouse_task.c.
| bit is_mouse_event | ( | void | ) |
This function checks the board interface and fill the HID mouse report.
Definition at line 196 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().
{
Hid_mouse_report_reset();
// Check Click events
if(Is_mouse_click_left_event()) {
Hid_mouse_report_click_left();
}
if(Is_mouse_click_middle_event()) {
Hid_mouse_report_click_middle();
}
if(Is_mouse_click_right_event()) {
Hid_mouse_report_click_right();
}
// Check Mouve events
if (Is_mouse_left_event()) {
Hid_mouse_report_left();
}
if (Is_mouse_right_event()) {
Hid_mouse_report_right();
}
if (Is_mouse_up_event()) {
Hid_mouse_report_up();
}
if (Is_mouse_down_event()) {
Hid_mouse_report_down();
}
if (Is_mouse_scroll_up_event()) {
Hid_mouse_report_scroll_up();
}
if (Is_mouse_scroll_down_event()) {
Hid_mouse_report_scroll_down();
}
// Check report
if((0==g_hid_mouse_report[0])
&& (0==g_hid_mouse_report[1])
&& (0==g_hid_mouse_report[2])
&& (0==g_hid_mouse_report[3]))
{
return FALSE; // No event
}
return TRUE; // Event(s) occurs
}

| void mouse_task_init | ( | void | ) |
This function initializes the hardware/software resources required for mouse task.
Definition at line 115 of file mouse_task.c.
References FALSE, g_b_send_ack_report, g_b_send_report, g_int_cpt_cal_update, g_u8_cpt_sof, Led6_off, Led7_on, Leds_init, Switches_init, TRUE, and Usb_enable_sof_interrupt.
{
// Init SOF
g_u8_cpt_sof=0;
Usb_enable_sof_interrupt();
// Init interface board
Switches_init();
Leds_init();
Led7_on();
Led6_off();
// Send a ack report at startup
g_b_send_report = FALSE;
g_b_send_ack_report = TRUE;
// Init the internal OSC calibration counter
g_int_cpt_cal_update = 0;
}
| void mouse_task | ( | void | ) |
Task which links mouse events with the USB HID mouse device.
Definition at line 138 of file mouse_task.c.
References EP_MOUSE_IN, FALSE, g_b_send_ack_report, g_b_send_report, g_hid_mouse_report, g_u8_cpt_sof, Hid_mouse_report_reset, Is_device_enumerated, is_mouse_event(), Is_usb_write_enabled, Led6_off, Led6_on, NB_IDLE_POLLING_SOF, TRUE, Usb_ack_in_ready, Usb_select_endpoint, and Usb_write_byte.
{
if(!Is_device_enumerated())
return; // Device not ready
#if (USB_LOW_SPEED_DEVICE==DISABLE)
// The SOF is used to schedule the task at the same frequency that Endpoint Interrupt frequency
// This check allow to win a CPU time
if(g_u8_cpt_sof<NB_IDLE_POLLING_SOF)
return; // Wait a delay
g_u8_cpt_sof=0;
#endif
if(!g_b_send_report)
{
// No report sending on going then check mouse event to eventualy fill a new report
if(is_mouse_event())
{
// Enable sending of report
g_b_send_report = TRUE;
}
}
if((!g_b_send_report)&&(!g_b_send_ack_report))
return; // No report and ack to send
//** A report or ack must be send
Usb_select_endpoint(EP_MOUSE_IN);
if(!Is_usb_write_enabled())
return; // Endpoint no free
Led6_on();
if( g_b_send_report )
{
g_b_send_report = FALSE;
// Send an ack after a "clic" report only
g_b_send_ack_report = (0!=g_hid_mouse_report[0]);
}
else
{
Hid_mouse_report_reset(); // Reset report to have a ack report
g_b_send_ack_report = FALSE;
}
// Send report
Usb_write_byte(g_hid_mouse_report[0]);
Usb_write_byte(g_hid_mouse_report[1]);
Usb_write_byte(g_hid_mouse_report[2]);
Usb_write_byte(g_hid_mouse_report[3]);
Usb_ack_in_ready();
Led6_off();
}

| void update_osc_cal_task | ( | void | ) |
This function update the OSCCAL value each 30s.
//! The calibration of the internal OSC each 30s //!
Definition at line 261 of file mouse_task.c.
References calibrate_inter_osc(), g_int_cpt_cal_update, and vcc_5.
{
g_int_cpt_cal_update++;
if(g_int_cpt_cal_update > 3000)
{
g_int_cpt_cal_update = 0;
calibrate_inter_osc(vcc_5);
}
}

| __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 303 of file mouse_task.c.
References Switches_disable_it, and usb_generate_remote_wakeup().

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().
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().
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().
| volatile int g_int_cpt_cal_update |
Definition at line 110 of file mouse_task.c.
Referenced by mouse_task_init(), and update_osc_cal_task().
1.7.2