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.

107 lines
3.5 KiB

  1. /* Copyright 2019 ishtob
  2. * Driver for haptic feedback written for QMK
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include <stdint.h>
  19. #include <stdbool.h>
  20. #ifndef HAPTIC_DEFAULT_FEEDBACK
  21. # define HAPTIC_DEFAULT_FEEDBACK 0
  22. #endif
  23. #ifndef HAPTIC_DEFAULT_MODE
  24. # define HAPTIC_DEFAULT_MODE DRV2605L_DEFAULT_MODE
  25. #endif
  26. /* EEPROM config settings */
  27. typedef union {
  28. uint32_t raw;
  29. struct {
  30. bool enable : 1;
  31. uint8_t mode : 7;
  32. bool buzz : 1;
  33. uint8_t dwell : 7;
  34. uint8_t amplitude : 8;
  35. uint8_t feedback : 2;
  36. bool cont : 1;
  37. uint8_t reserved : 5;
  38. };
  39. } haptic_config_t;
  40. _Static_assert(sizeof(haptic_config_t) == sizeof(uint32_t), "Haptic EECONFIG out of spec.");
  41. typedef enum HAPTIC_FEEDBACK {
  42. KEY_PRESS,
  43. KEY_PRESS_RELEASE,
  44. KEY_RELEASE,
  45. HAPTIC_FEEDBACK_MAX,
  46. } HAPTIC_FEEDBACK;
  47. void haptic_init(void);
  48. void haptic_task(void);
  49. void eeconfig_debug_haptic(void);
  50. void haptic_enable(void);
  51. void haptic_disable(void);
  52. void haptic_toggle(void);
  53. void haptic_feedback_toggle(void);
  54. void haptic_mode_increase(void);
  55. void haptic_mode_decrease(void);
  56. void haptic_mode(uint8_t mode);
  57. void haptic_reset(void);
  58. void haptic_set_feedback(uint8_t feedback);
  59. void haptic_set_mode(uint8_t mode);
  60. void haptic_set_dwell(uint8_t dwell);
  61. void haptic_set_buzz(uint8_t buzz);
  62. void haptic_buzz_toggle(void);
  63. uint8_t haptic_get_enable(void);
  64. uint8_t haptic_get_mode(void);
  65. uint8_t haptic_get_feedback(void);
  66. void haptic_dwell_increase(void);
  67. void haptic_dwell_decrease(void);
  68. void haptic_toggle_continuous(void);
  69. void haptic_cont_increase(void);
  70. void haptic_cont_decrease(void);
  71. void haptic_play(void);
  72. void haptic_shutdown(void);
  73. void haptic_notify_usb_device_state_change(void);
  74. #ifdef HAPTIC_ENABLE_PIN_ACTIVE_LOW
  75. # ifndef HAPTIC_ENABLE_PIN
  76. # error HAPTIC_ENABLE_PIN not defined
  77. # endif
  78. # define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_PIN)
  79. # define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_PIN)
  80. #else
  81. # define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_PIN)
  82. # define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_PIN)
  83. #endif
  84. #ifdef HAPTIC_ENABLE_STATUS_LED_ACTIVE_LOW
  85. # ifndef HAPTIC_ENABLE_STATUS_LED
  86. # error HAPTIC_ENABLE_STATUS_LED not defined
  87. # endif
  88. # define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_STATUS_LED)
  89. # define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_STATUS_LED)
  90. #else
  91. # define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_STATUS_LED)
  92. # define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_STATUS_LED)
  93. #endif
  94. #ifndef HAPTIC_OFF_IN_LOW_POWER
  95. # define HAPTIC_OFF_IN_LOW_POWER 0
  96. #endif