From 1388412d70fc9673465d9ae1f115d7696c06d77d Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 16 May 2020 19:52:22 +0200 Subject: [PATCH] Change interface to only pass i2c backend driver into class --- ds3231.hpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ds3231.hpp b/ds3231.hpp index 3d6c5d8..ef0f032 100644 --- a/ds3231.hpp +++ b/ds3231.hpp @@ -28,6 +28,8 @@ struct DateTime : Date, Time { template class DS3231 { + using i2c_t = i2c::I2c; + public: static constexpr auto I2C_ADDRESS = 0x68; @@ -50,7 +52,7 @@ class DS3231 { static inline void init() { - I2cDriver::init(); + i2c_t::init(); } static auto getDate() @@ -136,14 +138,14 @@ class DS3231 { template static Register readRegisterHelper() { - I2cDriver::template start(false); - I2cDriver::write(Address); - I2cDriver::stop(); + i2c_t::template start(false); + i2c_t::write(Address); + i2c_t::stop(); Register reg; - I2cDriver::template start(true); - I2cDriver::template readBytes(reinterpret_cast(®)); - I2cDriver::stop(); + i2c_t::template start(true); + i2c_t::template readBytes(reinterpret_cast(®)); + i2c_t::stop(); return reg; } @@ -197,10 +199,10 @@ class DS3231 { static_assert(util::always_false_v, "Invalid register address"); } - I2cDriver::template start(false); - I2cDriver::write(Address + StartOffset); - I2cDriver::template writeBytes(reinterpret_cast(®) + StartOffset); - I2cDriver::stop(); + i2c_t::template start(false); + i2c_t::write(Address + StartOffset); + i2c_t::template writeBytes(reinterpret_cast(®) + StartOffset); + i2c_t::stop(); } static uint8_t calcDayOfWeek(uint16_t year, uint8_t month, uint16_t day)