summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Li2017-08-03 08:47:59 -0500
committerPeter Li2017-08-03 08:47:59 -0500
commit6df61bc36a0c6580e77c25c28b64faf5114b2cf0 (patch)
tree09531eb2156b0ab465c81be7c6c392403f28d22f
parent95e4ac43427e108c5b6110b66d64b515c99430ef (diff)
downloaddrv260x-util-6df61bc36a0c6580e77c25c28b64faf5114b2cf0.tar.gz
drv260x-util-6df61bc36a0c6580e77c25c28b64faf5114b2cf0.tar.xz
drv260x-util-6df61bc36a0c6580e77c25c28b64faf5114b2cf0.zip
update util
-rwxr-xr-xdrv260xutil/Android.mk (renamed from haptics/Android.mk)6
-rwxr-xr-xdrv260xutil/CleanSpec.mk (renamed from haptics/CleanSpec.mk)0
-rwxr-xr-xdrv260xutil/haptics.h (renamed from haptics/haptics.h)47
-rwxr-xr-xdrv260xutil/main.c856
-rwxr-xr-xhaptics/main.c1119
5 files changed, 893 insertions, 1135 deletions
diff --git a/haptics/Android.mk b/drv260xutil/Android.mk
index cf19f9d..82b1f4b 100755
--- a/haptics/Android.mk
+++ b/drv260xutil/Android.mk
@@ -6,13 +6,13 @@ include $(CLEAR_VARS)
6 6
7LOCAL_SRC_FILES := main.c 7LOCAL_SRC_FILES := main.c
8 8
9LOCAL_C_INCLUDES := external/haptics/ 9LOCAL_C_INCLUDES := external/drv260xutil/
10 10
11LOCAL_CFLAGS := -O2 -g -W -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 11LOCAL_CFLAGS := -O2 -g -W -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
12 12
13LOCAL_MODULE := haptics 13LOCAL_MODULE := drv260xutil
14LOCAL_MODULE_TAGS := debug 14LOCAL_MODULE_TAGS := debug
15LOCAL_SYSTEM_SHARED_LIBRARIES := libc 15LOCAL_SYSTEM_SHARED_LIBRARIES := libc libm
16 16
17include $(BUILD_EXECUTABLE) 17include $(BUILD_EXECUTABLE)
18 18
diff --git a/haptics/CleanSpec.mk b/drv260xutil/CleanSpec.mk
index b84e1b6..b84e1b6 100755
--- a/haptics/CleanSpec.mk
+++ b/drv260xutil/CleanSpec.mk
diff --git a/haptics/haptics.h b/drv260xutil/haptics.h
index afccb1d..c18196c 100755
--- a/haptics/haptics.h
+++ b/drv260xutil/haptics.h
@@ -1,18 +1,27 @@
1/* 1/*
2 * 2013 @ Texas Intruments, Inc. 2 * 2016 @ Texas Intruments, Inc.
3 * 3 *
4*/ 4*/
5#include <fcntl.h>
6#include <stdio.h>
7#include <sys/ioctl.h>
5 8
6#define HAPTICS_VERSION "Version : 2.02 (30th, May, 2014)" 9#define HAPTICS_VERSION "Version : 3.01 (09th, March, 2017)"
10
11#define DRV26xx_SEQUENCER_SIZE 8
7 12
8enum Haptic_Target{ 13enum Haptic_Target{
9 HAPTIC_DRVXXXX, 14 HAPTIC_DRVXXXX,
10 HAPTIC_DRV2604, 15 HAPTIC_DRV2604,
11 HAPTIC_DRV2604L,
12 HAPTIC_DRV2605, 16 HAPTIC_DRV2605,
13 HAPTIC_DRV2605L, 17};
14 HAPTIC_DRV2667, 18
15 HAPTIC_DRV2669 19struct drv260x_waveform {
20 unsigned char mnEffect;
21};
22
23struct drv260x_waveform_sequencer {
24 struct drv260x_waveform msWaveform[DRV26xx_SEQUENCER_SIZE];
16}; 25};
17 26
18#define FIFO_PBK_BYTES_LEN 100 27#define FIFO_PBK_BYTES_LEN 100
@@ -29,17 +38,22 @@ enum Haptic_Target{
29#define HAPTIC_CMDID_AUDIOHAPTIC_DISABLE 0x07 38#define HAPTIC_CMDID_AUDIOHAPTIC_DISABLE 0x07
30#define HAPTIC_CMDID_AUDIOHAPTIC_GETSTATUS 0x08 39#define HAPTIC_CMDID_AUDIOHAPTIC_GETSTATUS 0x08
31 40
32#define HAPTIC_CMDID_REG_WRITE 0x09 41#define HAPTIC_CMDID_REG_WRITE 0x09
33#define HAPTIC_CMDID_REG_READ 0x0a 42#define HAPTIC_CMDID_REG_READ 0x0a
34#define HAPTIC_CMDID_REG_SETBIT 0x0b 43#define HAPTIC_CMDID_REG_SETBIT 0x0b
35#define HAPTIC_CMDID_PATTERN_RTP 0x0c 44#define HAPTIC_CMDID_PATTERN_RTP 0x0c
36#define HAPTIC_CMDID_RTP_SEQUENCE 0x0d 45#define HAPTIC_CMDID_RTP_SEQUENCE 0x0d
37#define HAPTIC_CMDID_PLAY_FIFO 0x0e 46#define HAPTIC_CMDID_PLAY_FIFO 0x0e
38#define HAPTIC_CMDID_ANALOG_INPUT 0x0f 47#define HAPTIC_CMDID_ANALOG_INPUT 0x0f
39#define HAPTIC_CMDID_GET_EFFECT_COUNT 0x10 48#define HAPTIC_CMDID_GET_EFFECT_COUNT 0x10
40#define HAPTIC_CMDID_UPDATE_FIRMWARE 0x11 49#define HAPTIC_CMDID_UPDATE_FIRMWARE 0x11
41#define HAPTIC_CMDID_READ_FIRMWARE 0x12 50#define HAPTIC_CMDID_READ_FIRMWARE 0x12
42#define HAPTIC_CMDID_STOP 0xFF 51#define HAPTIC_CMDID_RUN_CALIBRATION 0x13
52#define HAPTIC_CMDID_CONFIG_WAVEFORM 0x14
53#define HAPTIC_CMDID_SET_SEQUENCER 0x15
54#define HAPTIC_CMDID_REGLOG_ENABLE 0x16
55
56#define HAPTIC_CMDID_STOP 0xFF
43 57
44/* Command size */ 58/* Command size */
45#define HAPTIC_CMDSZ_SINGLE_EFFECT 2 59#define HAPTIC_CMDSZ_SINGLE_EFFECT 2
@@ -48,8 +62,15 @@ enum Haptic_Target{
48#define HAPTIC_CMDSZ_STOP 1 62#define HAPTIC_CMDSZ_STOP 1
49 63
50#define MAX_TIMEOUT 10000 /* 10s */ 64#define MAX_TIMEOUT 10000 /* 10s */
51#define REGS_TOTAL 0x23 65#define REGS_TOTAL 0x30
66
67#define MAX_INT_STR "4294967295"
52 68
53#define RTP_DURATION_MAX 10000 //ms 69#define RTP_DURATION_MAX 10000 //ms
54 70
55#define ARRAY_LEN(x) ((int)(sizeof(x)/sizeof((x)[0]))) 71#define ARRAY_LEN(x) ((int)(sizeof(x)/sizeof((x)[0])))
72
73#define DRV2625_MAGIC_NUMBER 'T'
74
75#define DRV2625_CONFIG_WAVEFORM _IOWR(DRV2625_MAGIC_NUMBER, 1, struct drv2625_wave_setting *)
76#define DRV2625_SET_SEQUENCER _IOWR(DRV2625_MAGIC_NUMBER, 2, struct drv2625_waveform_sequencer *)
diff --git a/drv260xutil/main.c b/drv260xutil/main.c
new file mode 100755
index 0000000..4ce05e7
--- /dev/null
+++ b/drv260xutil/main.c
@@ -0,0 +1,856 @@
1/*
2 * main.c
3 *
4 * device driver test tool for Haptics devices
5 *
6 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
7 * ALL RIGHTS RESERVED
8 *
9*/
10
11#include <sys/cdefs.h>
12#include <sys/stat.h>
13#include <stdlib.h>
14#include <string.h>
15#include <ctype.h>
16#include <stdio.h>
17#include <unistd.h>
18#include <errno.h>
19#include <stdarg.h>
20#include <time.h>
21#include <math.h>
22#include <pthread.h>
23#include <fcntl.h>
24#include "haptics.h"
25
26const char *haptic_devices[] = {
27 "/dev/drvxxxx",
28 "/dev/drv2604",
29 "/dev/drv2605",
30 };
31
32const char *target_str[] = {
33 "DRVXXXX",
34 "DRV2604",
35 "DRV2605",
36 };
37
38const char *TS2200EffectNameStr[]={
39 "1 Strong Click - 100%",
40 "2 Strong Click - 60%",
41 "3 Strong Click - 30%",
42 "4 Sharp Click - 100%",
43 "5 Sharp Click - 60%",
44 "6 Sharp Click - 30%",
45 "7 Soft Bump - 100%",
46 "8 Soft Bump - 60%",
47 "9 Soft Bump - 30%",
48 "10 Double Click - 100%",
49 "11 Double Click - 60%",
50 "12 Triple Click - 100%",
51 "13 Soft Fuzz - 60%",
52 "14 Strong Buzz - 100%",
53 "15 750 ms Alert 100%",
54 "16 1000 ms Alert 100%",
55 "17 Strong Click 1 - 100%",
56 "18 Strong Click 2 - 80%",
57 "19 Strong Click 3 - 60%",
58 "20 Strong Click 4 - 30%",
59 "21 Medium Click 1 - 100%",
60 "22 Medium Click 2 - 80%",
61 "23 Medium Click 3 - 60%",
62 "24 Sharp Tick 1 - 100%",
63 "25 Sharp Tick 2 - 80%",
64 "26 Sharp Tick 3 – 60%",
65 "27 Short Double Click Strong 1 – 100%",
66 "28 Short Double Click Strong 2 – 80%",
67 "29 Short Double Click Strong 3 – 60%",
68 "30 Short Double Click Strong 4 – 30%",
69 "31 Short Double Click Medium 1 – 100%",
70 "32 Short Double Click Medium 2 – 80%",
71 "33 Short Double Click Medium 3 – 60%",
72 "34 Short Double Sharp Tick 1 – 100%",
73 "35 Short Double Sharp Tick 2 – 80%",
74 "36 Short Double Sharp Tick 3 – 60%",
75 "37 Long Double Sharp Click Strong 1 – 100%",
76 "38 Long Double Sharp Click Strong 2 – 80%",
77 "39 Long Double Sharp Click Strong 3 – 60%",
78 "40 Long Double Sharp Click Strong 4 – 30%",
79 "41 Long Double Sharp Click Medium 1 – 100%",
80 "42 Long Double Sharp Click Medium 2 – 80%",
81 "43 Long Double Sharp Click Medium 3 – 60%",
82 "44 Long Double Sharp Tick 1 – 100%",
83 "45 Long Double Sharp Tick 2 – 80%",
84 "46 Long Double Sharp Tick 3 – 60%",
85 "47 Buzz 1 – 100%",
86 "48 Buzz 2 – 80%",
87 "49 Buzz 3 – 60%",
88 "50 Buzz 4 – 40%",
89 "51 Buzz 5 – 20%",
90 "52 Pulsing Strong 1 – 100%",
91 "53 Pulsing Strong 2 – 60%",
92 "54 Pulsing Medium 1 – 100%",
93 "55 Pulsing Medium 2 – 60%",
94 "56 Pulsing Sharp 1 – 100%",
95 "57 Pulsing Sharp 2 – 60%",
96 "58 Transition Click 1 – 100%",
97 "59 Transition Click 2 – 80%",
98 "60 Transition Click 3 – 60%",
99 "61 Transition Click 4 – 40%",
100 "62 Transition Click 5 – 20%",
101 "63 Transition Click 6 – 10%",
102 "64 Transition Hum 1 – 100%",
103 "65 Transition Hum 2 – 80%",
104 "66 Transition Hum 3 – 60%",
105 "67 Transition Hum 4 – 40%",
106 "68 Transition Hum 5 – 20%",
107 "69 Transition Hum 6 – 10%",
108 "70 Transition Ramp Down Long Smooth 1 – 100 to 0%",
109 "71 Transition Ramp Down Long Smooth 2 – 100 to 0%",
110 "72 Transition Ramp Down Medium Smooth 1 – 100 to 0%",
111 "73 Transition Ramp Down Medium Smooth 2 – 100 to 0%",
112 "74 Transition Ramp Down Short Smooth 1 – 100 to 0%",
113 "75 Transition Ramp Down Short Smooth 2 – 100 to 0%",
114 "76 Transition Ramp Down Long Sharp 1 – 100 to 0%",
115 "77 Transition Ramp Down Long Sharp 2 – 100 to 0%",
116 "78 Transition Ramp Down Medium Sharp 1 – 100 to 0%",
117 "79 Transition Ramp Down Medium Sharp 2 – 100 to 0%",
118 "80 Transition Ramp Down Short Sharp 1 – 100 to 0%",
119 "81 Transition Ramp Down Short Sharp 2 – 100 to 0%",
120 "82 Transition Ramp Up Long Smooth 1 – 0 to 100%",
121 "83 Transition Ramp Up Long Smooth 2 – 0 to 100%",
122 "84 Transition Ramp Up Medium Smooth 1 – 0 to 100%",
123 "85 Transition Ramp Up Medium Smooth 2 – 0 to 100%",
124 "86 Transition Ramp Up Short Smooth 1 – 0 to 100%",
125 "87 Transition Ramp Up Short Smooth 2 – 0 to 100%",
126 "88 Transition Ramp Up Long Sharp 1 – 0 to 100%",
127 "89 Transition Ramp Up Long Sharp 2 – 0 to 100%",
128 "90 Transition Ramp Up Medium Sharp 1 – 0 to 100%",
129 "91 Transition Ramp Up Medium Sharp 2 – 0 to 100%",
130 "92 Transition Ramp Up Short Sharp 1 – 0 to 100%",
131 "93 Transition Ramp Up Short Sharp 2 – 0 to 100%",
132 "94 Transition Ramp Down Long Smooth 1 – 50 to 0%",
133 "95 Transition Ramp Down Long Smooth 2 – 50 to 0%",
134 "96 Transition Ramp Down Medium Smooth 1 – 50 to 0%",
135 "97 Transition Ramp Down Medium Smooth 2 – 50 to 0%",
136 "98 Transition Ramp Down Short Smooth 1 – 50 to 0%",
137 "99 Transition Ramp Down Short Smooth 2 – 50 to 0%",
138 "100 Transition Ramp Down Long Sharp 1 – 50 to 0%",
139 "101 Transition Ramp Down Long Sharp 2 – 50 to 0%",
140 "102 Transition Ramp Down Medium Sharp 1 – 50 to 0%",
141 "103 Transition Ramp Down Medium Sharp 2 – 50 to 0%",
142 "104 Transition Ramp Down Short Sharp 1 – 50 to 0%",
143 "105 Transition Ramp Down Short Sharp 2 – 50 to 0%",
144 "106 Transition Ramp Up Long Smooth 1 – 0 to 50%",
145 "107 Transition Ramp Up Long Smooth 2 – 0 to 50%",
146 "108 Transition Ramp Up Medium Smooth 1 – 0 to 50%",
147 "109 Transition Ramp Up Medium Smooth 2 – 0 to 50%",
148 "110 Transition Ramp Up Short Smooth 1 – 0 to 50%",
149 "111 Transition Ramp Up Short Smooth 2 – 0 to 50%",
150 "112 Transition Ramp Up Long Sharp 1 – 0 to 50%",
151 "113 Transition Ramp Up Long Sharp 2 – 0 to 50%",
152 "114 Transition Ramp Up Medium Sharp 1 – 0 to 50%",
153 "115 Transition Ramp Up Medium Sharp 2 – 0 to 50%",
154 "116 Transition Ramp Up Short Sharp 1 – 0 to 50%",
155 "117 Transition Ramp Up Short Sharp 2 – 0 to 50%",
156 "118 Long buzz for programmatic stopping – 100%",
157 "119 Smooth Hum 1 (No kick or brake pulse) – 50%",
158 "120 Smooth Hum 2 (No kick or brake pulse) – 40%",
159 "121 Smooth Hum 3 (No kick or brake pulse) – 30%",
160 "122 Smooth Hum 4 (No kick or brake pulse) – 20%",
161 "123 Smooth Hum 5 (No kick or brake pulse) – 10%"
162};
163
164static void usage(enum Haptic_Target target)
165{
166 if (target == HAPTIC_DRV2605) {
167 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
168 "usage: haptics -r Reg_Addr1 [count] (read, hexidecimal, U8)",
169 " haptics -w Reg_Addr Value1 Value2 ... (write, hexidecimal, U8)",
170 " haptics -s Reg_Addr Mask Value (set bit, hexidecimal, U8)",
171 " haptics -g (do diagnostics)",
172 " haptics -c (do calibration)",
173 " haptics -n [sequencer1 ...] (get/set sequencer, decimal)",
174 " haptics -p (play waveform sequencer)",
175 " haptics -i [enable] (enable more log)",
176 " haptics -x (stop playback)",
177 HAPTICS_VERSION);
178 } else if(target == HAPTIC_DRV2604) {
179 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\%s\n%s\n%s\n",
180 "usage: haptics -r Reg_Addr1 [count] (read, hexidecimal, U8)",
181 " haptics -w Reg_Addr Value1 Value2 ... (write, hexidecimal, U8)",
182 " haptics -s Reg_Addr Mask Value (set bit, hexidecimal, U8)",
183 " haptics -g (do diagnostics)",
184 " haptics -c (do calibration)",
185 " haptics -m [loop interval scale] (get/set main loop, decimal)",
186 " haptics -n [sequencer1 loop1 ...] (get/set sequencer, decimal)",
187 " haptics -p (play waveform sequencer)",
188 " haptics -f (firmware reload)",
189 " haptics -i [enable] (enable more log)",
190 " haptics -x (stop playback)",
191 HAPTICS_VERSION);
192 }
193}
194
195static int str2char(char *argv, unsigned char *pUInt8_Val){
196 int str_len = strlen(argv), i, result = -1, j;
197 unsigned char val[2] = {0};
198
199 if(str_len > 2){
200 fprintf(stderr, "invalid parameters\n");
201 goto err;
202 }
203
204 for(i = (str_len-1), j=0; i >= 0; i--, j++){
205 if((argv[i] <= '9')&&(argv[i] >= '0')){
206 val[j] = argv[i] - 0x30;
207 }else if((argv[i] <='f')&&(argv[i]>= 'a')){
208 val[j] = argv[i] - 0x57;
209 }else if((argv[i] <='F')&&(argv[i]>= 'A')){
210 val[j] = argv[i] - 0x37;
211 }else{
212 fprintf(stderr, "reg/data out of range\n");
213 goto err;
214 }
215 }
216
217 *pUInt8_Val = (unsigned char)(val[0]|(val[1]<<4));
218 result = 0;
219
220err:
221 return result;
222}
223
224static int str2decimal(char *argv, unsigned int *pUInt32_Val){
225 int max_len = strlen(MAX_INT_STR), i, result = -1, j;
226 int str_len = strlen(argv);
227 unsigned int nValue = 0;
228 unsigned char temp;
229
230 if(str_len > max_len){
231 fprintf(stderr, "invalid parameters\n");
232 goto err;
233 }
234
235 for(i = (str_len-1), j=0; i >= 0; i--, j++){
236 if((argv[i] <= '9')&&(argv[i] >= '0')){
237 temp = argv[i] - 0x30;
238 nValue += (temp * pow(10, j));
239 }else{
240 fprintf(stderr, "reg/data out of range\n");
241 goto err;
242 }
243 }
244
245 *pUInt32_Val = nValue;
246 result = 0;
247
248err:
249 return result;
250}
251#if 0
252static int str2short(char *argv, unsigned short *pUInt16_Val){
253 int str_len = strlen(argv), i, j, result = -1;
254 unsigned char val[4] = {0};
255
256 if(str_len > 4){
257 fprintf(stderr, "invalid parameters\n");
258 goto err;
259 }
260
261 for(i = (str_len-1), j=0; i >= 0; i--, j++){
262 if((argv[i] <= '9')&&(argv[i] >= '0')){
263 val[j] = argv[i] - 0x30;
264 }else if((argv[i] <='f')&&(argv[i]>= 'a')){
265 val[j] = argv[i] - 0x57;
266 }else if((argv[i] <='F')&&(argv[i]>= 'A')){
267 val[j] = argv[i] - 0x37;
268 }else{
269 fprintf(stderr, "reg/data out of range\n");
270 goto err;
271 }
272 }
273
274 *pUInt16_Val = (unsigned short)(val[0]|(val[1]<<4)|(val[2]<<8)|(val[3]<<12));
275 result = 0;
276
277err:
278 return result;
279}
280#endif
281
282static int DRV260x_Reg_Write(int fileHandle, int argc, char **argv){
283 int err = -1;
284 unsigned char *pBuff = NULL, regaddr_UInt8, regval_UInt8;
285 int i=0, reg_count = 0;
286
287 if(argc < 4){
288 fprintf(stderr, "invalid para numbers\n");
289 goto err;
290 }
291
292 reg_count = argc - 3;
293
294 pBuff = (unsigned char *)malloc(reg_count + 2);
295 if (pBuff == NULL) {
296 fprintf(stderr, "not enough mem\n");
297 goto err;
298 }
299
300 pBuff[0] = HAPTIC_CMDID_REG_WRITE;
301
302 err = str2char(argv[2], &regaddr_UInt8);
303 if (err < 0) {
304 goto err;
305 }
306 pBuff[1] = regaddr_UInt8;
307
308 for (i = 0; i < reg_count; i++) {
309 err = str2char(argv[i+3], &regval_UInt8);
310 if (err < 0) {
311 goto err;
312 }
313 pBuff[i + 2] = regval_UInt8;
314 }
315
316 err = write(fileHandle, pBuff, reg_count + 2);
317 if (err != (reg_count + 2)) {
318 fprintf(stderr, "write err=%d\n", err);
319 } else {
320 for (i = 0; i < reg_count; i++) {
321 fprintf(stderr, "W Reg(0x%x)=0x%x\n", regaddr_UInt8+i, pBuff[2+i]);
322 }
323 }
324
325err:
326 if(pBuff != NULL)
327 free(pBuff);
328
329 return err;
330}
331
332static int DRV260x_Reg_Read(int fileHandle, int argc, char **argv) {
333 int err = 0;
334 unsigned char pBuff[2], RegAddr_UInt8 = 0, RegCount_UInt8 = 1;
335 int i = 0;
336 unsigned char *pRead_Buff = NULL;
337
338 if (argc < 3) {
339 fprintf(stderr, "invalid para numbers\n");
340 goto err;
341 }
342
343 pBuff[0] = HAPTIC_CMDID_REG_READ;
344
345 err = str2char(argv[2], &RegAddr_UInt8);
346 if (err < 0) {
347 goto err;
348 }
349 pBuff[1] = RegAddr_UInt8;
350
351 err = write(fileHandle, pBuff, 2);
352 if (err != 2) {
353 fprintf(stderr, "send read err=%d\n", err);
354 goto err;
355 }
356
357 if (argc > 3) {
358 err = str2char(argv[3], &RegCount_UInt8);
359 if (err < 0) {
360 goto err;
361 }
362 }
363
364 pRead_Buff = (unsigned char *)malloc(RegCount_UInt8);
365 if (pRead_Buff == NULL) {
366 fprintf(stderr, "not enough mem\n");
367 goto err;
368 }
369
370 err = read(fileHandle, pRead_Buff, RegCount_UInt8);
371 if (err != RegCount_UInt8) {
372 fprintf(stderr, "read back err=%d\n", err);
373 } else {
374 for (i = 0; i< RegCount_UInt8; i++) {
375 fprintf(stderr, "R Reg[0x%x] = 0x%x\n", RegAddr_UInt8 + i, pRead_Buff[i]);
376 }
377 }
378
379err:
380 if(pRead_Buff != NULL)
381 free(pRead_Buff);
382
383 return err;
384}
385
386static int DRV260x_Reg_SetBit(int fileHandle, int argc, char **argv) {
387 int err = 0;
388 unsigned char pBuff[4], regAddr_UInt8, regMask_UInt8, regVal_UInt8;
389
390 if (argc != 5) {
391 fprintf(stderr, "invalid para numbers\n");
392 goto err;
393 }
394
395 pBuff[0] = HAPTIC_CMDID_REG_SETBIT;
396
397 err = str2char(argv[2], &regAddr_UInt8);
398 if (err < 0) {
399 goto err;
400 }
401 pBuff[1] = regAddr_UInt8;
402
403 err = str2char(argv[3], &regMask_UInt8);
404 if (err < 0) {
405 goto err;
406 }
407 pBuff[2] = regMask_UInt8;
408
409 err = str2char(argv[4], &regVal_UInt8);
410 if (err < 0) {
411 goto err;
412 }
413 pBuff[3] = regVal_UInt8;
414
415 err = write(fileHandle, pBuff, 4);
416 if (err != 4) {
417 fprintf(stderr, "setbit err=%d\n", err);
418 } else {
419 fprintf(stderr, "S Reg(0x%x) Msk(0x%x) Val=0x%x\n", pBuff[1], pBuff[2], pBuff[3]);
420 }
421
422err:
423 return err;
424}
425
426static int DRV260x_doCalibration(int fileHandle) {
427 int err = 0;
428 unsigned char pBuff[4];
429 int i = 0;
430 struct timeval t_start,t_end;
431 long cost_time = 0, start, end;
432
433 pBuff[0] = HAPTIC_CMDID_RUN_CALIBRATION;
434
435 gettimeofday(&t_start, NULL);
436 start = ((long)t_start.tv_sec) * 1000 + (long)t_start.tv_usec / 1000;
437
438 err = write(fileHandle, pBuff, 1);
439 if (err != 1) {
440 fprintf(stderr, "doCalibration err=%d\n", err);
441 goto err;
442 }
443
444 while (1) {
445 usleep(100*1000);
446 fprintf(stderr, "%d ms\n", (i+1)*100);
447 err = read(fileHandle, pBuff, 4);
448 if(err == 4){
449 gettimeofday(&t_end, NULL);
450 end = ((long)t_end.tv_sec) * 1000 + (long)t_end.tv_usec / 1000;
451 cost_time = end - start;
452 fprintf(stderr, "calibration finish after %ld ms\n", cost_time);
453
454 if ((pBuff[0] & 0x08) == 0x00) {
455 fprintf(stderr, "calibration pass\n");
456 fprintf(stderr, "Status = 0x%x,\n\tA_CAL_COMP=0x%x, A_CAL_BEMF=0x%x, BEMF_GAIN=%d\n",
457 pBuff[0], pBuff[1], pBuff[2], pBuff[3] & 0x03);
458 } else {
459 fprintf(stderr, "calibration fail, status=0x%x\n", pBuff[0]);
460 }
461 break;
462 } else {
463 i++;
464 }
465 }
466
467err:
468 return err;
469}
470
471static int DRV260x_doDiagnostics(int fileHandle) {
472 int err = 0;
473 unsigned char pBuff[3];
474 int i=0;
475 struct timeval t_start,t_end;
476 long cost_time = 0, start, end;
477
478 pBuff[0] = HAPTIC_CMDID_RUN_DIAG;
479
480 gettimeofday(&t_start, NULL);
481 start = ((long)t_start.tv_sec) * 1000 + (long)t_start.tv_usec / 1000;
482
483 err = write(fileHandle, pBuff, 1);
484 if (err != 1) {
485 fprintf(stderr, "doDiagnostic err=%d\n", err);
486 goto err;
487 }
488
489 while (1) {
490 fprintf(stderr, "%d ms\n", (i+1)*100);
491 usleep(100*1000);
492
493 err = read(fileHandle, pBuff, 1);
494 if (err == 1) {
495 gettimeofday(&t_end, NULL);
496 end = ((long)t_end.tv_sec) * 1000 + (long)t_end.tv_usec / 1000;
497 cost_time = end - start;
498 fprintf(stderr, "Diagnostics finish after %ld ms\n", cost_time);
499
500 if ((pBuff[0] & 0x08) == 0x00) {
501 fprintf(stderr, "Diagnostics pass, status=0x%x\n", pBuff[0]);
502 } else
503 fprintf(stderr, "Diagnostics fail, status=0x%x\n", pBuff[0]);
504
505 break;
506 } else
507 i++;
508 }
509
510err:
511 return err;
512}
513
514static int DRV260x_set_sequencer(int fileHandle, enum Haptic_Target target, int argc, char **argv)
515{
516 int ret = 0, i;
517 unsigned int value = 0;
518 int count = 0;
519 struct drv260x_waveform_sequencer sequencer;
520 int add_tail = 0;
521 int len = 0;
522 int seq_size = sizeof(struct drv260x_waveform_sequencer);
523 unsigned char *pBuff = NULL;
524
525 if (argc < 2) {
526 fprintf(stderr, "invalid para numbers\n");
527 goto err;
528 }
529
530 memset(&sequencer, 0, seq_size);
531
532 count = (argc - 2);
533 if(count > DRV26xx_SEQUENCER_SIZE){
534 fprintf(stderr, "invalid para numbers\n");
535 goto err;
536 }
537
538 for (i = 0; i < count; i++) {
539 ret = str2decimal(argv[2 + i], &value);
540 if (ret < 0) {
541 fprintf(stderr, "invalid para\n");
542 goto err;
543 }
544 if (((value & 0x80) == 0x00)
545 && (value > (ARRAY_LEN(TS2200EffectNameStr) + 1))) {
546 fprintf(stderr, "invalid para\n");
547 goto err;
548 }
549 sequencer.msWaveform[i].mnEffect = (unsigned char)value;
550 if(sequencer.msWaveform[i].mnEffect == 0) {
551 add_tail = 1;
552 break;
553 }
554 }
555
556 if((add_tail == 0)
557 && (count < DRV26xx_SEQUENCER_SIZE)
558 && (count > 0)) {
559 sequencer.msWaveform[count].mnEffect = 0;
560 }
561
562 if (count > 0)
563 len = 1 + seq_size;
564 else
565 len = 1;
566 pBuff = (unsigned char *)malloc(1 + seq_size);
567 if (pBuff == NULL) {
568 fprintf(stderr, "not enough mem\n");
569 goto err;
570 }
571
572 pBuff[0] = HAPTIC_CMDID_SET_SEQUENCER;
573 if (len > 1) {
574 memcpy(&pBuff[1], &sequencer, seq_size);
575 }
576
577 ret = write(fileHandle, pBuff, len);
578 if(ret != len){
579 fprintf(stderr, "write error %d\n", ret);
580 goto err;
581 }
582
583 if (len > 1) {
584 fprintf(stderr, "Set Sequencer :\n");
585 for (i = 0; i < count; i++) {
586 if (sequencer.msWaveform[i].mnEffect == 0) {
587 fprintf(stderr, "\tSequencer[%d]: end\n", i);
588 break;
589 } else if (sequencer.msWaveform[i].mnEffect < (ARRAY_LEN(TS2200EffectNameStr) + 1)) {
590 if (target == HAPTIC_DRV2605) {
591 fprintf(stderr, "\tSequencer[%d]:Effect(%s)\n",
592 i,
593 TS2200EffectNameStr[sequencer.msWaveform[i].mnEffect -1]);
594 } else if (target == HAPTIC_DRV2604) {
595 fprintf(stderr, "\tSequencer[%d]:Effect(%d)\n",
596 i,
597 i+1);
598 }
599 } else if (sequencer.msWaveform[i].mnEffect & 0x80) {
600 fprintf(stderr, "\tSequencer[%d]:Delay(%d ms)\n",
601 i,
602 (sequencer.msWaveform[i].mnEffect&0x7f)*10);
603 }else{
604 fprintf(stderr, "\tSequencer[%d]: error, effect id=%d\n",
605 i,
606 sequencer.msWaveform[i].mnEffect);
607 }
608 }
609 } else {
610 ret = read(fileHandle, pBuff, seq_size);
611 if (ret != seq_size) {
612 fprintf(stderr, "read sequence err=%d\n", ret);
613 goto err;
614 } else {
615 memcpy(&sequencer, pBuff, seq_size);
616 fprintf(stderr, "Get Sequencer :\n");
617
618 for(i = 0; i < DRV26xx_SEQUENCER_SIZE; i++) {
619 if (sequencer.msWaveform[i].mnEffect == 0) {
620 fprintf(stderr, "\tSequencer[%d]: end\n", i);
621 break;
622 } else if (sequencer.msWaveform[i].mnEffect < (ARRAY_LEN(TS2200EffectNameStr) + 1)) {
623 if (target == HAPTIC_DRV2605) {
624 fprintf(stderr, "\tSequencer[%d]:Effect(%s)\n",
625 i,
626 TS2200EffectNameStr[sequencer.msWaveform[i].mnEffect -1]);
627 } else if (target == HAPTIC_DRV2604) {
628 fprintf(stderr, "\tSequencer[%d]:Effect(%d)\n",
629 i,
630 i+1);
631 }
632 } else if (sequencer.msWaveform[i].mnEffect & 0x80) {
633 fprintf(stderr, "\tSequencer[%d]:Delay(%d ms)\n",
634 i,
635 (sequencer.msWaveform[i].mnEffect&0x7f)*10);
636 } else {
637 fprintf(stderr, "\tSequencer[%d]: error, effect id=%d\n",
638 i,
639 sequencer.msWaveform[i].mnEffect);
640 }
641 }
642 }
643 }
644
645err:
646 if(pBuff != NULL)
647 free(pBuff);
648
649 return ret;
650}
651
652static int DRV260x_play_sequencer(int fileHandle){
653 int err = 0;
654 unsigned char pBuff[3];
655
656 pBuff[0] = HAPTIC_CMDID_PLAY_EFFECT_SEQUENCE;
657
658 err = write(fileHandle, pBuff, 1);
659 if(err != 1){
660 fprintf(stderr, "Play Sequence err %d\n", err);
661 goto err;
662 }
663
664 fprintf(stderr, "Play Sequence Start\n");
665err:
666 return err;
667}
668
669static int DRV260x_enable_log(int fileHandle, int argc, char **argv)
670{
671 int err = 0, len;
672 unsigned char pBuff[4], nValue;
673
674 pBuff[0] = HAPTIC_CMDID_REGLOG_ENABLE;
675 len = 1;
676
677 if(argc > 2) {
678 err = str2char(argv[2], &nValue);
679 if(err < 0){
680 goto err;
681 }
682 pBuff[1] = nValue;
683 len++;
684 }
685
686 err = write(fileHandle, pBuff, len);
687 if(err != len){
688 fprintf(stderr, "enable log error=%d\n", err);
689 goto err;
690 }
691
692 if (len == 2) {
693 if(pBuff[1])
694 fprintf(stderr, "Enable Log\n");
695 else
696 fprintf(stderr, "Disable Log\n");
697 goto err;
698 }
699
700 err = read(fileHandle, pBuff, 1);
701 if (err != 1) {
702 fprintf(stderr, "enable log read error=%d\n", err);
703 goto err;
704 }
705
706 if(pBuff[0])
707 fprintf(stderr, "Log Enabled\n");
708 else
709 fprintf(stderr, "Log Disabled\n");
710
711err:
712 return err;
713}
714
715static int DRV260x_stop(int fileHandle)
716{
717 int err = 0;
718 unsigned char pBuff[3];
719
720 pBuff[0] = HAPTIC_CMDID_STOP;
721
722 err = write(fileHandle, pBuff, 1);
723 if(err != 1){
724 fprintf(stderr, "stop err %d\n", err);
725 goto err;
726 }
727
728 fprintf(stderr, "Stop playback\n");
729
730err:
731 return err;
732}
733
734static enum Haptic_Target getDevTarget(int index){
735 enum Haptic_Target target;
736 switch(index){
737 case 1:
738 target = HAPTIC_DRV2604;
739 break;
740 case 2:
741 target = HAPTIC_DRV2605;
742 break;
743 default:
744 target = HAPTIC_DRVXXXX;
745 break;
746 }
747 return target;
748}
749
750static int getDevHandle(enum Haptic_Target *pTarget){
751 int fileHandle = -1, i;
752 struct stat sbuf;
753 int dev_count = ARRAY_LEN(haptic_devices);
754
755 for (i = 0; i < dev_count; i++) {
756 if (stat(haptic_devices[i], &sbuf) == 0) {
757 *pTarget = getDevTarget(i);
758 break;
759 }
760 }
761
762 if (i == dev_count) {
763 fprintf(stderr, "[ERROR]dev nodes not found\n");
764 } else {
765 fileHandle = open(haptic_devices[i], O_RDWR);
766 if (fileHandle < 0 ) {
767 fprintf(stderr, "[ERROR]file(%s) open_RDWR error\n", haptic_devices[i]);
768 }
769 }
770
771 return fileHandle;
772}
773
774static int DRV260x_fw_reload(int fileHandle)
775{
776 int err = 0;
777 unsigned char pBuff[3];
778
779 pBuff[0] = HAPTIC_CMDID_UPDATE_FIRMWARE;
780
781 err = write(fileHandle, pBuff, 1);
782 if(err != 1){
783 fprintf(stderr, "fw reload err %d\n", err);
784 goto err;
785 }
786
787 fprintf(stderr, "fw reload triggered\n");
788
789err:
790 return err;
791}
792
793int main(int argc, char **argv)
794{
795 int ret = 0;
796 int ch;
797 int fileHandle = -1;
798 enum Haptic_Target target;
799
800 fileHandle = getDevHandle(&target);
801 if (fileHandle < 0) {
802 fprintf(stderr, " file handle err=%d\n", fileHandle);
803 return ret;
804 }
805
806 if (argc == 1) {
807 usage(target);
808 return 0;
809 }
810
811 while ((ch = getopt(argc, argv, "wrsgcnpfix")) != -1) {
812 switch (ch) {
813 case 'w':
814 ret = DRV260x_Reg_Write(fileHandle, argc, argv);
815 break;
816 case 'r':
817 ret = DRV260x_Reg_Read(fileHandle, argc, argv);
818 break;
819 case 's':
820 ret = DRV260x_Reg_SetBit(fileHandle, argc, argv);
821 break;
822 case 'g':
823 ret = DRV260x_doDiagnostics(fileHandle);
824 break;
825 case 'c':
826 ret = DRV260x_doCalibration(fileHandle);
827 break;
828 case 'n':
829 ret = DRV260x_set_sequencer(fileHandle, target, argc, argv);
830 break;
831 case 'p':
832 ret = DRV260x_play_sequencer(fileHandle);
833 break;
834 case 'f':
835 if (target != HAPTIC_DRV2604)
836 usage(target);
837 else
838 ret = DRV260x_fw_reload(fileHandle);
839 break;
840 case 'i':
841 ret = DRV260x_enable_log(fileHandle, argc, argv);
842 break;
843 case 'x':
844 ret = DRV260x_stop(fileHandle);
845 break;
846 default:
847 usage(target);
848 break;
849 }
850 }
851
852 if(fileHandle > 0 )
853 close(fileHandle);
854
855 return ret;
856}
diff --git a/haptics/main.c b/haptics/main.c
deleted file mode 100755
index 40c3765..0000000
--- a/haptics/main.c
+++ /dev/null
@@ -1,1119 +0,0 @@
1/*
2 * main.c
3 *
4 * device driver test tool for Haptics devices
5 *
6 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
7 * ALL RIGHTS RESERVED
8 *
9*/
10
11#include <sys/cdefs.h>
12#include <sys/stat.h>
13#include <stdlib.h>
14#include <string.h>
15#include <ctype.h>
16#include <stdio.h>
17#include <unistd.h>
18#include <errno.h>
19#include <stdarg.h>
20#include <fcntl.h>
21#include "haptics.h"
22
23const char *haptic_devices[] = {
24 "/dev/drvxxxx",
25 "/dev/drv2604",
26 "/dev/drv2604L",
27 "/dev/drv2605",
28 "/dev/drv2605L",
29 "/dev/drv2667",
30 "/dev/drv2669"
31 };
32
33const char *target_str[] = {
34 "DRVXXXX",
35 "DRV2604",
36 "DRV2604L",
37 "DRV2605",
38 "DRV2605L",
39 "DRV2667",
40 "DRV2669"
41 };
42
43static void usage(enum Haptic_Target target){
44 if(target == HAPTIC_DRV2667){
45 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
46 "usage: haptics -r Reg_Addr1 [count] (read)",
47 " haptics -w Reg_Addr Value1 Value2 ... (write)",
48 " haptics -s Reg_Addr1 Mask1 Value1 Reg_Addr2 Mask2 Value2 ... (set bit)",
49 " haptics -e effect1 effect2... (play effect sequence)",
50 " haptics -v OnTime (vibrate for OnTime ms, maximum 0x2710(10000ms))",
51 " haptics -f fifo.bin (play binary from fifo.bin)",
52 " haptics -a (analog input mode enable)",
53 " haptics -p (stop any vibration)",
54 " haptics -d (dump all the registers)",
55 " haptics -t (get target, DRVXXXX/DRV2604/DRV2605/DRV2667/DRV2669)",
56 "NOTE: 1. all numbers are Hexadecimal numbers without prefix 0x .",
57 "NOTE: 2. Reg_Addr/OnTime is UInt16, others are all UInt8 .",
58 HAPTICS_VERSION);
59 }else if(target == HAPTIC_DRV2669){
60 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\t%s\n",
61 "usage: haptics -r Reg_Addr1 [count] (read)",
62 " haptics -w Reg_Addr Value1 Value2 ... (write)",
63 " haptics -s Reg_Addr1 Mask1 Value1 Reg_Addr2 Mask2 Value2 ... (set bit)",
64 " haptics -e effect1 effect2... (play effect sequence)",
65 " haptics -v OnTime (vibrate for OnTime ms, maximum 0x2710(10000ms))",
66 " haptics -f fifo.bin (play binary from fifo.bin)",
67 " haptics -p (stop any vibration)",
68 " haptics -d (dump all the registers)",
69 " haptics -t (get target, DRVXXXX/DRV2604/DRV2605/DRV2667/DRV2669)",
70 "NOTE: 1. all numbers are Hexadecimal numbers without prefix 0x .",
71 "NOTE: 2. Reg_Addr/OnTime is UInt16, others are all UInt8 .",
72 HAPTICS_VERSION);
73 }else if((target == HAPTIC_DRV2605)||(target == HAPTIC_DRV2605L)){
74 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\t%s\n\t%s\n",
75 "usage: haptics -r Reg_Addr [count] (read)",
76 " haptics -w Reg_Addr Value1 [Value2 ...] (write)",
77 " haptics -s Reg_Addr1 Mask1 Value1 [Reg_Addr2 Mask2 Value2 ...](set bit)",
78 " haptics -e effect1 [effect2...] (play effect sequence)",
79 " haptics -v OnTime (vibrate for OnTime ms, maximum 0x2710(10000ms))",
80 " haptics -p (stop any vibration)",
81 " haptics -q Amp1 Time1 [Amp2 Time2 ...] (RTP seq playback)",
82 " haptics -n OnTime OffTime Strength Repeat (Pattern RTP playback)",
83 " haptics -a enable (enable/disable audio2haptics)",
84 " haptics -d (dump all the registers)",
85 " haptics -t (target, DRVXXXX/DRV2604(L)/DRV2605(L)/DRV2667/DRV2669)",
86 "NOTE: 1. all numbers are Hex(UInt8) without prefix 0x(except OnTime) .",
87 HAPTICS_VERSION);
88 }else if((target == HAPTIC_DRV2604)||(target == HAPTIC_DRV2604L)){
89 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\t%s\n\t%s\n",
90 "usage: haptics -r Reg_Addr [count] (read)",
91 " haptics -w Reg_Addr Value1 [Value2 ...] (write)",
92 " haptics -s Reg_Addr1 Mask1 Value1 [Reg_Addr2 Mask2 Value2 ...](set bit)",
93 " haptics -e effect1 [effect2...] (play effect sequence)",
94 " haptics -v OnTime (vibrate for OnTime ms, maximum 0x2710(10000ms))",
95 " haptics -p (stop any vibration)",
96 " haptics -q Amp1 Time1 [Amp2 Time2 ...] (RTP seq playback)",
97 " haptics -n OnTime OffTime Strength Repeat (Pattern RTP playback)",
98 " haptics -f fw.bin (update firmware)",
99 " haptics -b addr_uint16 [count] (read back firmware)",
100 " haptics -d (dump all the registers)",
101 " haptics -t (get target, DRVXXXX/DRV2604/DRV2605/DRV2667/DRV2669)",
102 "NOTE: 1. all numbers are Hex(UInt8) without prefix 0x(except OnTime) .",
103 HAPTICS_VERSION);
104 }else{
105 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\t%s\n",
106 "usage: haptics -r Reg_Addr [count] (read)",
107 " haptics -w Reg_Addr Value1 [Value2 ...] (write)",
108 " haptics -s Reg_Addr1 Mask1 Value1 [Reg_Addr2 Mask2 Value2 ...](set bit)",
109 " haptics -e effect1 [effect2...] (play effect sequence)",
110 " haptics -v OnTime (vibrate for OnTime ms, maximum 0x2710(10000ms))",
111 " haptics -p (stop any vibration)",
112 " haptics -q Amp1 Time1 [Amp2 Time2 ...] (RTP seq playback)",
113 " haptics -n OnTime OffTime Strength Repeat (Pattern RTP playback)",
114 " haptics -t (get target, DRVXXXX/DRV2604/DRV2605/DRV2667/DRV2669)",
115 "NOTE: 1. all numbers are Hex(UInt8) without prefix 0x(except OnTime) .",
116 HAPTICS_VERSION);
117 }
118}
119
120static int str2char(char *argv, unsigned char *pUInt8_Val){
121 int str_len = strlen(argv), i, result = -1, j;
122 unsigned char val[2] = {0};
123
124 if(str_len > 2){
125 fprintf(stderr, "invalid parameters\n");
126 goto err;
127 }
128
129 for(i = (str_len-1), j=0; i >= 0; i--, j++){
130 if((argv[i] <= '9')&&(argv[i] >= '0')){
131 val[j] = argv[i] - 0x30;
132 }else if((argv[i] <='f')&&(argv[i]>= 'a')){
133 val[j] = argv[i] - 0x57;
134 }else if((argv[i] <='F')&&(argv[i]>= 'A')){
135 val[j] = argv[i] - 0x37;
136 }else{
137 fprintf(stderr, "reg/data out of range\n");
138 goto err;
139 }
140 }
141
142 *pUInt8_Val = (unsigned char)(val[0]|(val[1]<<4));
143 result = 0;
144
145err:
146 return result;
147}
148
149static int str2short(char *argv, unsigned short *pUInt16_Val){
150 int str_len = strlen(argv), i, j, result = -1;
151 unsigned char val[4] = {0};
152
153 if(str_len > 4){
154 fprintf(stderr, "invalid parameters\n");
155 goto err;
156 }
157
158 for(i = (str_len-1), j=0; i >= 0; i--, j++){
159 if((argv[i] <= '9')&&(argv[i] >= '0')){
160 val[j] = argv[i] - 0x30;
161 }else if((argv[i] <='f')&&(argv[i]>= 'a')){
162 val[j] = argv[i] - 0x57;
163 }else if((argv[i] <='F')&&(argv[i]>= 'A')){
164 val[j] = argv[i] - 0x37;
165 }else{
166 fprintf(stderr, "reg/data out of range\n");
167 goto err;
168 }
169 }
170
171 *pUInt16_Val = (unsigned short)(val[0]|(val[1]<<4)|(val[2]<<8)|(val[3]<<12));
172 result = 0;
173
174err:
175 return result;
176}
177
178static int DRV266x_Reg_Write(int fileHandle, int argc, char **argv){
179 int err = -1;
180 unsigned short regaddr_UInt16;
181 unsigned char *pBuff = NULL, regval_UInt8;
182 int i=0, reg_count = 0;
183
184 if(argc < 4){
185 fprintf(stderr, "invalid para numbers\n");
186 goto err;
187 }
188
189 reg_count = (argc - 3);
190
191 pBuff = (unsigned char *)malloc(sizeof(unsigned char)*reg_count+3);
192 if(pBuff == NULL){
193 fprintf(stderr, "not enough mem\n");
194 goto err;
195 }
196
197 pBuff[0] = HAPTIC_CMDID_REG_WRITE;
198 err = str2short(argv[2], &regaddr_UInt16);
199 if(err < 0){
200 goto err;
201 }
202
203 pBuff[1] = (unsigned char)(regaddr_UInt16&0x00ff);
204 pBuff[2] = (unsigned char)((regaddr_UInt16&0xff00)>>8);
205
206 for(i=0 ; i< reg_count; i++){
207 err = str2char(argv[i+3], &regval_UInt8);
208 if(err < 0){
209 goto err;
210 }
211 pBuff[3 + i] = regval_UInt8;
212 }
213
214 err = write(fileHandle, pBuff, reg_count+3);
215 if(err != (reg_count+3)){
216 fprintf(stderr, "write err=%d\n", err);
217 }else{
218 fprintf(stderr, "WRegs(0x%x)=", regaddr_UInt16);
219 for(i=0; i< reg_count; i++){
220 fprintf(stderr, "0x%x ", pBuff[3+i]);
221 }
222 fprintf(stderr, "\n");
223 }
224
225err:
226 if(pBuff != NULL)
227 free(pBuff);
228
229 return err;
230}
231
232static int DRV260x_Reg_Write(int fileHandle, int argc, char **argv){
233 int err = -1;
234 unsigned char *pBuff = NULL, regaddr_UInt8, regval_UInt8;
235 int i=0, reg_count = 0;
236
237 if(argc < 4){
238 fprintf(stderr, "invalid para numbers\n");
239 goto err;
240 }
241
242 reg_count = argc - 3;
243
244 pBuff = (unsigned char *)malloc(reg_count+2);
245 if(pBuff == NULL){
246 fprintf(stderr, "not enough mem\n");
247 goto err;
248 }
249
250 pBuff[0] = HAPTIC_CMDID_REG_WRITE;
251
252 err = str2char(argv[2], &regaddr_UInt8);
253 if(err < 0){
254 goto err;
255 }
256 pBuff[1] = regaddr_UInt8;
257
258 for(i=0; i< reg_count; i++){
259 err = str2char(argv[i+3], &regval_UInt8);
260 if(err < 0){
261 goto err;
262 }
263 pBuff[i + 2] = regval_UInt8;
264 }
265
266 err = write(fileHandle, pBuff, reg_count+2);
267 if(err != (reg_count+2)){
268 fprintf(stderr, "write err=%d\n", err);
269 }else{
270 for(i=0; i< reg_count; i++){
271 fprintf(stderr, "WReg(0x%x)=0x%x\n", regaddr_UInt8+i, pBuff[2+i]);
272 }
273 }
274
275err:
276 if(pBuff != NULL)
277 free(pBuff);
278
279 return err;
280}
281
282static int DRV266x_Reg_Read(int fileHandle, int argc, char **argv){
283 int err = 0;
284 unsigned char Buff[4], RegCount_UInt8;
285 unsigned char *pRead_Buff = NULL;
286 unsigned short regAddr_UInt16;
287 int i=0;
288
289 if((argc < 3)||(argc > 4)){
290 fprintf(stderr, "invalid para numbers\n");
291 goto err;
292 }
293
294 Buff[0] = HAPTIC_CMDID_REG_READ;
295 err = str2short(argv[2], &regAddr_UInt16);
296 if(err < 0){
297 fprintf(stderr, "addr err=%d\n", err);
298 goto err;
299 }
300
301 Buff[1] = (unsigned char)(regAddr_UInt16&0x00ff);
302 Buff[2] = (unsigned char)((regAddr_UInt16&0xff00)>>8);
303
304 if(argc == 4){
305 err = str2char(argv[3], &RegCount_UInt8);
306 if(err < 0){
307 fprintf(stderr, "count err=%d\n", err);
308 goto err;
309 }
310 }else{
311 RegCount_UInt8 = 1;
312 }
313
314 Buff[3] = RegCount_UInt8;
315
316 err = write(fileHandle, Buff, 4);
317 if(err != 4){
318 fprintf(stderr, "send read err=%d\n", err);
319 goto err;
320 }
321
322 pRead_Buff = (unsigned char *)malloc(RegCount_UInt8);
323 if(pRead_Buff == NULL){
324 fprintf(stderr, "not enough mem\n");
325 goto err;
326 }
327
328 err = read(fileHandle, pRead_Buff, RegCount_UInt8);
329 if(err != (RegCount_UInt8)){
330 fprintf(stderr, "read back err=%d\n", err);
331 }else{
332 for(i=0; i< RegCount_UInt8; i++){
333 fprintf(stderr, "RReg[0x%x]=0x%x\n", regAddr_UInt16+i, pRead_Buff[i]);
334 }
335 }
336
337err:
338 if(pRead_Buff != NULL)
339 free(pRead_Buff);
340
341 return err;
342}
343
344static int DRV260x_Reg_Read(int fileHandle, int argc, char **argv){
345 int err = 0;
346 unsigned char pBuff[3], RegAddr_UInt8=0, RegCount_UInt8 = 1;
347 int i=0;
348 unsigned char *pRead_Buff = NULL;
349
350 if(argc < 3){
351 fprintf(stderr, "invalid para numbers\n");
352 goto err;
353 }
354
355 pBuff[0] = HAPTIC_CMDID_REG_READ;
356
357 err = str2char(argv[2], &RegAddr_UInt8);
358 if(err < 0){
359 goto err;
360 }
361 pBuff[1] = RegAddr_UInt8;
362
363 if(argc > 3){
364 err = str2char(argv[3], &RegCount_UInt8);
365 if(err < 0){
366 goto err;
367 }
368 }
369
370 pBuff[2] = RegCount_UInt8;
371
372 pRead_Buff = (unsigned char *)malloc(RegCount_UInt8);
373 if(pRead_Buff == NULL){
374 fprintf(stderr, "not enough mem\n");
375 goto err;
376 }
377
378 err = write(fileHandle, pBuff, 3);
379 if(err != 3){
380 fprintf(stderr, "send read err=%d\n", err);
381 goto err;
382 }
383
384 err = read(fileHandle, pRead_Buff, RegCount_UInt8 );
385 if(err != RegCount_UInt8){
386 fprintf(stderr, "read back err=%d\n", err);
387 }else{
388 for(i=0; i< RegCount_UInt8; i++){
389 fprintf(stderr, "RReg[0x%x] = 0x%x\n", RegAddr_UInt8+i, pRead_Buff[i]);
390 }
391 }
392
393err:
394 if(pRead_Buff != NULL)
395 free(pRead_Buff);
396
397 return err;
398}
399
400static int DRV266x_Reg_SetBit(int fileHandle, int argc, char **argv){
401 int err = 0;
402 unsigned char *pBuff = NULL, regMask_UInt8, regVal_UInt8;
403 int i=0, j, reg_count;
404 unsigned short regAddr_UInt16;
405
406 if((argc < 5)||((argc-2)%3 != 0)){
407 fprintf(stderr, "invalid para numbers\n");
408 goto err;
409 }
410
411 reg_count = (argc - 2)/3;
412
413 pBuff = (unsigned char *)malloc(reg_count*4 + 1);
414 if(pBuff == NULL){
415 fprintf(stderr, "not enough mem\n");
416 goto err;
417 }
418
419 pBuff[0] = HAPTIC_CMDID_REG_SETBIT;
420
421 for(i=0, j =0; i< reg_count; i++ , j++){
422 err = str2short(argv[j*3 + 2], &regAddr_UInt16);
423 if(err < 0){
424 goto err;
425 }
426
427 err = str2char(argv[j*3 + 3], &regMask_UInt8);
428 if(err < 0){
429 goto err;
430 }
431
432 err = str2char(argv[j*3 + 4], &regVal_UInt8);
433 if(err < 0){
434 goto err;
435 }
436
437 pBuff[i*4+1] = (unsigned char)(regAddr_UInt16&0x00ff);
438 pBuff[i*4+2] = (unsigned char)((regAddr_UInt16&0xff00)>>8);
439 pBuff[i*4+3] = regMask_UInt8;
440 pBuff[i*4+4] = regVal_UInt8;
441 }
442
443 err = write(fileHandle, pBuff, reg_count*4 + 1);
444 if(err != (reg_count*4 + 1)){
445 fprintf(stderr, "setbit err=%d\n", err);
446 }else{
447 for(i=0; i<reg_count; i++){
448 regAddr_UInt16 = (unsigned short)((pBuff[i*4+2]<<8)|pBuff[i*4+1] );
449 fprintf(stderr, "SReg(0x%x) Msk(0x%x) Val=0x%x\n", regAddr_UInt16, pBuff[i*4+3], pBuff[i*4+4]);
450 }
451 }
452
453err:
454 if(pBuff != NULL)
455 free(pBuff);
456
457 return err;
458}
459
460static int DRV260x_Reg_SetBit(int fileHandle, int argc, char **argv){
461 int err = 0;
462 unsigned char *pBuff = NULL, regAddr_UInt8, regMask_UInt8, regVal_UInt8;
463 int i=0, reg_count, j;
464
465 if((argc < 5)||((argc-2)%3 != 0)){
466 fprintf(stderr, "invalid para numbers\n");
467 goto err;
468 }
469
470 reg_count = (argc-2)/3;
471
472 pBuff = (unsigned char *)malloc(reg_count*3 + 1);
473 if(pBuff == NULL){
474 fprintf(stderr, "not enough mem\n");
475 goto err;
476 }
477
478 pBuff[0] = HAPTIC_CMDID_REG_SETBIT;
479
480 for(i=0, j=0; i< reg_count; i++, j++){
481 err = str2char(argv[j*3 + 2], &regAddr_UInt8);
482 if(err < 0){
483 goto err;
484 }
485 err = str2char(argv[j*3 + 3], &regMask_UInt8);
486 if(err < 0){
487 goto err;
488 }
489 err = str2char(argv[j*3 + 4], &regVal_UInt8);
490 if(err < 0){
491 goto err;
492 }
493
494 pBuff[i*3 + 1] = regAddr_UInt8;
495 pBuff[i*3 + 2] = regMask_UInt8;
496 pBuff[i*3 + 3] = regVal_UInt8;
497 }
498
499 err = write(fileHandle, pBuff, argc-1);
500 if(err != (argc-1)){
501 fprintf(stderr, "setbit err=%d\n", err);
502 }else{
503 for(i=0 ; i< reg_count; i++){
504 fprintf(stderr, "SReg(0x%x) Msk(0x%x) Val=0x%x\n", pBuff[i*3 + 1], pBuff[i*3+2], pBuff[i*3+3]);
505 }
506 }
507
508err:
509 if(pBuff != NULL)
510 free(pBuff);
511
512 return err;
513}
514
515static int DRV266x_Reg_Dump(int fileHandle){
516 char *argv_266x[] = {"haptics","-r", "0", "b"};
517 return DRV266x_Reg_Read(fileHandle, 4, argv_266x);
518}
519
520static int DRV260x_Reg_Dump(int fileHandle){
521 char *argv_260x[] = {"haptics","-r", "0", "23"};
522 return DRV260x_Reg_Read(fileHandle, 4, argv_260x);
523}
524
525static int DRV260x_Reg_RTPSeqPlay(int fileHandle, int argc, char **argv){
526 int err = 0;
527 unsigned char *pBuff = NULL, amp_UInt8, time_UInt8, count;
528 int i=0;
529
530 if((argc < 4)||( (argc%2) != 0)){
531 fprintf(stderr, "invalid para numbers\n");
532 goto err;
533 }
534
535 pBuff = (unsigned char *)malloc(argc-1);
536 if(pBuff == NULL){
537 fprintf(stderr, "not enough mem\n");
538 goto err;
539 }
540
541 pBuff[0] = HAPTIC_CMDID_RTP_SEQUENCE;
542 count = (argc-2)/2;
543
544 for(i=0; i< count; i++){
545 err = str2char(argv[i*2+2], &amp_UInt8);
546 if(err < 0){
547 goto err;
548 }
549 err = str2char(argv[i*2+3], &time_UInt8);
550 if(err < 0){
551 goto err;
552 }
553 pBuff[i*2+1] = amp_UInt8;
554 pBuff[i*2+2] = time_UInt8;
555 fprintf(stderr, "RTP[%d]:amp=0x%x,time=0x%x\n", i, amp_UInt8, time_UInt8 );
556 }
557
558 err = write(fileHandle, pBuff, count*2 +1);
559 if(err != (count*2 +1)){
560 fprintf(stderr, "write err=%d\n", err);
561 }else{
562
563 }
564
565err:
566 if(pBuff != NULL)
567 free(pBuff);
568
569 return err;
570
571}
572
573static int DRV26xx_SeqPlay(int fileHandle, int argc, char **argv){
574 int err = 0;
575 unsigned char *pBuff = NULL, seq_UInt8;
576 int i=0, seq_count;
577
578 if(argc < 3){
579 fprintf(stderr, "invalid para numbers\n");
580 goto err;
581 }
582
583 seq_count = argc - 2;
584
585 pBuff = (unsigned char *)malloc(seq_count + 1);
586 if(pBuff == NULL){
587 fprintf(stderr, "not enough mem\n");
588 goto err;
589 }
590
591 pBuff[0] = HAPTIC_CMDID_PLAY_EFFECT_SEQUENCE;
592
593 for(i=0; i< seq_count; i++){
594 err = str2char(argv[i+2], &seq_UInt8);
595 if(err < 0){
596 goto err;
597 }
598
599 pBuff[i+1] = seq_UInt8;
600 }
601
602 fprintf(stderr, "SeqPlay[%d]:", seq_count );
603 for(i=0; i< seq_count; i++)
604 fprintf(stderr, "%d ", pBuff[i+1]);
605 fprintf(stderr, "\n");
606
607 err = write(fileHandle, pBuff, seq_count + 1);
608 if(err != (seq_count + 1)){
609 fprintf(stderr, "write err=%d\n", err);
610 }
611
612err:
613 if(pBuff != NULL)
614 free(pBuff);
615
616 return err;
617}
618
619static int DRV26xx_VIBPlay(int fileHandle, int argc, char **argv){
620 int err = 0;
621 unsigned char Buff[3];
622 unsigned short OnTime;
623
624 if(argc < 3){
625 fprintf(stderr, "invalid para numbers\n");
626 goto err;
627 }
628
629 Buff[0] = HAPTIC_CMDID_PLAY_TIMED_EFFECT;
630 err = str2short(argv[2], &OnTime);
631 if(err < 0){
632 goto err;
633 }
634
635 if(OnTime > RTP_DURATION_MAX){
636 OnTime = RTP_DURATION_MAX;
637 }
638
639 Buff[1] = (unsigned char)(OnTime&0x00ff);
640 Buff[2] = (unsigned char)((OnTime&0xff00)>>8);
641
642 err = write(fileHandle, Buff, 3);
643 if(err != 3){
644 fprintf(stderr, "write err=%d\n", err);
645 }else{
646 fprintf(stderr, "VIBPlay %d ms\n", OnTime);
647 }
648
649err:
650
651 return err;
652}
653
654static int DRV260x_PatternRTPPlay(int fileHandle, int argc, char **argv){
655 int err = 0;
656 unsigned char Buff[7], strength=0, repeat=0;
657 unsigned short OnTime = 0, OffTime = 0;
658
659 if(argc < 6){
660 fprintf(stderr, "invalid para numbers\n");
661 goto err;
662 }
663
664 Buff[0] = HAPTIC_CMDID_PATTERN_RTP;
665 err = str2short(argv[2], &OnTime);
666 if(err < 0){
667 goto err;
668 }
669 if(OnTime > RTP_DURATION_MAX){
670 OnTime = RTP_DURATION_MAX;
671 }
672 Buff[1] = (unsigned char)(OnTime&0x00ff);
673 Buff[2] = (unsigned char)((OnTime&0xff00)>>8);
674
675 err = str2short(argv[3], &OffTime);
676 if(err < 0){
677 goto err;
678 }
679 Buff[3] = (unsigned char)(OffTime&0x00ff);
680 Buff[4] = (unsigned char)((OffTime&0xff00)>>8);
681
682 err = str2char(argv[4], &strength);
683 if(err < 0){
684 goto err;
685 }
686 Buff[5] = strength;
687
688 err = str2char(argv[5], &repeat);
689 if(err < 0){
690 goto err;
691 }
692 Buff[6] = repeat;
693
694 err = write(fileHandle, Buff, 7);
695 if(err != 7){
696 fprintf(stderr, "write err=%d\n", err);
697 }else{
698 fprintf(stderr, "Pattern Strength(0x%x), On(%d ms)-Off(%d ms), repeat %d\n", strength, OnTime, OffTime, repeat);
699 }
700
701err:
702 return err;
703}
704
705static int DRV266x_FIFOPlay(int fileHandle, int argc, char **argv){
706 int err = 0;
707 unsigned char *pBuff = NULL;
708 char *filename;
709 int fifoHandle = -1;
710 size_t filesize, readsize;
711 struct stat st;
712
713 if(argc < 3){
714 fprintf(stderr, "invalid para numbers\n");
715 goto err;
716 }
717
718 filename = argv[2];
719 err = stat(filename, &st);
720 if ( err < 0) {
721 fprintf(stderr, "file error\n");
722 goto err;
723 }
724
725 filesize = (st.st_size > FIFO_PBK_BYTES_LEN)?FIFO_PBK_BYTES_LEN:st.st_size;
726
727 pBuff = (unsigned char *)malloc(filesize + 1);
728 if (pBuff == NULL) {
729 fprintf(stderr, "not enough memory\n");
730 goto err;
731 }
732
733 pBuff[0] = HAPTIC_CMDID_PLAY_FIFO;
734
735 fifoHandle = open(filename, O_RDONLY);
736 if (fifoHandle < 0) {
737 fprintf(stderr, "fifo open error(%d)\n", fifoHandle);
738 goto err;
739 }
740
741 readsize = read(fifoHandle, &pBuff[1], filesize);
742 if ( readsize != filesize) {
743 fprintf(stderr, "fifo read error\n");
744 goto err;
745 }
746
747 err = write(fileHandle, pBuff, filesize + 1);
748 if(err != ((int)filesize + 1)){
749 fprintf(stderr, "write err=%d\n", err);
750 }else{
751 fprintf(stderr, "FIFOPlay OK\n");
752 }
753
754err:
755 if(pBuff != NULL)
756 free(pBuff);
757
758 if(fifoHandle > 0){
759 close(fifoHandle);
760 }
761
762 return err;
763}
764
765static int DRV2604_FirmwareUpdate(int fileHandle, int argc, char **argv){
766 int err = 0;
767 unsigned char *pBuff = NULL;
768 char *filename;
769 int fwhandle = -1;
770 size_t filesize, readsize;
771 struct stat st;
772
773 if(argc < 3){
774 fprintf(stderr, "invalid para numbers\n");
775 goto err;
776 }
777
778 filename = argv[2];
779 err = stat(filename, &st);
780 if ( err < 0) {
781 fprintf(stderr, "file error\n");
782 goto err;
783 }
784
785 if(st.st_size > DRV2604_RAM_SIZE){
786 filesize = DRV2604_RAM_SIZE;
787 }else{
788 filesize = st.st_size;
789 }
790
791 pBuff = (unsigned char *)malloc(filesize + 1);
792 if (pBuff == NULL) {
793 fprintf(stderr, "not enough memory\n");
794 goto err;
795 }
796
797 pBuff[0] = HAPTIC_CMDID_UPDATE_FIRMWARE;
798
799 fwhandle = open(filename, O_RDONLY);
800 if (fwhandle < 0) {
801 fprintf(stderr, "fw open error(%d)\n", fwhandle);
802 goto err;
803 }
804
805 readsize = read(fwhandle, &pBuff[1], filesize);
806 if ( readsize != filesize) {
807 fprintf(stderr, "fifo read error\n");
808 goto err;
809 }
810
811 err = write(fileHandle, pBuff, filesize + 1);
812 if(err != ((int)filesize + 1)){
813 fprintf(stderr, "write err=%d\n", err);
814 }else{
815 fprintf(stderr, "Firmware Update OK\n");
816 }
817
818err:
819 if(pBuff != NULL)
820 free(pBuff);
821
822 if(fwhandle > 0){
823 close(fwhandle);
824 }
825
826 return err;
827}
828
829static int DRV2604_ReadRam(int fileHandle, int argc, char **argv){
830 int err = 0, i;
831 unsigned char Buff[4];
832 unsigned char data[MAX_READ_BYTES];
833 unsigned char count = 0, send_count, read_count;
834 unsigned short addr;
835
836 if((argc != 3)&&(argc != 4)){
837 fprintf(stderr, "invalid para numbers\n");
838 goto err;
839 }
840
841 err = str2short(argv[2], &addr);
842 if ( err < 0) {
843 fprintf(stderr, "addr error\n");
844 goto err;
845 }
846
847 if(argc == 4){
848 err = str2char(argv[3], &count);
849 if ( err < 0) {
850 fprintf(stderr, "addr error\n");
851 goto err;
852 }
853 Buff[3] = count;
854 }
855
856 Buff[0] = HAPTIC_CMDID_READ_FIRMWARE;
857 Buff[1] = (unsigned char)addr;
858 Buff[2] = (unsigned char)(addr>>8);
859
860 send_count = (argc==4)?4:3;
861
862 err = write(fileHandle, Buff, send_count);
863 if(err != send_count){
864 fprintf(stderr, "read ram send err=%d\n", err);
865 goto err;
866 }
867
868 read_count = (argc==4)?count:1;
869 err = read(fileHandle, data, read_count);
870 if(err != read_count){
871 fprintf(stderr, "read ram get err=%d\n", err);
872 goto err;
873 }
874
875 for(i=0; i < read_count; i++){
876 fprintf(stderr, "DRV2604 RAM[0x%x]=0x%x\n", addr + i, data[i]);
877 }
878
879err:
880 return err;
881}
882
883static int DRV26xx_StopPlay(int fileHandle){
884 int err = 0;
885 unsigned char Buff;
886
887 Buff = HAPTIC_CMDID_STOP;
888
889 err = write(fileHandle, &Buff, 1);
890 if(err != 1){
891 fprintf(stderr, "write err=%d\n", err);
892 }else{
893 fprintf(stderr, "Stop Vibration\n");
894 }
895
896 return err;
897}
898
899static int DRV2667_AnalogInput(int fileHandle){
900 int err = 0;
901 unsigned char Buff;
902
903 Buff = HAPTIC_CMDID_ANALOG_INPUT;
904
905 err = write(fileHandle, &Buff, 1);
906 if(err != 1){
907 fprintf(stderr, "write err=%d\n", err);
908 }else{
909 fprintf(stderr, "DRV2667 AnalogInput Enable\n");
910 }
911
912 return err;
913}
914
915static enum Haptic_Target getDevTarget(int index){
916 enum Haptic_Target target;
917 switch(index){
918 case 1:
919 target = HAPTIC_DRV2604;
920 break;
921 case 2:
922 target = HAPTIC_DRV2604L;
923 break;
924 case 3:
925 target = HAPTIC_DRV2605;
926 break;
927 case 4:
928 target = HAPTIC_DRV2605L;
929 break;
930 case 5:
931 target = HAPTIC_DRV2667;
932 break;
933 case 6:
934 target = HAPTIC_DRV2669;
935 break;
936 default:
937 target = HAPTIC_DRVXXXX;
938 break;
939 }
940 return target;
941}
942
943static int getDevHandle(enum Haptic_Target *pTarget){
944 int fileHandle = -1, i;
945 struct stat sbuf;
946 int dev_count = ARRAY_LEN(haptic_devices);
947
948 for(i=0; i< dev_count; i++){
949 if (stat(haptic_devices[i], &sbuf) == 0){
950 *pTarget = getDevTarget(i);
951 break;
952 }
953 }
954
955 if(i == dev_count){
956 fprintf(stderr, "[ERROR]dev nodes not found\n");
957 }else{
958 fileHandle = open(haptic_devices[i], O_RDWR);
959 if(fileHandle < 0 ){
960 fprintf(stderr, "[ERROR]file(%s) open_RDWR error\n", haptic_devices[i]);
961 }
962 }
963
964 return fileHandle;
965}
966
967static int DRV2605_Audio2Haptics(int fileHandle, int argc, char **argv){
968 int err = -1;
969 unsigned char Buff;
970 unsigned char enable;
971
972 if(argc != 3){
973 fprintf(stderr, "invalid argc=%d\n", argc);
974 goto err;
975 }
976
977 err = str2char(argv[2], &enable);
978 if(err < 0){
979 fprintf(stderr, "invalid argv[2]=%d\n", argc);
980 goto err;
981 }
982
983 if(enable != 0){
984 Buff = HAPTIC_CMDID_AUDIOHAPTIC_ENABLE;
985 }else{
986 Buff = HAPTIC_CMDID_AUDIOHAPTIC_DISABLE;
987 }
988
989 err = write(fileHandle, &Buff, 1);
990 if(err != 1){
991 fprintf(stderr, "write err=%d\n", err);
992 }else{
993 fprintf(stderr, "DRV2605 A2H %s\n", (Buff==HAPTIC_CMDID_AUDIOHAPTIC_ENABLE)?"enabled":"disabled");
994 }
995
996err:
997 return err;
998}
999
1000static int getDeviceTarget(enum Haptic_Target target){
1001 int result = 0;;
1002
1003 fprintf(stderr, "Haptic Target=%s\n", target_str[target]);
1004
1005 return result;
1006}
1007
1008int main(int argc, char **argv)
1009{
1010 int ret = 0;
1011 int ch;
1012 int fileHandle = -1;
1013 enum Haptic_Target target;
1014
1015 fileHandle = getDevHandle(&target);
1016 if(fileHandle < 0 ){
1017 fprintf(stderr, " file handle err=%d\n", fileHandle);
1018 return ret;
1019 }
1020
1021 if(argc == 1){
1022 usage(target);
1023 return 0;
1024 }
1025
1026 while ((ch = getopt(argc, argv, "wrsdptevfaqnb")) != -1) {
1027 switch (ch) {
1028 case 'w':
1029 if((target == HAPTIC_DRV2667)||(target == HAPTIC_DRV2669)){
1030 ret = DRV266x_Reg_Write(fileHandle, argc, argv);
1031 }else{
1032 ret = DRV260x_Reg_Write(fileHandle, argc, argv);
1033 }
1034 break;
1035 case 'r':
1036 if((target == HAPTIC_DRV2667)||(target == HAPTIC_DRV2669)){
1037 ret = DRV266x_Reg_Read( fileHandle, argc, argv);
1038 }else{
1039 ret = DRV260x_Reg_Read( fileHandle, argc, argv);
1040 }
1041 break;
1042 case 's':
1043 if((target == HAPTIC_DRV2667)||(target == HAPTIC_DRV2669)){
1044 ret = DRV266x_Reg_SetBit( fileHandle, argc, argv);
1045 }else{
1046 ret = DRV260x_Reg_SetBit( fileHandle, argc, argv);
1047 }
1048 break;
1049 case 'e':
1050 ret = DRV26xx_SeqPlay( fileHandle, argc, argv);
1051 break;
1052 case 'd':
1053 if((target == HAPTIC_DRV2667)||(target == HAPTIC_DRV2669)){
1054 ret = DRV266x_Reg_Dump( fileHandle );
1055 }else if((target == HAPTIC_DRV2604)||(target == HAPTIC_DRV2605)||(target == HAPTIC_DRV2604L)||(target == HAPTIC_DRV2605L)){
1056 ret = DRV260x_Reg_Dump( fileHandle);
1057 }else{
1058 fprintf(stderr, " target not support=%d\n", target);
1059 }
1060 break;
1061 case 'p':
1062 ret = DRV26xx_StopPlay(fileHandle);
1063 break;
1064 case 'q':
1065 if((target == HAPTIC_DRV2604)||(target == HAPTIC_DRV2605)||(target == HAPTIC_DRV2604L)||(target == HAPTIC_DRV2605L))
1066 ret = DRV260x_Reg_RTPSeqPlay(fileHandle, argc, argv);
1067 else{
1068 fprintf(stderr, " target not support=%d\n", target);
1069 }
1070 break;
1071 case 'n':
1072 if((target == HAPTIC_DRV2604)||(target == HAPTIC_DRV2605)||(target == HAPTIC_DRV2604L)||(target == HAPTIC_DRV2605L))
1073 ret = DRV260x_PatternRTPPlay(fileHandle, argc, argv);
1074 else{
1075 fprintf(stderr, " target not support=%d\n", target);
1076 }
1077 break;
1078 case 'v':
1079 ret = DRV26xx_VIBPlay(fileHandle, argc, argv);
1080 break;
1081 case 'f':
1082 if((target == HAPTIC_DRV2667)||(target == HAPTIC_DRV2669)){
1083 ret = DRV266x_FIFOPlay(fileHandle, argc, argv);
1084 }else if((target == HAPTIC_DRV2604)||(target == HAPTIC_DRV2604L)){
1085 ret = DRV2604_FirmwareUpdate(fileHandle, argc, argv);
1086 }else{
1087 fprintf(stderr, " target not support=%d\n", target);
1088 }
1089 break;
1090 case 'a':
1091 if(target == HAPTIC_DRV2667){
1092 ret = DRV2667_AnalogInput(fileHandle);
1093 }else if(target == HAPTIC_DRV2605){
1094 ret = DRV2605_Audio2Haptics(fileHandle, argc, argv);
1095 }else{
1096 fprintf(stderr, " target not support=%d\n", target);
1097 }
1098 break;
1099 case 'b':
1100 if((target == HAPTIC_DRV2604)||(target == HAPTIC_DRV2604L)){
1101 ret = DRV2604_ReadRam(fileHandle, argc, argv);
1102 }else{
1103 fprintf(stderr, " target not support=%d\n", target);
1104 }
1105 break;
1106 case 't':
1107 ret = getDeviceTarget(target);
1108 break;
1109 default:
1110 usage(target);
1111 break;
1112 }
1113 }
1114
1115 if(fileHandle > 0 )
1116 close(fileHandle);
1117
1118 return ret;
1119}