@@ -138,6 +138,7 @@ uint32_t frame_crc;
138138int32_t crc_previous_frame = 0 ;
139139uint8_t skip_frames = 0 ;
140140bool locked_in = false ;
141+ bool plane0_shifted = false ;
141142
142143// SPI PIO
143144PIO spi_pio;
@@ -511,6 +512,9 @@ void dmd_dma_handler() {
511512 return ;
512513 }
513514
515+ // Required as long as CAPCOM is not locked-in:
516+ plane0_shifted = false ;
517+
514518 // Fix byte order within the buffer
515519 uint32_t *planebuf = (uint32_t *)currentPlaneBuffer;
516520 buf32_t *v;
@@ -549,21 +553,29 @@ void dmd_dma_handler() {
549553 // The other three combinations that reuslt in a valus of 1 indicate that
550554 // the signal is out of sync. It is sufficient to check one pixel of the
551555 // group.
552- if (DMD_CAPCOM == dmd_type && !locked_in && 1 == (pixval & 0xF )) {
553- if (planebuf[offset[0 ] + px] & 0xF ) {
554- // We are in sync.
555- locked_in = true ;
556- } else {
557- // Stop the state machine that detects frames.
558- pio_sm_set_enabled (dmd_pio, frame_sm, false );
559- // Start state machine again. The PIO program will skip at least one
560- // plane as it is waiting for RDATA at the beginning.
561- pio_sm_set_enabled (dmd_pio, frame_sm, true );
562- // We're out of sync. Skip the next frame which will contain garbage
563- // as it gets filles already in the background in this moment and would
564- // trigger the same correction.
565- skip_frames = 1 ;
566- // Do not switch buffers and return here. The DMD should show something.
556+ if (DMD_CAPCOM == dmd_type && !locked_in && !plane0_shifted) {
557+ if ((pixval & 0xF ) == 1 ) {
558+ if ((planebuf[px] & 0xF ) == 1 ) {
559+ // We are in sync.
560+ locked_in = true ;
561+ } else {
562+ // Stop the state machine that detects frames.
563+ pio_sm_set_enabled (dmd_pio, frame_sm, false );
564+ dma_channel_abort (dmd_dma_channel);
565+ // Enable DMA interrupt 0 to be triggered when the transfer is done.
566+ dma_channel_set_irq0_enabled (dmd_dma_channel, true );
567+ dma_channel_configure (
568+ dmd_dma_channel, &dmd_dma_channel_cfg,
569+ (currentPlaneBuffer == planebuf1) ? planebuf2 : planebuf1,
570+ &dmd_pio->rxf [dmd_sm], // Source pointer
571+ source_dwordsperframe, // Number of transfers
572+ true // Start now
573+ );
574+ // Start state machine again. The PIO program will skip at least one
575+ // plane as it is waiting for RDATA at the beginning.
576+ pio_sm_set_enabled (dmd_pio, frame_sm, true );
577+ plane0_shifted = true ;
578+ }
567579 }
568580 }
569581
@@ -822,7 +834,7 @@ void dmdreader_init(PIO pio) {
822834 source_width = 128 ;
823835 source_height = 32 ;
824836 source_bitsperpixel = 4 ;
825- target_bitsperpixel = 4 ;
837+ target_bitsperpixel = 2 ;
826838 source_planesperframe = 4 ;
827839 source_lineoversampling = LINEOVERSAMPLING_NONE;
828840 source_mergeplanes = MERGEPLANES_ADD;
0 commit comments