From 6af5bbcbc87eecccf7613785a3c9540c07d2fd3b Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 19 Jul 2020 20:30:44 +0200 Subject: New implementation of the I²C/TWI driver. Fix reset timing and add dummy reading in Cst816S to fix init error on some devices. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/TwiMaster.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/drivers/TwiMaster.h (limited to 'src/drivers/TwiMaster.h') diff --git a/src/drivers/TwiMaster.h b/src/drivers/TwiMaster.h new file mode 100644 index 00000000..3b7555f5 --- /dev/null +++ b/src/drivers/TwiMaster.h @@ -0,0 +1,38 @@ +#pragma once +#include +#include +#include + + +namespace Pinetime { + namespace Drivers { + class TwiMaster { + public: + enum class Modules { TWIM1 }; + enum class Frequencies {Khz100, Khz250, Khz400}; + struct Parameters { + uint32_t frequency; + uint8_t pinSda; + uint8_t pinScl; + }; + + TwiMaster(const Modules module, const Parameters& params); + + void Init(); + void Read(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, size_t size); + void Write(uint8_t deviceAddress, uint8_t registerAddress, const uint8_t* data, size_t size); + + private: + void Read(uint8_t deviceAddress, uint8_t* buffer, size_t size, bool stop); + void Write(uint8_t deviceAddress, const uint8_t* data, size_t size, bool stop); + NRF_TWIM_Type* twiBaseAddress; + SemaphoreHandle_t mutex; + const Modules module; + const Parameters params; + static constexpr uint8_t maxDataSize{8}; + static constexpr uint8_t registerSize{1}; + uint8_t internalBuffer[maxDataSize + registerSize]; + + }; + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2