/****************************************************************************** * * @name Emulate_Mouse_WithButton * * @brief This function gets the input from mouse movement, the mouse * will move if the any button are pushed,otherwise USB gets NAK * * @param None * * @return None * ***************************************************************************** * This function sends the mouse data depending on which key was pressed on * the board *****************************************************************************/ static void Emulate_Mouse_WithButton(void) { if(kbi_stat > 0) { switch(kbi_stat & KBI_STAT_MASK) { case LEFT_CLICK : /* PTG0 (left click) is pressed */ rpt_buf[0] = LEFT_CLICK; rpt_buf[1] = 0x00; rpt_buf[2] = 0x00; break; case RIGHT_CLICK : /* PTG1 (right click) is pressed */ rpt_buf[0] = RIGHT_CLICK; rpt_buf[1] = 0x00; rpt_buf[2] = 0x00; break; case MOVE_LEFT_RIGHT : /* PTG2 (left or right movement--depends on UP_LEFT macro) is pressed*/ rpt_buf[1] = SHIFT_VAL; rpt_buf[0] = 0x00; rpt_buf[2] = 0x00; break; case MOVE_UP_DOWN : /* PTG3 (up or down movement--depends on UP_LEFT macro) is pressed*/ rpt_buf[2] = SHIFT_VAL; rpt_buf[1] = 0x00; rpt_buf[0] = 0x00; break; default:break; /* otherwise */ } kbi_stat = 0x00; /* reset status after servicing interrupt*/ (void)USB_Class_HID_Send_Data(CONTROLLER_ID,HID_ENDPOINT,rpt_buf, MOUSE_BUFF_SIZE); if(rpt_buf[0]) { /* required to send Click Release for Click Press Events */ (void)USB_Class_HID_Send_Data(CONTROLLER_ID,HID_ENDPOINT,null_buf, MOUSE_BUFF_SIZE); } } return; }
/****************************************************************************** * @name: KeyBoard_Events_Process * * @brief: This function gets the input data from HID and sends to the * host device. * * @param: None * * @return: None * *****************************************************************************/ void hid1_hid_events_process(void) { #ifdef hid1_HID_DEMO /* USB HID PEx demo project (This code is possible to enable by 'USB HID demo' property). */ static int32_t Count = 0; static enum { STATE_0, STATE_1} State = STATE_0; switch (State) { case STATE_0: hid1_SetInputReportBufferState0(hid1_InputReportBuffer); Count++; if (Count > hid1_StateMaxCount) { State = STATE_1; } break; case STATE_1: hid1_SetInputReportBufferState1(hid1_InputReportBuffer); Count--; if (Count < 0) { State = STATE_0; } break; } (void)USB_Class_HID_Send_Data(hid1_HidHandle, hid1_InputPipeNumber, hid1_InputReportBuffer, hid1_InputReportBufferSize); #else /* Write your code here ... */ #endif }
/****************************************************************************** * @name: KeyBoard_Events_Process * * @brief: This function gets the input from keyboard, the keyboard * does not include the code to filter the glitch on keys since * it is just for demo * * @param: None * * @return: None * ***************************************************************************** * This function sends the keyboard data depending on which key is pressed on * the board *****************************************************************************/ void KeyBoard_Events_Process(void) { static int32_t x = 0; static enum { UP, DOWN} dir = UP; switch (dir) { case UP: g_keyboard.rpt_buf[g_key_index] = KEY_PAGEUP; x++; if (x > 100) { dir = DOWN; } break; case DOWN: g_keyboard.rpt_buf[g_key_index] = KEY_PAGEDOWN; x--; if (x < 0) { dir = UP; } break; } (void)USB_Class_HID_Send_Data(g_keyboard.app_handle, HID_ENDPOINT, g_keyboard.rpt_buf, KEYBOARD_BUFF_SIZE); return; }
/***************************************************************************** * * @name move_mouse * * @brief This function gets makes the cursor on screen move left,right * up and down * * @param None * * @return None * * ******************************************************************************/ void move_mouse(void) { static int x = 0, y = 0; static enum { RIGHT, DOWN, LEFT, UP } dir = RIGHT; switch (dir) { case RIGHT: g_mouse.rpt_buf[1] = 2; g_mouse.rpt_buf[2] = 0; x++; if (x > 100) dir++; break; case DOWN: g_mouse.rpt_buf[1] = 0; g_mouse.rpt_buf[2] = 2; y++; if (y > 100) dir++; break; case LEFT: g_mouse.rpt_buf[1] = (uint_8)(-2); g_mouse.rpt_buf[2] = 0; x--; if (x < 0) dir++; break; case UP: g_mouse.rpt_buf[1] = 0; g_mouse.rpt_buf[2] = (uint_8)(-2); y--; if (y < 0) dir = RIGHT; break; } (void)USB_Class_HID_Send_Data(g_mouse.app_handle,HID_ENDPOINT, g_mouse.rpt_buf,MOUSE_BUFF_SIZE); }