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.

78 lines
1.4 KiB

  1. #include "trackpad.h"
  2. // bool isScrollingMode = false;
  3. bool isScrollMode = false;
  4. void pointing_device_init(void){
  5. SPI_Init(SPI_SPEED_FCPU_DIV_8 | SPI_MODE_MASTER);
  6. // Set as output
  7. TP_RESET_INIT;
  8. TP_SHUTDOWN_INIT;
  9. TP_CS_INIT;
  10. LVL_SHIFT_EN_INIT;
  11. // Reset level shifter
  12. LVL_SHIFT_EN_LO;
  13. wait_ms(100);
  14. LVL_SHIFT_EN_HI;
  15. // Force a BB-8520 reset
  16. TP_RESET_HI;
  17. wait_ms(100);
  18. TP_RESET_LO;
  19. // Turn on BB-8520 trackpad
  20. TP_SHUTDOWN_LO;
  21. TP_CS_HI;
  22. }
  23. uint8_t readRegister(uint8_t address) {
  24. uint8_t data;
  25. TP_CS_LO;
  26. // Read the data
  27. SPI_TransferByte(address);
  28. data = SPI_TransferByte(0x00);
  29. TP_CS_HI;
  30. return data;
  31. }
  32. void pointing_device_task(void){
  33. uint8_t motion = readRegister(0x02);
  34. // Motion has occurred on the trackpad
  35. if (motion > 127) {
  36. int8_t dx, dy;
  37. if(TRACKPAD_CONNECTOR_VER == 1) {
  38. dx = readRegister(0x03);
  39. dy = -readRegister(0x04);
  40. }
  41. else {
  42. dy = -readRegister(0x03);
  43. dx = -readRegister(0x04);
  44. }
  45. report_mouse_t currentReport = pointing_device_get_report();
  46. if (isScrollMode)
  47. {
  48. currentReport.h = dx/SCROLL_SPEED_DIVIDER;
  49. currentReport.v = dy/SCROLL_SPEED_DIVIDER;
  50. }
  51. else
  52. {
  53. currentReport.x = dx * POINTER_SPEED_MULTIPLIER;
  54. currentReport.y = dy * POINTER_SPEED_MULTIPLIER;
  55. }
  56. pointing_device_set_report(currentReport);
  57. pointing_device_send();
  58. }
  59. }