upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bmm150.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 Intel Corporation.
4  *
5  * The MIT License
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <unistd.h>
29 #include <string.h>
30 
31 #include <mraa/i2c.h>
32 #include <mraa/spi.h>
33 #include <mraa/gpio.h>
34 
35 #include "upm.h"
36 
37 #include "bmm150_defs.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
54  typedef struct _bmm150_context {
55  mraa_i2c_context i2c;
56  mraa_spi_context spi;
57  mraa_gpio_context gpioCS; // SPI CS pin
58  mraa_gpio_context gpioINT; // intr
59  mraa_gpio_context gpioDR; // DR (Data Ready) intr
60 
61  // using SPI?
62  bool isSPI;
63  BMM150_OPERATION_MODE_T opmode;
64 
65  // mag data
66  float magX;
67  float magY;
68  float magZ;
69 
70  // hall resistance (it is NOT futile!)
71  uint16_t hall;
72 
73  // trimming data
74  int8_t dig_x1;
75  int8_t dig_y1;
76 
77  int16_t dig_z4;
78  int8_t dig_x2;
79  int8_t dig_y2;
80 
81  int16_t dig_z2;
82  uint16_t dig_z1;
83  uint16_t dig_xyz1;
84  int16_t dig_z3;
85  int8_t dig_xy2;
86  uint8_t dig_xy1;
87  } *bmm150_context;
88 
89 
106  bmm150_context bmm150_init(int bus, int addr, int cs);
107 
113  void bmm150_close(bmm150_context dev);
114 
121  upm_result_t bmm150_update(const bmm150_context dev);
122 
129  uint8_t bmm150_get_chip_id(const bmm150_context dev);
130 
144  float *x, float *y, float *z);
145 
157  upm_result_t bmm150_devinit(const bmm150_context dev,
158  BMM150_USAGE_PRESETS_T usage);
159 
170  upm_result_t bmm150_set_preset_mode(const bmm150_context dev,
171  BMM150_USAGE_PRESETS_T usage);
172 
183  upm_result_t bmm150_reset(const bmm150_context dev);
184 
193  upm_result_t bmm150_set_output_data_rate(const bmm150_context dev,
194  BMM150_DATA_RATE_T odr);
195 
209  upm_result_t bmm150_set_power_bit(const bmm150_context dev, bool power);
210 
219  upm_result_t bmm150_set_opmode(const bmm150_context dev,
220  BMM150_OPERATION_MODE_T opmode);
221 
229  BMM150_OPERATION_MODE_T bmm150_get_opmode(const bmm150_context dev);
230 
239  uint8_t bmm150_get_interrupt_enable(const bmm150_context dev);
240 
249  upm_result_t bmm150_set_interrupt_enable(const bmm150_context dev,
250  uint8_t bits);
251 
261  uint8_t bmm150_get_interrupt_config(const bmm150_context dev);
262 
273  upm_result_t bmm150_set_interrupt_config(const bmm150_context dev,
274  uint8_t bits);
275 
284  uint8_t bmm150_get_interrupt_status(const bmm150_context dev);
285 
296  upm_result_t bmm150_set_repetitions_xy(const bmm150_context dev,
297  uint8_t reps);
298 
309  upm_result_t bmm150_set_repetitions_z(const bmm150_context dev,
310  uint8_t reps);
311 
326  upm_result_t bmm150_install_isr(const bmm150_context dev,
327  BMM150_INTERRUPT_PINS_T intr,
328  int gpio, mraa_gpio_edge_t level,
329  void (*isr)(void *), void *arg);
330 
338  void bmm150_uninstall_isr(const bmm150_context dev,
339  BMM150_INTERRUPT_PINS_T intr);
340 
348  uint8_t bmm150_read_reg(const bmm150_context dev, uint8_t reg);
349 
358  int bmm150_read_regs(const bmm150_context dev, uint8_t reg,
359  uint8_t *buffer, int len);
360 
369  upm_result_t bmm150_write_reg(const bmm150_context dev,
370  uint8_t reg, uint8_t val);
371 
372 #ifdef __cplusplus
373 }
374 #endif
upm_result_t bmm150_write_reg(const bmm150_context dev, uint8_t reg, uint8_t val)
Definition: bmm150.c:474
upm_result_t bmm150_install_isr(const bmm150_context dev, BMM150_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: bmm150.c:736
bmm150_context bmm150_init(int bus, int addr, int cs)
Definition: bmm150.c:192
upm_result_t bmm150_reset(const bmm150_context dev)
Definition: bmm150.c:530
upm_result_t bmm150_set_output_data_rate(const bmm150_context dev, BMM150_DATA_RATE_T odr)
Definition: bmm150.c:550
upm_result_t bmm150_set_repetitions_z(const bmm150_context dev, uint8_t reps)
Definition: bmm150.c:671
upm_result_t bmm150_set_opmode(const bmm150_context dev, BMM150_OPERATION_MODE_T opmode)
Definition: bmm150.c:586
uint8_t bmm150_get_interrupt_config(const bmm150_context dev)
Definition: bmm150.c:635
upm_result_t bmm150_update(const bmm150_context dev)
Definition: bmm150.c:351
uint8_t bmm150_get_chip_id(const bmm150_context dev)
Definition: bmm150.c:508
upm_result_t bmm150_set_power_bit(const bmm150_context dev, bool power)
Definition: bmm150.c:566
struct _bmm150_context * bmm150_context
void bmm150_get_magnetometer(const bmm150_context dev, float *x, float *y, float *z)
Definition: bmm150.c:515
upm_result_t bmm150_set_interrupt_config(const bmm150_context dev, uint8_t bits)
Definition: bmm150.c:642
upm_result_t bmm150_devinit(const bmm150_context dev, BMM150_USAGE_PRESETS_T usage)
Definition: bmm150.c:312
uint8_t bmm150_get_interrupt_status(const bmm150_context dev)
Definition: bmm150.c:653
upm_result_t bmm150_set_preset_mode(const bmm150_context dev, BMM150_USAGE_PRESETS_T usage)
Definition: bmm150.c:682
uint8_t bmm150_get_interrupt_enable(const bmm150_context dev)
Definition: bmm150.c:617
Definition: bmm150.h:54
upm_result_t bmm150_set_repetitions_xy(const bmm150_context dev, uint8_t reps)
Definition: bmm150.c:660
void bmm150_close(bmm150_context dev)
Definition: bmm150.c:295
upm_result_t bmm150_set_interrupt_enable(const bmm150_context dev, uint8_t bits)
Definition: bmm150.c:624
int bmm150_read_regs(const bmm150_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: bmm150.c:439
uint8_t bmm150_read_reg(const bmm150_context dev, uint8_t reg)
Definition: bmm150.c:415
BMM150_OPERATION_MODE_T bmm150_get_opmode(const bmm150_context dev)
Definition: bmm150.c:604
void bmm150_uninstall_isr(const bmm150_context dev, BMM150_INTERRUPT_PINS_T intr)
Definition: bmm150.c:778