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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
/*
* Copyright (c) 2010 Yamaha Corporation
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __YAS_H__
#define __YAS_H__
#include "yas_cfg.h"
#define YAS_VERSION "4.1.0"
#define __LINUX_KERNEL_DRIVER__
/* -------------------------------------------------------------------------- */
/* Typedef definition */
/* -------------------------------------------------------------------------- */
#if defined(__LINUX_KERNEL_DRIVER__)
#include <linux/types.h>
#elif defined(__ANDROID__)
#include <stdint.h>
#else
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
#endif
/* -------------------------------------------------------------------------- */
/* Macro definition */
/* -------------------------------------------------------------------------- */
/* Debugging */
#define DEBUG (0)
#define MEDIATEK_CODE
#if DEBUG
#ifdef __LINUX_KERNEL_DRIVER__
#include <linux/kernel.h>
#define YLOGD(args) (printk args )
#define YLOGI(args) (printk args )
#define YLOGE(args) (printk args )
#define YLOGW(args) (printk args )
#elif defined __ANDROID__
#include <cutils/log.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "yas"
#define YLOGD(args) (LOGD args )
#define YLOGI(args) (LOGI args )
#define YLOGE(args) (LOGE args )
#define YLOGW(args) (LOGW args )
#else /* __ANDROID__ */
#include <stdio.h>
#define YLOGD(args) (printf args )
#define YLOGI(args) (printf args )
#define YLOGE(args) (printf args )
#define YLOGW(args) (printf args )
#endif /* __ANDROID__ */
#else /* DEBUG */
#define YLOGD(args)
#define YLOGI(args)
#define YLOGW(args)
#define YLOGE(args)
#endif /* DEBUG */
#define YAS_REPORT_DATA (0x01)
#define YAS_REPORT_CALIB (0x02)
#define YAS_REPORT_OVERFLOW_OCCURED (0x04)
#define YAS_REPORT_HARD_OFFSET_CHANGED (0x08)
#define YAS_REPORT_CALIB_OFFSET_CHANGED (0x10)
#define YAS_HARD_OFFSET_UNKNOWN (0x7f)
#define YAS_CALIB_OFFSET_UNKNOWN (0x7fffffff)
#define YAS_NO_ERROR (0)
#define YAS_ERROR_ARG (-1)
#define YAS_ERROR_NOT_INITIALIZED (-2)
#define YAS_ERROR_BUSY (-3)
#define YAS_ERROR_I2C (-4)
#define YAS_ERROR_CHIP_ID (-5)
#define YAS_ERROR_NOT_ACTIVE (-6)
#define YAS_ERROR_RESTARTSYS (-7)
#define YAS_ERROR_HARDOFFSET_NOT_WRITTEN (-8)
#define YAS_ERROR_ERROR (-128)
#ifndef NULL
#define NULL ((void*)(0))
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!(0))
#endif
#ifndef NELEMS
#define NELEMS(a) ((int)(sizeof(a)/sizeof(a[0])))
#endif
#ifndef ABS
#define ABS(a) ((a) > 0 ? (a) : -(a))
#endif
#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif
/* -------------------------------------------------------------------------- */
/* Structure definition */
/* -------------------------------------------------------------------------- */
struct yas_mag_filter {
int len;
int noise[3];
int threshold; /* nT */
};
struct yas_vector {
int32_t v[3];
};
struct yas_matrix {
int32_t matrix[9];
};
struct yas_acc_data {
struct yas_vector xyz;
struct yas_vector raw;
};
struct yas_mag_data {
struct yas_vector xyz; /* without offset, filtered */
struct yas_vector raw; /* with offset, not filtered */
struct yas_vector xy1y2;
int16_t temperature;
};
struct yas_mag_offset {
int8_t hard_offset[3];
struct yas_vector calib_offset;
};
struct yas_mag_status {
struct yas_mag_offset offset;
int accuracy;
};
struct yas_offset {
struct yas_mag_status mag[YAS_MAGCALIB_SHAPE_NUM];
};
struct yas_mag_driver_callback {
int (*lock)(void);
int (*unlock)(void);
int (*i2c_open)(void);
int (*i2c_close)(void);
#if YAS_MAG_DRIVER == YAS_MAG_DRIVER_YAS529
int (*i2c_write)(uint8_t slave, const uint8_t *buf, int len);
int (*i2c_read)(uint8_t slave, uint8_t *buf, int len);
#else
int (*i2c_write)(uint8_t slave, uint8_t addr, const uint8_t *buf, int len);
int (*i2c_read)(uint8_t slave, uint8_t addr, uint8_t *buf, int len);
#endif
void (*msleep)(int msec);
void (*current_time)(int32_t *sec, int32_t *msec);
};
struct yas_mag_driver {
int (*init)(void);
int (*term)(void);
int (*get_delay)(void);
int (*set_delay)(int msec);
int (*get_offset)(struct yas_mag_offset *offset);
int (*set_offset)(struct yas_mag_offset *offset);
int (*get_enable)(void);
int (*set_enable)(int enable);
int (*get_filter)(struct yas_mag_filter *filter);
int (*set_filter)(struct yas_mag_filter *filter);
int (*get_filter_enable)(void);
int (*set_filter_enable)(int enable);
int (*get_position)(void);
int (*set_position)(int position);
#if YAS_MAG_DRIVER == YAS_MAG_DRIVER_YAS529
int (*read_reg)(uint8_t *buf, int len);
int (*write_reg)(const uint8_t *buf, int len);
#else
int (*read_reg)(uint8_t addr, uint8_t *buf, int len);
int (*write_reg)(uint8_t addr, const uint8_t *buf, int len);
#endif
int (*measure)(struct yas_mag_data *data, int *time_delay_ms);
struct yas_mag_driver_callback callback;
};
struct yas_mag_calibration_result {
int32_t spread;
int32_t variation;
int32_t radius;
int8_t axis;
int8_t level;
int8_t accuracy;
};
struct yas_mag_calibration_threshold {
int32_t spread;
int32_t variation[3];
};
struct yas_mag_calibration_callback {
int (*lock)(void);
int (*unlock)(void);
};
struct yas_mag_calibration {
int (*init)(void);
int (*term)(void);
int (*update)(struct yas_vector *mag,
struct yas_mag_calibration_result *result);
int (*get_accuracy)(void);
int (*set_accuracy)(int accuracy);
int (*get_offset)(struct yas_vector *offset);
int (*set_offset)(struct yas_vector *offset);
int (*get_shape)(void);
int (*set_shape)(int shape);
int (*get_threshold)(struct yas_mag_calibration_threshold *threshold);
int (*set_threshold)(struct yas_mag_calibration_threshold *threshold);
struct yas_mag_calibration_callback callback;
};
struct yas_acc_filter {
int threshold; /* um/s^2 */
};
struct yas_acc_driver_callback {
int (*lock)(void);
int (*unlock)(void);
int (*i2c_open)(void);
int (*i2c_close)(void);
int (*i2c_write)(uint8_t slave, uint8_t adr, const uint8_t *buf, int len);
int (*i2c_read) (uint8_t slave, uint8_t adr, uint8_t *buf, int len);
void (*msleep)(int msec);
};
struct yas_acc_driver {
int (*init)(void);
int (*term)(void);
int (*get_delay)(void);
int (*set_delay)(int delay);
int (*get_offset)(struct yas_vector *offset);
int (*set_offset)(struct yas_vector *offset);
int (*get_enable)(void);
int (*set_enable)(int enable);
int (*get_filter)(struct yas_acc_filter *filter);
int (*set_filter)(struct yas_acc_filter *filter);
int (*get_filter_enable)(void);
int (*set_filter_enable)(int enable);
int (*get_position)(void);
int (*set_position)(int position);
int (*measure)(struct yas_acc_data *data);
#if DEBUG
int (*get_register)(uint8_t adr, uint8_t *val);
#endif
struct yas_acc_driver_callback callback;
};
struct yas_acc_calibration_threshold {
int32_t variation;
};
struct yas_acc_calibration_callback {
int (*lock)(void);
int (*unlock)(void);
};
struct yas_acc_calibration {
int (*init)(void);
int (*term)(void);
int (*update)(struct yas_vector *acc);
int (*get_offset)(struct yas_vector *offset);
int (*get_threshold)(struct yas_acc_calibration_threshold *threshold);
int (*set_threshold)(struct yas_acc_calibration_threshold *threshold);
struct yas_acc_calibration_callback callback;
};
struct yas_utility {
int (*get_rotation_matrix)(struct yas_vector *acc, struct yas_vector *mag,
struct yas_matrix *matrix);
int (*get_euler)(struct yas_matrix *matrix, struct yas_vector *euler);
};
/* -------------------------------------------------------------------------- */
/* Global function definition */
/* -------------------------------------------------------------------------- */
extern int yas_mag_driver_init(struct yas_mag_driver *f);
extern int is_valid_calib_offset(const int32_t *p);
int yas_mag_calibration_init(struct yas_mag_calibration *f);
int yas_acc_driver_init(struct yas_acc_driver *f);
int yas_acc_calibration_init(struct yas_acc_calibration *f);
int yas_utility_init(struct yas_utility *f);
#endif /* __YAS_H__ */
|