upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bmg160.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 "bmg160_defs.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
54  typedef struct _bmg160_context {
55  mraa_i2c_context i2c;
56  mraa_spi_context spi;
57  mraa_gpio_context gpioCS; // SPI CS pin
58  mraa_gpio_context gpio1; // intr 1
59  mraa_gpio_context gpio2; // intr 2
60 
61  // using SPI?
62  bool isSPI;
63  // use the FIFO?
64  bool useFIFO;
65 
66  // always stored in C
67  float temperature;
68 
69  // gyr data
70  float gyrX;
71  float gyrY;
72  float gyrZ;
73 
74  // gyr scaling
75  float gyrScale;
76  } *bmg160_context;
77 
94  bmg160_context bmg160_init(int bus, int addr, int cs);
95 
101  void bmg160_close(bmg160_context dev);
102 
109  upm_result_t bmg160_update(const bmg160_context dev);
110 
117  uint8_t bmg160_get_chip_id(const bmg160_context dev);
118 
131  void bmg160_get_gyroscope(const bmg160_context dev,
132  float *x, float *y, float *z);
133 
142  float bmg160_get_temperature(const bmg160_context dev);
143 
158  upm_result_t bmg160_devinit(const bmg160_context dev,
159  BMG160_POWER_MODE_T pwr,
160  BMG160_RANGE_T range,
161  BMG160_BW_T bw);
162 
172  upm_result_t bmg160_reset(const bmg160_context dev);
173 
182  upm_result_t bmg160_set_range(const bmg160_context dev,
183  BMG160_RANGE_T range);
184 
192  upm_result_t bmg160_set_bandwidth(const bmg160_context dev,
193  BMG160_BW_T bw);
194 
205  upm_result_t bmg160_set_power_mode(const bmg160_context dev,
206  BMG160_POWER_MODE_T power);
207 
224  void bmg160_enable_fifo(const bmg160_context dev, bool useFIFO);
225 
234  upm_result_t bmg160_fifo_set_watermark(const bmg160_context dev, int wm);
235 
246  upm_result_t bmg160_fifo_config(const bmg160_context dev,
247  BMG160_FIFO_MODE_T mode,
248  BMG160_FIFO_DATA_SEL_T axes);
249 
258  uint8_t bmg160_get_interrupt_enable0(const bmg160_context dev);
259 
268  upm_result_t bmg160_set_interrupt_enable0(const bmg160_context dev,
269  uint8_t bits);
270 
279  uint8_t bmg160_get_interrupt_map0(const bmg160_context dev);
280 
290  upm_result_t bmg160_set_interrupt_map0(const bmg160_context dev,
291  uint8_t bits);
292 
300  uint8_t bmg160_get_interrupt_map1(const bmg160_context dev);
301 
310  upm_result_t bmg160_set_interrupt_map1(const bmg160_context dev,
311  uint8_t bits);
312 
322  uint8_t bmg160_get_interrupt_src(const bmg160_context dev);
323 
334  upm_result_t bmg160_set_interrupt_src(const bmg160_context dev,
335  uint8_t bits);
336 
347 
359  uint8_t bits);
360 
367  upm_result_t bmg160_clear_interrupt_latches(const bmg160_context dev);
368 
376  BMG160_RST_LATCH_T bmg160_get_interrupt_latch_behavior(
377  const bmg160_context dev);
378 
388  BMG160_RST_LATCH_T latch);
389 
398  uint8_t bmg160_get_interrupt_status0(const bmg160_context dev);
399 
407  uint8_t bmg160_get_interrupt_status1(const bmg160_context dev);
408 
416  uint8_t bmg160_get_interrupt_status2(const bmg160_context dev);
417 
425  uint8_t bmg160_get_interrupt_status3(const bmg160_context dev);
426 
440  upm_result_t bmg160_enable_register_shadowing(const bmg160_context dev,
441  bool shadow);
442 
453  upm_result_t bmg160_enable_output_filtering(const bmg160_context dev,
454  bool filter);
455 
470  upm_result_t bmg160_install_isr(const bmg160_context dev,
471  BMG160_INTERRUPT_PINS_T intr, int gpio,
472  mraa_gpio_edge_t level,
473  void (*isr)(void *), void *arg);
474 
482  void bmg160_uninstall_isr(const bmg160_context dev,
483  BMG160_INTERRUPT_PINS_T intr);
484 
492  uint8_t bmg160_read_reg(const bmg160_context dev, uint8_t reg);
493 
502  int bmg160_read_regs(const bmg160_context dev, uint8_t reg,
503  uint8_t *buffer, int len);
504 
513  upm_result_t bmg160_write_reg(const bmg160_context dev,
514  uint8_t reg, uint8_t val);
515 
516 
517 #ifdef __cplusplus
518 }
519 #endif
upm_result_t bmg160_update(const bmg160_context dev)
Definition: bmg160.c:204
upm_result_t bmg160_fifo_config(const bmg160_context dev, BMG160_FIFO_MODE_T mode, BMG160_FIFO_DATA_SEL_T axes)
Definition: bmg160.c:481
upm_result_t bmg160_set_power_mode(const bmg160_context dev, BMG160_POWER_MODE_T power)
Definition: bmg160.c:450
upm_result_t bmg160_enable_output_filtering(const bmg160_context dev, bool filter)
Definition: bmg160.c:659
upm_result_t bmg160_devinit(const bmg160_context dev, BMG160_POWER_MODE_T pwr, BMG160_RANGE_T range, BMG160_BW_T bw)
Definition: bmg160.c:166
upm_result_t bmg160_set_bandwidth(const bmg160_context dev, BMG160_BW_T bw)
Definition: bmg160.c:439
upm_result_t bmg160_set_interrupt_map1(const bmg160_context dev, uint8_t bits)
Definition: bmg160.c:544
struct _bmg160_context * bmg160_context
void bmg160_close(bmg160_context dev)
Definition: bmg160.c:149
upm_result_t bmg160_install_isr(const bmg160_context dev, BMG160_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: bmg160.c:710
uint8_t bmg160_get_interrupt_src(const bmg160_context dev)
Definition: bmg160.c:555
uint8_t bmg160_get_interrupt_output_control(const bmg160_context dev)
Definition: bmg160.c:575
uint8_t bmg160_get_interrupt_status3(const bmg160_context dev)
Definition: bmg160.c:702
uint8_t bmg160_get_interrupt_map0(const bmg160_context dev)
Definition: bmg160.c:517
upm_result_t bmg160_reset(const bmg160_context dev)
Definition: bmg160.c:389
int bmg160_read_regs(const bmg160_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: bmg160.c:286
upm_result_t bmg160_enable_register_shadowing(const bmg160_context dev, bool shadow)
Definition: bmg160.c:640
uint8_t bmg160_get_interrupt_status2(const bmg160_context dev)
Definition: bmg160.c:694
upm_result_t bmg160_set_range(const bmg160_context dev, BMG160_RANGE_T range)
Definition: bmg160.c:401
float bmg160_get_temperature(const bmg160_context dev)
Definition: bmg160.c:382
uint8_t bmg160_get_interrupt_map1(const bmg160_context dev)
Definition: bmg160.c:537
uint8_t bmg160_get_interrupt_enable0(const bmg160_context dev)
Definition: bmg160.c:496
uint8_t bmg160_get_chip_id(const bmg160_context dev)
Definition: bmg160.c:360
upm_result_t bmg160_write_reg(const bmg160_context dev, uint8_t reg, uint8_t val)
Definition: bmg160.c:326
upm_result_t bmg160_fifo_set_watermark(const bmg160_context dev, int wm)
Definition: bmg160.c:468
uint8_t bmg160_get_interrupt_status0(const bmg160_context dev)
Definition: bmg160.c:678
BMG160_RST_LATCH_T bmg160_get_interrupt_latch_behavior(const bmg160_context dev)
Definition: bmg160.c:611
bmg160_context bmg160_init(int bus, int addr, int cs)
Definition: bmg160.c:55
upm_result_t bmg160_clear_interrupt_latches(const bmg160_context dev)
Definition: bmg160.c:596
upm_result_t bmg160_set_interrupt_map0(const bmg160_context dev, uint8_t bits)
Definition: bmg160.c:525
void bmg160_uninstall_isr(const bmg160_context dev, BMG160_INTERRUPT_PINS_T intr)
Definition: bmg160.c:752
upm_result_t bmg160_set_interrupt_latch_behavior(const bmg160_context dev, BMG160_RST_LATCH_T latch)
Definition: bmg160.c:623
void bmg160_enable_fifo(const bmg160_context dev, bool useFIFO)
Definition: bmg160.c:255
uint8_t bmg160_read_reg(const bmg160_context dev, uint8_t reg)
Definition: bmg160.c:262
upm_result_t bmg160_set_interrupt_output_control(const bmg160_context dev, uint8_t bits)
Definition: bmg160.c:583
upm_result_t bmg160_set_interrupt_src(const bmg160_context dev, uint8_t bits)
Definition: bmg160.c:563
upm_result_t bmg160_set_interrupt_enable0(const bmg160_context dev, uint8_t bits)
Definition: bmg160.c:504
Definition: bmg160.h:54
uint8_t bmg160_get_interrupt_status1(const bmg160_context dev)
Definition: bmg160.c:686
void bmg160_get_gyroscope(const bmg160_context dev, float *x, float *y, float *z)
Definition: bmg160.c:367