upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bma250e.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 "bma250e_defs.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
54  typedef struct _bma250e_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  // does this chip support the fifo?
70  bool fifoAvailable;
71 
72  // supported resolution
73  BMA250E_RESOLUTION_T resolution;
74 
75  // acc data
76  float accX;
77  float accY;
78  float accZ;
79 
80  // acceleration scaling
81  float accScale;
82  } *bma250e_context;
83 
100  bma250e_context bma250e_init(int bus, int addr, int cs);
101 
107  void bma250e_close(bma250e_context dev);
108 
115  upm_result_t bma250e_update(const bma250e_context dev);
116 
123  uint8_t bma250e_get_chip_id(const bma250e_context dev);
124 
138  float *x, float *y, float *z);
139 
148  float bma250e_get_temperature(const bma250e_context dev);
149 
161  upm_result_t bma250e_devinit(const bma250e_context dev,
162  BMA250E_POWER_MODE_T pwr,
163  BMA250E_RANGE_T range,
164  BMA250E_BW_T bw);
165 
175  upm_result_t bma250e_reset(const bma250e_context dev);
176 
185  upm_result_t bma250e_set_range(const bma250e_context dev,
186  BMA250E_RANGE_T range);
187 
195  upm_result_t bma250e_set_bandwidth(const bma250e_context dev,
196  BMA250E_BW_T bw);
197 
219  upm_result_t bma250e_set_power_mode(const bma250e_context dev,
220  BMA250E_POWER_MODE_T power);
221 
238  void bma250e_enable_fifo(const bma250e_context dev, bool useFIFO);
239 
248  upm_result_t bma250e_fifo_set_watermark(const bma250e_context dev, int wm);
249 
260  upm_result_t bma250e_fifo_config(const bma250e_context dev,
261  BMA250E_FIFO_MODE_T mode,
262  BMA250E_FIFO_DATA_SEL_T axes);
263 
275  upm_result_t bma250e_set_self_test(const bma250e_context dev,
276  bool sign, bool amp,
277  BMA250E_SELFTTEST_AXIS_T axis);
278 
288 
297  upm_result_t bma250e_set_interrupt_enable0(const bma250e_context dev,
298  uint8_t bits);
299 
309 
318  upm_result_t bma250e_set_interrupt_enable1(const bma250e_context dev,
319  uint8_t bits);
329 
338  upm_result_t bma250e_set_interrupt_enable2(const bma250e_context dev,
339  uint8_t bits);
340 
349  uint8_t bma250e_get_interrupt_map0(const bma250e_context dev);
350 
360  upm_result_t bma250e_set_interrupt_map0(const bma250e_context dev,
361  uint8_t bits);
362 
370  uint8_t bma250e_get_interrupt_map1(const bma250e_context dev);
371 
380  upm_result_t bma250e_set_interrupt_map1(const bma250e_context dev,
381  uint8_t bits);
382 
390  uint8_t bma250e_get_interrupt_map2(const bma250e_context dev);
391 
400  upm_result_t bma250e_set_interrupt_map2(const bma250e_context dev,
401  uint8_t bits);
402 
412  uint8_t bma250e_get_interrupt_src(const bma250e_context dev);
413 
424  upm_result_t bma250e_set_interrupt_src(const bma250e_context dev,
425  uint8_t bits);
426 
437 
449  uint8_t bits);
450 
457  upm_result_t bma250e_clear_interrupt_latches(const bma250e_context dev);
458 
466  BMA250E_RST_LATCH_T bma250e_get_interrupt_latch_behavior(
467  const bma250e_context dev);
468 
478  const bma250e_context dev,
479  BMA250E_RST_LATCH_T latch);
480 
490 
499 
508 
520 
529  const bma250e_context dev);
530 
544  upm_result_t bma250e_enable_register_shadowing(const bma250e_context dev,
545  bool shadow);
546 
558  upm_result_t bma250e_enable_output_filtering(const bma250e_context dev,
559  bool filter);
560 
570  upm_result_t bma250e_set_low_power_mode2(const bma250e_context dev);
571 
586  upm_result_t bma250e_install_isr(const bma250e_context dev,
587  BMA250E_INTERRUPT_PINS_T intr, int gpio,
588  mraa_gpio_edge_t level,
589  void (*isr)(void *), void *arg);
590 
598  void bma250e_uninstall_isr(const bma250e_context dev,
599  BMA250E_INTERRUPT_PINS_T intr);
600 
608  uint8_t bma250e_read_reg(const bma250e_context dev, uint8_t reg);
609 
618  int bma250e_read_regs(const bma250e_context dev, uint8_t reg,
619  uint8_t *buffer, int len);
620 
629  upm_result_t bma250e_write_reg(const bma250e_context dev,
630  uint8_t reg, uint8_t val);
631 
632 
633 #ifdef __cplusplus
634 }
635 #endif
upm_result_t bma250e_set_interrupt_enable0(const bma250e_context dev, uint8_t bits)
Definition: bma250e.c:596
void bma250e_close(bma250e_context dev)
Definition: bma250e.c:171
float bma250e_get_temperature(const bma250e_context dev)
Definition: bma250e.c:426
uint8_t bma250e_get_interrupt_status3_bits(const bma250e_context dev)
Definition: bma250e.c:855
upm_result_t bma250e_clear_interrupt_latches(const bma250e_context dev)
Definition: bma250e.c:746
uint8_t bma250e_get_interrupt_map0(const bma250e_context dev)
Definition: bma250e.c:651
upm_result_t bma250e_fifo_config(const bma250e_context dev, BMA250E_FIFO_MODE_T mode, BMA250E_FIFO_DATA_SEL_T axes)
Definition: bma250e.c:550
uint8_t bma250e_get_interrupt_output_control(const bma250e_context dev)
Definition: bma250e.c:725
upm_result_t bma250e_set_low_power_mode2(const bma250e_context dev)
Definition: bma250e.c:880
uint8_t bma250e_get_interrupt_status0(const bma250e_context dev)
Definition: bma250e.c:833
uint8_t bma250e_get_interrupt_enable1(const bma250e_context dev)
Definition: bma250e.c:609
upm_result_t bma250e_update(const bma250e_context dev)
Definition: bma250e.c:232
upm_result_t bma250e_set_interrupt_map1(const bma250e_context dev, uint8_t bits)
Definition: bma250e.c:676
upm_result_t bma250e_install_isr(const bma250e_context dev, BMA250E_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: bma250e.c:900
int bma250e_read_regs(const bma250e_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: bma250e.c:335
uint8_t bma250e_get_interrupt_map2(const bma250e_context dev)
Definition: bma250e.c:688
BMA250E_RST_LATCH_T bma250e_get_interrupt_latch_behavior(const bma250e_context dev)
Definition: bma250e.c:762
upm_result_t bma250e_set_self_test(const bma250e_context dev, bool sign, bool amp, BMA250E_SELFTTEST_AXIS_T axis)
Definition: bma250e.c:568
upm_result_t bma250e_set_power_mode(const bma250e_context dev, BMA250E_POWER_MODE_T power)
Definition: bma250e.c:514
upm_result_t bma250e_enable_output_filtering(const bma250e_context dev, bool filter)
Definition: bma250e.c:813
uint8_t bma250e_get_interrupt_status2(const bma250e_context dev)
Definition: bma250e.c:848
uint8_t bma250e_get_interrupt_map1(const bma250e_context dev)
Definition: bma250e.c:668
uint8_t bma250e_read_reg(const bma250e_context dev, uint8_t reg)
Definition: bma250e.c:311
upm_result_t bma250e_set_interrupt_src(const bma250e_context dev, uint8_t bits)
Definition: bma250e.c:713
uint8_t bma250e_get_chip_id(const bma250e_context dev)
Definition: bma250e.c:404
void bma250e_enable_fifo(const bma250e_context dev, bool useFIFO)
Definition: bma250e.c:303
uint8_t bma250e_get_interrupt_enable2(const bma250e_context dev)
Definition: bma250e.c:630
upm_result_t bma250e_set_interrupt_output_control(const bma250e_context dev, uint8_t bits)
Definition: bma250e.c:733
upm_result_t bma250e_set_range(const bma250e_context dev, BMA250E_RANGE_T range)
Definition: bma250e.c:445
Definition: bma250e.h:54
uint8_t bma250e_get_interrupt_src(const bma250e_context dev)
Definition: bma250e.c:705
upm_result_t bma250e_set_interrupt_latch_behavior(const bma250e_context dev, BMA250E_RST_LATCH_T latch)
Definition: bma250e.c:775
uint8_t bma250e_get_interrupt_status1(const bma250e_context dev)
Definition: bma250e.c:840
bma250e_context bma250e_init(int bus, int addr, int cs)
Definition: bma250e.c:55
upm_result_t bma250e_write_reg(const bma250e_context dev, uint8_t reg, uint8_t val)
Definition: bma250e.c:370
uint8_t bma250e_get_interrupt_enable0(const bma250e_context dev)
Definition: bma250e.c:588
upm_result_t bma250e_fifo_set_watermark(const bma250e_context dev, int wm)
Definition: bma250e.c:534
upm_result_t bma250e_reset(const bma250e_context dev)
Definition: bma250e.c:433
upm_result_t bma250e_set_interrupt_enable2(const bma250e_context dev, uint8_t bits)
Definition: bma250e.c:638
void bma250e_uninstall_isr(const bma250e_context dev, BMA250E_INTERRUPT_PINS_T intr)
Definition: bma250e.c:942
upm_result_t bma250e_devinit(const bma250e_context dev, BMA250E_POWER_MODE_T pwr, BMA250E_RANGE_T range, BMA250E_BW_T bw)
Definition: bma250e.c:188
BMA250E_ORIENT_T bma250e_get_interrupt_status3_orientation(const bma250e_context dev)
Definition: bma250e.c:865
upm_result_t bma250e_enable_register_shadowing(const bma250e_context dev, bool shadow)
Definition: bma250e.c:793
upm_result_t bma250e_set_bandwidth(const bma250e_context dev, BMA250E_BW_T bw)
Definition: bma250e.c:503
upm_result_t bma250e_set_interrupt_map0(const bma250e_context dev, uint8_t bits)
Definition: bma250e.c:658
upm_result_t bma250e_set_interrupt_map2(const bma250e_context dev, uint8_t bits)
Definition: bma250e.c:695
upm_result_t bma250e_set_interrupt_enable1(const bma250e_context dev, uint8_t bits)
Definition: bma250e.c:617
struct _bma250e_context * bma250e_context
void bma250e_get_accelerometer(const bma250e_context dev, float *x, float *y, float *z)
Definition: bma250e.c:411