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.

403 lines
12 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
  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. #pragma once
  18. #include "i2c_master.h"
  19. /* Initialization settings
  20. * Feedback Control Settings */
  21. #ifndef FB_ERM_LRA
  22. #define FB_ERM_LRA 1 /* For ERM:0 or LRA:1*/
  23. #endif
  24. #ifndef FB_BRAKEFACTOR
  25. #define FB_BRAKEFACTOR 3 /* For 1x:0, 2x:1, 3x:2, 4x:3, 6x:4, 8x:5, 16x:6, Disable Braking:7 */
  26. #endif
  27. #ifndef FB_LOOPGAIN
  28. #define FB_LOOPGAIN 1 /* For Low:0, Medium:1, High:2, Very High:3 */
  29. #endif
  30. /* LRA specific settings */
  31. #if FB_ERM_LRA == 1
  32. #ifndef V_RMS
  33. #define V_RMS 2.0
  34. #endif
  35. #ifndef V_PEAK
  36. #define V_PEAK 2.1
  37. #endif
  38. #ifndef F_LRA
  39. #define F_LRA 205
  40. #endif
  41. #ifndef RATED_VOLTAGE
  42. #define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
  43. #endif
  44. #endif
  45. #ifndef RATED_VOLTAGE
  46. #define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
  47. #endif
  48. #ifndef V_PEAK
  49. #define V_PEAK 2.8
  50. #endif
  51. /* Library Selection */
  52. #ifndef LIB_SELECTION
  53. #if FB_ERM_LRA == 1
  54. #define LIB_SELECTION 6 /* For Empty:0' TS2200 library A to D:1-5, LRA Library: 6 */
  55. #else
  56. #define LIB_SELECTION 1
  57. #endif
  58. #endif
  59. #ifndef DRV_GREETING
  60. #define DRV_GREETING alert_750ms
  61. #endif
  62. #ifndef DRV_MODE_DEFAULT
  63. #define DRV_MODE_DEFAULT strong_click1
  64. #endif
  65. /* Control 1 register settings */
  66. #ifndef DRIVE_TIME
  67. #define DRIVE_TIME 25
  68. #endif
  69. #ifndef AC_COUPLE
  70. #define AC_COUPLE 0
  71. #endif
  72. #ifndef STARTUP_BOOST
  73. #define STARTUP_BOOST 1
  74. #endif
  75. /* Control 2 Settings */
  76. #ifndef BIDIR_INPUT
  77. #define BIDIR_INPUT 1
  78. #endif
  79. #ifndef BRAKE_STAB
  80. #define BRAKE_STAB 1 /* Loopgain is reduced when braking is almost complete to improve stability */
  81. #endif
  82. #ifndef SAMPLE_TIME
  83. #define SAMPLE_TIME 3
  84. #endif
  85. #ifndef BLANKING_TIME
  86. #define BLANKING_TIME 1
  87. #endif
  88. #ifndef IDISS_TIME
  89. #define IDISS_TIME 1
  90. #endif
  91. /* Control 3 settings */
  92. #ifndef NG_THRESH
  93. #define NG_THRESH 2
  94. #endif
  95. #ifndef ERM_OPEN_LOOP
  96. #define ERM_OPEN_LOOP 1
  97. #endif
  98. #ifndef SUPPLY_COMP_DIS
  99. #define SUPPLY_COMP_DIS 0
  100. #endif
  101. #ifndef DATA_FORMAT_RTO
  102. #define DATA_FORMAT_RTO 0
  103. #endif
  104. #ifndef LRA_DRIVE_MODE
  105. #define LRA_DRIVE_MODE 0
  106. #endif
  107. #ifndef N_PWM_ANALOG
  108. #define N_PWM_ANALOG 0
  109. #endif
  110. #ifndef LRA_OPEN_LOOP
  111. #define LRA_OPEN_LOOP 0
  112. #endif
  113. /* Control 4 settings */
  114. #ifndef ZC_DET_TIME
  115. #define ZC_DET_TIME 0
  116. #endif
  117. #ifndef AUTO_CAL_TIME
  118. #define AUTO_CAL_TIME 3
  119. #endif
  120. /* register defines -------------------------------------------------------- */
  121. #define DRV2605L_BASE_ADDRESS 0x5A /* DRV2605L Base address */
  122. #define DRV_STATUS 0x00
  123. #define DRV_MODE 0x01
  124. #define DRV_RTP_INPUT 0x02
  125. #define DRV_LIB_SELECTION 0x03
  126. #define DRV_WAVEFORM_SEQ_1 0x04
  127. #define DRV_WAVEFORM_SEQ_2 0x05
  128. #define DRV_WAVEFORM_SEQ_3 0x06
  129. #define DRV_WAVEFORM_SEQ_4 0x07
  130. #define DRV_WAVEFORM_SEQ_5 0x08
  131. #define DRV_WAVEFORM_SEQ_6 0x09
  132. #define DRV_WAVEFORM_SEQ_7 0x0A
  133. #define DRV_WAVEFORM_SEQ_8 0x0B
  134. #define DRV_GO 0x0C
  135. #define DRV_OVERDRIVE_TIME_OFFSET 0x0D
  136. #define DRV_SUSTAIN_TIME_OFFSET_P 0x0E
  137. #define DRV_SUSTAIN_TIME_OFFSET_N 0x0F
  138. #define DRV_BRAKE_TIME_OFFSET 0x10
  139. #define DRV_AUDIO_2_VIBE_CTRL 0x11
  140. #define DRV_AUDIO_2_VIBE_MIN_IN 0x12
  141. #define DRV_AUDIO_2_VIBE_MAX_IN 0x13
  142. #define DRV_AUDIO_2_VIBE_MIN_OUTDRV 0x14
  143. #define DRV_AUDIO_2_VIBE_MAX_OUTDRV 0x15
  144. #define DRV_RATED_VOLT 0x16
  145. #define DRV_OVERDRIVE_CLAMP_VOLT 0x17
  146. #define DRV_AUTO_CALIB_COMP_RESULT 0x18
  147. #define DRV_AUTO_CALIB_BEMF_RESULT 0x19
  148. #define DRV_FEEDBACK_CTRL 0x1A
  149. #define DRV_CTRL_1 0x1B
  150. #define DRV_CTRL_2 0x1C
  151. #define DRV_CTRL_3 0x1D
  152. #define DRV_CTRL_4 0x1E
  153. #define DRV_CTRL_5 0x1F
  154. #define DRV_OPEN_LOOP_PERIOD 0x20
  155. #define DRV_VBAT_VOLT_MONITOR 0x21
  156. #define DRV_LRA_RESONANCE_PERIOD 0x22
  157. void DRV_init(void);
  158. void DRV_write(const uint8_t drv_register, const uint8_t settings);
  159. uint8_t DRV_read(const uint8_t regaddress);
  160. void DRV_pulse(const uint8_t sequence);
  161. typedef enum DRV_EFFECT{
  162. clear_sequence = 0,
  163. strong_click = 1,
  164. strong_click_60 = 2,
  165. strong_click_30 = 3,
  166. sharp_click = 4,
  167. sharp_click_60 = 5,
  168. sharp_click_30 = 6,
  169. soft_bump = 7,
  170. soft_bump_60 = 8,
  171. soft_bump_30 = 9,
  172. dbl_click = 10,
  173. dbl_click_60 = 11,
  174. trp_click = 12,
  175. soft_fuzz = 13,
  176. strong_buzz = 14,
  177. alert_750ms = 15,
  178. alert_1000ms = 16,
  179. strong_click1 = 17,
  180. strong_click2_80 = 18,
  181. strong_click3_60 = 19,
  182. strong_click4_30 = 20,
  183. medium_click1 = 21,
  184. medium_click2_80 = 22,
  185. medium_click3_60 = 23,
  186. sharp_tick1 = 24,
  187. sharp_tick2_80 = 25,
  188. sharp_tick3_60 = 26,
  189. sh_dblclick_str = 27,
  190. sh_dblclick_str_80 = 28,
  191. sh_dblclick_str_60 = 29,
  192. sh_dblclick_str_30 = 30,
  193. sh_dblclick_med = 31,
  194. sh_dblclick_med_80 = 32,
  195. sh_dblclick_med_60 = 33,
  196. sh_dblsharp_tick = 34,
  197. sh_dblsharp_tick_80 = 35,
  198. sh_dblsharp_tick_60 = 36,
  199. lg_dblclick_str = 37,
  200. lg_dblclick_str_80 = 38,
  201. lg_dblclick_str_60 = 39,
  202. lg_dblclick_str_30 = 40,
  203. lg_dblclick_med = 41,
  204. lg_dblclick_med_80 = 42,
  205. lg_dblclick_med_60 = 43,
  206. lg_dblsharp_tick = 44,
  207. lg_dblsharp_tick_80 = 45,
  208. lg_dblsharp_tick_60 = 46,
  209. buzz = 47,
  210. buzz_80 = 48,
  211. buzz_60 = 49,
  212. buzz_40 = 50,
  213. buzz_20 = 51,
  214. pulsing_strong = 52,
  215. pulsing_strong_80 = 53,
  216. pulsing_medium = 54,
  217. pulsing_medium_80 = 55,
  218. pulsing_sharp = 56,
  219. pulsing_sharp_80 = 57,
  220. transition_click = 58,
  221. transition_click_80 = 59,
  222. transition_click_60 = 60,
  223. transition_click_40 = 61,
  224. transition_click_20 = 62,
  225. transition_click_10 = 63,
  226. transition_hum = 64,
  227. transition_hum_80 = 65,
  228. transition_hum_60 = 66,
  229. transition_hum_40 = 67,
  230. transition_hum_20 = 68,
  231. transition_hum_10 = 69,
  232. transition_rampdown_long_smooth1 = 70,
  233. transition_rampdown_long_smooth2 = 71,
  234. transition_rampdown_med_smooth1 = 72,
  235. transition_rampdown_med_smooth2 = 73,
  236. transition_rampdown_short_smooth1 = 74,
  237. transition_rampdown_short_smooth2 = 75,
  238. transition_rampdown_long_sharp1 = 76,
  239. transition_rampdown_long_sharp2 = 77,
  240. transition_rampdown_med_sharp1 = 78,
  241. transition_rampdown_med_sharp2 = 79,
  242. transition_rampdown_short_sharp1 = 80,
  243. transition_rampdown_short_sharp2 = 81,
  244. transition_rampup_long_smooth1 = 82,
  245. transition_rampup_long_smooth2 = 83,
  246. transition_rampup_med_smooth1 = 84,
  247. transition_rampup_med_smooth2 = 85,
  248. transition_rampup_short_smooth1 = 86,
  249. transition_rampup_short_smooth2 = 87,
  250. transition_rampup_long_sharp1 = 88,
  251. transition_rampup_long_sharp2 = 89,
  252. transition_rampup_med_sharp1 = 90,
  253. transition_rampup_med_sharp2 = 91,
  254. transition_rampup_short_sharp1 = 92,
  255. transition_rampup_short_sharp2 = 93,
  256. transition_rampdown_long_smooth1_50 = 94,
  257. transition_rampdown_long_smooth2_50 = 95,
  258. transition_rampdown_med_smooth1_50 = 96,
  259. transition_rampdown_med_smooth2_50 = 97,
  260. transition_rampdown_short_smooth1_50 = 98,
  261. transition_rampdown_short_smooth2_50 = 99,
  262. transition_rampdown_long_sharp1_50 = 100,
  263. transition_rampdown_long_sharp2_50 = 101,
  264. transition_rampdown_med_sharp1_50 = 102,
  265. transition_rampdown_med_sharp2_50 = 103,
  266. transition_rampdown_short_sharp1_50 = 104,
  267. transition_rampdown_short_sharp2_50 = 105,
  268. transition_rampup_long_smooth1_50 = 106,
  269. transition_rampup_long_smooth2_50 = 107,
  270. transition_rampup_med_smooth1_50 = 108,
  271. transition_rampup_med_smooth2_50 = 109,
  272. transition_rampup_short_smooth1_50 = 110,
  273. transition_rampup_short_smooth2_50 = 111,
  274. transition_rampup_long_sharp1_50 = 112,
  275. transition_rampup_long_sharp2_50 = 113,
  276. transition_rampup_med_sharp1_50 = 114,
  277. transition_rampup_med_sharp2_50 = 115,
  278. transition_rampup_short_sharp1_50 = 116,
  279. transition_rampup_short_sharp2_50 = 117,
  280. long_buzz_for_programmatic_stopping = 118,
  281. smooth_hum1_50 = 119,
  282. smooth_hum2_40 = 120,
  283. smooth_hum3_30 = 121,
  284. smooth_hum4_20 = 122,
  285. smooth_hum5_10 = 123,
  286. drv_effect_max = 124,
  287. } DRV_EFFECT;
  288. /* Register bit array unions */
  289. typedef union DRVREG_STATUS { /* register 0x00 */
  290. uint8_t Byte;
  291. struct {
  292. uint8_t OC_DETECT :1; /* set to 1 when overcurrent event is detected */
  293. uint8_t OVER_TEMP :1; /* set to 1 when device exceeds temp threshold */
  294. uint8_t FB_STS :1; /* set to 1 when feedback controller has timed out */
  295. /* auto-calibration routine and diagnostic result
  296. * result | auto-calibation | diagnostic |
  297. * 0 | passed | actuator func normal |
  298. * 1 | failed | actuator func fault* |
  299. * * actuator is not present or is shorted, timing out, or giving outof-range back-EMF */
  300. uint8_t DIAG_RESULT :1;
  301. uint8_t :1;
  302. uint8_t DEVICE_ID :3; /* Device IDs 3: DRV2605 4: DRV2604 5: DRV2604L 6: DRV2605L */
  303. } Bits;
  304. } DRVREG_STATUS;
  305. typedef union DRVREG_MODE { /* register 0x01 */
  306. uint8_t Byte;
  307. struct {
  308. uint8_t MODE :3; /* Mode setting */
  309. uint8_t :3;
  310. uint8_t STANDBY :1; /* 0:standby 1:ready */
  311. } Bits;
  312. } DRVREG_MODE;
  313. typedef union DRVREG_WAIT {
  314. uint8_t Byte;
  315. struct {
  316. uint8_t WAIT_MODE :1; /* Set to 1 to interpret as wait for next 7 bits x10ms */
  317. uint8_t WAIT_TIME :7;
  318. } Bits;
  319. } DRVREG_WAIT;
  320. typedef union DRVREG_FBR{ /* register 0x1A */
  321. uint8_t Byte;
  322. struct {
  323. uint8_t BEMF_GAIN :2;
  324. uint8_t LOOP_GAIN :2;
  325. uint8_t BRAKE_FACTOR :3;
  326. uint8_t ERM_LRA :1;
  327. } Bits;
  328. } DRVREG_FBR;
  329. typedef union DRVREG_CTRL1{ /* register 0x1B */
  330. uint8_t Byte;
  331. struct {
  332. uint8_t C1_DRIVE_TIME :5;
  333. uint8_t C1_AC_COUPLE :1;
  334. uint8_t :1;
  335. uint8_t C1_STARTUP_BOOST :1;
  336. } Bits;
  337. } DRVREG_CTRL1;
  338. typedef union DRVREG_CTRL2{ /* register 0x1C */
  339. uint8_t Byte;
  340. struct {
  341. uint8_t C2_IDISS_TIME :2;
  342. uint8_t C2_BLANKING_TIME :2;
  343. uint8_t C2_SAMPLE_TIME :2;
  344. uint8_t C2_BRAKE_STAB :1;
  345. uint8_t C2_BIDIR_INPUT :1;
  346. } Bits;
  347. } DRVREG_CTRL2;
  348. typedef union DRVREG_CTRL3{ /* register 0x1D */
  349. uint8_t Byte;
  350. struct {
  351. uint8_t C3_LRA_OPEN_LOOP :1;
  352. uint8_t C3_N_PWM_ANALOG :1;
  353. uint8_t C3_LRA_DRIVE_MODE :1;
  354. uint8_t C3_DATA_FORMAT_RTO :1;
  355. uint8_t C3_SUPPLY_COMP_DIS :1;
  356. uint8_t C3_ERM_OPEN_LOOP :1;
  357. uint8_t C3_NG_THRESH :2;
  358. } Bits;
  359. } DRVREG_CTRL3;
  360. typedef union DRVREG_CTRL4{ /* register 0x1E */
  361. uint8_t Byte;
  362. struct {
  363. uint8_t C4_OTP_PROGRAM :1;
  364. uint8_t :1;
  365. uint8_t C4_OTP_STATUS :1;
  366. uint8_t :1;
  367. uint8_t C4_AUTO_CAL_TIME :2;
  368. uint8_t C4_ZC_DET_TIME :2;
  369. } Bits;
  370. } DRVREG_CTRL4;
  371. typedef union DRVREG_CTRL5{ /* register 0x1F */
  372. uint8_t Byte;
  373. struct {
  374. uint8_t C5_IDISS_TIME :2;
  375. uint8_t C5_BLANKING_TIME :2;
  376. uint8_t C5_PLAYBACK_INTERVAL :1;
  377. uint8_t C5_LRA_AUTO_OPEN_LOOP :1;
  378. uint8_t C5_AUTO_OL_CNT :2;
  379. } Bits;
  380. } DRVREG_CTRL5;