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.

128 lines
4.3 KiB

adding Hadron v3 keyboard, QWIIC devices support, haptic feedback support (#4462) * add initial support for hadron ver3 * add initial support for hadron ver3 * pull qwiic support for micro_led to be modified for use in hadron's 64x24 ssd1306 oled display * initial work on OLED using qwiic driver * early work to get 128x32 oled working by redefining qwiic micro oled parameters. Currently working, but would affect qwiic's micro oled functionality * moved oled defines to config.h and added ifndef to micro_oled driver * WORKING :D - note, still work in progress to get the start location correct on the 128x32 display. * added equation to automatically calculate display offset based on screen width * adding time-out timer to oled display * changed read lock staus via read_led_state * lock indications fixes * Added scroll lock indication to oled * add support for DRV2605 haptic driver * Improve readabiity of DRV2605 driver. -added typedef for waveform library -added unions for registers * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Fixes for PR * PR fixes * fix old persistent layer function to use new set_single_persistent_default_layer * fix issues with changing makefile defines that broken per-key haptic pulse * Comment fixes * Add definable parameter and auto-calibration based on motor choice
5 years ago
adding Hadron v3 keyboard, QWIIC devices support, haptic feedback support (#4462) * add initial support for hadron ver3 * add initial support for hadron ver3 * pull qwiic support for micro_led to be modified for use in hadron's 64x24 ssd1306 oled display * initial work on OLED using qwiic driver * early work to get 128x32 oled working by redefining qwiic micro oled parameters. Currently working, but would affect qwiic's micro oled functionality * moved oled defines to config.h and added ifndef to micro_oled driver * WORKING :D - note, still work in progress to get the start location correct on the 128x32 display. * added equation to automatically calculate display offset based on screen width * adding time-out timer to oled display * changed read lock staus via read_led_state * lock indications fixes * Added scroll lock indication to oled * add support for DRV2605 haptic driver * Improve readabiity of DRV2605 driver. -added typedef for waveform library -added unions for registers * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Fixes for PR * PR fixes * fix old persistent layer function to use new set_single_persistent_default_layer * fix issues with changing makefile defines that broken per-key haptic pulse * Comment fixes * Add definable parameter and auto-calibration based on motor choice
5 years ago
adding Hadron v3 keyboard, QWIIC devices support, haptic feedback support (#4462) * add initial support for hadron ver3 * add initial support for hadron ver3 * pull qwiic support for micro_led to be modified for use in hadron's 64x24 ssd1306 oled display * initial work on OLED using qwiic driver * early work to get 128x32 oled working by redefining qwiic micro oled parameters. Currently working, but would affect qwiic's micro oled functionality * moved oled defines to config.h and added ifndef to micro_oled driver * WORKING :D - note, still work in progress to get the start location correct on the 128x32 display. * added equation to automatically calculate display offset based on screen width * adding time-out timer to oled display * changed read lock staus via read_led_state * lock indications fixes * Added scroll lock indication to oled * add support for DRV2605 haptic driver * Improve readabiity of DRV2605 driver. -added typedef for waveform library -added unions for registers * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Fixes for PR * PR fixes * fix old persistent layer function to use new set_single_persistent_default_layer * fix issues with changing makefile defines that broken per-key haptic pulse * Comment fixes * Add definable parameter and auto-calibration based on motor choice
5 years ago
adding Hadron v3 keyboard, QWIIC devices support, haptic feedback support (#4462) * add initial support for hadron ver3 * add initial support for hadron ver3 * pull qwiic support for micro_led to be modified for use in hadron's 64x24 ssd1306 oled display * initial work on OLED using qwiic driver * early work to get 128x32 oled working by redefining qwiic micro oled parameters. Currently working, but would affect qwiic's micro oled functionality * moved oled defines to config.h and added ifndef to micro_oled driver * WORKING :D - note, still work in progress to get the start location correct on the 128x32 display. * added equation to automatically calculate display offset based on screen width * adding time-out timer to oled display * changed read lock staus via read_led_state * lock indications fixes * Added scroll lock indication to oled * add support for DRV2605 haptic driver * Improve readabiity of DRV2605 driver. -added typedef for waveform library -added unions for registers * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Fixes for PR * PR fixes * fix old persistent layer function to use new set_single_persistent_default_layer * fix issues with changing makefile defines that broken per-key haptic pulse * Comment fixes * Add definable parameter and auto-calibration based on motor choice
5 years ago
adding Hadron v3 keyboard, QWIIC devices support, haptic feedback support (#4462) * add initial support for hadron ver3 * add initial support for hadron ver3 * pull qwiic support for micro_led to be modified for use in hadron's 64x24 ssd1306 oled display * initial work on OLED using qwiic driver * early work to get 128x32 oled working by redefining qwiic micro oled parameters. Currently working, but would affect qwiic's micro oled functionality * moved oled defines to config.h and added ifndef to micro_oled driver * WORKING :D - note, still work in progress to get the start location correct on the 128x32 display. * added equation to automatically calculate display offset based on screen width * adding time-out timer to oled display * changed read lock staus via read_led_state * lock indications fixes * Added scroll lock indication to oled * add support for DRV2605 haptic driver * Improve readabiity of DRV2605 driver. -added typedef for waveform library -added unions for registers * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Fixes for PR * PR fixes * fix old persistent layer function to use new set_single_persistent_default_layer * fix issues with changing makefile defines that broken per-key haptic pulse * Comment fixes * Add definable parameter and auto-calibration based on motor choice
5 years ago
adding Hadron v3 keyboard, QWIIC devices support, haptic feedback support (#4462) * add initial support for hadron ver3 * add initial support for hadron ver3 * pull qwiic support for micro_led to be modified for use in hadron's 64x24 ssd1306 oled display * initial work on OLED using qwiic driver * early work to get 128x32 oled working by redefining qwiic micro oled parameters. Currently working, but would affect qwiic's micro oled functionality * moved oled defines to config.h and added ifndef to micro_oled driver * WORKING :D - note, still work in progress to get the start location correct on the 128x32 display. * added equation to automatically calculate display offset based on screen width * adding time-out timer to oled display * changed read lock staus via read_led_state * lock indications fixes * Added scroll lock indication to oled * add support for DRV2605 haptic driver * Improve readabiity of DRV2605 driver. -added typedef for waveform library -added unions for registers * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Fixes for PR * PR fixes * fix old persistent layer function to use new set_single_persistent_default_layer * fix issues with changing makefile defines that broken per-key haptic pulse * Comment fixes * Add definable parameter and auto-calibration based on motor choice
5 years ago
  1. /* Copyright 2018 ishtob
  2. * Driver for DRV2605L 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. #include "DRV2605L.h"
  18. #include "print.h"
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <math.h>
  22. uint8_t DRV2605L_transfer_buffer[2];
  23. uint8_t DRV2605L_tx_register[0];
  24. uint8_t DRV2605L_read_buffer[0];
  25. uint8_t DRV2605L_read_register;
  26. void DRV_write(uint8_t drv_register, uint8_t settings) {
  27. DRV2605L_transfer_buffer[0] = drv_register;
  28. DRV2605L_transfer_buffer[1] = settings;
  29. i2c_transmit(DRV2605L_BASE_ADDRESS << 1, DRV2605L_transfer_buffer, 2, 100);
  30. }
  31. uint8_t DRV_read(uint8_t regaddress) {
  32. #ifdef __AVR__
  33. i2c_readReg(DRV2605L_BASE_ADDRESS << 1,
  34. regaddress, DRV2605L_read_buffer, 1, 100);
  35. DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
  36. #else
  37. DRV2605L_tx_register[0] = regaddress;
  38. if (MSG_OK != i2c_transmit_receive(DRV2605L_BASE_ADDRESS << 1,
  39. DRV2605L_tx_register, 1,
  40. DRV2605L_read_buffer, 1
  41. )){
  42. printf("err reading reg \n");
  43. }
  44. DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
  45. #endif
  46. return DRV2605L_read_register;
  47. }
  48. void DRV_init(void)
  49. {
  50. i2c_init();
  51. /* 0x07 sets DRV2605 into calibration mode */
  52. DRV_write(DRV_MODE,0x07);
  53. // DRV_write(DRV_FEEDBACK_CTRL,0xB6);
  54. #if FB_ERM_LRA == 0
  55. /* ERM settings */
  56. DRV_write(DRV_RATED_VOLT, (RATED_VOLTAGE/21.33)*1000);
  57. #if ERM_OPEN_LOOP == 0
  58. DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (((V_PEAK*(DRIVE_TIME+BLANKING_TIME+IDISS_TIME))/0.02133)/(DRIVE_TIME-0.0003)));
  59. #elif ERM_OPEN_LOOP == 1
  60. DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK/0.02196));
  61. #endif
  62. #elif FB_ERM_LRA == 1
  63. DRV_write(DRV_RATED_VOLT, ((V_RMS * sqrt(1 - ((4 * ((150+(SAMPLE_TIME*50))*0.000001)) + 0.0003)* F_LRA)/0.02071)));
  64. #if LRA_OPEN_LOOP == 0
  65. DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, ((V_PEAK/sqrt(1-(F_LRA*0.0008))/0.02133)));
  66. #elif LRA_OPEN_LOOP == 1
  67. DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK/0.02196));
  68. #endif
  69. #endif
  70. DRVREG_FBR FB_SET;
  71. FB_SET.Bits.ERM_LRA = FB_ERM_LRA;
  72. FB_SET.Bits.BRAKE_FACTOR = FB_BRAKEFACTOR;
  73. FB_SET.Bits.LOOP_GAIN =FB_LOOPGAIN;
  74. FB_SET.Bits.BEMF_GAIN = 0; /* auto-calibration populates this field*/
  75. DRV_write(DRV_FEEDBACK_CTRL, (uint8_t) FB_SET.Byte);
  76. DRVREG_CTRL1 C1_SET;
  77. C1_SET.Bits.C1_DRIVE_TIME = DRIVE_TIME;
  78. C1_SET.Bits.C1_AC_COUPLE = AC_COUPLE;
  79. C1_SET.Bits.C1_STARTUP_BOOST = STARTUP_BOOST;
  80. DRV_write(DRV_CTRL_1, (uint8_t) C1_SET.Byte);
  81. DRVREG_CTRL2 C2_SET;
  82. C2_SET.Bits.C2_BIDIR_INPUT = BIDIR_INPUT;
  83. C2_SET.Bits.C2_BRAKE_STAB = BRAKE_STAB;
  84. C2_SET.Bits.C2_SAMPLE_TIME = SAMPLE_TIME;
  85. C2_SET.Bits.C2_BLANKING_TIME = BLANKING_TIME;
  86. C2_SET.Bits.C2_IDISS_TIME = IDISS_TIME;
  87. DRV_write(DRV_CTRL_2, (uint8_t) C2_SET.Byte);
  88. DRVREG_CTRL3 C3_SET;
  89. C3_SET.Bits.C3_LRA_OPEN_LOOP = LRA_OPEN_LOOP;
  90. C3_SET.Bits.C3_N_PWM_ANALOG = N_PWM_ANALOG;
  91. C3_SET.Bits.C3_LRA_DRIVE_MODE = LRA_DRIVE_MODE;
  92. C3_SET.Bits.C3_DATA_FORMAT_RTO = DATA_FORMAT_RTO;
  93. C3_SET.Bits.C3_SUPPLY_COMP_DIS = SUPPLY_COMP_DIS;
  94. C3_SET.Bits.C3_ERM_OPEN_LOOP = ERM_OPEN_LOOP;
  95. C3_SET.Bits.C3_NG_THRESH = NG_THRESH;
  96. DRV_write(DRV_CTRL_3, (uint8_t) C3_SET.Byte);
  97. DRVREG_CTRL4 C4_SET;
  98. C4_SET.Bits.C4_ZC_DET_TIME = ZC_DET_TIME;
  99. C4_SET.Bits.C4_AUTO_CAL_TIME = AUTO_CAL_TIME;
  100. DRV_write(DRV_CTRL_4, (uint8_t) C4_SET.Byte);
  101. DRV_write(DRV_LIB_SELECTION,LIB_SELECTION);
  102. DRV_write(DRV_GO, 0x01);
  103. /* 0x00 sets DRV2605 out of standby and to use internal trigger
  104. * 0x01 sets DRV2605 out of standby and to use external trigger */
  105. DRV_write(DRV_MODE,0x00);
  106. //Play greeting sequence
  107. DRV_write(DRV_GO, 0x00);
  108. DRV_write(DRV_WAVEFORM_SEQ_1, DRV_GREETING);
  109. DRV_write(DRV_GO, 0x01);
  110. }
  111. void DRV_pulse(uint8_t sequence)
  112. {
  113. DRV_write(DRV_GO, 0x00);
  114. DRV_write(DRV_WAVEFORM_SEQ_1, sequence);
  115. DRV_write(DRV_GO, 0x01);
  116. }