hc
2023-11-22 9ca5fbcb63a8dcaee0527f96afb91dc4b4bd8fa9
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
/* Core header for MiraMEMS 3-Axis Accelerometer's driver.
 *
 * mir3da_core.h - Linux kernel modules for MiraMEMS 3-Axis Accelerometer
 *
 * Copyright (C) 2011-2013 MiraMEMS Sensing Technology Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
 
#ifndef __MIR3DA_CORE_H__
#define __MIR3DA_CORE_H__
 
#define CUST_VER                            ""                                          /* for Custom debug version */
#define CORE_VER                            "4.2.0_2018-08-10-14:56:30_"CUST_VER
 
#define MIR3DA_SUPPORT_CHIP_LIST            MIR_NSA_NTO
 
#define MIR3DA_BUFSIZE                      256
 
#define MIR3DA_STK_TEMP_SOLUTION            0
#define MIR3DA_OFFSET_TEMP_SOLUTION         0
#if MIR3DA_OFFSET_TEMP_SOLUTION
#define MIR3DA_AUTO_CALIBRATE               0
#else
#define MIR3DA_AUTO_CALIBRATE               0
#endif /* !MIR3DA_OFFSET_TEMP_SOLUTION */
#if MIR3DA_AUTO_CALIBRATE
#define MIR3DA_SUPPORT_FAST_AUTO_CALI       0
#else
#define MIR3DA_SUPPORT_FAST_AUTO_CALI       0
#endif
#define MIR3DA_SENS_TEMP_SOLUTION           1
#define FILTER_AVERAGE_ENHANCE              0
#define FILTER_AVERAGE_EX                   0
#define MIR3DA_SUPPORT_MULTI_LAYOUT         0
#define YZ_CROSS_TALK_ENABLE                1
 
#define MIR3DA_OFFSET_LEN                   9
 
typedef void*   MIR_HANDLE;
typedef void*   PLAT_HANDLE;
 
 
struct serial_manage_if_s {
 
    int                         (*read)(PLAT_HANDLE handle, unsigned char addr, unsigned char *data);
    int                         (*write)(PLAT_HANDLE handle, unsigned char addr, unsigned char data);
    int                         (*read_block)(PLAT_HANDLE handle, unsigned char base_addr, unsigned char count, unsigned char *data);
};
 
struct general_op_s {
 
    struct serial_manage_if_s   smi;
 
    int                         (*data_save)(unsigned char *data);
    int                         (*data_get)(unsigned char *data);
    int                         (*data_check)(void);
    int                         (*get_address)(PLAT_HANDLE handle);
    int                         (*support_fast_auto_cali)(void);
 
    int                         (*myprintf)(const char *fmt, ...);
    int                         (*mysprintf)(char *buf, const char *fmt, ...);
    void                        (*msdelay)(int ms);
};
 
#define MIR_GENERAL_OPS_DECLARE(OPS_HDL, SMI_RD, SMI_RDBL, SMI_WR, DAT_SAVE, DAT_GET,DAT_CHECK, GET_ADDRESS,SUPPORT_FAST_AUTO_CALI,MDELAY, MYPRINTF, MYSPRINTF)                                      \
                                                                                                                                                        \
                                struct general_op_s     OPS_HDL = { { SMI_RD, SMI_WR, SMI_RDBL }, DAT_SAVE, DAT_GET,DAT_CHECK,GET_ADDRESS, SUPPORT_FAST_AUTO_CALI,MYPRINTF, MYSPRINTF, MDELAY }
enum interrupt_src {
 
    INTERRUPT_ACTIVITY     = 1,
    INTERRUPT_CLICK,
 
};
 
typedef enum _int_op_type {
 
    INTERRUPT_OP_INIT,
    INTERRUPT_OP_ENABLE,
    INTERRUPT_OP_CONFIG,
    INTERRUPT_OP_DISABLE,
 
} mir_int_op_type;
 
enum interrupt_pin {
 
    INTERRUPT_PIN1,
    INTERRUPT_PIN2,
};
 
enum pin_output_mode {
 
    OUTPUT_MOD_PULL_PUSH,
    OUTPUT_MOD_OD,
};
 
struct int_act_cfg_s {
 
    unsigned char           threshold;
    unsigned char           duration;
};
 
struct int_clk_cfg_s {
 
    unsigned char                   threshold;
    unsigned char                   click_time;     /* click time */
    unsigned char                   quiet_time;     /* quiet time after click */
    unsigned char                   window;         /* for second click time window */
};
 
typedef union _int_src_configuration {
 
    struct int_act_cfg_s            act;
    struct int_clk_cfg_s            clk;
 
} mir_int_src_cfg_t;
 
typedef struct _int_configuration {
 
    enum interrupt_pin              pin;
    enum interrupt_src              int_src;
 
    mir_int_src_cfg_t               int_cfg;
 
} mir_int_cfg_t;
 
typedef struct _int_init_data {
 
    enum pin_output_mode            pin_mod;
 
    unsigned char                   level;      /* 1: high active, 0: low active */
    unsigned char                   latch;          /* >0: latch time, 0: no latch */
     
} mir_int_init_t ;
 
typedef union _int_op_data {
 
    enum interrupt_src              int_src;
    mir_int_init_t                  init;
    mir_int_cfg_t                   cfg;
 
} mir_int_op_data;
 
typedef struct _int_operations {
 
    mir_int_op_type                 type;
    mir_int_op_data                 data;
 
} mir_int_ops_t; 
 
/* Register define for NSA asic */
#define NSA_REG_SPI_I2C                 0x00
#define NSA_REG_WHO_AM_I                0x01
#define NSA_REG_ACC_X_LSB               0x02
#define NSA_REG_ACC_X_MSB               0x03
#define NSA_REG_ACC_Y_LSB               0x04
#define NSA_REG_ACC_Y_MSB               0x05
#define NSA_REG_ACC_Z_LSB               0x06
#define NSA_REG_ACC_Z_MSB               0x07
#define NSA_REG_MOTION_FLAG                0x09
#define NSA_REG_STEPS_MSB                0x0D
#define NSA_REG_STEPS_LSB                0x0E
#define NSA_REG_G_RANGE                 0x0F
#define NSA_REG_ODR_AXIS_DISABLE        0x10
#define NSA_REG_POWERMODE_BW            0x11
#define NSA_REG_SWAP_POLARITY           0x12
#define NSA_REG_FIFO_CTRL               0x14
#define NAS_REG_INT_SET0                0x15
#define NSA_REG_INTERRUPT_SETTINGS1     0x16
#define NSA_REG_INTERRUPT_SETTINGS2     0x17
#define NSA_REG_INTERRUPT_MAPPING1      0x19
#define NSA_REG_INTERRUPT_MAPPING2      0x1a
#define NSA_REG_INTERRUPT_MAPPING3      0x1b
#define NSA_REG_INT_PIN_CONFIG          0x20
#define NSA_REG_INT_LATCH               0x21
#define NSA_REG_ACTIVE_DURATION         0x27
#define NSA_REG_ACTIVE_THRESHOLD        0x28
#define NSA_REG_TAP_DURATION            0x2A
#define NSA_REG_TAP_THRESHOLD           0x2B
#define NSA_REG_STEP_CONFIG1            0x2F
#define NSA_REG_STEP_CONFIG2            0x30
#define NSA_REG_STEP_CONFIG3            0x31
#define NSA_REG_STEP_CONFIG4            0x32
#define NSA_REG_STEP_FILTER                0x33
#define NSA_REG_SM_THRESHOLD            0x34
#define NSA_REG_CUSTOM_OFFSET_X         0x38
#define NSA_REG_CUSTOM_OFFSET_Y         0x39
#define NSA_REG_CUSTOM_OFFSET_Z         0x3a
#define NSA_REG_ENGINEERING_MODE        0x7f
#define NSA_REG_SENSITIVITY_TRIM_X      0x80
#define NSA_REG_SENSITIVITY_TRIM_Y      0x81
#define NSA_REG_SENSITIVITY_TRIM_Z      0x82
#define NSA_REG_COARSE_OFFSET_TRIM_X    0x83
#define NSA_REG_COARSE_OFFSET_TRIM_Y    0x84
#define NSA_REG_COARSE_OFFSET_TRIM_Z    0x85
#define NSA_REG_FINE_OFFSET_TRIM_X      0x86
#define NSA_REG_FINE_OFFSET_TRIM_Y      0x87
#define NSA_REG_FINE_OFFSET_TRIM_Z      0x88
#define NSA_REG_SENS_COMP               0x8c
#define NSA_REG_MEMS_OPTION             0x8f
#define NSA_REG_CHIP_INFO               0xc0
#define NSA_REG_CHIP_INFO_SECOND        0xc1
#define NSA_REG_MEMS_OPTION_SECOND      0xc7
#define NSA_REG_SENS_COARSE_TRIM        0xd1
#define NAS_REG_OSC_TRIM                0x8e
 
#define MIR3DA_ODR_50HZ                  0
#define MIR3DA_ODR_100HZ                 1
#define MIR3DA_ODR_200HZ                 2
 
#define MI_TAG                          "[MIR3DA] "
enum{
   DEBUG_ERR=1,
   DEBUG_ASSERT=1<<1,
   DEBUG_MSG=1<<2,
   DEBUG_FUNC=1<<3,
   DEBUG_DATA=1<<4,
};
 
extern int mir3da_Log_level;
 
/* register operation */
int mir3da_register_read(MIR_HANDLE handle, short reg, unsigned char *data);
int mir3da_register_write(MIR_HANDLE handle, short reg, unsigned char data);
int mir3da_register_read_continuously(MIR_HANDLE handle, short base_reg, unsigned char count, unsigned char *data);
int mir3da_register_mask_write(MIR_HANDLE handle, short addr, unsigned char mask, unsigned char data);
 
int mir3da_install_general_ops(struct general_op_s *ops);
/* chip init */
MIR_HANDLE mir3da_core_init(PLAT_HANDLE handle);
 
/* data polling */
int mir3da_read_data(MIR_HANDLE handle, short *x, short *y, short *z);
 
/* filter configure */
#if FILTER_AVERAGE_ENHANCE
struct mir3da_filter_param_s{
    int filter_param_l;
    int filter_param_h;
    int filter_threhold;
};
 
int mir3da_get_filter_param(struct mir3da_filter_param_s* param);
int mir3da_set_filter_param(struct mir3da_filter_param_s* param);
#endif
 
#if MIR3DA_STK_TEMP_SOLUTION
#endif
 
enum {
    GSENSOR_MOD_NSA_NTO=0,
};
 
/* CALI */
int mir3da_calibrate(MIR_HANDLE handle, int z_dir);
 
/* calibration */
#if MIR3DA_OFFSET_TEMP_SOLUTION
enum file_check_statu {
    FILE_NO_EXIST  ,
    FILE_CHECKING  ,
    FILE_EXIST,
};
#endif
 
/* Interrupt operations */
int mir3da_interrupt_ops(MIR_HANDLE handle, mir_int_ops_t *ops);
 
int mir3da_read_offset(MIR_HANDLE handle, unsigned char* offst);
int mir3da_write_offset(MIR_HANDLE handle, unsigned char* offset);
 
int mir3da_set_enable(MIR_HANDLE handle, char bEnable);
int mir3da_get_enable(MIR_HANDLE handle, char *bEnable);
int mir3da_get_reg_data(MIR_HANDLE handle, char *buf);
int mir3da_set_odr(MIR_HANDLE handle, int delay);
int mir3da_direction_remap(short *x,short *y, short *z, int direction);
 
int mir3da_chip_resume(MIR_HANDLE handle);
int mir3da_get_primary_offset(MIR_HANDLE handle,int *x,int *y,int *z);
 
int mir3da_read_step(MIR_HANDLE handle, unsigned short *count);
int mir3da_step_count_init(MIR_HANDLE handle);
int mir3da_irq_init(MIR_HANDLE handle);
int mir3da_step_count_init(MIR_HANDLE handle);
int mir3da_get_step_enable(MIR_HANDLE handle, char *enable);
int mir3da_set_step_enable(MIR_HANDLE handle, char enable);
int mir3da_get_sm_enable(MIR_HANDLE handle, char *enable);
int mir3da_set_sm_enable(MIR_HANDLE handle, char enable);
int mir3da_get_tilt_enable(MIR_HANDLE handle, char *enable);
int mir3da_set_tilt_enable(MIR_HANDLE handle, char enable);
 
 
#endif    /* __MIR3DA_CORE_H__ */