1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2012-01-03 Yi Qiu first version 9 */ 10 11 #include <rtthread.h> 12 #include <drivers/usb_host.h> 13 #include "hid.h" 14 15 #if defined(RT_USBH_HID) && defined(RT_USBH_HID_KEYBOARD) 16 17 static struct uprotocal kbd_protocal; 18 19 static rt_err_t rt_usbh_hid_kbd_callback(void* arg) 20 { 21 int int1, int2; 22 struct uhid* hid; 23 24 hid = (struct uhid*)arg; 25 26 int1 = *(rt_uint32_t*)hid->buffer; 27 int2 = *(rt_uint32_t*)(&hid->buffer[4]); 28 29 if(int1 != 0 || int2 != 0) 30 { 31 RT_DEBUG_LOG(RT_DEBUG_USB, ("key down 0x%x, 0x%x\n", int1, int2)); 32 } 33 34 return RT_EOK; 35 } 36 37 static rt_err_t rt_usbh_hid_kbd_init(void* arg) 38 { 39 struct uintf* intf = (struct uintf*)arg; 40 41 RT_ASSERT(intf != RT_NULL); 42 43 rt_usbh_hid_set_protocal(intf, 0); 44 45 rt_usbh_hid_set_idle(intf, 10, 0); 46 47 //RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb keyboard\n")); 48 49 return RT_EOK; 50 } 51 52 /** 53 * This function will define the hid keyboard protocal, it will be register to the protocal list. 54 * 55 * @return the keyboard protocal structure. 56 */ 57 uprotocal_t rt_usbh_hid_protocal_kbd(void) 58 { 59 kbd_protocal.pro_id = USB_HID_KEYBOARD; 60 61 kbd_protocal.init = rt_usbh_hid_kbd_init; 62 kbd_protocal.callback = rt_usbh_hid_kbd_callback; 63 64 return &kbd_protocal; 65 } 66 67 #endif 68 69