@@ -348,9 +348,9 @@ def clear(self):
348348 # Write the buffer to the display
349349 self ._write (None , self .buffer )
350350
351- def saveDcPin (self ):
351+ def savePinModeAlt (self , pin ):
352352 """
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
354354 later. Mostly used to restore the SPI mode (MISO) of the DC pin after
355355 communication with the display in case another device is using the same
356356 SPI bus.
@@ -361,12 +361,12 @@ def saveDcPin(self):
361361 # There's no way to get the mode and alt of a pin directly, so we
362362 # convert the pin to a string and parse it. Example format:
363363 # "Pin(GPIO16, mode=ALT, alt=SPI)"
364- dcStr = str (self . dc )
364+ pinStr = str (pin )
365365
366366 # Extract the "mode" parameter from the pin string
367- if "mode=" in dcStr :
367+ if "mode=" in pinStr :
368368 # 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 ]
370370
371371 # Look up the mode in Pin class dictionary
372372 mode = Pin .__dict__ [modeStr ]
@@ -375,9 +375,9 @@ def saveDcPin(self):
375375 mode = None
376376
377377 # Extrct the "alt" parameter from the pin string
378- if "alt=" in dcStr :
378+ if "alt=" in pinStr :
379379 # 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 ]
381381
382382 # Look up the alt in Pin class dictionary (with "ALT_" prefix)
383383 alt = Pin .__dict__ ["ALT_" + altStr ]
@@ -392,10 +392,12 @@ def _write(self, command=None, data=None):
392392 """SPI write to the device: commands and data."""
393393 # Save the current mode and alt of the DC pin in case it's used by
394394 # another device on the same SPI bus
395- mode , alt = self .saveDcPin ()
395+ dcMode , dcAlt = self .savePinModeAlt (self .dc )
396+
396397 # Temporarily set the DC pin to output mode
397398 self .dc .init (mode = Pin .OUT )
398399
400+ # Write to the display
399401 if self .cs :
400402 self .cs .off ()
401403 if command is not None :
@@ -408,4 +410,4 @@ def _write(self, command=None, data=None):
408410 self .cs .on ()
409411
410412 # 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