LibDriver MMA7660FC
Loading...
Searching...
No Matches
driver_mma7660fc_basic.c
Go to the documentation of this file.
1
36
38
39static mma7660fc_handle_t gs_handle;
40
49{
50 uint8_t res;
51
52 /* link interface function */
61
62 /* mma7660fc init */
63 res = mma7660fc_init(&gs_handle);
64 if (res != 0)
65 {
66 mma7660fc_interface_debug_print("mma7660fc: init failed.\n");
67
68 return 1;
69 }
70
71 /* set sleep count 0 */
72 res = mma7660fc_set_sleep_count(&gs_handle, 0);
73 if (res != 0)
74 {
75 mma7660fc_interface_debug_print("mma7660fc: set sleep count failed.\n");
76 (void)mma7660fc_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* disable front back interrupt */
83 if (res != 0)
84 {
85 mma7660fc_interface_debug_print("mma7660fc: set front back interrupt failed.\n");
86 (void)mma7660fc_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* disable up down right left interrupt */
93 if (res != 0)
94 {
95 mma7660fc_interface_debug_print("mma7660fc: set up down right left interrupt failed.\n");
96 (void)mma7660fc_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* disable tap interrupt */
103 if (res != 0)
104 {
105 mma7660fc_interface_debug_print("mma7660fc: set tap interrupt failed.\n");
106 (void)mma7660fc_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* disable auto sleep interrupt */
113 if (res != 0)
114 {
115 mma7660fc_interface_debug_print("mma7660fc: set auto sleep interrupt failed.\n");
116 (void)mma7660fc_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* disable update interrupt */
123 if (res != 0)
124 {
125 mma7660fc_interface_debug_print("mma7660fc: set update interrupt failed.\n");
126 (void)mma7660fc_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* disable shake x interrupt */
133 if (res != 0)
134 {
135 mma7660fc_interface_debug_print("mma7660fc: set shake x interrupt failed.\n");
136 (void)mma7660fc_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 /* disable shake y interrupt */
143 if (res != 0)
144 {
145 mma7660fc_interface_debug_print("mma7660fc: set shake y interrupt failed.\n");
146 (void)mma7660fc_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 /* disable shake z interrupt */
153 if (res != 0)
154 {
155 mma7660fc_interface_debug_print("mma7660fc: set shake z interrupt failed.\n");
156 (void)mma7660fc_deinit(&gs_handle);
157
158 return 1;
159 }
160
161 /* disable auto wake up */
163 if (res != 0)
164 {
165 mma7660fc_interface_debug_print("mma7660fc: set auto wake up failed.\n");
166 (void)mma7660fc_deinit(&gs_handle);
167
168 return 1;
169 }
170
171 /* disable auto sleep */
173 if (res != 0)
174 {
175 mma7660fc_interface_debug_print("mma7660fc: set auto sleep failed.\n");
176 (void)mma7660fc_deinit(&gs_handle);
177
178 return 1;
179 }
180
181 /* set sleep counter prescaler 1 */
183 if (res != 0)
184 {
185 mma7660fc_interface_debug_print("mma7660fc: set sleep counter prescaler failed.\n");
186 (void)mma7660fc_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* set interrupt pin type push pull */
193 if (res != 0)
194 {
195 mma7660fc_interface_debug_print("mma7660fc: set interrupt pin type failed.\n");
196 (void)mma7660fc_deinit(&gs_handle);
197
198 return 1;
199 }
200
201 /* set interrupt active level low */
203 if (res != 0)
204 {
205 mma7660fc_interface_debug_print("mma7660fc: set interrupt active level failed.\n");
206 (void)mma7660fc_deinit(&gs_handle);
207
208 return 1;
209 }
210
211 /* set tap detection rate 8 */
213 if (res != 0)
214 {
215 mma7660fc_interface_debug_print("mma7660fc: set tap detection rate failed.\n");
216 (void)mma7660fc_deinit(&gs_handle);
217
218 return 1;
219 }
220
221 /* set auto wake rate 16 */
223 if (res != 0)
224 {
225 mma7660fc_interface_debug_print("mma7660fc: set auto wake rate failed.\n");
226 (void)mma7660fc_deinit(&gs_handle);
227
228 return 1;
229 }
230
231 /* set tilt debounce filter 2 */
233 if (res != 0)
234 {
235 mma7660fc_interface_debug_print("mma7660fc: set tilt debounce filter failed.\n");
236 (void)mma7660fc_deinit(&gs_handle);
237
238 return 1;
239 }
240
241 /* set tap detection threshold 0 */
242 res = mma7660fc_set_tap_detection_threshold(&gs_handle, 0);
243 if (res != 0)
244 {
245 mma7660fc_interface_debug_print("mma7660fc: set tap detection threshold failed.\n");
246 (void)mma7660fc_deinit(&gs_handle);
247
248 return 1;
249 }
250
251 /* disable tap x detection */
253 if (res != 0)
254 {
255 mma7660fc_interface_debug_print("mma7660fc: set tap x detection failed.\n");
256 (void)mma7660fc_deinit(&gs_handle);
257
258 return 1;
259 }
260
261 /* disable tap y detection */
263 if (res != 0)
264 {
265 mma7660fc_interface_debug_print("mma7660fc: set tap y detection failed.\n");
266 (void)mma7660fc_deinit(&gs_handle);
267
268 return 1;
269 }
270
271 /* disable tap z detection */
273 if (res != 0)
274 {
275 mma7660fc_interface_debug_print("mma7660fc: set tap z detection failed.\n");
276 (void)mma7660fc_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* set tap pulse debounce count 0 */
282 res = mma7660fc_set_tap_pulse_debounce_count(&gs_handle, 0);
283 if (res != 0)
284 {
285 mma7660fc_interface_debug_print("mma7660fc: set tap pulse debounce count failed.\n");
286 (void)mma7660fc_deinit(&gs_handle);
287
288 return 1;
289 }
290
291 /* set mode active */
292 res = mma7660fc_set_mode(&gs_handle, MMA7660FC_MODE_ACTIVE);
293 if (res != 0)
294 {
295 mma7660fc_interface_debug_print("mma7660fc: set mode failed.\n");
296 (void)mma7660fc_deinit(&gs_handle);
297
298 return 1;
299 }
300
301 return 0;
302}
303
312uint8_t mma7660fc_basic_read(float g[3])
313{
314 uint8_t res;
315 int8_t raw[3];
316
317 res = mma7660fc_read(&gs_handle, raw, g);
318 if (res != 0)
319 {
320 return 1;
321 }
322
323 return 0;
324}
325
334{
335 /* close mma7660fc */
336 if (mma7660fc_deinit(&gs_handle) != 0)
337 {
338 return 1;
339 }
340
341 return 0;
342}
driver mma7660fc basic 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_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_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
uint8_t mma7660fc_basic_deinit(void)
basic example deinit
uint8_t mma7660fc_basic_init(void)
basic example init
uint8_t mma7660fc_basic_read(float g[3])
basic example read
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