aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers/Bma421.h
blob: d36d1db568c7a0e7f7aad52c3b6dc7fa4c95a624 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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;

      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;
    };
  }
}