@@ -100,6 +100,7 @@ uint16_t source_bytesperframe;
100100uint16_t source_lineoversampling;
101101uint16_t source_dwordsperline;
102102uint16_t source_mergeplanes;
103+ uint16_t offset[MAX_PLANESPERFRAME];
103104
104105static uint8_t *alloc_aligned_buffer (size_t size, size_t alignment,
105106 void **base_out) {
@@ -297,17 +298,17 @@ void spi_dma_handler() {
297298 * @return uint32_t Number of clocks per second
298299 */
299300uint32_t count_clock (uint pin) {
300- uint offset ;
301+ uint pio_offset ;
301302 pio_claim_free_sm_and_add_program_for_gpio_range (
302- &dmd_count_signal_program, &dmd_pio, &dmd_sm, &offset , pin, 1 , true );
303- dmd_counter_program_init (dmd_pio, dmd_sm, offset , pin);
303+ &dmd_count_signal_program, &dmd_pio, &dmd_sm, &pio_offset , pin, 1 , true );
304+ dmd_counter_program_init (dmd_pio, dmd_sm, pio_offset , pin);
304305 pio_sm_set_enabled (dmd_pio, dmd_sm, true );
305306 delay (500 );
306307 pio_sm_exec (dmd_pio, dmd_sm, pio_encode_in (pio_x, 32 ));
307308 uint32_t count = ~pio_sm_get (dmd_pio, dmd_sm);
308309 pio_sm_set_enabled (dmd_pio, dmd_sm, false );
309310 pio_remove_program_and_unclaim_sm (&dmd_count_signal_program, dmd_pio, dmd_sm,
310- offset );
311+ pio_offset );
311312
312313 return count * 2 ;
313314}
@@ -499,13 +500,6 @@ void dmd_dma_handler() {
499500 planebuf++;
500501 }
501502
502- // Merge multiple planes to get the frame data.
503- // Calculate offsets for the first pixel of each plane and cache these.
504- uint16_t offset[MAX_PLANESPERFRAME];
505- for (int i = 0 ; i < MAX_PLANESPERFRAME; i++) {
506- offset[i] = i * source_dwordsperplane;
507- }
508-
509503 // Get a 32bit pointer to the frame buffer to handle more pixels at once.
510504 uint32_t *framebuf = (uint32_t *)current_framebuf;
511505
@@ -977,6 +971,12 @@ bool dmdreader_init(bool return_on_no_detection) {
977971 current_framebuf = framebuf1;
978972 framebuf_to_send = framebuf2;
979973
974+ // Merge multiple planes to get the frame data.
975+ // Calculate offsets for the first pixel of each plane and cache these.
976+ for (int i = 0 ; i < MAX_PLANESPERFRAME; i++) {
977+ offset[i] = i * source_dwordsperplane;
978+ }
979+
980980 // DMA for DMD reader
981981 dmd_dma_channel = dma_claim_unused_channel (true );
982982 dmd_dma_channel_cfg = dma_channel_get_default_config (dmd_dma_channel);
@@ -1019,10 +1019,11 @@ void dmdreader_spi_init() {
10191019 digitalWrite (SPI0_CS, LOW);
10201020
10211021 // initialize SPI slave PIO
1022- uint offset ;
1022+ uint pio_offset ;
10231023 dmdreader_error_blink (pio_claim_free_sm_and_add_program_for_gpio_range (
1024- &clocked_output_program, &spi_pio, &spi_sm, &offset, SPI_BASE, 4 , true ));
1025- clocked_output_program_init (spi_pio, spi_sm, offset, SPI_BASE);
1024+ &clocked_output_program, &spi_pio, &spi_sm, &pio_offset, SPI_BASE, 4 ,
1025+ true ));
1026+ clocked_output_program_init (spi_pio, spi_sm, pio_offset, SPI_BASE);
10261027
10271028 // DMA for SPI
10281029 spi_dma_channel = dma_claim_unused_channel (true );
0 commit comments