hid-debug.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * $Id: hid-debug.h,v 1.3 2001/05/10 15:56:07 vojtech Exp $
  3.  *
  4.  *  (c) 1999 Andreas Gal <gal@cs.uni-magdeburg.de>
  5.  *  (c) 2000-2001 Vojtech Pavlik <vojtech@suse.cz>
  6.  *
  7.  *  Some debug stuff for the HID parser.
  8.  *
  9.  *  Sponsored by SuSE
  10.  */
  11. /*
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25.  *
  26.  * Should you need to contact me, the author, you can do so either by
  27.  * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
  28.  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
  29.  */
  30. struct hid_usage_entry {
  31. unsigned  page;
  32. unsigned  usage;
  33. char     *description;
  34. };
  35. static struct hid_usage_entry hid_usage_table[] = {
  36.   {  1,      0, "GenericDesktop" },
  37.     {0, 0x01, "Pointer"},
  38.     {0, 0x02, "Mouse"},
  39.     {0, 0x04, "Joystick"},
  40.     {0, 0x05, "GamePad"},
  41.     {0, 0x06, "Keyboard"},
  42.     {0, 0x07, "Keypad"},
  43.     {0, 0x08, "MultiAxis"},
  44.       {0, 0x30, "X"},
  45.       {0, 0x31, "Y"},
  46.       {0, 0x32, "Z"},
  47.       {0, 0x33, "Rx"},
  48.       {0, 0x34, "Ry"},
  49.       {0, 0x35, "Rz"},
  50.       {0, 0x36, "Slider"},
  51.       {0, 0x37, "Dial"},
  52.       {0, 0x38, "Wheel"},
  53.       {0, 0x39, "HatSwitch"},
  54.     {0, 0x3a, "CountedBuffer"},
  55.       {0, 0x3b, "ByteCount"},
  56.       {0, 0x3c, "MotionWakeup"},
  57.       {0, 0x3d, "Start"},
  58.       {0, 0x3e, "Select"},
  59.       {0, 0x40, "Vx"},
  60.       {0, 0x41, "Vy"},
  61.       {0, 0x42, "Vz"},
  62.       {0, 0x43, "Vbrx"},
  63.       {0, 0x44, "Vbry"},
  64.       {0, 0x45, "Vbrz"},
  65.       {0, 0x46, "Vno"},
  66.     {0, 0x80, "SystemControl"}, 
  67.       {0, 0x81, "SystemPowerDown"},
  68.       {0, 0x82, "SystemSleep"},
  69.       {0, 0x83, "SystemWakeUp"},
  70.       {0, 0x84, "SystemContextMenu"},
  71.       {0, 0x85, "SystemMainMenu"},
  72.       {0, 0x86, "SystemAppMenu"},
  73.       {0, 0x87, "SystemMenuHelp"},
  74.       {0, 0x88, "SystemMenuExit"},
  75.       {0, 0x89, "SystemMenuSelect"},
  76.       {0, 0x8a, "SystemMenuRight"},
  77.       {0, 0x8b, "SystemMenuLeft"},
  78.       {0, 0x8c, "SystemMenuUp"},
  79.       {0, 0x8d, "SystemMenuDown"},
  80.     {0, 0x90, "D-padUp"},
  81.     {0, 0x91, "D-padDown"},
  82.     {0, 0x92, "D-padRight"},
  83.     {0, 0x93, "D-padLeft"},
  84.   {  7, 0, "Keyboard" },
  85.   {  8, 0, "LED" },
  86.   {  9, 0, "Button" },
  87.   { 12, 0, "Hotkey" },
  88.   { 13, 0, "Digitizers" },
  89.     {0, 0x01, "Digitizer"},
  90.     {0, 0x02, "Pen"},
  91.     {0, 0x03, "LightPen"},
  92.     {0, 0x04, "TouchScreen"},
  93.     {0, 0x05, "TouchPad"},
  94.     {0, 0x20, "Stylus"},
  95.     {0, 0x21, "Puck"},
  96.     {0, 0x22, "Finger"},
  97.     {0, 0x30, "TipPressure"},
  98.     {0, 0x31, "BarrelPressure"},
  99.     {0, 0x32, "InRange"},
  100.     {0, 0x33, "Touch"},
  101.     {0, 0x34, "UnTouch"},
  102.     {0, 0x35, "Tap"},
  103.     {0, 0x39, "TabletFunctionKey"},
  104.     {0, 0x3a, "ProgramChangeKey"},
  105.     {0, 0x3c, "Invert"},
  106.     {0, 0x42, "TipSwitch"},
  107.     {0, 0x43, "SecondaryTipSwitch"},
  108.     {0, 0x44, "BarrelSwitch"},
  109.     {0, 0x45, "Eraser"},
  110.     {0, 0x46, "TabletPick"},
  111.   { 15, 0, "PhysicalInterfaceDevice" },
  112.   { 0, 0, NULL }
  113. };
  114. static void resolv_usage_page(unsigned page) {
  115. struct hid_usage_entry *p;
  116. for (p = hid_usage_table; p->description; p++)
  117. if (p->page == page) {
  118. printk("%s", p->description);
  119. return;
  120. }
  121. printk("%04x", page);
  122. }
  123. static void resolv_usage(unsigned usage) {
  124. struct hid_usage_entry *p;
  125. resolv_usage_page(usage >> 16);
  126. printk(".");
  127. for (p = hid_usage_table; p->description; p++)
  128. if (p->page == (usage >> 16)) {
  129. for(++p; p->description && p->page == 0; p++)
  130. if (p->usage == (usage & 0xffff)) {
  131. printk("%s", p->description);
  132. return;
  133. }
  134. break;
  135. }
  136. printk("%04x", usage & 0xffff);
  137. }
  138. __inline__ static void tab(int n) {
  139. while (n--) printk(" ");
  140. }
  141. static void hid_dump_field(struct hid_field *field, int n) {
  142. int j;
  143. if (field->physical) {
  144. tab(n);
  145. printk("Physical(");
  146. resolv_usage(field->physical); printk(")n");
  147. }
  148. if (field->logical) {
  149. tab(n);
  150. printk("Logical(");
  151. resolv_usage(field->logical); printk(")n");
  152. }
  153. tab(n); printk("Usage(%d)n", field->maxusage);
  154. for (j = 0; j < field->maxusage; j++) {
  155. tab(n+2);resolv_usage(field->usage[j].hid); printk("n");
  156. }
  157. if (field->logical_minimum != field->logical_maximum) {
  158. tab(n); printk("Logical Minimum(%d)n", field->logical_minimum);
  159. tab(n); printk("Logical Maximum(%d)n", field->logical_maximum);
  160. }
  161. if (field->physical_minimum != field->physical_maximum) {
  162. tab(n); printk("Physical Minimum(%d)n", field->physical_minimum);
  163. tab(n); printk("Physical Maximum(%d)n", field->physical_maximum);
  164. }
  165. if (field->unit_exponent) {
  166. tab(n); printk("Unit Exponent(%d)n", field->unit_exponent);
  167. }
  168. if (field->unit) {
  169. tab(n); printk("Unit(%u)n", field->unit);
  170. }
  171. tab(n); printk("Report Size(%u)n", field->report_size);
  172. tab(n); printk("Report Count(%u)n", field->report_count);
  173. tab(n); printk("Report Offset(%u)n", field->report_offset);
  174. tab(n); printk("Flags( ");
  175. j = field->flags;
  176. printk("%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : "");
  177. printk("%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array ");
  178. printk("%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute ");
  179. printk("%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : "");
  180. printk("%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : "");
  181. printk("%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPrefferedState " : "");
  182. printk("%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : "");
  183. printk("%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : "");
  184. printk("%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : "");
  185. printk(")n");
  186. }
  187. static void hid_dump_device(struct hid_device *device) {
  188. struct hid_report_enum *report_enum;
  189. struct hid_report *report;
  190. struct list_head *list;
  191. unsigned i,k;
  192. static char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
  193. for (i = 0; i < device->maxapplication; i++) {
  194. printk("Application(");
  195. resolv_usage(device->application[i]);
  196. printk(")n");
  197. }
  198. for (i = 0; i < HID_REPORT_TYPES; i++) {
  199. report_enum = device->report_enum + i;
  200. list = report_enum->report_list.next;
  201. while (list != &report_enum->report_list) {
  202. report = (struct hid_report *) list;
  203. tab(2);
  204. printk("%s", table[i]);
  205. if (report->id)
  206. printk("(%d)", report->id);
  207. printk("[%s]", table[report->type]);
  208. printk("n");
  209. for (k = 0; k < report->maxfield; k++) {
  210. tab(4);
  211. printk("Field(%d)n", k);
  212. hid_dump_field(report->field[k], 6);
  213. }
  214. list = list->next;
  215. }
  216. }
  217. }
  218. static void hid_dump_input(struct hid_usage *usage, __s32 value) {
  219. printk("hid-debug: input ");
  220. resolv_usage(usage->hid);
  221. printk(" = %dn", value);
  222. }