@@ -50,23 +50,10 @@ def __init__(
50
50
self .dc = Pin (pin_dc ) # Don't change mode/alt
51
51
self .cs = Pin (pin_cs , Pin .OUT , value = 1 ) if pin_cs else None
52
52
self .freq = freq
53
-
54
- # Get the current mode and alt of the pins so they can be restored
55
- txMode , txAlt = self .savePinModeAlt (self .tx )
56
- clkMode , clkAlt = self .savePinModeAlt (self .clk )
57
53
58
54
# Start the PIO state machine and DMA with 1 bytes per transfer
59
55
self ._setup_sm_and_dma (1 )
60
56
61
- # The tx and clk pins just got their mode and alt set for PIO0 or PIO1,
62
- # so we need to save them again to restore later when _write() is called
63
- self .txMode , self .txAlt = self .savePinModeAlt (self .tx )
64
- self .clkMode , self .clkAlt = self .savePinModeAlt (self .clk )
65
-
66
- # Now restore the original mode and alt of the pins
67
- self .tx .init (mode = txMode , alt = txAlt )
68
- self .clk .init (mode = clkMode , alt = clkAlt )
69
-
70
57
# Call the parent class constructor
71
58
super ().__init__ (width , height , rotation , color_order , reverse_bytes_in_word )
72
59
@@ -78,6 +65,10 @@ def _setup_sm_and_dma(self, bytes_per_transfer):
78
65
# Store the bytes per transfer for later use
79
66
self .bytes_per_transfer = bytes_per_transfer
80
67
68
+ # Get the current mode and alt of the pins so they can be restored
69
+ txMode , txAlt = self .savePinModeAlt (self .tx )
70
+ clkMode , clkAlt = self .savePinModeAlt (self .clk )
71
+
81
72
# Initialize the PIO state machine
82
73
self .sm = rp2 .StateMachine (
83
74
self .sm_id ,
@@ -88,7 +79,18 @@ def _setup_sm_and_dma(self, bytes_per_transfer):
88
79
pull_thresh = bytes_per_transfer * 8
89
80
)
90
81
91
- # Instantiate a DMA controller if not already done
82
+ # The tx and clk pins just got their mode and alt set for PIO0 or PIO1.
83
+ # We need to save them again to restore later when _write() is called,
84
+ # if we haven't already
85
+ if not hasattr (self , 'txMode' ):
86
+ self .txMode , self .txAlt = self .savePinModeAlt (self .tx )
87
+ self .clkMode , self .clkAlt = self .savePinModeAlt (self .clk )
88
+
89
+ # Now restore the original mode and alt of the pins
90
+ self .tx .init (mode = txMode , alt = txAlt )
91
+ self .clk .init (mode = clkMode , alt = clkAlt )
92
+
93
+ # Instantiate a DMA controller if not already done
92
94
if not hasattr (self , 'dma' ):
93
95
self .dma = rp2 .DMA ()
94
96
0 commit comments