danny hack
Lis2dh12.h@2:1fa08c7a2a3c, 2018-01-12 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Jan 12 16:06:45 2018 +0000
- Revision:
- 2:1fa08c7a2a3c
- Parent:
- 0:cc5d477d5dbe
- Child:
- 7:f1ba533021b8
Threshold value interrupt works. Power c. is 5.2uA (in system off). Todo: ble battery beacon adv.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 0:cc5d477d5dbe | 1 | /* |
jurica238814 | 0:cc5d477d5dbe | 2 | * |
jurica238814 | 0:cc5d477d5dbe | 3 | * LIS2DH12 MEMS digital output motion sensor |
jurica238814 | 0:cc5d477d5dbe | 4 | * More info @ aconno.de |
jurica238814 | 0:cc5d477d5dbe | 5 | * Made by Jurica Resetar |
jurica238814 | 0:cc5d477d5dbe | 6 | * jurica_resetar@yahoo.com |
jurica238814 | 0:cc5d477d5dbe | 7 | * |
jurica238814 | 0:cc5d477d5dbe | 8 | */ |
jurica238814 | 0:cc5d477d5dbe | 9 | |
jurica238814 | 0:cc5d477d5dbe | 10 | #ifndef LIS2DH12_H |
jurica238814 | 0:cc5d477d5dbe | 11 | #define LIS2DH12_H |
jurica238814 | 0:cc5d477d5dbe | 12 | |
jurica238814 | 0:cc5d477d5dbe | 13 | #include "mbed.h" |
jurica238814 | 0:cc5d477d5dbe | 14 | #include "aconno_i2c.h" |
jurica238814 | 0:cc5d477d5dbe | 15 | #include "Lis2dh12_regs.h" |
jurica238814 | 0:cc5d477d5dbe | 16 | |
jurica238814 | 0:cc5d477d5dbe | 17 | enum Mode{ |
jurica238814 | 0:cc5d477d5dbe | 18 | HIGH_RES = 0, |
jurica238814 | 0:cc5d477d5dbe | 19 | NORMAL, |
jurica238814 | 0:cc5d477d5dbe | 20 | LOW_POWER, |
jurica238814 | 0:cc5d477d5dbe | 21 | }; |
jurica238814 | 0:cc5d477d5dbe | 22 | |
jurica238814 | 0:cc5d477d5dbe | 23 | enum Axis{ |
jurica238814 | 0:cc5d477d5dbe | 24 | X_axis = 0x01, |
jurica238814 | 0:cc5d477d5dbe | 25 | Y_axis = 0x02, |
jurica238814 | 0:cc5d477d5dbe | 26 | Z_axis = 0x04, |
jurica238814 | 0:cc5d477d5dbe | 27 | }; |
jurica238814 | 0:cc5d477d5dbe | 28 | |
jurica238814 | 0:cc5d477d5dbe | 29 | enum Odr{ |
jurica238814 | 0:cc5d477d5dbe | 30 | PowerDown = 0x00, |
jurica238814 | 0:cc5d477d5dbe | 31 | ODR_1Hz = 0x01, |
jurica238814 | 0:cc5d477d5dbe | 32 | ODR_10Hz = 0x02, |
jurica238814 | 0:cc5d477d5dbe | 33 | ODR_25Hz = 0x03, |
jurica238814 | 0:cc5d477d5dbe | 34 | ODR_50Hz = 0x04, |
jurica238814 | 0:cc5d477d5dbe | 35 | ODR_100Hz = 0x05, |
jurica238814 | 0:cc5d477d5dbe | 36 | ODR_200Hz = 0x06, |
jurica238814 | 0:cc5d477d5dbe | 37 | ODR_400Hz = 0x07, |
jurica238814 | 0:cc5d477d5dbe | 38 | ODR_1620Hz = 0x08, |
jurica238814 | 0:cc5d477d5dbe | 39 | ODR_Max = 0x09, // HighRes/Normal -> 1.344kHz, LowPower -> 5.376kHz |
jurica238814 | 0:cc5d477d5dbe | 40 | }; |
jurica238814 | 0:cc5d477d5dbe | 41 | |
jurica238814 | 0:cc5d477d5dbe | 42 | enum Scale{ |
jurica238814 | 0:cc5d477d5dbe | 43 | _2g = 0x00, |
jurica238814 | 0:cc5d477d5dbe | 44 | _4g = 0x01, |
jurica238814 | 0:cc5d477d5dbe | 45 | _8g = 0x02, |
jurica238814 | 0:cc5d477d5dbe | 46 | _16g = 0x03, |
jurica238814 | 0:cc5d477d5dbe | 47 | }; |
jurica238814 | 0:cc5d477d5dbe | 48 | |
jurica238814 | 0:cc5d477d5dbe | 49 | class Lis2dh12{ |
jurica238814 | 0:cc5d477d5dbe | 50 | public: |
jurica238814 | 0:cc5d477d5dbe | 51 | Lis2dh12(I2C *i2c_, char address); |
jurica238814 | 0:cc5d477d5dbe | 52 | uint8_t whoIAm(); |
jurica238814 | 0:cc5d477d5dbe | 53 | uint8_t setMode(Mode mode); |
jurica238814 | 0:cc5d477d5dbe | 54 | uint8_t enableAxes(Axis axis); |
jurica238814 | 0:cc5d477d5dbe | 55 | uint8_t disableAxes(Axis axis); |
jurica238814 | 0:cc5d477d5dbe | 56 | int16_t readXAxis(); |
jurica238814 | 0:cc5d477d5dbe | 57 | int16_t readYAxis(); |
jurica238814 | 0:cc5d477d5dbe | 58 | int16_t readZAxis(); |
jurica238814 | 0:cc5d477d5dbe | 59 | uint8_t setODR(Odr odr); |
jurica238814 | 0:cc5d477d5dbe | 60 | uint8_t setScale(Scale scale); |
jurica238814 | 2:1fa08c7a2a3c | 61 | uint8_t int1Setup(uint8_t setup); |
jurica238814 | 2:1fa08c7a2a3c | 62 | uint8_t int1Latch(uint8_t enable); |
jurica238814 | 2:1fa08c7a2a3c | 63 | uint8_t int1Duration(uint8_t duration); |
jurica238814 | 2:1fa08c7a2a3c | 64 | uint8_t int1Threshold(uint8_t threshold); |
jurica238814 | 2:1fa08c7a2a3c | 65 | uint8_t int1Config(uint8_t config); |
jurica238814 | 2:1fa08c7a2a3c | 66 | void clearIntFlag(); |
jurica238814 | 2:1fa08c7a2a3c | 67 | private: |
jurica238814 | 0:cc5d477d5dbe | 68 | aconno_i2c i2c; |
jurica238814 | 0:cc5d477d5dbe | 69 | |
jurica238814 | 0:cc5d477d5dbe | 70 | }; |
jurica238814 | 0:cc5d477d5dbe | 71 | |
jurica238814 | 0:cc5d477d5dbe | 72 | |
jurica238814 | 0:cc5d477d5dbe | 73 | #endif |
jurica238814 | 0:cc5d477d5dbe | 74 |