LibDriver MMA7660FC
Loading...
Searching...
No Matches
driver_mma7660fc_motion.c
Go to the documentation of this file.
1
36
38
39static mma7660fc_handle_t gs_handle;
40
49{
50 if (mma7660fc_irq_handler(&gs_handle) != 0)
51 {
52 return 1;
53 }
54
55 return 0;
56}
57
66uint8_t mma7660fc_motion_init(void (*callback)(uint8_t type))
67{
68 uint8_t res;
69 uint8_t count;
70
71 /* link interface function */
79 DRIVER_MMA7660FC_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
80
81 /* mma7660fc init */
82 res = mma7660fc_init(&gs_handle);
83 if (res != 0)
84 {
85 mma7660fc_interface_debug_print("mma7660fc: init failed.\n");
86
87 return 1;
88 }
89
90 /* set default front back interrupt */
92 if (res != 0)
93 {
94 mma7660fc_interface_debug_print("mma7660fc: set front back interrupt failed.\n");
95 (void)mma7660fc_deinit(&gs_handle);
96
97 return 1;
98 }
99
100 /* set default up down right left interrupt */
102 if (res != 0)
103 {
104 mma7660fc_interface_debug_print("mma7660fc: set up down right left interrupt failed.\n");
105 (void)mma7660fc_deinit(&gs_handle);
106
107 return 1;
108 }
109
110 /* set default tap interrupt */
112 if (res != 0)
113 {
114 mma7660fc_interface_debug_print("mma7660fc: set tap interrupt failed.\n");
115 (void)mma7660fc_deinit(&gs_handle);
116
117 return 1;
118 }
119
120 /* set default auto sleep interrupt */
122 if (res != 0)
123 {
124 mma7660fc_interface_debug_print("mma7660fc: set auto sleep interrupt failed.\n");
125 (void)mma7660fc_deinit(&gs_handle);
126
127 return 1;
128 }
129
130 /* set default update interrupt */
132 if (res != 0)
133 {
134 mma7660fc_interface_debug_print("mma7660fc: set update interrupt failed.\n");
135 (void)mma7660fc_deinit(&gs_handle);
136
137 return 1;
138 }
139
140 /* set default shake x interrupt */
142 if (res != 0)
143 {
144 mma7660fc_interface_debug_print("mma7660fc: set shake x interrupt failed.\n");
145 (void)mma7660fc_deinit(&gs_handle);
146
147 return 1;
148 }
149
150 /* set default shake y interrupt */
152 if (res != 0)
153 {
154 mma7660fc_interface_debug_print("mma7660fc: set shake y interrupt failed.\n");
155 (void)mma7660fc_deinit(&gs_handle);
156
157 return 1;
158 }
159
160 /* set default shake z interrupt */
162 if (res != 0)
163 {
164 mma7660fc_interface_debug_print("mma7660fc: set shake z interrupt failed.\n");
165 (void)mma7660fc_deinit(&gs_handle);
166
167 return 1;
168 }
169
170 /* set default sleep counter prescaler */
172 if (res != 0)
173 {
174 mma7660fc_interface_debug_print("mma7660fc: set sleep counter prescaler failed.\n");
175 (void)mma7660fc_deinit(&gs_handle);
176
177 return 1;
178 }
179
180 /* set default tap detection rate */
182 if (res != 0)
183 {
184 mma7660fc_interface_debug_print("mma7660fc: set tap detection rate failed.\n");
185 (void)mma7660fc_deinit(&gs_handle);
186
187 return 1;
188 }
189
190 /* set default auto wake rate */
192 if (res != 0)
193 {
194 mma7660fc_interface_debug_print("mma7660fc: set auto wake rate failed.\n");
195 (void)mma7660fc_deinit(&gs_handle);
196
197 return 1;
198 }
199
200 /* set default sleep count */
202 if (res != 0)
203 {
204 mma7660fc_interface_debug_print("mma7660fc: set sleep count failed.\n");
205 (void)mma7660fc_deinit(&gs_handle);
206
207 return 1;
208 }
209
210 /* set default auto wake up */
212 if (res != 0)
213 {
214 mma7660fc_interface_debug_print("mma7660fc: set auto wake up failed.\n");
215 (void)mma7660fc_deinit(&gs_handle);
216
217 return 1;
218 }
219
220 /* set default auto sleep */
222 if (res != 0)
223 {
224 mma7660fc_interface_debug_print("mma7660fc: set auto sleep failed.\n");
225 (void)mma7660fc_deinit(&gs_handle);
226
227 return 1;
228 }
229
230 /* set default interrupt pin type */
232 if (res != 0)
233 {
234 mma7660fc_interface_debug_print("mma7660fc: set interrupt pin type failed.\n");
235 (void)mma7660fc_deinit(&gs_handle);
236
237 return 1;
238 }
239
240 /* set default interrupt active level */
242 if (res != 0)
243 {
244 mma7660fc_interface_debug_print("mma7660fc: set interrupt active level failed.\n");
245 (void)mma7660fc_deinit(&gs_handle);
246
247 return 1;
248 }
249
250 /* set default tilt debounce filter */
252 if (res != 0)
253 {
254 mma7660fc_interface_debug_print("mma7660fc: set tilt debounce filter failed.\n");
255 (void)mma7660fc_deinit(&gs_handle);
256
257 return 1;
258 }
259
260 /* set default tap detection threshold */
262 if (res != 0)
263 {
264 mma7660fc_interface_debug_print("mma7660fc: set tap detection threshold failed.\n");
265 (void)mma7660fc_deinit(&gs_handle);
266
267 return 1;
268 }
269
270 /* set default tap x detection */
272 if (res != 0)
273 {
274 mma7660fc_interface_debug_print("mma7660fc: set tap x detection failed.\n");
275 (void)mma7660fc_deinit(&gs_handle);
276
277 return 1;
278 }
279
280 /* set default tap y detection */
282 if (res != 0)
283 {
284 mma7660fc_interface_debug_print("mma7660fc: set tap y detection failed.\n");
285 (void)mma7660fc_deinit(&gs_handle);
286
287 return 1;
288 }
289
290 /* set default tap z detection */
292 if (res != 0)
293 {
294 mma7660fc_interface_debug_print("mma7660fc: set tap z detection failed.\n");
295 (void)mma7660fc_deinit(&gs_handle);
296
297 return 1;
298 }
299
300 /* set default tap pulse debounce */
302 if (res != 0)
303 {
304 mma7660fc_interface_debug_print("mma7660fc: tap pulse debounce convert to register failed.\n");
305 (void)mma7660fc_deinit(&gs_handle);
306
307 return 1;
308 }
309
310 /* set tap pulse debounce count */
311 res = mma7660fc_set_tap_pulse_debounce_count(&gs_handle, count);
312 if (res != 0)
313 {
314 mma7660fc_interface_debug_print("mma7660fc: set tap pulse debounce count failed.\n");
315 (void)mma7660fc_deinit(&gs_handle);
316
317 return 1;
318 }
319
320 /* set active mode */
321 res = mma7660fc_set_mode(&gs_handle, MMA7660FC_MODE_ACTIVE);
322 if (res != 0)
323 {
324 mma7660fc_interface_debug_print("mma7660fc: set mode failed.\n");
325 (void)mma7660fc_deinit(&gs_handle);
326
327 return 1;
328 }
329
330 return 0;
331}
332
341uint8_t mma7660fc_motion_read(float g[3])
342{
343 uint8_t res;
344 int8_t raw[3];
345
346 res = mma7660fc_read(&gs_handle, raw, g);
347 if (res != 0)
348 {
349 return 1;
350 }
351
352 return 0;
353}
354
363{
364 /* close mma7660fc */
365 if (mma7660fc_deinit(&gs_handle) != 0)
366 {
367 return 1;
368 }
369
370 return 0;
371}
driver mma7660fc motion 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_tap_pulse_debounce_convert_to_register(mma7660fc_handle_t *handle, float ms, uint8_t *reg)
convert tap pulse debounce to the register raw data
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
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_irq_handler(mma7660fc_handle_t *handle)
irq handler
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_MODE_ACTIVE
#define MMA7660FC_MOTION_DEFAULT_UPDATE_INTERRUPT
uint8_t mma7660fc_motion_read(float g[3])
motion example read
uint8_t mma7660fc_motion_deinit(void)
motion example deinit
#define MMA7660FC_MOTION_DEFAULT_AUTO_SLEEP
#define MMA7660FC_MOTION_DEFAULT_INTERRUPT_PIN_TYPE
#define MMA7660FC_MOTION_DEFAULT_SLEEP_COUNTER_PRESCALER
#define MMA7660FC_MOTION_DEFAULT_TAP_INTERRUPT
#define MMA7660FC_MOTION_DEFAULT_FRONT_BACK_INTERRUPT
mma7660fc motion example default definition
uint8_t mma7660fc_motion_irq_handler(void)
motion irq
#define MMA7660FC_MOTION_DEFAULT_AUTO_WAKE_UP
#define MMA7660FC_MOTION_DEFAULT_SLEEP_COUNT
#define MMA7660FC_MOTION_DEFAULT_TAP_Y
#define MMA7660FC_MOTION_DEFAULT_SHAKE_X
#define MMA7660FC_MOTION_DEFAULT_SHAKE_Y
#define MMA7660FC_MOTION_DEFAULT_TAP_DETECTION_THRESHOLD
#define MMA7660FC_MOTION_DEFAULT_TAP_PULSE_DEBOUNCE
#define MMA7660FC_MOTION_DEFAULT_TAP_Z
#define MMA7660FC_MOTION_DEFAULT_TAP_X
#define MMA7660FC_MOTION_DEFAULT_AUTO_WAKE_RATE
#define MMA7660FC_MOTION_DEFAULT_AUTO_SLEEP_INTERRUPT
#define MMA7660FC_MOTION_DEFAULT_INTERRUPT_ACTIVE_LEVEL
#define MMA7660FC_MOTION_DEFAULT_AUTO_SLEEP_RATE
#define MMA7660FC_MOTION_DEFAULT_TILT_DEBOUNCE_FILTER
uint8_t mma7660fc_motion_init(void(*callback)(uint8_t type))
motion example init
#define MMA7660FC_MOTION_DEFAULT_UP_DOWN_RIGHT_LEFT_INTERRUPT
#define MMA7660FC_MOTION_DEFAULT_SHAKE_Z
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