-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
144 lines (103 loc) · 4 KB
/
main.c
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "msp.h"
#include "DRV2605.h"
/**
* main.c
*
* Author: Kevin Kuwata
* Date: 1/14/18
*
* @brief: This is an example project to get the motor driver working. I am using the pinouts found
* in the smartwatch v2 schematic.
* Depends on I2C to communicate to the DRV2605 motor driver.
* Also uses Enable and PWM pins.
* Enable pin P7.5 GPIO
* PWM pin P7.6 TA1.2 Primary //trigger or pwm pin
* SDA P6.6 Tertiary// i bet you this is that bull shit needs to be secondary.
* SCL P6.7 Tertiary
*
* LRA (disk motor) focused. Only can use Library 6 or Library 7 for preprogrammed
*
* I2C UCB3
*
*
*/
extern uint8_t I2CReceived[10]; //just picked 10 but it should be as small as possible
/* ======================================================================================================================================================*/
/* ======================================================================================================================================================*/
/* ======================================================================================================================================================*/
/* ======================================================================================================================================================*/
void initHBLed(void){
P9SEL0 &= ~BIT3;
P9SEL1 &= ~BIT3;
P9DIR |= BIT3;
P9OUT |= BIT3;
}
void beatHeart(uint32_t duration){
P9OUT|=BIT3;
uint32_t duration_mS = duration*300; // .1 seconds, like 1 is .1 seconds, 10 is 1 second
uint32_t i = 0;
for(i=0; i<duration_mS; i++);
P9OUT &= ~BIT3;
for(i=0; i<duration_mS; i++);
}
void main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer
__enable_interrupt(); //globals
initHBLed();
initDriver();
//analogMode();
// beatHeart(3000);
/* device reset 7th bit to 0x01 */
//writeRegister(DRV_DEFAULT_ADDRESS, 0x01, 0x80); //7th bit in binary
/* set up for auto calibration */
//preAutoCalibrationLRA();
//autoCalibrationLRA();
autoCalibrationERM();
//setAndPlay(118);
beatHeart(500);
//LRA resonance is 127??
// comp result: 12 decimal, 0x0C
// auto bemf: 108
#ifdef fixed
uint8_t a = readRegister(DRV_DEFAULT_ADDRESS, FB_CTRL_R); //0x1A
uint8_t aa = readRegister(DRV_DEFAULT_ADDRESS, FB_CTRL_R); //0x1A
uint8_t b = readRegister(DRV_DEFAULT_ADDRESS, STATUS_R); //0x00
uint8_t bb = readRegister(DRV_DEFAULT_ADDRESS, STATUS_R); //0x00
uint8_t c = readRegister(DRV_DEFAULT_ADDRESS, LRA_RESONANCE_R); //0x22
uint8_t cc = readRegister(DRV_DEFAULT_ADDRESS, LRA_RESONANCE_R); //0x22
uint8_t d = readRegister(DRV_DEFAULT_ADDRESS, AUTO_CAL_COMP_RESULT_R); //0x18
uint8_t dd = readRegister(DRV_DEFAULT_ADDRESS, AUTO_CAL_COMP_RESULT_R); //0x18
uint8_t e = readRegister(DRV_DEFAULT_ADDRESS, AUTO_CAL_BEMF_RESULT_R); //0x19
uint8_t ee = readRegister(DRV_DEFAULT_ADDRESS, AUTO_CAL_BEMF_RESULT_R); //0x19
uint8_t f = readRegister(DRV_DEFAULT_ADDRESS, FB_CTRL_R); //0x1A
uint8_t ff = readRegister(DRV_DEFAULT_ADDRESS, FB_CTRL_R); //0x1A
uint8_t fff = readRegister(DRV_DEFAULT_ADDRESS, FB_CTRL_R); //0x1A
#endif
while(1){
// P7OUT |= PWM_PIN;
beatHeart(100);
// P7OUT &= ~PWM_PIN;
// analogMode();
// setAndPlay(118);
setAndPlay(98);
beatHeart(300);
setAndPlay(1);
beatHeart(300);
setAndPlay(46);
beatHeart(300);
setAndPlay(46);
beatHeart(300);
setAndPlay(27);
beatHeart(300);
setAndPlay(93);
beatHeart(300);
setAndPlay(12);
beatHeart(300);
setAndPlay(16);
beatHeart(300);
setAndPlay(80);
beatHeart(300);
beatHeart(500);
}
}