logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

dichotomy.c (2638B)


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