This file manages the USB device mouse HID task.
Definition in file device_mouse_hid_task.c.
#include "conf_usb.h"
#include "qt1081.h"
#include "lis3l06al.h"
#include "board.h"
#include "FreeRTOS.h"
#include "task.h"
#include "usb_drv.h"
#include "gpio.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "device_mouse_hid_task.h"
Go to the source code of this file.
Defines | |
#define | BUTTON_0_EVENT_PUSH 1 |
#define | BUTTON_1_EVENT_PUSH 4 |
#define | BUTTON_2_EVENT_PUSH 2 |
#define | DISP_LIMIT_HIGH 300 |
#define | DISP_LIMIT_LOW 150 |
Functions | |
void | device_mouse_hid_task (void *pvParameters) |
Entry point of the device mouse HID task management. | |
void | device_mouse_hid_task_init (void) |
This function initializes the hardware/software resources required for device mouse HID task. | |
Bool | is_usb_mouse_event (void) |
Looks for mouse events. | |
void | usb_sof_action (void) |
usb_sof_action | |
Variables | |
static U16 | sof_cnt |
U8 | u8_report_buttons = 0 |
S8 | u8_report_disp_wheel = 0 |
S8 | u8_report_disp_x = 0 |
S8 | u8_report_disp_y = 0 |
#define BUTTON_0_EVENT_PUSH 1 |
#define BUTTON_1_EVENT_PUSH 4 |
#define BUTTON_2_EVENT_PUSH 2 |
#define DISP_LIMIT_HIGH 300 |
#define DISP_LIMIT_LOW 150 |
void device_mouse_hid_task | ( | void * | pvParameters | ) |
Entry point of the device mouse HID task management.
Write report
Definition at line 353 of file device_mouse_hid_task.c.
References configTSK_USB_DHID_MOUSE_PERIOD, EP_HID_MOUSE_IN, is_usb_mouse_event(), u8_report_buttons, u8_report_disp_wheel, u8_report_disp_x, and u8_report_disp_y.
Referenced by device_mouse_hid_task_init(), and main().
00357 { 00358 #ifdef FREERTOS_USED 00359 portTickType xLastWakeTime; 00360 00361 xLastWakeTime = xTaskGetTickCount(); 00362 while (TRUE) 00363 { 00364 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DHID_MOUSE_PERIOD); 00365 00366 // First, check the device enumeration state 00367 if (!Is_device_enumerated()) continue; 00368 #else 00369 // First, check the device enumeration state 00370 if (!Is_device_enumerated()) return; 00371 #endif // FREERTOS_USED 00372 00373 if( is_usb_mouse_event() ) 00374 { 00375 if( Is_usb_in_ready(EP_HID_MOUSE_IN) ) 00376 { 00377 Usb_reset_endpoint_fifo_access(EP_HID_MOUSE_IN); 00378 00380 Usb_write_endpoint_data(EP_HID_MOUSE_IN, 8, u8_report_buttons); 00381 Usb_write_endpoint_data(EP_HID_MOUSE_IN, 8, u8_report_disp_x); 00382 Usb_write_endpoint_data(EP_HID_MOUSE_IN, 8, u8_report_disp_y); 00383 Usb_write_endpoint_data(EP_HID_MOUSE_IN, 8, u8_report_disp_wheel); 00384 00385 Usb_ack_in_ready_send(EP_HID_MOUSE_IN); 00386 } 00387 } 00388 #ifdef FREERTOS_USED 00389 } 00390 #endif 00391 }
void device_mouse_hid_task_init | ( | void | ) |
This function initializes the hardware/software resources required for device mouse HID task.
Definition at line 105 of file device_mouse_hid_task.c.
References configTSK_USB_DHID_MOUSE_NAME, configTSK_USB_DHID_MOUSE_PRIORITY, configTSK_USB_DHID_MOUSE_STACK_SIZE, device_mouse_hid_task(), and sof_cnt.
Referenced by main().
00106 { 00107 sof_cnt = 0; 00108 00109 #if BOARD == EVK1101 00110 // Initialize accelerometer driver 00111 acc_init(); 00112 #endif 00113 00114 #ifndef FREERTOS_USED 00115 #if USB_HOST_FEATURE == ENABLED 00116 // If both device and host features are enabled, check if device mode is engaged 00117 // (accessing the USB registers of a non-engaged mode, even with load operations, 00118 // may corrupt USB FIFO data). 00119 if (Is_usb_device()) 00120 #endif // USB_HOST_FEATURE == ENABLED 00121 Usb_enable_sof_interrupt(); 00122 #endif // FREERTOS_USED 00123 00124 #ifdef FREERTOS_USED 00125 xTaskCreate(device_mouse_hid_task, 00126 configTSK_USB_DHID_MOUSE_NAME, 00127 configTSK_USB_DHID_MOUSE_STACK_SIZE, 00128 NULL, 00129 configTSK_USB_DHID_MOUSE_PRIORITY, 00130 NULL); 00131 #endif // FREERTOS_USED 00132 }
Bool is_usb_mouse_event | ( | void | ) |
Looks for mouse events.
Definition at line 138 of file device_mouse_hid_task.c.
References BUTTON_0_EVENT_PUSH, BUTTON_1_EVENT_PUSH, BUTTON_2_EVENT_PUSH, DISP_LIMIT_HIGH, DISP_LIMIT_LOW, u8_report_buttons, u8_report_disp_wheel, u8_report_disp_x, and u8_report_disp_y.
Referenced by device_mouse_hid_task().
00139 { 00140 static U8 disp=1; 00141 static U16 count=0; 00142 #if BOARD != EVK1104 && BOARD != UC3C_EK && BOARD != EVK1105 00143 static Bool old_click_0=FALSE; // FALSE means released, TRUE means pushed 00144 static Bool old_click_1=FALSE; // FALSE means released, TRUE means pushed 00145 #endif 00146 #if BOARD == EVK1100 00147 static Bool old_click_2=FALSE; // FALSE means released, TRUE means pushed 00148 #endif 00149 Bool b_activity; 00150 00151 u8_report_buttons=0; 00152 u8_report_disp_x=0; 00153 u8_report_disp_y=0; 00154 u8_report_disp_wheel=0; 00155 b_activity=FALSE; 00156 00157 #if BOARD == EVK1101 00158 signed int res; 00159 00160 // Get accelerometer acquisition and process datas 00161 acc_update(); 00162 00163 // Look joystick activity for the Wheel events 00164 // input is pulled up, if 1 : input is not active 00165 if( is_joystick_up() ) 00166 u8_report_disp_wheel=disp, b_activity=TRUE; 00167 00168 if( is_joystick_down() ) 00169 u8_report_disp_wheel=-disp, b_activity=TRUE; 00170 00171 // Look accelerometer activity for the X and Y events 00172 if( 0!=(res=is_acc_abs_angle_x(40)) ) 00173 { 00174 if( res>0 ) 00175 u8_report_disp_x=-10*disp, b_activity=TRUE; 00176 else if( res<0 ) 00177 u8_report_disp_x=10*disp, b_activity=TRUE; 00178 } 00179 else if( 0!=(res=is_acc_abs_angle_x(30)) ) 00180 { 00181 if( res>0 ) 00182 u8_report_disp_x=-6*disp, b_activity=TRUE; 00183 else if( res<0 ) 00184 u8_report_disp_x=6*disp, b_activity=TRUE; 00185 } 00186 else if( 0!=(res=is_acc_abs_angle_x(20)) ) 00187 { 00188 if( res>0 ) 00189 u8_report_disp_x=-4*disp, b_activity=TRUE; 00190 else if( res<0 ) 00191 u8_report_disp_x=4*disp, b_activity=TRUE; 00192 } 00193 00194 else if( 0!=(res=is_acc_abs_angle_x(15)) ) 00195 { 00196 if( res>0 ) 00197 u8_report_disp_x=-2*disp, b_activity=TRUE; 00198 else if( res<0 ) 00199 u8_report_disp_x=2*disp, b_activity=TRUE; 00200 } 00201 else if( 0!=(res=is_acc_abs_angle_x(10)) ) 00202 { 00203 if( res>0 ) 00204 u8_report_disp_x=-disp, b_activity=TRUE; 00205 else if( res<0 ) 00206 u8_report_disp_x=disp, b_activity=TRUE; 00207 } 00208 00209 00210 00211 if( 0!=(res=is_acc_abs_angle_y(40)) ) 00212 { 00213 if( res>0 ) 00214 u8_report_disp_y=-10*disp, b_activity=TRUE; 00215 else if( res<0 ) 00216 u8_report_disp_y=10*disp, b_activity=TRUE; 00217 } 00218 else if( 0!=(res=is_acc_abs_angle_y(30)) ) 00219 { 00220 if( res>0 ) 00221 u8_report_disp_y=-6*disp, b_activity=TRUE; 00222 else if( res<0 ) 00223 u8_report_disp_y=6*disp, b_activity=TRUE; 00224 } 00225 else if( 0!=(res=is_acc_abs_angle_y(20)) ) 00226 { 00227 if( res>0 ) 00228 u8_report_disp_y=-4*disp, b_activity=TRUE; 00229 else if( res<0 ) 00230 u8_report_disp_y=4*disp, b_activity=TRUE; 00231 } 00232 else if( 0!=(res=is_acc_abs_angle_y(15)) ) 00233 { 00234 if( res>0 ) 00235 u8_report_disp_y=-2*disp, b_activity=TRUE; 00236 else if( res<0 ) 00237 u8_report_disp_y=2*disp, b_activity=TRUE; 00238 } 00239 else if( 0!=(res=is_acc_abs_angle_y(10)) ) 00240 { 00241 if( res>0 ) 00242 u8_report_disp_y=-disp, b_activity=TRUE; 00243 else if( res<0 ) 00244 u8_report_disp_y=disp, b_activity=TRUE; 00245 } 00246 00247 #elif BOARD == EVK1100 00248 00249 // Look Joystick activity for the X and Y events 00250 // input is pulled up, if 1 : input is not active 00251 if (is_joystick_right()) 00252 u8_report_disp_x=disp, b_activity=TRUE; 00253 00254 if (is_joystick_left()) 00255 u8_report_disp_x=-disp, b_activity=TRUE; 00256 00257 if (is_joystick_down()) 00258 u8_report_disp_y=disp, b_activity=TRUE; 00259 00260 if (is_joystick_up()) 00261 u8_report_disp_y=-disp, b_activity=TRUE; 00262 00263 #elif BOARD == EVK1105 00264 00265 // Right 00266 if (is_touch_sensor_2()) 00267 u8_report_disp_x=disp, b_activity=TRUE; 00268 // Left 00269 if (is_touch_sensor_3()) 00270 u8_report_disp_x=-disp, b_activity=TRUE; 00271 // Down 00272 if (is_touch_sensor_1()) 00273 u8_report_disp_y=disp, b_activity=TRUE; 00274 // Up 00275 if (is_touch_sensor_0()) 00276 u8_report_disp_y=-disp, b_activity=TRUE; 00277 00278 #elif BOARD == EVK1104 00279 if (gpio_get_pin_value(GPIO_PUSH_BUTTON_SW2) == GPIO_PUSH_BUTTON_SW2_PRESSED) 00280 u8_report_disp_y=-disp, b_activity=TRUE; 00281 #elif BOARD == UC3C_EK 00282 // mouse pointer down 00283 if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_0)) { 00284 u8_report_disp_y=disp, b_activity=TRUE; 00285 } 00286 00287 // mouse pointer up 00288 if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_1)) { 00289 u8_report_disp_y=-disp, b_activity=TRUE; 00290 } 00291 #endif 00292 00293 if( b_activity ) 00294 { 00295 count++; 00296 if( count >= DISP_LIMIT_HIGH ) 00297 disp=3; 00298 else if( count >= DISP_LIMIT_LOW ) 00299 disp=2; 00300 } 00301 else 00302 count=0, disp=1; 00303 00304 00305 00306 // Look for button activity 00307 #if BOARD != EVK1104 && BOARD != UC3C_EK && BOARD != EVK1105 00308 // input is pulled up, if 1 : input is not active 00309 if( (!gpio_get_pin_value(GPIO_PUSH_BUTTON_0)) 00310 || (is_joystick_pressed() ) ) 00311 { 00312 Set_bits(u8_report_buttons, BUTTON_0_EVENT_PUSH); 00313 if( old_click_0==FALSE ) 00314 old_click_0=TRUE, b_activity=TRUE; 00315 } 00316 else 00317 if( old_click_0==TRUE ) 00318 old_click_0=FALSE, b_activity=TRUE; 00319 00320 00321 00322 if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_1) ) 00323 { 00324 Set_bits(u8_report_buttons, BUTTON_1_EVENT_PUSH); 00325 if( old_click_1==FALSE ) 00326 old_click_1=TRUE, b_activity=TRUE; 00327 } 00328 else 00329 if( old_click_1==TRUE ) 00330 old_click_1=FALSE, b_activity=TRUE; 00331 #endif 00332 #if BOARD == EVK1100 00333 if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_2) ) 00334 { 00335 Set_bits(u8_report_buttons, BUTTON_2_EVENT_PUSH); 00336 if( old_click_2==FALSE ) 00337 old_click_2=TRUE, b_activity=TRUE; 00338 } 00339 else 00340 if( old_click_2==TRUE ) 00341 old_click_2=FALSE, b_activity=TRUE; 00342 #endif 00343 00344 if( b_activity ) return TRUE; 00345 else return FALSE; 00346 }
U16 sof_cnt [static] |
Definition at line 92 of file device_mouse_hid_task.c.
Referenced by device_mouse_hid_task_init(), host_keyboard_hid_task(), host_keyboard_hid_task_init(), host_mouse_hid_task_init(), host_sof_action(), and usb_sof_action().
U8 u8_report_buttons = 0 |
Definition at line 94 of file device_mouse_hid_task.c.
Referenced by device_mouse_hid_task(), and is_usb_mouse_event().
S8 u8_report_disp_wheel = 0 |
Definition at line 97 of file device_mouse_hid_task.c.
Referenced by device_mouse_hid_task(), and is_usb_mouse_event().
S8 u8_report_disp_x = 0 |
Definition at line 95 of file device_mouse_hid_task.c.
Referenced by device_mouse_hid_task(), and is_usb_mouse_event().
S8 u8_report_disp_y = 0 |
Definition at line 96 of file device_mouse_hid_task.c.
Referenced by device_mouse_hid_task(), and is_usb_mouse_event().