mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
DS1307: Add string based constructor for Clock
Signed-off-by: Adelin Dobre <adelin.dobre@rinftech.com>
This commit is contained in:
parent
9ba72d8717
commit
2bb89d47ca
@ -46,6 +46,27 @@ DS1307::DS1307(int bus) : m_i2c(bus)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DS1307::DS1307(std::string initStr) : m_i2c(nullptr), mraaIo(initStr)
|
||||||
|
{
|
||||||
|
mraa_io_descriptor* descs = mraaIo.getMraaDescriptors();
|
||||||
|
|
||||||
|
if(!descs->i2cs[0]) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_i2c_init() failed");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
m_i2c = descs->i2cs[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup our i2c link
|
||||||
|
mraa::Result ret = m_i2c.address(DS1307_I2C_ADDR);
|
||||||
|
if (ret != mraa::SUCCESS){
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": i2c.address() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mraa::Result DS1307::writeBytes(uint8_t reg, uint8_t *buffer, int len)
|
mraa::Result DS1307::writeBytes(uint8_t reg, uint8_t *buffer, int len)
|
||||||
{
|
{
|
||||||
if (!len || !buffer)
|
if (!len || !buffer)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mraa/i2c.hpp>
|
#include <mraa/i2c.hpp>
|
||||||
|
#include <mraa/initio.hpp>
|
||||||
|
|
||||||
#define DS1307_I2C_BUS 0
|
#define DS1307_I2C_BUS 0
|
||||||
#define DS1307_I2C_ADDR 0x68
|
#define DS1307_I2C_ADDR 0x68
|
||||||
@ -77,6 +78,13 @@ namespace upm {
|
|||||||
* @param bus I2C bus to use
|
* @param bus I2C bus to use
|
||||||
*/
|
*/
|
||||||
DS1307(int bus);
|
DS1307(int bus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates DS1307 Clock based on a given string.
|
||||||
|
*
|
||||||
|
* @param initStr string containing specific information for DS1307 initialization.
|
||||||
|
*/
|
||||||
|
DS1307(std::string initStr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all the time values
|
* Loads all the time values
|
||||||
@ -188,6 +196,7 @@ namespace upm {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mraa::I2c m_i2c;
|
mraa::I2c m_i2c;
|
||||||
|
mraa::MraaIo mraaIo;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user