@@ -185,12 +185,6 @@ bool DisplayHardware::beginEPD(
185185 return false ;
186186 }
187187
188- // Validate mode is a correct EPD mode
189- if (config->mode == wippersnapper_display_v1_EPDMode_EPD_MODE_UNSPECIFIED) {
190- WS_DEBUG_PRINTLN (" [display] Unsupported EPD mode!" );
191- return false ;
192- }
193-
194188 // If we already have a display driver assigned to this hardware instance,
195189 // clean it up!
196190 if (_drvDisp) {
@@ -219,6 +213,21 @@ bool DisplayHardware::beginEPD(
219213 return false ;
220214 }
221215
216+ // For MagTag "Generic" display component, attempt to auto-detect SSD1680 EPD
217+ if (strncmp (_name, " eink-magtag" , 13 ) == 0 ) {
218+ if (detect_ssd1680 (cs, dc, rst)) {
219+ WS_DEBUG_PRINTLN (" [display] Detected SSD1680 EPD driver" );
220+ *driver =
221+ wippersnapper_display_v1_DisplayDriver_DISPLAY_DRIVER_EPD_SSD1680;
222+ config->mode = wippersnapper_display_v1_EPDMode_EPD_MODE_MONO;
223+ } else {
224+ WS_DEBUG_PRINTLN (" [display] Detected ILI0373 EPD driver" );
225+ *driver =
226+ wippersnapper_display_v1_DisplayDriver_DISPLAY_DRIVER_EPD_ILI0373;
227+ config->mode = wippersnapper_display_v1_EPDMode_EPD_MODE_GRAYSCALE4;
228+ }
229+ }
230+
222231 // Create display driver object using the factory function
223232 _drvDisp = CreateDrvDispEpd (*driver, dc, rst, cs, srcs, busy);
224233 if (!_drvDisp) {
@@ -387,20 +396,28 @@ void DisplayHardware::writeMessage(const char *message) {
387396 EPD).
388397*/
389398bool DisplayHardware::detect_ssd1680 (uint8_t cs, uint8_t dc, uint8_t rst) {
390- // note: for a complete implementation reference, see
391- // https://github.com/adafruit/circuitpython/commit/f4316cb2491c815b128acca47f1bb75519fe306e
392399 // Configure SPI pins to bit-bang
393400 pinMode (MOSI, OUTPUT);
394401 pinMode (SCK, OUTPUT);
395402 pinMode (cs, OUTPUT);
396403 pinMode (dc, OUTPUT);
397404 pinMode (rst, OUTPUT);
398405
406+ // Reset the display
407+ digitalWrite (cs, HIGH);
408+ digitalWrite (rst, HIGH);
409+ delay (10 );
410+ digitalWrite (rst, LOW);
411+ delay (10 );
412+ digitalWrite (rst, HIGH);
413+ delay (200 );
414+
399415 // Begin transaction by pulling cs and dc LOW
400416 digitalWrite (cs, LOW);
401417 digitalWrite (dc, LOW);
402- digitalWrite (SCK , LOW);
418+ digitalWrite (MOSI , LOW);
403419 digitalWrite (rst, HIGH);
420+ digitalWrite (SCK, LOW);
404421
405422 // Write to read register 0x71
406423 uint8_t cmd = 0x71 ;
@@ -412,10 +429,8 @@ bool DisplayHardware::detect_ssd1680(uint8_t cs, uint8_t dc, uint8_t rst) {
412429
413430 // Set DC high to indicate data and switch MOSI to input with PUR in case
414431 // SSD1680 does not send data back
415- digitalWrite (dc, HIGH);
416- delayMicroseconds (1 );
417432 pinMode (MOSI, INPUT_PULLUP);
418- delayMicroseconds ( 1 );
433+ digitalWrite (dc, HIGH );
419434
420435 // Read response from register
421436 uint8_t status = 0 ;
@@ -424,20 +439,12 @@ bool DisplayHardware::detect_ssd1680(uint8_t cs, uint8_t dc, uint8_t rst) {
424439 if (digitalRead (MOSI)) {
425440 status |= 1 ;
426441 }
442+
427443 digitalWrite (SCK, HIGH);
428- delayMicroseconds (1 );
429444 digitalWrite (SCK, LOW);
430- delayMicroseconds (1 );
431445 }
432-
433- // End transaction by pulling CS high
434446 digitalWrite (cs, HIGH);
435-
436- // Put back MOSI pin as an output
437447 pinMode (MOSI, OUTPUT);
438448
439- WS_DEBUG_PRINT (" [display] Bitbang read 0x71: 0x" );
440- WS_DEBUG_PRINTLN (status, HEX);
441-
442449 return status == 0xFF ;
443450}
0 commit comments