00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include "conf_usb.h"
00051
00052
00053 #if USB_HOST_FEATURE == ENABLED
00054
00055 #include "board.h"
00056 #ifdef FREERTOS_USED
00057 #include "FreeRTOS.h"
00058 #include "task.h"
00059 #endif
00060 #include "conf_usb.h"
00061 #include "usb_drv.h"
00062 #include "usb_host_enum.h"
00063 #include "usb_host_task.h"
00064 #include "host_hid.h"
00065 #include "host_mouse_hid_task.h"
00066 #include <stdio.h>
00067
00068
00069
00070
00071
00072
00073
00074 #define MOUSE_X_MIN 0
00075 #define MOUSE_X_MAX 80
00076 #define MOUSE_Y_MIN 0
00077 #define MOUSE_Y_MAX 18
00078
00079
00080
00081 U8 pipe_mouse_in;
00082 volatile Bool mouse_hid_new_device_connected;
00083 volatile Bool mouse_hid_connected;
00084 static U16 sof_cnt;
00085 volatile S8 usb_report[4];
00086 S8 mouse_x;
00087 S8 mouse_y;
00088 S8 new_x, new_y;
00089 Bool mouse_b0;
00090 Bool mouse_b1;
00091 Bool mouse_b2;
00092
00093 static void disp_led_mouse(void);
00094 static void disp_ascii_mouse(void);
00095
00099 void host_mouse_hid_task_init(void)
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 }
00114
00115
00119 #ifdef FREERTOS_USED
00120 void host_mouse_hid_task(void *pvParameters)
00121 #else
00122 void host_mouse_hid_task(void)
00123 #endif
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
00137
00138 if (Is_host_ready())
00139 {
00140
00141 if (mouse_hid_new_device_connected)
00142 {
00143 mouse_hid_new_device_connected = FALSE;
00144
00145
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 }
00203
00204
00212 void host_sof_action(void)
00213 {
00214 sof_cnt++;
00215 }
00216
00217
00221 static void disp_led_mouse(void)
00222 {
00223
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
00234 if( mouse_b1 ) LED_Toggle( LED_HOST_MOUSE_B1 );
00235
00236 if( mouse_b2 ) LED_Toggle( LED_HOST_MOUSE_B2 );
00237
00238 }
00239
00240
00245
00247 static void disp_ascii_mouse(void)
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 ) {
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 }
00323
00324
00325 #endif // USB_HOST_FEATURE == ENABLED