brix5 / firmware / demo / QuadDRV-CompassBelt / Adafruit_DRV2605.h @ master
History | View | Annotate | Download (2.729 KB)
1 | a2a2cf8b | Jan | /***************************************************
|
---|---|---|---|
2 | This is a library for the Adafruit DRV2605L Haptic Driver
|
||
3 | |||
4 | ----> http://www.adafruit.com/products/2305
|
||
5 | |||
6 | Check out the links above for our tutorials and wiring diagrams
|
||
7 | This motor/haptic driver uses I2C to communicate
|
||
8 | |||
9 | Adafruit invests time and resources providing this open source code,
|
||
10 | please support Adafruit and open-source hardware by purchasing
|
||
11 | products from Adafruit!
|
||
12 | |||
13 | Written by Limor Fried/Ladyada for Adafruit Industries.
|
||
14 | MIT license, all text above must be included in any redistribution
|
||
15 | ****************************************************/
|
||
16 | |||
17 | |||
18 | #if ARDUINO >= 100 |
||
19 | #include "Arduino.h" |
||
20 | #else
|
||
21 | #include "WProgram.h" |
||
22 | #endif
|
||
23 | |||
24 | #if defined(__MK20DX128__) || defined(__MK20DX256__)
|
||
25 | #include "i2c_t3.h" |
||
26 | #else
|
||
27 | #include "Wire.h" |
||
28 | #endif
|
||
29 | |||
30 | |||
31 | |||
32 | #define DRV2605_ADDR 0x5A |
||
33 | |||
34 | #define DRV2605_REG_STATUS 0x00 |
||
35 | #define DRV2605_REG_MODE 0x01 |
||
36 | #define DRV2605_MODE_INTTRIG 0x00 |
||
37 | #define DRV2605_MODE_EXTTRIGEDGE 0x01 |
||
38 | #define DRV2605_MODE_EXTTRIGLVL 0x02 |
||
39 | #define DRV2605_MODE_PWMANALOG 0x03 |
||
40 | #define DRV2605_MODE_AUDIOVIBE 0x04 |
||
41 | #define DRV2605_MODE_REALTIME 0x05 |
||
42 | #define DRV2605_MODE_DIAGNOS 0x06 |
||
43 | #define DRV2605_MODE_AUTOCAL 0x07 |
||
44 | |||
45 | |||
46 | #define DRV2605_REG_RTPIN 0x02 |
||
47 | #define DRV2605_REG_LIBRARY 0x03 |
||
48 | #define DRV2605_REG_WAVESEQ1 0x04 |
||
49 | #define DRV2605_REG_WAVESEQ2 0x05 |
||
50 | #define DRV2605_REG_WAVESEQ3 0x06 |
||
51 | #define DRV2605_REG_WAVESEQ4 0x07 |
||
52 | #define DRV2605_REG_WAVESEQ5 0x08 |
||
53 | #define DRV2605_REG_WAVESEQ6 0x09 |
||
54 | #define DRV2605_REG_WAVESEQ7 0x0A |
||
55 | #define DRV2605_REG_WAVESEQ8 0x0B |
||
56 | |||
57 | #define DRV2605_REG_GO 0x0C |
||
58 | #define DRV2605_REG_OVERDRIVE 0x0D |
||
59 | #define DRV2605_REG_SUSTAINPOS 0x0E |
||
60 | #define DRV2605_REG_SUSTAINNEG 0x0F |
||
61 | #define DRV2605_REG_BREAK 0x10 |
||
62 | #define DRV2605_REG_AUDIOCTRL 0x11 |
||
63 | #define DRV2605_REG_AUDIOLVL 0x12 |
||
64 | #define DRV2605_REG_AUDIOMAX 0x13 |
||
65 | #define DRV2605_REG_RATEDV 0x16 |
||
66 | #define DRV2605_REG_CLAMPV 0x17 |
||
67 | #define DRV2605_REG_AUTOCALCOMP 0x18 |
||
68 | #define DRV2605_REG_AUTOCALEMP 0x19 |
||
69 | #define DRV2605_REG_FEEDBACK 0x1A |
||
70 | #define DRV2605_REG_CONTROL1 0x1B |
||
71 | #define DRV2605_REG_CONTROL2 0x1C |
||
72 | #define DRV2605_REG_CONTROL3 0x1D |
||
73 | #define DRV2605_REG_CONTROL4 0x1E |
||
74 | #define DRV2605_REG_VBAT 0x21 |
||
75 | #define DRV2605_REG_LRARESON 0x22 |
||
76 | |||
77 | |||
78 | class Adafruit_DRV2605 { |
||
79 | public:
|
||
80 | Adafruit_DRV2605(uint8_t channel); |
||
81 | boolean begin(void);
|
||
82 | void selectChannel(uint8_t channel);
|
||
83 | void writeRegister8(uint8_t reg, uint8_t val);
|
||
84 | uint8_t readRegister8(uint8_t reg); |
||
85 | void setWaveform(uint8_t slot, uint8_t w);
|
||
86 | void selectLibrary(uint8_t lib);
|
||
87 | void go(void); |
||
88 | void setMode(uint8_t mode);
|
||
89 | void setRealtimeValue(uint8_t rtp);
|
||
90 | // Select ERM (Eccentric Rotating Mass) or LRA (Linear Resonant Actuator) vibration motor
|
||
91 | // The default is ERM, which is more common
|
||
92 | void useERM();
|
||
93 | void useLRA();
|
||
94 | |||
95 | private:
|
||
96 | uint8_t _channel; |
||
97 | }; |