drv2605.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. drv2605.h
  3. A library for Grove-Haptic Motor 1.0
  4. Copyright (c) 2015 seeed technology inc.
  5. Website : http://www.seeedstudio.com/
  6. Author : WuRuibin & Sujianzhang
  7. The MIT License (MIT)
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. THE SOFTWARE.
  23. */
  24. #ifndef __DRV2605_H__
  25. #define __DRV2605_H__
  26. #include <Arduino.h>
  27. #define DRV2605_SUPPORT_WIRE_I2C 1
  28. #define DRV2605_SUPPORT_SOFT_I2C 0
  29. //#define SDA_PORT PORTD
  30. //#define SDA_PIN 3
  31. //#define SCL_PORT PORTD
  32. //#define SCL_PIN 2
  33. #define STATUS_Reg 0x00
  34. #define MODE_Reg 0x01
  35. #define RTP_INPUT_Reg 0x02
  36. #define LIB_SEL_Reg 0x03
  37. #define WAV_SEQ1_Reg 0x04
  38. #define WAV_SEQ2_Reg 0x05
  39. #define WAV_SEQ3_Reg 0x06
  40. #define WAV_SEQ4_Reg 0x07
  41. #define WAV_SEQ5_Reg 0x08
  42. #define WAV_SEQ6_Reg 0x09
  43. #define WAV_SEQ7_Reg 0x0A
  44. #define WAV_SEQ8_Reg 0x0B
  45. #define GO_Reg 0x0C
  46. #define ODT_OFFSET_Reg 0x0D
  47. #define SPT_Reg 0x0E
  48. #define SNT_Reg 0x0F
  49. #define BRT_Reg 0x10
  50. #define ATV_CON_Reg 0x11
  51. #define ATV_MIN_IN_Reg 0x12
  52. #define ATV_MAX_IN_Reg 0x13
  53. #define ATV_MIN_OUT_Reg 0x14
  54. #define ATV_MAX_OUT_Reg 0x15
  55. #define RATED_VOLTAGE_Reg 0x16
  56. #define OD_CLAMP_Reg 0x17
  57. #define A_CAL_COMP_Reg 0x18
  58. #define A_CAL_BEMF_Reg 0x19
  59. #define FB_CON_Reg 0x1A
  60. #define CONTRL1_Reg 0x1B
  61. #define CONTRL2_Reg 0x1C
  62. #define CONTRL3_Reg 0x1D
  63. #define CONTRL4_Reg 0x1E
  64. #define VBAT_MON_Reg 0x21
  65. #define LRA_RESON_Reg 0x22
  66. #define DRV2605_ADDRESS 0x5A
  67. /*** Register Bits ***/
  68. /*
  69. #define Dev_Reset (0x80)
  70. #define STANDBY (0x40)
  71. #define ACTIVE (0x00)
  72. */
  73. class DRV2605 {
  74. public:
  75. int init(bool bSoftI2C, bool bVerbose);
  76. int drv2605Read(unsigned char ucRegAddress, char* pcValue);
  77. int drv2605ReadInt(unsigned char ucRegAddress, int* piValue);
  78. int drv2605Write(unsigned char ucRegAddress, char cValue);
  79. int drv2605_AutoCal(void);
  80. int drv2605_Play_Waveform(unsigned char ucEffect);
  81. private:
  82. bool bSoftI2C; /* Use software I2C on digital pins or Wire I2C on designated I2C pins */
  83. bool bVerbose; /* Write diagnostic information to the serial port */
  84. };
  85. #endif /* __DRV2605_H__ */