diff options
| author | Frederic LESUR <contact@memiks.fr> | 2020-07-21 08:15:48 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-21 08:15:48 +0900 |
| commit | 445e7f38e2fe34f1dd65c6ba661e15b65d586308 (patch) | |
| tree | 0f51c3c077937814fb8bea088ebe5f960e350a36 /src/drivers/TwiMaster.h | |
| parent | 42d8a18fe74b060a84ea74b29aefca69f9471d5f (diff) | |
| parent | 55417794551211c0e86eebc661b76339d35de8ef (diff) | |
Merge pull request #2 from JF002/develop
merge update from JF002 into Develop
Diffstat (limited to 'src/drivers/TwiMaster.h')
| -rw-r--r-- | src/drivers/TwiMaster.h | 38 |
1 files changed, 38 insertions, 0 deletions
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 <FreeRTOS.h> +#include <semphr.h> +#include <drivers/include/nrfx_twi.h> + + +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 |
