LibDriver MMA7660FC
Loading...
Searching...
No Matches
driver_mma7660fc_read_test.c
Go to the documentation of this file.
1
36
38
39static mma7660fc_handle_t gs_handle;
40
49uint8_t mma7660fc_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint32_t i;
54
55 /* link interface function */
64
65 /* get mma7660fc info */
66 res = mma7660fc_info(&info);
67 if (res != 0)
68 {
69 mma7660fc_interface_debug_print("mma7660fc: get info failed.\n");
70
71 return 1;
72 }
73 else
74 {
75 /* print mma7660fc */
76 mma7660fc_interface_debug_print("mma7660fc: chip is %s.\n", info.chip_name);
77 mma7660fc_interface_debug_print("mma7660fc: manufacturer is %s.\n", info.manufacturer_name);
78 mma7660fc_interface_debug_print("mma7660fc: interface is %s.\n", info.interface);
79 mma7660fc_interface_debug_print("mma7660fc: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
80 mma7660fc_interface_debug_print("mma7660fc: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
81 mma7660fc_interface_debug_print("mma7660fc: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
82 mma7660fc_interface_debug_print("mma7660fc: max current is %0.2fmA.\n", info.max_current_ma);
83 mma7660fc_interface_debug_print("mma7660fc: max temperature is %0.1fC.\n", info.temperature_max);
84 mma7660fc_interface_debug_print("mma7660fc: min temperature is %0.1fC.\n", info.temperature_min);
85 }
86
87 /* start read test */
88 mma7660fc_interface_debug_print("mma7660fc: start read test.\n");
89
90 /* init */
91 res = mma7660fc_init(&gs_handle);
92 if (res != 0)
93 {
94 mma7660fc_interface_debug_print("mma7660fc: init failed.\n");
95
96 return 1;
97 }
98
99 /* set sleep count 0 */
100 res = mma7660fc_set_sleep_count(&gs_handle, 0);
101 if (res != 0)
102 {
103 mma7660fc_interface_debug_print("mma7660fc: set sleep count failed.\n");
104 (void)mma7660fc_deinit(&gs_handle);
105
106 return 1;
107 }
108
109 /* disable front back interrupt */
111 if (res != 0)
112 {
113 mma7660fc_interface_debug_print("mma7660fc: set front back interrupt failed.\n");
114 (void)mma7660fc_deinit(&gs_handle);
115
116 return 1;
117 }
118
119 /* disable up down right left interrupt */
121 if (res != 0)
122 {
123 mma7660fc_interface_debug_print("mma7660fc: set up down right left interrupt failed.\n");
124 (void)mma7660fc_deinit(&gs_handle);
125
126 return 1;
127 }
128
129 /* disable tap interrupt */
131 if (res != 0)
132 {
133 mma7660fc_interface_debug_print("mma7660fc: set tap interrupt failed.\n");
134 (void)mma7660fc_deinit(&gs_handle);
135
136 return 1;
137 }
138
139 /* disable auto sleep interrupt */
141 if (res != 0)
142 {
143 mma7660fc_interface_debug_print("mma7660fc: set auto sleep interrupt failed.\n");
144 (void)mma7660fc_deinit(&gs_handle);
145
146 return 1;
147 }
148
149 /* disable update interrupt */
151 if (res != 0)
152 {
153 mma7660fc_interface_debug_print("mma7660fc: set update interrupt failed.\n");
154 (void)mma7660fc_deinit(&gs_handle);
155
156 return 1;
157 }
158
159 /* disable shake x interrupt */
161 if (res != 0)
162 {
163 mma7660fc_interface_debug_print("mma7660fc: set shake x interrupt failed.\n");
164 (void)mma7660fc_deinit(&gs_handle);
165
166 return 1;
167 }
168
169 /* disable shake y interrupt */
171 if (res != 0)
172 {
173 mma7660fc_interface_debug_print("mma7660fc: set shake y interrupt failed.\n");
174 (void)mma7660fc_deinit(&gs_handle);
175
176 return 1;
177 }
178
179 /* disable shake z interrupt */
181 if (res != 0)
182 {
183 mma7660fc_interface_debug_print("mma7660fc: set shake z interrupt failed.\n");
184 (void)mma7660fc_deinit(&gs_handle);
185
186 return 1;
187 }
188
189 /* disable auto wake up */
191 if (res != 0)
192 {
193 mma7660fc_interface_debug_print("mma7660fc: set auto wake up failed.\n");
194 (void)mma7660fc_deinit(&gs_handle);
195
196 return 1;
197 }
198
199 /* disable auto sleep */
201 if (res != 0)
202 {
203 mma7660fc_interface_debug_print("mma7660fc: set auto sleep failed.\n");
204 (void)mma7660fc_deinit(&gs_handle);
205
206 return 1;
207 }
208
209 /* set sleep counter prescaler 1 */
211 if (res != 0)
212 {
213 mma7660fc_interface_debug_print("mma7660fc: set sleep counter prescaler failed.\n");
214 (void)mma7660fc_deinit(&gs_handle);
215
216 return 1;
217 }
218
219 /* set interrupt pin type push-pull */
221 if (res != 0)
222 {
223 mma7660fc_interface_debug_print("mma7660fc: set interrupt pin type failed.\n");
224 (void)mma7660fc_deinit(&gs_handle);
225
226 return 1;
227 }
228
229 /* set interrupt active level low */
231 if (res != 0)
232 {
233 mma7660fc_interface_debug_print("mma7660fc: set interrupt active level failed.\n");
234 (void)mma7660fc_deinit(&gs_handle);
235
236 return 1;
237 }
238
239 /* set tap detection rate 8 */
241 if (res != 0)
242 {
243 mma7660fc_interface_debug_print("mma7660fc: set tap detection rate failed.\n");
244 (void)mma7660fc_deinit(&gs_handle);
245
246 return 1;
247 }
248
249 /* set auto wake rate 16 */
251 if (res != 0)
252 {
253 mma7660fc_interface_debug_print("mma7660fc: set auto wake rate failed.\n");
254 (void)mma7660fc_deinit(&gs_handle);
255
256 return 1;
257 }
258
259 /* set tilt debounce filter 2 */
261 if (res != 0)
262 {
263 mma7660fc_interface_debug_print("mma7660fc: set tilt debounce filter failed.\n");
264 (void)mma7660fc_deinit(&gs_handle);
265
266 return 1;
267 }
268
269 /* set tap detection threshold 0 */
270 res = mma7660fc_set_tap_detection_threshold(&gs_handle, 0);
271 if (res != 0)
272 {
273 mma7660fc_interface_debug_print("mma7660fc: set tap detection threshold failed.\n");
274 (void)mma7660fc_deinit(&gs_handle);
275
276 return 1;
277 }
278
279 /* disable tap x detection */
281 if (res != 0)
282 {
283 mma7660fc_interface_debug_print("mma7660fc: set tap x detection failed.\n");
284 (void)mma7660fc_deinit(&gs_handle);
285
286 return 1;
287 }
288
289 /* disable tap y detection */
291 if (res != 0)
292 {
293 mma7660fc_interface_debug_print("mma7660fc: set tap y detection failed.\n");
294 (void)mma7660fc_deinit(&gs_handle);
295
296 return 1;
297 }
298
299 /* disable tap z detection */
301 if (res != 0)
302 {
303 mma7660fc_interface_debug_print("mma7660fc: set tap z detection failed.\n");
304 (void)mma7660fc_deinit(&gs_handle);
305
306 return 1;
307 }
308
309 /* set tap pulse debounce count 0 */
310 res = mma7660fc_set_tap_pulse_debounce_count(&gs_handle, 0);
311 if (res != 0)
312 {
313 mma7660fc_interface_debug_print("mma7660fc: set tap pulse debounce count failed.\n");
314 (void)mma7660fc_deinit(&gs_handle);
315
316 return 1;
317 }
318
319 /* set mode active */
320 res = mma7660fc_set_mode(&gs_handle, MMA7660FC_MODE_ACTIVE);
321 if (res != 0)
322 {
323 mma7660fc_interface_debug_print("mma7660fc: set mode failed.\n");
324 (void)mma7660fc_deinit(&gs_handle);
325
326 return 1;
327 }
328
329 for (i = 0; i < times; i++)
330 {
331 int8_t raw[3];
332 float g[3];
333
334 /* delay 1000ms */
336
337 /* read data */
338 res = mma7660fc_read(&gs_handle, raw, g);
339 if (res != 0)
340 {
341 mma7660fc_interface_debug_print("mma7660fc: read failed.\n");
342 (void)mma7660fc_deinit(&gs_handle);
343
344 return 1;
345 }
346 mma7660fc_interface_debug_print("mma7660fc: x is %0.2fg.\n", g[0]);
347 mma7660fc_interface_debug_print("mma7660fc: y is %0.2fg.\n", g[1]);
348 mma7660fc_interface_debug_print("mma7660fc: z is %0.2fg.\n", g[2]);
349 }
350
351 /* finish read test */
352 mma7660fc_interface_debug_print("mma7660fc: finish read test.\n");
353 (void)mma7660fc_deinit(&gs_handle);
354
355 return 0;
356}
driver mma7660fc read test header file
uint8_t mma7660fc_set_auto_wake_up(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable auto wake up
uint8_t mma7660fc_init(mma7660fc_handle_t *handle)
initialize the chip
uint8_t mma7660fc_set_shake_x_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable shake x interrupt
uint8_t mma7660fc_set_sleep_counter_prescaler(mma7660fc_handle_t *handle, mma7660fc_sleep_counter_prescaler_t prescaler)
set sleep counter prescaler
uint8_t mma7660fc_set_interrupt_pin_type(mma7660fc_handle_t *handle, mma7660fc_interrupt_pin_type_t type)
set interrupt pin type
uint8_t mma7660fc_read(mma7660fc_handle_t *handle, int8_t raw[3], float g[3])
read the data
uint8_t mma7660fc_set_tap_detection_threshold(mma7660fc_handle_t *handle, uint8_t threshold)
set tap detection threshold
uint8_t mma7660fc_deinit(mma7660fc_handle_t *handle)
close the chip
uint8_t mma7660fc_set_shake_z_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable shake z interrupt
uint8_t mma7660fc_info(mma7660fc_info_t *info)
get chip's information
uint8_t mma7660fc_set_tilt_debounce_filter(mma7660fc_handle_t *handle, mma7660fc_tilt_debounce_filter_t filter)
set tilt debounce filter
uint8_t mma7660fc_set_auto_wake_rate(mma7660fc_handle_t *handle, mma7660fc_auto_wake_rate_t rate)
set auto wake rate
struct mma7660fc_info_s mma7660fc_info_t
mma7660fc information structure definition
uint8_t mma7660fc_set_mode(mma7660fc_handle_t *handle, mma7660fc_mode_t mode)
set mode
uint8_t mma7660fc_set_auto_sleep_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable auto sleep interrupt
struct mma7660fc_handle_s mma7660fc_handle_t
mma7660fc handle structure definition
uint8_t mma7660fc_set_update_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable update interrupt status
uint8_t mma7660fc_set_front_back_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable front back interrupt
uint8_t mma7660fc_set_tap_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable tap interrupt
uint8_t mma7660fc_set_tap_x_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable tap x detection
uint8_t mma7660fc_set_tap_y_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable tap y detection
uint8_t mma7660fc_set_auto_sleep(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable auto sleep
uint8_t mma7660fc_set_interrupt_active_level(mma7660fc_handle_t *handle, mma7660fc_interrupt_active_level_t level)
set interrupt active level
uint8_t mma7660fc_set_tap_pulse_debounce_count(mma7660fc_handle_t *handle, uint8_t count)
set tap pulse debounce count
uint8_t mma7660fc_set_tap_detection_rate(mma7660fc_handle_t *handle, mma7660fc_auto_sleep_rate_t rate)
set tap detection rate
uint8_t mma7660fc_set_shake_y_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable shake y interrupt
uint8_t mma7660fc_set_sleep_count(mma7660fc_handle_t *handle, uint8_t count)
set sleep count
uint8_t mma7660fc_set_tap_z_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable tap z detection
uint8_t mma7660fc_set_up_down_right_left_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable up down right left interrupt
@ MMA7660FC_INTERRUPT_PIN_TYPE_PUSH_PULL
@ MMA7660FC_BOOL_FALSE
@ MMA7660FC_INTERRUPT_ACTIVE_LEVEL_LOW
@ MMA7660FC_SLEEP_COUNTER_PRESCALER_1
@ MMA7660FC_AUTO_SLEEP_RATE_8
@ MMA7660FC_TILT_DEBOUNCE_FILTER_2
@ MMA7660FC_MODE_ACTIVE
@ MMA7660FC_AUTO_WAKE_RATE_16
void mma7660fc_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t mma7660fc_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void mma7660fc_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t mma7660fc_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t mma7660fc_interface_iic_init(void)
interface iic bus init
void mma7660fc_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t mma7660fc_interface_iic_deinit(void)
interface iic bus deinit
uint8_t mma7660fc_read_test(uint32_t times)
read test