This commit is contained in:
2020-06-11 11:25:19 +02:00
parent 5cb02880b3
commit 5177cd5cbd
15 changed files with 1090 additions and 411 deletions

View File

@@ -70,17 +70,23 @@
class SSD1306 {
template <typename I2C> class SSD1306 {
private:
static constexpr uint8_t ADDR7 = 0b0111100;
bool inited = false;
I2C& i2c;
public:
SSD1306(I2C& i2c) : i2c(i2c) {
}
bool isPresent() {
return i2c::query(ADDR7);
return i2c.query(ADDR7);
}
void initOnce() {
@@ -137,15 +143,15 @@ public:
// i2c::stop();
// }
i2c::startWrite(ADDR7);
bool ok = i2c::writeByteAndCheck(0x40);
i2c.startWrite(ADDR7);
bool ok = i2c.writeByteAndCheck(0x40);
if (!ok) {os_printf("failed write data\n");}
for (uint16_t i=0; i < (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
i2c::writeByteAndCheck(data[i]);
i2c.writeByteAndCheck(data[i]);
}
i2c::stop();
i2c.stop();
}
@@ -240,13 +246,13 @@ private:
void sendCommand(uint8_t cmd) {
bool ok;
ok = i2c::startWrite(ADDR7);
ok = i2c.startWrite(ADDR7);
if (!ok) {os_printf("failed start write\n");}
ok = i2c::writeByteAndCheck(0x00); // command
ok = i2c.writeByteAndCheck(0x00); // command
if (!ok) {os_printf("failed command mode\n");}
ok = i2c::writeByteAndCheck(cmd);
ok = i2c.writeByteAndCheck(cmd);
if (!ok) {os_printf("failed command\n");}
i2c::stop();
i2c.stop();
}
};