LibDriver BMM150
Loading...
Searching...
No Matches
driver_bmm150_basic.c
Go to the documentation of this file.
1
36
37#include "driver_bmm150_basic.h"
38
39static bmm150_handle_t gs_handle;
40
51{
52 uint8_t res;
53
54 /* link interface function */
67
68 /* set the interface */
69 res = bmm150_set_interface(&gs_handle, interface);
70 if (res != 0)
71 {
72 bmm150_interface_debug_print("bmm150: set interface failed.\n");
73
74 return 1;
75 }
76
77 /* set addr pin */
78 res = bmm150_set_addr_pin(&gs_handle, addr_pin);
79 if (res != 0)
80 {
81 bmm150_interface_debug_print("bmm150: set addr pin failed.\n");
82
83 return 1;
84 }
85
86 /* bmm150 initialization */
87 res = bmm150_init(&gs_handle);
88 if (res != 0)
89 {
90 bmm150_interface_debug_print("bmm150: init failed.\n");
91
92 return 1;
93 }
94
95 /* power on */
96 res = bmm150_set_power_on(&gs_handle, BMM150_BOOL_TRUE);
97 if (res != 0)
98 {
99 bmm150_interface_debug_print("bmm150: set power on failed.\n");
100 (void)bmm150_deinit(&gs_handle);
101
102 return 1;
103 }
104
105 /* set advanced self test normal mode */
107 if (res != 0)
108 {
109 bmm150_interface_debug_print("bmm150: set advanced self test failed.\n");
110 (void)bmm150_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* disable self test */
116 res = bmm150_set_self_test(&gs_handle, BMM150_BOOL_FALSE);
117 if (res != 0)
118 {
119 bmm150_interface_debug_print("bmm150: set self test failed.\n");
120 (void)bmm150_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* disable data overrun */
127 if (res != 0)
128 {
129 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
130 (void)bmm150_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* disable overflow */
137 if (res != 0)
138 {
139 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
140 (void)bmm150_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* disable high threshold z */
147 if (res != 0)
148 {
149 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
150 (void)bmm150_deinit(&gs_handle);
151
152 return 1;
153 }
154
155 /* disable high threshold y */
157 if (res != 0)
158 {
159 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
160 (void)bmm150_deinit(&gs_handle);
161
162 return 1;
163 }
164
165 /* disable high threshold x */
167 if (res != 0)
168 {
169 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
170 (void)bmm150_deinit(&gs_handle);
171
172 return 1;
173 }
174
175 /* disable low threshold z */
177 if (res != 0)
178 {
179 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
180 (void)bmm150_deinit(&gs_handle);
181
182 return 1;
183 }
184
185 /* disable low threshold y */
187 if (res != 0)
188 {
189 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
190 (void)bmm150_deinit(&gs_handle);
191
192 return 1;
193 }
194
195 /* disable low threshold x */
197 if (res != 0)
198 {
199 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
200 (void)bmm150_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* disable data ready pin */
207 if (res != 0)
208 {
209 bmm150_interface_debug_print("bmm150: set data ready pin failed.\n");
210 (void)bmm150_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* disable interrupt pin */
217 if (res != 0)
218 {
219 bmm150_interface_debug_print("bmm150: set interrupt pin failed.\n");
220 (void)bmm150_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* enable channel z */
226 res = bmm150_set_channel_z(&gs_handle, BMM150_BOOL_TRUE);
227 if (res != 0)
228 {
229 bmm150_interface_debug_print("bmm150: set channel z failed.\n");
230 (void)bmm150_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 /* enable channel y */
236 res = bmm150_set_channel_y(&gs_handle, BMM150_BOOL_TRUE);
237 if (res != 0)
238 {
239 bmm150_interface_debug_print("bmm150: set channel y failed.\n");
240 (void)bmm150_deinit(&gs_handle);
241
242 return 1;
243 }
244
245 /* enable channel x */
246 res = bmm150_set_channel_x(&gs_handle, BMM150_BOOL_TRUE);
247 if (res != 0)
248 {
249 bmm150_interface_debug_print("bmm150: set channel x failed.\n");
250 (void)bmm150_deinit(&gs_handle);
251
252 return 1;
253 }
254
255 /* set default repxy number */
257 if (res != 0)
258 {
259 bmm150_interface_debug_print("bmm150: set repxy number failed.\n");
260 (void)bmm150_deinit(&gs_handle);
261
262 return 1;
263 }
264
265 /* set default repz number */
267 if (res != 0)
268 {
269 bmm150_interface_debug_print("bmm150: set repz number failed.\n");
270 (void)bmm150_deinit(&gs_handle);
271
272 return 1;
273 }
274
275 /* set default data rate */
277 if (res != 0)
278 {
279 bmm150_interface_debug_print("bmm150: set data rate failed.\n");
280 (void)bmm150_deinit(&gs_handle);
281
282 return 1;
283 }
284
285 /* set normal mode */
286 res = bmm150_set_mode(&gs_handle, BMM150_MODE_NORMAL);
287 if (res != 0)
288 {
289 bmm150_interface_debug_print("bmm150: set mode failed.\n");
290 (void)bmm150_deinit(&gs_handle);
291
292 return 1;
293 }
294
295 return 0;
296}
297
306uint8_t bmm150_basic_read(float ut[3])
307{
308 int16_t raw[3];
309
310 /* read data */
311 if (bmm150_read(&gs_handle, raw, ut) != 0)
312 {
313 return 1;
314 }
315
316 return 0;
317}
318
327{
328 /* set sleep mode */
329 if (bmm150_set_mode(&gs_handle, BMM150_MODE_SLEEP) != 0)
330 {
331 return 1;
332 }
333
334 /* deinit */
335 if (bmm150_deinit(&gs_handle) != 0)
336 {
337 return 1;
338 }
339
340 return 0;
341}
driver bmm150 basic header file
uint8_t bmm150_deinit(bmm150_handle_t *handle)
close the chip
uint8_t bmm150_init(bmm150_handle_t *handle)
initialize the chip
uint8_t bmm150_set_data_ready_pin(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable data ready pin
uint8_t bmm150_set_repz_number(bmm150_handle_t *handle, uint8_t number)
set repz number
uint8_t bmm150_set_interrupt_pin(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable interrupt pin
uint8_t bmm150_set_addr_pin(bmm150_handle_t *handle, bmm150_address_t addr_pin)
set the iic address pin
uint8_t bmm150_set_advanced_self_test(bmm150_handle_t *handle, bmm150_advanced_self_test_t test)
set advanced self test
uint8_t bmm150_set_interface(bmm150_handle_t *handle, bmm150_interface_t interface)
set the chip interface
bmm150_interface_t
bmm150 interface enumeration definition
uint8_t bmm150_set_channel_y(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable channel y
uint8_t bmm150_set_mode(bmm150_handle_t *handle, bmm150_mode_t mode)
set mode
uint8_t bmm150_set_power_on(bmm150_handle_t *handle, bmm150_bool_t enable)
set power on
struct bmm150_handle_s bmm150_handle_t
bmm150 handle structure definition
uint8_t bmm150_set_self_test(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable self test
uint8_t bmm150_read(bmm150_handle_t *handle, int16_t raw[3], float ut[3])
read data
uint8_t bmm150_set_channel_z(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable channel z
uint8_t bmm150_set_repxy_number(bmm150_handle_t *handle, uint8_t number)
set repxy number
bmm150_address_t
bmm150 address enumeration definition
uint8_t bmm150_set_interrupt(bmm150_handle_t *handle, bmm150_interrupt_status_t status, bmm150_bool_t enable)
enable or disable interrupt
uint8_t bmm150_set_data_rate(bmm150_handle_t *handle, bmm150_data_rate_t rate)
set data rate
uint8_t bmm150_set_channel_x(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable channel x
@ BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Z
@ BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Y
@ BMM150_INTERRUPT_STATUS_OVERFLOW
@ BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Y
@ BMM150_INTERRUPT_STATUS_DATA_OVERRUN
@ BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_X
@ BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_X
@ BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Z
@ BMM150_BOOL_FALSE
@ BMM150_BOOL_TRUE
@ BMM150_ADVANCED_SELF_TEST_NORMAL
@ BMM150_MODE_SLEEP
@ BMM150_MODE_NORMAL
uint8_t bmm150_basic_deinit(void)
basic example deinit
#define BMM150_BASIC_DEFAULT_DATA_RATE
#define BMM150_BASIC_DEFAULT_REPZ
#define BMM150_BASIC_DEFAULT_REPXY
bmm150 basic example default definition
uint8_t bmm150_basic_init(bmm150_interface_t interface, bmm150_address_t addr_pin)
basic example init
uint8_t bmm150_basic_read(float ut[3])
basic example read
uint8_t bmm150_interface_spi_init(void)
interface spi bus init
uint8_t bmm150_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t bmm150_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmm150_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void bmm150_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t bmm150_interface_iic_init(void)
interface iic bus init
uint8_t bmm150_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmm150_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t bmm150_interface_iic_deinit(void)
interface iic bus deinit
void bmm150_interface_debug_print(const char *const fmt,...)
interface print format data
void bmm150_interface_delay_ms(uint32_t ms)
interface delay ms