TwiMaster is now based on the NRFX TWI driver, as it handles more edge cases and workarounds for errors on the bus.

Reset the TWI bus after the soft-reset of the motion sensor to workaround issues on the TWI bus.
This commit is contained in:
Jean-François Milants
2021-04-08 20:07:24 +02:00
parent 1d7576de64
commit 9ac4be8b75
7 changed files with 67 additions and 207 deletions

View File

@@ -3,13 +3,13 @@
#include <semphr.h>
#include <drivers/include/nrfx_twi.h> // NRF_TWIM_Type
#include <cstdint>
#include <nrfx_twim.h>
namespace Pinetime {
namespace Drivers {
class TwiMaster {
public:
enum class Modules { TWIM1 };
enum class Frequencies {Khz100, Khz250, Khz400};
enum class ErrorCodes {NoError, TransactionFailed};
struct Parameters {
uint32_t frequency;
@@ -27,21 +27,13 @@ namespace Pinetime {
void Wakeup();
private:
ErrorCodes ReadWithRetry(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, size_t size);
ErrorCodes WriteWithRetry(uint8_t deviceAddress, uint8_t registerAddress, const uint8_t* data, size_t size);
ErrorCodes Read(uint8_t deviceAddress, uint8_t* buffer, size_t size, bool stop);
ErrorCodes Write(uint8_t deviceAddress, const uint8_t* data, size_t size, bool stop);
void FixHwFreezed();
NRF_TWIM_Type* twiBaseAddress;
SemaphoreHandle_t mutex;
nrfx_twim_t twim;
const Modules module;
const Parameters params;
SemaphoreHandle_t mutex;
static constexpr uint8_t maxDataSize{8};
static constexpr uint8_t registerSize{1};
uint8_t internalBuffer[maxDataSize + registerSize];
uint32_t txStartedCycleCount = 0;
static constexpr uint32_t HwFreezedDelay{161000};
};
}
}