Skip to content

Commit e4143b9

Browse files
committed
Guard against undefined behavior with rst pin
1 parent df785e4 commit e4143b9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/components/display/hardware.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,22 +405,26 @@ bool DisplayHardware::detect_ssd1680(uint8_t cs, uint8_t dc, uint8_t rst) {
405405
pinMode(SCK, OUTPUT);
406406
pinMode(cs, OUTPUT);
407407
pinMode(dc, OUTPUT);
408-
pinMode(rst, OUTPUT);
408+
if (rst >= 0)
409+
pinMode(rst, OUTPUT);
409410

410411
// Reset the display
411412
digitalWrite(cs, HIGH);
412-
digitalWrite(rst, HIGH);
413-
delay(10);
414-
digitalWrite(rst, LOW);
415-
delay(10);
416-
digitalWrite(rst, HIGH);
417-
delay(200);
413+
if (rst >= 0) {
414+
digitalWrite(rst, HIGH);
415+
delay(10);
416+
digitalWrite(rst, LOW);
417+
delay(10);
418+
digitalWrite(rst, HIGH);
419+
delay(200);
420+
}
418421

419422
// Begin transaction by pulling cs and dc LOW
420423
digitalWrite(cs, LOW);
421424
digitalWrite(dc, LOW);
422425
digitalWrite(MOSI, LOW);
423-
digitalWrite(rst, HIGH);
426+
if (rst >= 0)
427+
digitalWrite(rst, HIGH);
424428
digitalWrite(SCK, LOW);
425429

426430
// Write to read register 0x71

0 commit comments

Comments
 (0)