@@ -113,12 +113,6 @@ void Hub75::FM6126A_setup() {
113
113
114
114
void Hub75::start (irq_handler_t handler) {
115
115
if (handler) {
116
- dma_channel = 0 ;
117
-
118
- // Try as I might, I can't seem to coax MicroPython into leaving PIO in a known state upon soft reset
119
- // check for claimed PIO and prepare a clean slate.
120
- stop (handler);
121
-
122
116
if (panel_type == PANEL_FM6126A) {
123
117
FM6126A_setup ();
124
118
}
@@ -139,7 +133,7 @@ void Hub75::start(irq_handler_t handler) {
139
133
// Prevent flicker in Python caused by the smaller dataset just blasting through the PIO too quickly
140
134
pio_sm_set_clkdiv (pio, sm_data, width <= 32 ? 2 .0f : 1 .0f );
141
135
142
- dma_channel_claim ( dma_channel);
136
+ dma_channel = dma_claim_unused_channel ( true );
143
137
dma_channel_config config = dma_channel_get_default_config (dma_channel);
144
138
channel_config_set_transfer_data_size (&config, DMA_SIZE_32);
145
139
channel_config_set_bswap (&config, false );
@@ -148,15 +142,13 @@ void Hub75::start(irq_handler_t handler) {
148
142
149
143
150
144
// Same handler for both DMA channels
151
- irq_set_exclusive_handler (DMA_IRQ_0, handler);
152
- irq_set_exclusive_handler (DMA_IRQ_1, handler);
145
+ irq_add_shared_handler (DMA_IRQ_0, handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
153
146
154
147
dma_channel_set_irq0_enabled (dma_channel, true );
155
148
156
149
irq_set_enabled (pio_get_dreq (pio, sm_data, true ), true );
157
150
irq_set_enabled (DMA_IRQ_0, true );
158
151
159
-
160
152
row = 0 ;
161
153
bit = 0 ;
162
154
@@ -169,10 +161,9 @@ void Hub75::start(irq_handler_t handler) {
169
161
void Hub75::stop (irq_handler_t handler) {
170
162
171
163
irq_set_enabled (DMA_IRQ_0, false );
172
- irq_set_enabled (DMA_IRQ_1, false );
173
164
irq_set_enabled (pio_get_dreq (pio, sm_data, true ), false );
174
165
175
- if (dma_channel_is_claimed (dma_channel)) {
166
+ if (dma_channel != - 1 && dma_channel_is_claimed (dma_channel)) {
176
167
dma_channel_set_irq0_enabled (dma_channel, false );
177
168
irq_remove_handler (DMA_IRQ_0, handler);
178
169
// dma_channel_wait_for_finish_blocking(dma_channel);
@@ -184,17 +175,21 @@ void Hub75::stop(irq_handler_t handler) {
184
175
if (pio_sm_is_claimed (pio, sm_data)) {
185
176
pio_sm_set_enabled (pio, sm_data, false );
186
177
pio_sm_drain_tx_fifo (pio, sm_data);
178
+ pio_remove_program (pio, &hub75_data_rgb888_program, data_prog_offs);
187
179
pio_sm_unclaim (pio, sm_data);
188
180
}
189
181
190
182
if (pio_sm_is_claimed (pio, sm_row)) {
191
183
pio_sm_set_enabled (pio, sm_row, false );
192
184
pio_sm_drain_tx_fifo (pio, sm_row);
185
+ if (inverted_stb) {
186
+ pio_remove_program (pio, &hub75_row_inverted_program, row_prog_offs);
187
+ } else {
188
+ pio_remove_program (pio, &hub75_row_program, row_prog_offs);
189
+ }
193
190
pio_sm_unclaim (pio, sm_row);
194
191
}
195
192
196
- pio_clear_instruction_memory (pio);
197
-
198
193
// Make sure the GPIO is in a known good state
199
194
// since we don't know what the PIO might have done with it
200
195
gpio_put_masked (0b111111 << pin_r0, 0 );
0 commit comments