@@ -93,22 +93,23 @@ typedef struct __attribute__((__packed__)) block_pix_crc_header_t {
9393#define MAX_MEMORY_OVERHEAD \
9494 4 // reserve additional memory in framebuf for line oversampling
9595
96+ // Use uint16_t for all of these variables to erase calculations:
9697uint16_t source_width;
9798uint16_t source_height;
98- uint8_t source_bitsperpixel;
99- uint8_t target_bitsperpixel;
100- uint8_t source_pixelsperbyte;
99+ uint16_t source_bitsperpixel;
100+ uint16_t target_bitsperpixel;
101+ uint16_t source_pixelsperbyte;
101102uint16_t source_bytes;
102103uint16_t target_bytes;
103104uint16_t source_pixelsperframe;
104105uint16_t source_dwordsperplane;
105106uint16_t source_bytesperplane;
106- uint8_t source_planesperframe;
107- uint8_t source_wordsperframe ;
107+ uint16_t source_planesperframe;
108+ uint16_t source_dwordsperframe ;
108109uint16_t source_bytesperframe;
109- uint8_t source_lineoversampling;
110- uint8_t source_wordsperline ;
111- uint8_t source_mergeplanes;
110+ uint16_t source_lineoversampling;
111+ uint16_t source_dwordsperline ;
112+ uint16_t source_mergeplanes;
112113
113114// the buffers need to be aligned to 4 byte because we work with uint32_t
114115// pointers later. raw data read from DMD
@@ -470,7 +471,7 @@ void dmd_dma_handler() {
470471 uint32_t *planebuf = (uint32_t *)currentPlaneBuffer;
471472 buf32_t *v;
472473 uint32_t res;
473- for (int i = 0 ; i < source_wordsperframe ; i++) {
474+ for (int i = 0 ; i < source_dwordsperframe ; i++) {
474475 v = (buf32_t *)planebuf;
475476 res = (v->byte3 << 24 ) | (v->byte2 << 16 ) | (v->byte1 << 8 ) | (v->byte0 );
476477 *planebuf = res;
@@ -534,38 +535,38 @@ void dmd_dma_handler() {
534535 uint16_t i = 0 ;
535536 uint32_t *dst, *src1, *src2;
536537 dst = src1 = framebuf;
537- src2 = src1 + source_wordsperline ;
538+ src2 = src1 + source_dwordsperline ;
538539 uint32_t v;
539540
540541 for (int l = 0 ; l < source_height; l++) {
541- for (int w = 0 ; w < source_wordsperline ; w++) {
542+ for (int w = 0 ; w < source_dwordsperline ; w++) {
542543 v = src1[w] * 2 + src2[w];
543544 dst[w] = v;
544545 }
545- src1 += source_wordsperline * 2 ; // source skips 2 lines forward
546- src2 += source_wordsperline * 2 ;
547- dst += source_wordsperline ; // destination skips only one line
546+ src1 += source_dwordsperline * 2 ; // source skips 2 lines forward
547+ src2 += source_dwordsperline * 2 ;
548+ dst += source_dwordsperline ; // destination skips only one line
548549 }
549550 } else if (source_lineoversampling == LINEOVERSAMPLING_4X) {
550551 uint16_t i = 0 ;
551552 uint32_t *dst, *src1, *src2, *src3, *src4;
552553 dst = src1 = framebuf;
553- src2 = src1 + source_wordsperline ;
554- src3 = src2 + source_wordsperline ;
555- src4 = src3 + source_wordsperline ;
554+ src2 = src1 + source_dwordsperline ;
555+ src3 = src2 + source_dwordsperline ;
556+ src4 = src3 + source_dwordsperline ;
556557 uint32_t v;
557558
558- for (int l = 0 ; l < source_height; l++) {
559- for (int w = 0 ; w < source_wordsperline ; w++) {
559+ for (int l = 0 ; l < source_height; l++) {
560+ for (int w = 0 ; w < source_dwordsperline ; w++) {
560561 // On SAM line order is really messed up :-(
561562 v = src4[w] * 8 + src3[w] * 1 + src2[w] * 4 + src1[w] * 2 ;
562563 dst[w] = v;
563564 }
564- src1 += source_wordsperline * 4 ; // source skips 4 lines forward
565- src2 += source_wordsperline * 4 ;
566- src3 += source_wordsperline * 4 ;
567- src4 += source_wordsperline * 4 ;
568- dst += source_wordsperline ; // destination skips only one line
565+ src1 += source_dwordsperline * 4 ; // source skips 4 lines forward
566+ src2 += source_dwordsperline * 4 ;
567+ src3 += source_dwordsperline * 4 ;
568+ src4 += source_dwordsperline * 4 ;
569+ dst += source_dwordsperline ; // destination skips only one line
569570 }
570571 }
571572
@@ -846,9 +847,9 @@ void dmdreader_init() {
846847 source_dwordsperplane *= 4 ;
847848 }
848849 source_bytesperplane = source_bytes;
849- source_wordsperframe = source_dwordsperplane * source_planesperframe;
850+ source_dwordsperframe = source_dwordsperplane * source_planesperframe;
850851 source_bytesperframe = source_bytesperplane * source_planesperframe;
851- source_wordsperline = source_width * source_bitsperpixel / 32 ;
852+ source_dwordsperline = source_width * source_bitsperpixel / 32 ;
852853
853854 // DMA for DMD reader
854855 dmd_dma_channel_cfg = dma_channel_get_default_config (dmd_dma_channel);
@@ -859,11 +860,11 @@ void dmdreader_init() {
859860
860861 // Configure the DMA channel. As soon as the PIO pushed a specified number of
861862 // words to its RX FIFO, the DMA transfer will be triggered.
862- // The amount of words to transfer is source_wordsperframe .
863+ // The amount of words to transfer is source_dwordsperframe .
863864 dma_channel_configure (dmd_dma_channel, &dmd_dma_channel_cfg,
864865 NULL , // Destination pointer, needs to be set later
865866 &dmd_pio->rxf [dmd_sm], // Source pointer
866- source_wordsperframe , // Number of transfers
867+ source_dwordsperframe , // Number of transfers
867868 false // Do not yet start
868869 );
869870 // Enable DMA interrupt 0 to be triggered when the transfer is done.
0 commit comments