You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.5 KiB

  1. #include "dichotomy.h"
  2. void pointing_device_task(void){
  3. /*report_mouse_t currentReport = {};
  4. uint32_t timeout = 0;
  5. //the m character requests the RF slave to send the mouse report
  6. SERIAL_UART_DATA = 'm';
  7. //trust the external inputs completely, erase old data
  8. uint8_t uart_data[5] = {0};
  9. //there are 10 bytes corresponding to 10 columns, and an end byte
  10. for (uint8_t i = 0; i < 5; i++) {
  11. //wait for the serial data, timeout if it's been too long
  12. //this only happened in testing with a loose wire, but does no
  13. //harm to leave it in here
  14. while(!SERIAL_UART_RXD_PRESENT){
  15. timeout++;
  16. if (timeout > 10000){
  17. xprintf("\r\nTIMED OUT");
  18. break;
  19. }
  20. }
  21. xprintf("\r\nGOT DATA for %d",i);
  22. uart_data[i] = SERIAL_UART_DATA;
  23. }
  24. //check for the end packet, bytes 1-4 are movement and scroll
  25. //but byte 5 has bits 0-3 for the scroll button state
  26. //(1000 if pressed, 0000 if not) and bits 4-7 are always 1
  27. //We can use this to verify the report sent properly.
  28. if (uart_data[4] == 0x0F || uart_data[4] == 0x8F)
  29. {
  30. xprintf("\r\nREQUESTED MOUSE, RECEIVED %i, %i, %i, %i, %i",uart_data[0],uart_data[1],uart_data[2],uart_data[3],uart_data[4]);
  31. currentReport = pointing_device_get_report();
  32. //shifting and transferring the info to the mouse report varaible
  33. //mouseReport.x = 127 max -127 min
  34. currentReport.x = (int8_t) uart_data[0];
  35. //mouseReport.y = 127 max -127 min
  36. currentReport.y = (int8_t) uart_data[1];
  37. //mouseReport.v = 127 max -127 min (scroll vertical)
  38. currentReport.v = (int8_t) uart_data[2];
  39. //mouseReport.h = 127 max -127 min (scroll horizontal)
  40. currentReport.h = (int8_t) uart_data[3];
  41. //mouseReport.buttons = 0x31 max (bitmask for mouse buttons 1-5) 0x00 min
  42. //mouse buttons 1 and 2 are handled by the keymap, but not 3
  43. if (uart_data[4] == 0x0F) { //then 3 is not pressed
  44. currentReport.buttons &= ~MOUSE_BTN3; //MOUSE_BTN3 is def in report.h
  45. } else { //3 must be pressed
  46. currentReport.buttons |= MOUSE_BTN3;
  47. }
  48. pointing_device_set_report(currentReport);
  49. } else {
  50. xprintf("\r\nRequested packet, data 4 was %d",uart_data[4]);
  51. }*/
  52. pointing_device_send();
  53. }
  54. void led_init(void) {
  55. setPinOutput(D1);
  56. setPinOutput(F5);
  57. setPinOutput(F6);
  58. writePinHigh(D1);
  59. writePinHigh(F5);
  60. writePinHigh(F6);
  61. }
  62. void matrix_init_kb(void) {
  63. // put your keyboard start-up code here
  64. // runs once when the firmware starts up
  65. matrix_init_user();
  66. led_init();
  67. }