|
1 | 1 | #ifndef ADAFRUIT_LPS28_H
|
2 | 2 | #define ADAFRUIT_LPS28_H
|
3 | 3 |
|
4 |
| -#include <Arduino.h> |
5 |
| -#include <Adafruit_I2CDevice.h> |
6 | 4 | #include <Adafruit_BusIO_Register.h>
|
| 5 | +#include <Adafruit_I2CDevice.h> |
| 6 | +#include <Arduino.h> |
7 | 7 |
|
8 | 8 | // I2C Address and Register Definitions
|
9 | 9 | #define LPS28_DEFAULT_ADDRESS (0x5C) ///< Default I2C address
|
10 | 10 | #define LPS28_WHOAMI_REG 0x0F ///< WHO_AM_I register
|
11 | 11 | #define LPS28_WHOAMI_EXPECTED 0xB4 ///< Expected WHO_AM_I value
|
12 | 12 |
|
13 |
| -#define LPS28_THS_P 0x0C ///< Threshold Pressure (2 bytes) |
14 |
| -#define LPS28_CTRL_REG1 0x10 ///< Control Register 1 (ODR and AVG) |
15 |
| -#define LPS28_CTRL_REG2 0x11 ///< Control Register 2 |
16 |
| -#define LPS28_CTRL_REG3 0x12 ///< Control Register 3 (Interrupt config) |
17 |
| -#define LPS28_CTRL_REG4 0x13 ///< Control Register 4 |
18 |
| -#define LPS28_INTERRUPT_CFG 0x0B ///< Interrupt Configuration Register |
19 |
| -#define LPS28_IF_CTRL 0x0E ///< Interface Control Register |
20 |
| -#define LPS28_FIFO_CTRL 0x14 ///< FIFO Control Register |
21 |
| -#define LPS28_FIFO_WTM 0x15 ///< FIFO Watermark Register |
22 |
| -#define LPS28_REF_P 0x16 ///< Reference Pressure Register (2 bytes) |
23 |
| -#define LPS28_RPDS 0x18 ///< RPDS Register (Pressure Offset, 2 bytes) |
24 |
| -#define LPS28_INT_SOURCE 0x24 ///< INT_SOURCE Register |
25 |
| -#define LPS28_FIFO_STATUS1 0x25 ///< FIFO_STATUS1 Register |
26 |
| -#define LPS28_FIFO_STATUS2 0x26 ///< FIFO_STATUS2 Register |
27 |
| -#define LPS28_STATUS 0x27 ///< STATUS Register |
28 |
| -#define LPS28_PRESS_OUT 0x28 ///< PRESS_OUT Register (3 bytes) |
29 |
| -#define LPS28_TEMP_OUT 0x2B ///< TEMP_OUT Register (2 bytes) |
30 |
| -#define LPS28_FIFO_DATA_OUT_PRESS_XL 0x78 ///< FIFO_DATA_OUT_PRESS_XL Register (3 bytes) |
31 |
| - |
32 |
| - |
| 13 | +#define LPS28_THS_P 0x0C ///< Threshold Pressure (2 bytes) |
| 14 | +#define LPS28_CTRL_REG1 0x10 ///< Control Register 1 (ODR and AVG) |
| 15 | +#define LPS28_CTRL_REG2 0x11 ///< Control Register 2 |
| 16 | +#define LPS28_CTRL_REG3 0x12 ///< Control Register 3 (Interrupt config) |
| 17 | +#define LPS28_CTRL_REG4 0x13 ///< Control Register 4 |
| 18 | +#define LPS28_INTERRUPT_CFG 0x0B ///< Interrupt Configuration Register |
| 19 | +#define LPS28_IF_CTRL 0x0E ///< Interface Control Register |
| 20 | +#define LPS28_FIFO_CTRL 0x14 ///< FIFO Control Register |
| 21 | +#define LPS28_FIFO_WTM 0x15 ///< FIFO Watermark Register |
| 22 | +#define LPS28_REF_P 0x16 ///< Reference Pressure Register (2 bytes) |
| 23 | +#define LPS28_RPDS 0x18 ///< RPDS Register (Pressure Offset, 2 bytes) |
| 24 | +#define LPS28_INT_SOURCE 0x24 ///< INT_SOURCE Register |
| 25 | +#define LPS28_FIFO_STATUS1 0x25 ///< FIFO_STATUS1 Register |
| 26 | +#define LPS28_FIFO_STATUS2 0x26 ///< FIFO_STATUS2 Register |
| 27 | +#define LPS28_STATUS 0x27 ///< STATUS Register |
| 28 | +#define LPS28_PRESS_OUT 0x28 ///< PRESS_OUT Register (3 bytes) |
| 29 | +#define LPS28_TEMP_OUT 0x2B ///< TEMP_OUT Register (2 bytes) |
| 30 | +#define LPS28_FIFO_DATA_OUT_PRESS_XL \ |
| 31 | + 0x78 ///< FIFO_DATA_OUT_PRESS_XL Register (3 bytes) |
33 | 32 |
|
34 | 33 | // STATUS flags
|
35 |
| -#define LPS28_STATUS_TEMP_OVERRUN 0x20 ///< Temperature data overrun (bit 5) |
| 34 | +#define LPS28_STATUS_TEMP_OVERRUN 0x20 ///< Temperature data overrun (bit 5) |
36 | 35 | #define LPS28_STATUS_PRESS_OVERRUN 0x10 ///< Pressure data overrun (bit 4)
|
37 |
| -#define LPS28_STATUS_TEMP_READY 0x02 ///< Temperature data available (bit 1) |
38 |
| -#define LPS28_STATUS_PRESS_READY 0x01 ///< Pressure data available (bit 0) |
| 36 | +#define LPS28_STATUS_TEMP_READY 0x02 ///< Temperature data available (bit 1) |
| 37 | +#define LPS28_STATUS_PRESS_READY 0x01 ///< Pressure data available (bit 0) |
39 | 38 |
|
40 | 39 | // FIFO_STATUS2 flags
|
41 |
| -#define LPS28_FIFO_STATUS_WTM_IA 0x80 ///< FIFO Watermark interrupt active (bit 7) |
42 |
| -#define LPS28_FIFO_STATUS_OVR_IA 0x40 ///< FIFO Overrun interrupt active (bit 6) |
| 40 | +#define LPS28_FIFO_STATUS_WTM_IA \ |
| 41 | + 0x80 ///< FIFO Watermark interrupt active (bit 7) |
| 42 | +#define LPS28_FIFO_STATUS_OVR_IA 0x40 ///< FIFO Overrun interrupt active (bit 6) |
43 | 43 | #define LPS28_FIFO_STATUS_FULL_IA 0x20 ///< FIFO Full interrupt active (bit 5)
|
44 | 44 |
|
45 | 45 | // INT_SOURCE flags
|
46 |
| -#define LPS28_INT_SOURCE_IA 0x20 ///< Interrupt Active flag (bit 5) |
47 |
| -#define LPS28_INT_SOURCE_PL 0x10 ///< Low pressure event flag (bit 4) |
48 |
| -#define LPS28_INT_SOURCE_PH 0x08 ///< High pressure event flag (bit 3) |
49 |
| -#define LPS28_INT_SOURCE_BOOT_ON 0x80 ///< Boot status flag (bit 7) |
50 |
| - |
| 46 | +#define LPS28_INT_SOURCE_IA 0x20 ///< Interrupt Active flag (bit 5) |
| 47 | +#define LPS28_INT_SOURCE_PL 0x10 ///< Low pressure event flag (bit 4) |
| 48 | +#define LPS28_INT_SOURCE_PH 0x08 ///< High pressure event flag (bit 3) |
| 49 | +#define LPS28_INT_SOURCE_BOOT_ON 0x80 ///< Boot status flag (bit 7) |
51 | 50 |
|
52 | 51 | // Output Data Rate (ODR) configuration (Table 19)
|
53 | 52 | typedef enum {
|
54 | 53 | LPS28_ODR_ONESHOT = 0b0000, ///< One-shot mode
|
55 |
| - LPS28_ODR_1_HZ = 0b0001, ///< 1 Hz |
56 |
| - LPS28_ODR_4_HZ = 0b0010, ///< 4 Hz |
57 |
| - LPS28_ODR_10_HZ = 0b0011, ///< 10 Hz |
58 |
| - LPS28_ODR_25_HZ = 0b0100, ///< 25 Hz |
59 |
| - LPS28_ODR_50_HZ = 0b0101, ///< 50 Hz |
60 |
| - LPS28_ODR_75_HZ = 0b0110, ///< 75 Hz |
61 |
| - LPS28_ODR_100_HZ = 0b0111, ///< 100 Hz |
62 |
| - LPS28_ODR_200_HZ = 0b1000 ///< 200 Hz |
| 54 | + LPS28_ODR_1_HZ = 0b0001, ///< 1 Hz |
| 55 | + LPS28_ODR_4_HZ = 0b0010, ///< 4 Hz |
| 56 | + LPS28_ODR_10_HZ = 0b0011, ///< 10 Hz |
| 57 | + LPS28_ODR_25_HZ = 0b0100, ///< 25 Hz |
| 58 | + LPS28_ODR_50_HZ = 0b0101, ///< 50 Hz |
| 59 | + LPS28_ODR_75_HZ = 0b0110, ///< 75 Hz |
| 60 | + LPS28_ODR_100_HZ = 0b0111, ///< 100 Hz |
| 61 | + LPS28_ODR_200_HZ = 0b1000 ///< 200 Hz |
63 | 62 | } lps28_odr_t;
|
64 | 63 |
|
65 | 64 | // Averaging (AVG) selection (Table 20)
|
66 | 65 | typedef enum {
|
67 |
| - LPS28_AVG_4 = 0b000, ///< 4 samples |
68 |
| - LPS28_AVG_8 = 0b001, ///< 8 samples |
69 |
| - LPS28_AVG_16 = 0b010, ///< 16 samples |
70 |
| - LPS28_AVG_32 = 0b011, ///< 32 samples |
71 |
| - LPS28_AVG_64 = 0b100, ///< 64 samples |
| 66 | + LPS28_AVG_4 = 0b000, ///< 4 samples |
| 67 | + LPS28_AVG_8 = 0b001, ///< 8 samples |
| 68 | + LPS28_AVG_16 = 0b010, ///< 16 samples |
| 69 | + LPS28_AVG_32 = 0b011, ///< 32 samples |
| 70 | + LPS28_AVG_64 = 0b100, ///< 64 samples |
72 | 71 | LPS28_AVG_128 = 0b101, ///< 128 samples
|
73 | 72 | LPS28_AVG_512 = 0b111 ///< 512 samples
|
74 | 73 | } lps28_avg_t;
|
75 | 74 |
|
76 |
| - |
77 | 75 | // FIFO Mode Selection based on TRIG_MODE and F_MODE bits
|
78 | 76 | typedef enum {
|
79 |
| - LPS28_FIFO_BYPASS = 0b00, ///< Bypass mode (F_MODE[1:0] = 00) |
80 |
| - LPS28_FIFO_FIFO = 0b01, ///< FIFO mode (TRIG = 0, F_MODE[1:0] = 01) |
81 |
| - LPS28_FIFO_CONTINUOUS = 0b10, ///< Continuous mode (TRIG = 0, F_MODE[1:0] = 1x) |
82 |
| - LPS28_FIFO_BYPASS_TO_FIFO = 0b101, ///< Bypass-to-FIFO mode (TRIG = 1, F_MODE[1:0] = 01) |
83 |
| - LPS28_FIFO_BYPASS_TO_CONTINUOUS = 0b110, ///< Bypass-to-Continuous mode (TRIG = 1, F_MODE[1:0] = 10) |
84 |
| - LPS28_FIFO_CONTINUOUS_TO_FIFO = 0b111 ///< Continuous-to-FIFO mode (TRIG = 1, F_MODE[1:0] = 11) |
| 77 | + LPS28_FIFO_BYPASS = 0b00, ///< Bypass mode (F_MODE[1:0] = 00) |
| 78 | + LPS28_FIFO_FIFO = 0b01, ///< FIFO mode (TRIG = 0, F_MODE[1:0] = 01) |
| 79 | + LPS28_FIFO_CONTINUOUS = |
| 80 | + 0b10, ///< Continuous mode (TRIG = 0, F_MODE[1:0] = 1x) |
| 81 | + LPS28_FIFO_BYPASS_TO_FIFO = |
| 82 | + 0b101, ///< Bypass-to-FIFO mode (TRIG = 1, F_MODE[1:0] = 01) |
| 83 | + LPS28_FIFO_BYPASS_TO_CONTINUOUS = |
| 84 | + 0b110, ///< Bypass-to-Continuous mode (TRIG = 1, F_MODE[1:0] = 10) |
| 85 | + LPS28_FIFO_CONTINUOUS_TO_FIFO = |
| 86 | + 0b111 ///< Continuous-to-FIFO mode (TRIG = 1, F_MODE[1:0] = 11) |
85 | 87 | } lps28_fifo_mode_t;
|
86 | 88 |
|
87 |
| - |
88 |
| - |
89 | 89 | class Adafruit_LPS28 {
|
90 | 90 | public:
|
91 | 91 | Adafruit_LPS28();
|
92 | 92 |
|
93 |
| - bool begin(TwoWire *theWire = &Wire, uint8_t i2c_addr = LPS28_DEFAULT_ADDRESS); |
| 93 | + bool begin(TwoWire *theWire = &Wire, |
| 94 | + uint8_t i2c_addr = LPS28_DEFAULT_ADDRESS); |
94 | 95 |
|
95 | 96 | // Threshold Pressure (THS_P) functions
|
96 | 97 | bool setThresholdPressure(uint16_t threshold);
|
@@ -139,7 +140,7 @@ class Adafruit_LPS28 {
|
139 | 140 |
|
140 | 141 | // FIFO
|
141 | 142 | bool setFIFOWatermark(uint8_t wtm);
|
142 |
| - uint8_t getFIFOWatermark(); |
| 143 | + uint8_t getFIFOWatermark(); |
143 | 144 | uint8_t getFIFOunreadSamples();
|
144 | 145 | uint8_t getFIFOstatus();
|
145 | 146 | bool setFIFOmode(bool stop_on_watermark, lps28_fifo_mode_t mode);
|
|
0 commit comments