@@ -348,9 +348,9 @@ def clear(self):
348
348
# Write the buffer to the display
349
349
self ._write (None , self .buffer )
350
350
351
- def saveDcPin (self ):
351
+ def savePinModeAlt (self , pin ):
352
352
"""
353
- Saves the current `mode` and `alt` of the DC pin so it can be restored
353
+ Saves the current `mode` and `alt` of the pin so it can be restored
354
354
later. Mostly used to restore the SPI mode (MISO) of the DC pin after
355
355
communication with the display in case another device is using the same
356
356
SPI bus.
@@ -361,12 +361,12 @@ def saveDcPin(self):
361
361
# There's no way to get the mode and alt of a pin directly, so we
362
362
# convert the pin to a string and parse it. Example format:
363
363
# "Pin(GPIO16, mode=ALT, alt=SPI)"
364
- dcStr = str (self . dc )
364
+ pinStr = str (pin )
365
365
366
366
# Extract the "mode" parameter from the pin string
367
- if "mode=" in dcStr :
367
+ if "mode=" in pinStr :
368
368
# Split between "mode=" and the next comma or closing parenthesis
369
- modeStr = dcStr .split ("mode=" )[1 ].split ("," )[0 ].split (")" )[0 ]
369
+ modeStr = pinStr .split ("mode=" )[1 ].split ("," )[0 ].split (")" )[0 ]
370
370
371
371
# Look up the mode in Pin class dictionary
372
372
mode = Pin .__dict__ [modeStr ]
@@ -375,9 +375,9 @@ def saveDcPin(self):
375
375
mode = None
376
376
377
377
# Extrct the "alt" parameter from the pin string
378
- if "alt=" in dcStr :
378
+ if "alt=" in pinStr :
379
379
# Split between "alt=" and the next comma or closing parenthesis
380
- altStr = dcStr .split ("alt=" )[1 ].split ("," )[0 ].split (")" )[0 ]
380
+ altStr = pinStr .split ("alt=" )[1 ].split ("," )[0 ].split (")" )[0 ]
381
381
382
382
# Look up the alt in Pin class dictionary (with "ALT_" prefix)
383
383
alt = Pin .__dict__ ["ALT_" + altStr ]
@@ -392,10 +392,12 @@ def _write(self, command=None, data=None):
392
392
"""SPI write to the device: commands and data."""
393
393
# Save the current mode and alt of the DC pin in case it's used by
394
394
# another device on the same SPI bus
395
- mode , alt = self .saveDcPin ()
395
+ dcMode , dcAlt = self .savePinModeAlt (self .dc )
396
+
396
397
# Temporarily set the DC pin to output mode
397
398
self .dc .init (mode = Pin .OUT )
398
399
400
+ # Write to the display
399
401
if self .cs :
400
402
self .cs .off ()
401
403
if command is not None :
@@ -408,4 +410,4 @@ def _write(self, command=None, data=None):
408
410
self .cs .on ()
409
411
410
412
# Restore the DC pin to its original mode and alt
411
- self .dc .init (mode = mode , alt = alt )
413
+ self .dc .init (mode = dcMode , alt = dcAlt )
0 commit comments