logo

qmk_firmware

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

haptic.h (3589B)


  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. #include "compiler_support.h"
  21. #ifndef HAPTIC_DEFAULT_FEEDBACK
  22. # define HAPTIC_DEFAULT_FEEDBACK 0
  23. #endif
  24. #ifndef HAPTIC_DEFAULT_MODE
  25. # define HAPTIC_DEFAULT_MODE DRV2605L_DEFAULT_MODE
  26. #endif
  27. /* EEPROM config settings */
  28. typedef union haptic_config_t {
  29. uint32_t raw;
  30. struct {
  31. bool enable : 1;
  32. uint8_t mode : 7;
  33. bool buzz : 1;
  34. uint8_t dwell : 7;
  35. uint8_t amplitude : 8;
  36. uint8_t feedback : 2;
  37. bool cont : 1;
  38. uint8_t reserved : 5;
  39. };
  40. } haptic_config_t;
  41. STATIC_ASSERT(sizeof(haptic_config_t) == sizeof(uint32_t), "Haptic EECONFIG out of spec.");
  42. typedef enum HAPTIC_FEEDBACK {
  43. KEY_PRESS,
  44. KEY_PRESS_RELEASE,
  45. KEY_RELEASE,
  46. HAPTIC_FEEDBACK_MAX,
  47. } HAPTIC_FEEDBACK;
  48. void haptic_init(void);
  49. void haptic_task(void);
  50. void eeconfig_debug_haptic(void);
  51. void haptic_enable(void);
  52. void haptic_disable(void);
  53. void haptic_toggle(void);
  54. void haptic_feedback_toggle(void);
  55. void haptic_mode_increase(void);
  56. void haptic_mode_decrease(void);
  57. void haptic_mode(uint8_t mode);
  58. void haptic_reset(void);
  59. void haptic_set_feedback(uint8_t feedback);
  60. void haptic_set_mode(uint8_t mode);
  61. void haptic_set_dwell(uint8_t dwell);
  62. void haptic_set_buzz(uint8_t buzz);
  63. void haptic_buzz_toggle(void);
  64. uint8_t haptic_get_enable(void);
  65. uint8_t haptic_get_mode(void);
  66. uint8_t haptic_get_feedback(void);
  67. void haptic_dwell_increase(void);
  68. void haptic_dwell_decrease(void);
  69. void haptic_toggle_continuous(void);
  70. void haptic_cont_increase(void);
  71. void haptic_cont_decrease(void);
  72. void haptic_play(void);
  73. void haptic_shutdown(void);
  74. void haptic_notify_usb_device_state_change(void);
  75. #ifdef HAPTIC_ENABLE_PIN_ACTIVE_LOW
  76. # ifndef HAPTIC_ENABLE_PIN
  77. # error HAPTIC_ENABLE_PIN not defined
  78. # endif
  79. # define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_PIN)
  80. # define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_PIN)
  81. #else
  82. # define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_PIN)
  83. # define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_PIN)
  84. #endif
  85. #ifdef HAPTIC_ENABLE_STATUS_LED_ACTIVE_LOW
  86. # ifndef HAPTIC_ENABLE_STATUS_LED
  87. # error HAPTIC_ENABLE_STATUS_LED not defined
  88. # endif
  89. # define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_STATUS_LED)
  90. # define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_STATUS_LED)
  91. #else
  92. # define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_STATUS_LED)
  93. # define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_STATUS_LED)
  94. #endif
  95. #ifndef HAPTIC_OFF_IN_LOW_POWER
  96. # define HAPTIC_OFF_IN_LOW_POWER 0
  97. #endif