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.

92 lines
2.8 KiB

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