fixed some issue with SoftI2C not working (missing delay)

added code for a waveshare eInk
refactored some old code to match with the new SoftI2C
This commit is contained in:
2020-10-18 10:49:59 +02:00
parent 9c94faa24d
commit ac74587ee7
7 changed files with 426 additions and 44 deletions

View File

@@ -3,7 +3,7 @@
#include "../../io/SoftI2C.h"
class DS3231 {
template <typename I2C> class DS3231 {
static constexpr uint8_t ADDR7 = 0x68;
@@ -11,11 +11,17 @@ class DS3231 {
static constexpr uint8_t REG_MINUTES = 0x01;
static constexpr uint8_t REG_HOURS = 0x02;
I2C& i2c;
public:
DS3231(I2C& i2c) : i2c(i2c) {
;
}
bool isPresent() {
return i2c::query(ADDR7);
//return i2c::query(ADDR7);
return i2c.query(ADDR7);
}
struct Time {
@@ -37,7 +43,7 @@ public:
Res get() {
uint8_t buf[8];
readRegister(0x00, buf, 8);
i2c.readReg(ADDR7, 0x00, 8, buf);
Res res;
@@ -49,8 +55,8 @@ public:
res.date.m = (((buf[5] & 0b00010000)>>4)*10) + (buf[5] & 0b1111);
res.date.y = (((buf[6] & 0b11110000)>>4)*10) + (buf[6] & 0b1111);
os_printf("%d %d %d \n", res.time.h, res.time.m, res.time.s);
os_printf("%d %d %d \n", res.date.d, res.date.m, res.date.y);
printf("%d %d %d \n", res.time.h, res.time.m, res.time.s);
printf("%d %d %d \n", res.date.d, res.date.m, res.date.y);
return res;
@@ -62,7 +68,7 @@ public:
buf[0] = ((s/10)<<4) + (s % 10);
buf[1] = ((m/10)<<4) + (m % 10);
buf[2] = ((h/10)<<4) + (h % 10);
writeRegister(0x00, buf, 3);
i2c.writeReg(ADDR7, 0x00, 3, buf);
}
@@ -72,12 +78,13 @@ public:
buf[0] = ((d/10)<<4) + (d % 10);
buf[1] = ((m/10)<<4) + (m % 10);
buf[2] = ((y/10)<<4) + (y % 10);
writeRegister(0x04, buf, 3);
i2c.writeReg(ADDR7, 0x04, 3, buf);
}
private:
/*
bool readRegister(const uint8_t addr, uint8_t* dst, const uint8_t len) {
bool ok;
@@ -118,6 +125,7 @@ private:
return true;
}
*/
};