host_mouse_hid_task.c File Reference


Detailed Description

Management of the USB host mouse HID task.

This file manages the USB host mouse HID task.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file host_mouse_hid_task.c.

#include "conf_usb.h"
#include "board.h"
#include "FreeRTOS.h"
#include "task.h"
#include "usb_drv.h"
#include "usb_host_enum.h"
#include "usb_host_task.h"
#include "host_hid.h"
#include "host_mouse_hid_task.h"
#include <stdio.h>

Go to the source code of this file.

Defines

#define MOUSE_X_MAX   80
#define MOUSE_X_MIN   0
#define MOUSE_Y_MAX   18
#define MOUSE_Y_MIN   0

Functions

static void disp_ascii_mouse (void)
 Display the mouse pointer on a terminal.
static void disp_led_mouse (void)
 Display some animation on the LED according to the mouse status.
void host_mouse_hid_task (void *pvParameters)
 This function manages the host mouse HID task.
void host_mouse_hid_task_init (void)
 This function initializes the host mouse HID task.
void host_sof_action (void)
 host_sof_action

Variables

Bool mouse_b0
Bool mouse_b1
Bool mouse_b2
volatile Bool mouse_hid_connected
volatile Bool mouse_hid_new_device_connected
S8 mouse_x
S8 mouse_y
S8 new_x
S8 new_y
U8 pipe_mouse_in
static U16 sof_cnt
volatile S8 usb_report [4]


Define Documentation

#define MOUSE_X_MAX   80

Definition at line 75 of file host_mouse_hid_task.c.

Referenced by host_mouse_hid_task().

#define MOUSE_X_MIN   0

Definition at line 74 of file host_mouse_hid_task.c.

Referenced by host_mouse_hid_task().

#define MOUSE_Y_MAX   18

Definition at line 77 of file host_mouse_hid_task.c.

Referenced by host_mouse_hid_task().

#define MOUSE_Y_MIN   0

Definition at line 76 of file host_mouse_hid_task.c.

Referenced by host_mouse_hid_task().


Function Documentation

static void disp_ascii_mouse ( void   )  [static]

Display the mouse pointer on a terminal.

This function displays a mouse cursor through the USART port.

Definition at line 247 of file host_mouse_hid_task.c.

References mouse_b0, mouse_b1, mouse_b2, mouse_x, and mouse_y.

Referenced by host_mouse_hid_task().

00248 {
00249    static const char *const ad[]={"High Performance", "Code Density", "Low consumption", "CALL NOW !!!"};
00250    static U8 ad_id=0;
00251    puts("\x1B[2J\x1B[H--- HID MOUSE EXAMPLE ------------------------------------\r\n");
00252    if( mouse_b0 ) { // Thanks Banner!
00253 #if BOARD == EVK1100 || BOARD == EVK1105
00254       printf("\x1B[%.2hhd;%.2hhdHOOOO OOOO   OOO O   OOOO    OOOO    \r\n", mouse_y, mouse_x);
00255       printf("\x1B[%.2hhd;%.2hhdH O     O   O   OO       O     O O   \r\n", mouse_y+1, mouse_x);
00256       printf("\x1B[%.2hhd;%.2hhdH O     O  O     O       O     O O   \r\n", mouse_y+2, mouse_x);
00257       printf("\x1B[%.2hhd;%.2hhdH O     O  O           OO     O   O  \r\n", mouse_y+3, mouse_x);
00258       printf("\x1B[%.2hhd;%.2hhdH O     O  O             O    OOOOO  \r\n", mouse_y+4, mouse_x);
00259       printf("\x1B[%.2hhd;%.2hhdH OO   OO   O    O       O   O     O \r\n", mouse_y+5, mouse_x);
00260       printf("\x1B[%.2hhd;%.2hhdH   OOO      OOOO   OOOOO   OOO   OOO\r\n", mouse_y+6, mouse_x);
00261 #elif BOARD == EVK1101
00262       printf("\x1B[%.2hhd;%.2hhdHOOOO OOOO   OOO O   OOOO    OOOOOO \r\n", mouse_y, mouse_x);
00263       printf("\x1B[%.2hhd;%.2hhdH O     O   O   OO       O    O    O\r\n", mouse_y+1, mouse_x);
00264       printf("\x1B[%.2hhd;%.2hhdH O     O  O     O       O    O    O\r\n", mouse_y+2, mouse_x);
00265       printf("\x1B[%.2hhd;%.2hhdH O     O  O           OO     OOOOO \r\n", mouse_y+3, mouse_x);
00266       printf("\x1B[%.2hhd;%.2hhdH O     O  O             O    O    O\r\n", mouse_y+4, mouse_x);
00267       printf("\x1B[%.2hhd;%.2hhdH OO   OO   O    O       O    O    O\r\n", mouse_y+5, mouse_x);
00268       printf("\x1B[%.2hhd;%.2hhdH   OOO      OOOO   OOOOO    OOOOOO \r\n", mouse_y+6, mouse_x);
00269 #elif BOARD == EVK1104
00270       printf("\x1B[%.2hhd;%.2hhdHOOOO OOOO   OOO O   OOOO    OOOO       OOOO \r\n", mouse_y, mouse_x);
00271       printf("\x1B[%.2hhd;%.2hhdH O     O   O   OO       O     O O          O\r\n", mouse_y+1, mouse_x);
00272       printf("\x1B[%.2hhd;%.2hhdH O     O  O     O       O     O O          O\r\n", mouse_y+2, mouse_x);
00273       printf("\x1B[%.2hhd;%.2hhdH O     O  O           OO     O   O       OO \r\n", mouse_y+3, mouse_x);
00274       printf("\x1B[%.2hhd;%.2hhdH O     O  O             O    OOOOO         O\r\n", mouse_y+4, mouse_x);
00275       printf("\x1B[%.2hhd;%.2hhdH OO   OO   O    O       O   O     O        O\r\n", mouse_y+5, mouse_x);
00276       printf("\x1B[%.2hhd;%.2hhdH   OOO      OOOO   OOOOO   OOO   OOO  OOOOO \r\n", mouse_y+6, mouse_x);
00277 #elif BOARD == UC3C_EK
00278       printf("\x1B[%.2hhd;%.2hhdHOOOO OOOO   OOO O   OOOO     OOO O\r\n", mouse_y, mouse_x);
00279       printf("\x1B[%.2hhd;%.2hhdH O     O   O   OO       O   O   OO\r\n", mouse_y+1, mouse_x);
00280       printf("\x1B[%.2hhd;%.2hhdH O     O  O     O       O  O     O\r\n", mouse_y+2, mouse_x);
00281       printf("\x1B[%.2hhd;%.2hhdH O     O  O           OO   O      \r\n", mouse_y+3, mouse_x);
00282       printf("\x1B[%.2hhd;%.2hhdH O     O  O             O  O      \r\n", mouse_y+4, mouse_x);
00283       printf("\x1B[%.2hhd;%.2hhdH OO   OO   O    O       O   O    O\r\n", mouse_y+5, mouse_x);
00284       printf("\x1B[%.2hhd;%.2hhdH   OOO      OOOO   OOOOO     OOOO \r\n", mouse_y+6, mouse_x);
00285 #else
00286 #warning Board not supported
00287 #endif
00288    }
00289    else if( mouse_b1 ) {
00290 #if BOARD == EVK1100 || BOARD == EVK1105 || BOARD == EVK1104
00291       printf("\x1B[%.2hhd;%.2hhdH   OOO     OOOO      OOOOO   OOO    OO  OOOOO   OOOOOO    OOOOOO\r\n", mouse_y, mouse_x);
00292       printf("\x1B[%.2hhd;%.2hhdH  O   O        O      O   O   OO   OO     O      O    O  O     O\r\n", mouse_y+1, mouse_x);
00293       printf("\x1B[%.2hhd;%.2hhdH  O   O        O      O    O  O O O O     O      O    O  O      \r\n", mouse_y+2, mouse_x);
00294       printf("\x1B[%.2hhd;%.2hhdH   OOO       OO       O    O  O O O O     O      O    O   OOOOO \r\n", mouse_y+3, mouse_x);
00295       printf("\x1B[%.2hhd;%.2hhdH OO   O        O      O    O  O  O  O     O      OOOOO         O\r\n", mouse_y+4, mouse_x);
00296       printf("\x1B[%.2hhd;%.2hhdH O    O        O      O   O   O     O     O      O       O     O\r\n", mouse_y+5, mouse_x);
00297       printf("\x1B[%.2hhd;%.2hhdH  OOOO    OOOOO      OOOOO   OOO   OOO  OOOOO   OOOO     OOOOOO \r\n", mouse_y+6, mouse_x);
00298 #elif BOARD == EVK1101 || BOARD == UC3C_EK
00299       printf("\x1B[%.2hhd;%.2hhdH OOOOOOO   OOOOO      OOOOO   OOO    OO  OOOOO   OOOOOO    OOOOOO\r\n", mouse_y, mouse_x);
00300       printf("\x1B[%.2hhd;%.2hhdH O     O   O           O   O   OO   OO     O      O    O  O     O\r\n", mouse_y+1, mouse_x);
00301       printf("\x1B[%.2hhd;%.2hhdH      O    O           O    O  O O O O     O      O    O  O      \r\n", mouse_y+2, mouse_x);
00302       printf("\x1B[%.2hhd;%.2hhdH      O    OOOOO       O    O  O O O O     O      O    O   OOOOO \r\n", mouse_y+3, mouse_x);
00303       printf("\x1B[%.2hhd;%.2hhdH     O          O      O    O  O  O  O     O      OOOOO         O\r\n", mouse_y+4, mouse_x);
00304       printf("\x1B[%.2hhd;%.2hhdH    O           O      O   O   O     O     O      O       O     O\r\n", mouse_y+5, mouse_x);
00305       printf("\x1B[%.2hhd;%.2hhdH    O      OOOOO      OOOOO   OOO   OOO  OOOOO   OOOO     OOOOOO \r\n", mouse_y+6, mouse_x);
00306 #else
00307 #warning Board not supported
00308 #endif
00309    }
00310    else if( mouse_b2 ) {
00311       printf("\x1B[%.2hhd;%.2hhdH%s\r\n", mouse_y, mouse_x, ad[ad_id++]);
00312       if( ad_id==4 ) ad_id=0;
00313    }
00314    else
00315    {
00316       printf("\x1B[%.2hhd;%.2hhdH#    \r\n", mouse_y, mouse_x);
00317       printf("\x1B[%.2hhd;%.2hhdH###  \r\n", mouse_y+1, mouse_x);
00318       printf("\x1B[%.2hhd;%.2hhdH#####\r\n", mouse_y+2, mouse_x);
00319       printf("\x1B[%.2hhd;%.2hhdH# ## \r\n", mouse_y+3, mouse_x);
00320       printf("\x1B[%.2hhd;%.2hhdH   ##\r\n", mouse_y+4, mouse_x);
00321    }
00322 }

static void disp_led_mouse ( void   )  [static]

Display some animation on the LED according to the mouse status.

Definition at line 221 of file host_mouse_hid_task.c.

References LED_HOST_MOUSE_B0, LED_HOST_MOUSE_B1, LED_HOST_MOUSE_B2, LED_HOST_MOUSE_B3, mouse_b0, mouse_b1, mouse_b2, new_x, and new_y.

Referenced by host_mouse_hid_task().

00222 {
00223    // Use software debounce for the Led (can not use LED_Toggle(x) !)
00224    LED_Display_Field(LED_HOST_MOUSE_B0 |
00225                      LED_HOST_MOUSE_B1,
00226                      new_x %4);
00227 
00228    LED_Display_Field(LED_HOST_MOUSE_B2 |
00229                      LED_HOST_MOUSE_B3,
00230                      new_y %4);
00231 
00232    if( mouse_b0 ) LED_Toggle( LED_HOST_MOUSE_B0 );
00233    //else           LED_Off(LED_HOST_MOUSE_B0 );
00234    if( mouse_b1 ) LED_Toggle( LED_HOST_MOUSE_B1 );
00235    //else           LED_Off(LED_HOST_MOUSE_B1 );
00236    if( mouse_b2 ) LED_Toggle( LED_HOST_MOUSE_B2 );
00237    //else           LED_Off(LED_HOST_MOUSE_B2 );
00238 }

void host_mouse_hid_task ( void *  pvParameters  ) 

This function manages the host mouse HID task.

Definition at line 120 of file host_mouse_hid_task.c.

References configTSK_USB_HHID_MOUSE_PERIOD, disp_ascii_mouse(), disp_led_mouse(), HID_IDLE_DURATION_INDEFINITE, HID_REPORT_DESCRIPTOR, HID_REPORT_ID_ALL, host_hid_get_report(), host_hid_set_idle(), Is_host_mouse_hid_configured, LED_HOST_MOUSE_B0, LED_HOST_MOUSE_B1, LED_HOST_MOUSE_B2, LED_HOST_MOUSE_B3, mouse_b0, mouse_b1, mouse_b2, mouse_hid_connected, mouse_hid_new_device_connected, mouse_x, MOUSE_X_MAX, MOUSE_X_MIN, mouse_y, MOUSE_Y_MAX, MOUSE_Y_MIN, new_x, new_y, pipe_mouse_in, and usb_report.

Referenced by host_mouse_hid_task_init(), and main().

00124 {
00125   U8 i;
00126 
00127 #ifdef FREERTOS_USED
00128   portTickType xLastWakeTime;
00129 
00130   xLastWakeTime = xTaskGetTickCount();
00131   while (TRUE)
00132   {
00133     vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HHID_MOUSE_PERIOD);
00134 
00135 #endif  // FREERTOS_USED
00136     // First, check the host controller is in full operating mode with the
00137     // B-device attached and enumerated
00138     if (Is_host_ready())
00139     {
00140       // New device connection (executed only once after device connection)
00141       if (mouse_hid_new_device_connected)
00142       {
00143         mouse_hid_new_device_connected = FALSE;
00144 
00145         // For all supported interfaces
00146         for (i = 0; i < Get_nb_supported_interface(); i++)
00147         {
00148           if(Get_class(i)==HID_CLASS && Get_protocol(i)==MOUSE_PROTOCOL)
00149           {
00150             host_hid_set_idle(HID_IDLE_DURATION_INDEFINITE, HID_REPORT_ID_ALL, i);
00151             host_hid_get_report(HID_REPORT_DESCRIPTOR, 0, i);
00152             pipe_mouse_in = Get_ep_pipe(i, 0);
00153             Host_enable_continuous_in_mode(pipe_mouse_in);
00154             Host_unfreeze_pipe(pipe_mouse_in);
00155             mouse_hid_connected=TRUE;
00156             break;
00157           }
00158         }
00159       }
00160 
00161       if( Is_host_mouse_hid_configured() )
00162       {
00163         if((Is_host_in_received(pipe_mouse_in)) && (Is_host_stall(pipe_mouse_in)==FALSE) )
00164         {
00165            Host_reset_pipe_fifo_access(pipe_mouse_in);
00166            usb_report[0]=
00167            usb_report[1]=
00168            usb_report[2]=
00169            usb_report[3]=0;
00170            host_read_p_rxpacket(pipe_mouse_in, (void*)usb_report, 4, NULL);
00171            Host_ack_in_received(pipe_mouse_in);
00172            Host_free_in(pipe_mouse_in);
00173            new_x = usb_report[1];
00174            new_y = usb_report[2];
00175            mouse_x += new_x;
00176            mouse_y += new_y;
00177            if(      mouse_x<MOUSE_X_MIN ) mouse_x=MOUSE_X_MIN;
00178            else if( mouse_x>MOUSE_X_MAX ) mouse_x=MOUSE_X_MAX;
00179            if(      mouse_y<MOUSE_Y_MIN ) mouse_y=MOUSE_Y_MIN;
00180            else if( mouse_y>MOUSE_Y_MAX ) mouse_y=MOUSE_Y_MAX;
00181            mouse_b0=usb_report[0] & 1;
00182            mouse_b1=usb_report[0] & 2;
00183            mouse_b2=usb_report[0] & 4;
00184            disp_led_mouse();
00185            disp_ascii_mouse();
00186         }
00187         if(Is_host_nak_received(pipe_mouse_in))
00188         {
00189            Host_ack_nak_received(pipe_mouse_in);
00190            LED_Off(LED_HOST_MOUSE_B0 );
00191            LED_Off(LED_HOST_MOUSE_B1 );
00192            LED_Off(LED_HOST_MOUSE_B2 );
00193            LED_Off(LED_HOST_MOUSE_B3 );
00194         }
00195       }
00196     }
00197 
00198 
00199 #ifdef FREERTOS_USED
00200   }
00201 #endif
00202 }

void host_mouse_hid_task_init ( void   ) 

This function initializes the host mouse HID task.

Definition at line 99 of file host_mouse_hid_task.c.

References configTSK_USB_HHID_MOUSE_NAME, configTSK_USB_HHID_MOUSE_PRIORITY, configTSK_USB_HHID_MOUSE_STACK_SIZE, host_mouse_hid_task(), mouse_hid_connected, mouse_hid_new_device_connected, and sof_cnt.

Referenced by main().

00100 {
00101   sof_cnt = 0;
00102   mouse_hid_new_device_connected = FALSE;
00103   mouse_hid_connected = FALSE;
00104 
00105 #ifdef FREERTOS_USED
00106   xTaskCreate(host_mouse_hid_task,
00107               configTSK_USB_HHID_MOUSE_NAME,
00108               configTSK_USB_HHID_MOUSE_STACK_SIZE,
00109               NULL,
00110               configTSK_USB_HHID_MOUSE_PRIORITY,
00111               NULL);
00112 #endif  // FREERTOS_USED
00113 }


Variable Documentation

Bool mouse_b0

Definition at line 89 of file host_mouse_hid_task.c.

Referenced by disp_ascii_mouse(), disp_led_mouse(), and host_mouse_hid_task().

Bool mouse_b1

Definition at line 90 of file host_mouse_hid_task.c.

Referenced by disp_ascii_mouse(), disp_led_mouse(), and host_mouse_hid_task().

Bool mouse_b2

Definition at line 91 of file host_mouse_hid_task.c.

Referenced by disp_ascii_mouse(), disp_led_mouse(), and host_mouse_hid_task().

S8 mouse_x

Definition at line 86 of file host_mouse_hid_task.c.

Referenced by disp_ascii_mouse(), and host_mouse_hid_task().

S8 mouse_y

Definition at line 87 of file host_mouse_hid_task.c.

Referenced by disp_ascii_mouse(), and host_mouse_hid_task().

S8 new_x

Definition at line 88 of file host_mouse_hid_task.c.

Referenced by disp_led_mouse(), and host_mouse_hid_task().

S8 new_y

Definition at line 88 of file host_mouse_hid_task.c.

Referenced by disp_led_mouse(), and host_mouse_hid_task().

Definition at line 81 of file host_mouse_hid_task.c.

Referenced by host_mouse_hid_task().

U16 sof_cnt [static]

Definition at line 84 of file host_mouse_hid_task.c.

volatile S8 usb_report[4]

Definition at line 85 of file host_mouse_hid_task.c.

Referenced by host_mouse_hid_task().


Generated on Fri Feb 19 02:33:00 2010 for AVR32 - USB HID FreeRTOS Example by  doxygen 1.5.5