-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeftlib.h
94 lines (75 loc) · 3.23 KB
/
Weftlib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
WEFTlib Electrovibration library
2017, nfeehan / AKA aka.farm
Addition of some methods to make electrovibration actuation more convenient. Probably also useful for piezo effects?
Based gratefully off of:
Yurikleb_DRV2667.h - Library for controling the TI - DRV2667 Hapic Piezo Driver
Created by Yuri Klenaov, January, 2016. (yurikleb.com)
Released into the public domain.
For more information see the DRV2667 Datasheet http://www.ti.com/lit/ds/symlink/drv2667.pdf
...there are three modes for this IC that result in output.
waveform synthesis playback: ie, send the ic a description of a sequence of sine waves
waveform "Direct Playback": in this mode, the IC basically reads a soundfile you've stored in RAM (via the savePattern() call)
analog in: calling setToAnalogInput() or setToAnalogInputGain(byte gain)
*/
#ifndef Weftlib_h
#define Weftlib_h
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Wire.h> //Wire Library to use I2C
#define DRV2667_ADDR 0x59 //The DRV2667 Chip default I2C address.
#define REG_GAINS 0x01
#define REG_CTRL 0x02
#define REG_WAVEFORM0 0x03
#define REG_WAVEFORM1 0x04
#define REG_WAVEFORM2 0x05
#define REG_WAVEFORM3 0x06
#define REG_WAVEFORM4 0x07
#define REG_WAVEFORM5 0x08
#define REG_WAVEFORM6 0x09
#define REG_WAVEFORM7 0x0A
#define BOOST_AMP_ENABLED 0x02
#define RESET_DEVICE 0x80
#define STANDBY_ON 0x40
#define STANDBY_OFF 0x00
class Weft
{
public:
Weft(void);
void begin(void);
void playWave(byte WaveForm[][4], byte WavesNumber);
void playWaveGain(byte WaveForm[][4], byte WavesNumber, byte theGain);
float getWaveDuration(byte wf[][4], byte wn);
void setToAnalogInput();
void setToAnalogInputGain(byte theGain);
/*
The DRV2667 device has a timeout period after the FIFO has emptied.
This timeout period allows the user time to send a subsequent waveform before the device logic
puts the device into idle mode, that then allows the host processor time to cue up an adjoining
waveform from memory. After the timeout expires, the DRV2667 device must re-enter the 2 ms
startup sequence before the next waveform plays. The timeout period is register- selectable
to be 5, 10, 15 or 20 ms.
*/
void setTimeoutPeriod(byte thePeriod); // can only be 0x00, 0x04, 0x08, or 0x0c. Defaults to shortest, 5ms -> 0x00
// directPlayback()
/*
from datasheet:
The waveforms are stored as 8-bit twos-complement, Nyquist-rate data points, and are played from RAM at an 8- kHz data rate.
Up to 250 ms of total waveform playback time may be stored in the Direct Playback From RAM mode format in the 2-kB memory.
The waveform sizes are completely customizable, so many small waveforms may be stored or fewer long ones.
The sum of the waveform lengths must not be greater than the 2-kB RAM size.
*/
// patternWrite(data) // write a waveform to the internal RAM, can't be more than 2kb total. Successful write returns index / address?
// patternRead(index)
// This may need to return an index # if mult files are supported by this lib
void resetDevice();
void setToStandby();
void wakeFromStandby();
void writeRegisterBytes(byte reg, byte val);
void i2c_Scan(void);
// private:
};
#endif