Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

serial_mouse_microsoft.c 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. Copyright 2011,2013 Jun Wako <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdint.h>
  15. #include <avr/io.h>
  16. #include <util/delay.h>
  17. #include "serial.h"
  18. #include "serial_mouse.h"
  19. #include "report.h"
  20. #include "host.h"
  21. #include "timer.h"
  22. #include "print.h"
  23. #include "debug.h"
  24. static void print_usb_data(const report_mouse_t *report);
  25. uint8_t serial_mouse_init(void)
  26. {
  27. serial_init();
  28. return 0;
  29. }
  30. void serial_mouse_task(void)
  31. {
  32. /* 3 byte ring buffer */
  33. static uint8_t buffer[3];
  34. static int buffer_cur = 0;
  35. static report_mouse_t report = {};
  36. int16_t rcv;
  37. rcv = serial_recv2();
  38. if (rcv < 0)
  39. /* no new data */
  40. return;
  41. if (debug_mouse)
  42. xprintf("serial_mouse: byte: %04X\n", rcv);
  43. /*
  44. * If bit 6 is one, this signals the beginning
  45. * of a 3 byte sequence/packet.
  46. */
  47. if (rcv & (1 << 6))
  48. buffer_cur = 0;
  49. buffer[buffer_cur] = (uint8_t)rcv;
  50. if (buffer_cur == 0 && buffer[buffer_cur] == 0x20) {
  51. /*
  52. * Logitech extension: This must be a follow-up on
  53. * the last 3-byte packet signaling a middle button click
  54. */
  55. report.buttons |= MOUSE_BTN3;
  56. report.x = report.y = 0;
  57. print_usb_data(&report);
  58. host_mouse_send(&report);
  59. return;
  60. }
  61. buffer_cur++;
  62. if (buffer_cur < 3)
  63. return;
  64. buffer_cur = 0;
  65. /*
  66. * parse 3 byte packet.
  67. * NOTE: We only get a complete packet
  68. * if the mouse moved or the button states
  69. * change.
  70. */
  71. report.buttons = 0;
  72. if (buffer[0] & (1 << 5))
  73. report.buttons |= MOUSE_BTN1;
  74. if (buffer[0] & (1 << 4))
  75. report.buttons |= MOUSE_BTN2;
  76. report.x = (buffer[0] << 6) | buffer[1];
  77. report.y = ((buffer[0] << 4) & 0xC0) | buffer[2];
  78. /* USB HID uses values from -127 to 127 only */
  79. report.x = report.x < -127 ? -127 : report.x;
  80. report.y = report.y < -127 ? -127 : report.y;
  81. #if 0
  82. if (!report.buttons && !report.x && !report.y) {
  83. /*
  84. * Microsoft extension: Middle mouse button pressed
  85. * FIXME: I don't know how exactly this extension works.
  86. */
  87. report.buttons |= MOUSE_BTN3;
  88. }
  89. #endif
  90. print_usb_data(&report);
  91. host_mouse_send(&report);
  92. }
  93. static void print_usb_data(const report_mouse_t *report)
  94. {
  95. if (!debug_mouse)
  96. return;
  97. xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n",
  98. report->buttons, report->x, report->y,
  99. report->v, report->h);
  100. }