mousecmd.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* mouseinfo command: print mouse hardware/protocol info and exit. */
  2. #include "io.h"
  3. #include "mouse.h"
  4. #include "usb.h"
  5. #include "usbhid.h"
  6. static void put_uint(unsigned int n)
  7. {
  8. char buf[12];
  9. int i = 10;
  10. buf[11] = '\0';
  11. if (n == 0) {
  12. io_putchar('0');
  13. return;
  14. }
  15. while (n && i >= 0) {
  16. buf[i--] = (char)('0' + (n % 10u));
  17. n /= 10u;
  18. }
  19. io_putstr(buf + i + 1);
  20. }
  21. static void put_hex8(unsigned int x)
  22. {
  23. static const char hex[] = "0123456789ABCDEF";
  24. io_putchar(hex[(x >> 4) & 0xF]);
  25. io_putchar(hex[x & 0xF]);
  26. }
  27. void program_mouseinfo_main(void)
  28. {
  29. io_putstr("mouse present ");
  30. io_putstr(mouse_is_present() ? "yes\n" : "no\n");
  31. if (!mouse_is_present())
  32. return;
  33. if (mouse_ps2_present()) {
  34. unsigned int id = mouse_device_id();
  35. io_putstr("mouse ps/2 id 0x");
  36. put_hex8(id & 0xFFu);
  37. io_putchar('\n');
  38. io_putstr("mouse protocol ");
  39. if (id == 0x03)
  40. io_putstr("intellimouse (wheel)\n");
  41. else if (id == 0x04)
  42. io_putstr("intellimouse explorer (5-button)\n");
  43. else
  44. io_putstr("standard ps/2\n");
  45. io_putstr("mouse packet bytes ");
  46. put_uint(mouse_packet_size());
  47. io_putchar('\n');
  48. io_putstr("mouse streaming ");
  49. io_putstr(mouse_streaming_enabled() ? "on\n" : "off\n");
  50. }
  51. if (usbhid_mouse_attached()) {
  52. unsigned int ctrl, addr, ep, mps;
  53. int low;
  54. usbhid_get_info(&ctrl, &addr, &ep, &mps, &low);
  55. io_putstr("mouse usb ");
  56. io_putstr(usb_hcd_name());
  57. io_putstr(" hid boot\n");
  58. io_putstr("mouse usb ctrl ");
  59. put_uint(ctrl);
  60. io_putstr(" addr ");
  61. put_uint(addr);
  62. io_putstr(" ep 0x");
  63. put_hex8(0x80u | ep);
  64. io_putchar('\n');
  65. io_putstr("mouse usb mps ");
  66. put_uint(mps);
  67. io_putstr(low ? " (low speed)\n" : " (full speed)\n");
  68. }
  69. io_putstr("mouse usb keyboard ");
  70. io_putstr(usbhid_keyboard_attached() ? "yes\n" : "no\n");
  71. io_putstr("mouse cursor ");
  72. io_putstr(mouse_cursor_visible() ? "visible\n" : "hidden\n");
  73. io_putstr("mouse cursor backend ");
  74. io_putstr(mouse_cursor_backend_name());
  75. io_putchar('\n');
  76. }