aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers/Bma421.h
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-04-09 21:17:03 +0200
committerJean-François Milants <jf@codingfield.com>2021-04-09 21:17:03 +0200
commiteb769fb60ecb8f96ecf6901082ec3f0610842af8 (patch)
treec26870103f8baaa933399cfb86cca25aa7e60d8b /src/drivers/Bma421.h
parent57b4c3f0edc6acfa31bd2160abdcd6091920ba63 (diff)
parent15b3b8e282dd5b2132b0095716cd9d88740d4579 (diff)
Merge branch 'motion-sensor' into develop
Diffstat (limited to 'src/drivers/Bma421.h')
-rw-r--r--src/drivers/Bma421.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/drivers/Bma421.h b/src/drivers/Bma421.h
new file mode 100644
index 00000000..da021cbf
--- /dev/null
+++ b/src/drivers/Bma421.h
@@ -0,0 +1,43 @@
+#pragma once
+#include <drivers/Bma421_C/bma4_defs.h>
+
+namespace Pinetime {
+ namespace Drivers {
+ class TwiMaster;
+ class Bma421 {
+ public:
+ struct Values {
+ uint32_t steps;
+ int16_t x;
+ int16_t y;
+ int16_t z;
+ };
+ Bma421(TwiMaster& twiMaster, uint8_t twiAddress);
+ Bma421(const Bma421&) = delete;
+ Bma421& operator=(const Bma421&) = delete;
+ Bma421(Bma421&&) = delete;
+ Bma421& operator=(Bma421&&) = delete;
+
+ /// The chip freezes the TWI bus after the softreset operation. Softreset is separated from the
+ /// Init() method to allow the caller to uninit and then reinit the TWI device after the softreset.
+ void SoftReset();
+ void Init();
+ Values Process();
+ void ResetStepCounter();
+
+ void Read(uint8_t registerAddress, uint8_t *buffer, size_t size);
+ void Write(uint8_t registerAddress, const uint8_t *data, size_t size);
+
+ bool IsOk() const;
+
+ private:
+ void Reset();
+
+ TwiMaster& twiMaster;
+ uint8_t deviceAddress = 0x18;
+ struct bma4_dev bma;
+ bool isOk = false;
+ bool isResetOk = false;
+ };
+ }
+} \ No newline at end of file