dichotomy.c 2.7 KB

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