implement new auto detect display for sh1106 and ssd1306

This commit is contained in:
liamcottle committed 2026-10-21 15:41:11 +13:00
1 parent dec8ad6edc
commit 87c76a8b06
5 files changed
+100 -20

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
#include "AutoDetectDisplay.h"
#include <MeshCore.h>
int AutoDetectDisplay::getDisplayStatus(TwoWire& wire, uint8_t addr) {
int status = -1;
for(int i = 0; i < 4; i++){
// request display status
wire.beginTransmission(addr);
wire.write((uint8_t)0x00);
// ensure response received
if (wire.endTransmission() != 0) return -1; // expect success
if (wire.requestFrom((int)addr, 1) == 0) return -1; // expect at least 1 byte
// ensure two consecutive reads are the same
int previous = status;
status = wire.read() & 0x0F;
if(status == previous){
break;
}
}
return status;
}
bool AutoDetectDisplay::begin() {
// request status from display address
int status = getDisplayStatus(Wire, DISPLAY_ADDRESS);
MESH_DEBUG_PRINTLN("AutoDetectDisplay: status=0x%02X", status);
// detect SH1106
if(status == 0x00 || status == 0x08){
MESH_DEBUG_PRINTLN("AutoDetectDisplay: SH1106 detected");
_impl = &_sh1106;
return _sh1106.begin();
}
// fallback to SSD1306
MESH_DEBUG_PRINTLN("AutoDetectDisplay: falling back to SSD1306");
_impl = &_ssd1306;
return _ssd1306.begin();
}