2021-03-31 13:47:27 -04:00
|
|
|
#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;
|
|
|
|
|
2021-04-08 14:07:24 -04:00
|
|
|
/// 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();
|
2021-03-31 13:47:27 -04:00
|
|
|
void Init();
|
|
|
|
Values Process();
|
2021-04-02 11:33:49 -04:00
|
|
|
void ResetStepCounter();
|
2021-03-31 13:47:27 -04:00
|
|
|
|
|
|
|
void Read(uint8_t registerAddress, uint8_t *buffer, size_t size);
|
|
|
|
void Write(uint8_t registerAddress, const uint8_t *data, size_t size);
|
|
|
|
|
2021-04-02 10:56:14 -04:00
|
|
|
bool IsOk() const;
|
|
|
|
|
2021-03-31 13:47:27 -04:00
|
|
|
private:
|
2021-04-02 11:33:49 -04:00
|
|
|
void Reset();
|
|
|
|
|
2021-03-31 13:47:27 -04:00
|
|
|
TwiMaster& twiMaster;
|
2021-04-01 15:18:59 -04:00
|
|
|
uint8_t deviceAddress = 0x18;
|
|
|
|
struct bma4_dev bma;
|
2021-04-02 10:56:14 -04:00
|
|
|
bool isOk = false;
|
2021-04-08 14:07:24 -04:00
|
|
|
bool isResetOk = false;
|
2021-03-31 13:47:27 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|