bitluni / ESP32Lib

http://bitluni.net/esp32-vga/
441 stars 78 forks source link

Solving vsync in non-interrupt driver versions #40

Open Martin-Laclaustra opened 4 years ago

Martin-Laclaustra commented 4 years ago

You pose the problem here: https://github.com/bitluni/ESP32Lib/blob/222d95318fc5c61033dbdbd92c56f8a7d3a60129/src/VGA/VGA14Bit.h#L107 There is a solution. You need to use the interrupt though. Nevertheless I think I solved all the stability problems (see #39 ). The interrupt could be used just to read the buffer descriptor address of the DMA buffer just outed, to update dmaBufferDescriptorActive and then work currentLine from that (you implemented lines split in two buffers). This is how I did in the interrupt versions:

DMABufferDescriptor *currentDmaBufferDescriptor = (DMABufferDescriptor *)REG_READ(I2S_OUT_EOF_DES_ADDR_REG(staticthis->i2sIndex));
staticthis->dmaBufferDescriptorActive = ((uint32_t)currentDmaBufferDescriptor - (uint32_t)staticthis->dmaBufferDescriptors)/sizeof(DMABufferDescriptor);

staticthis is just a this pointer I prepared to be used in a static function. Also in that code I assume (I know because I create it so in the same source file) that descriptors are in an array block. This might be assuming too much if we want to implement a more generic code.

I would implement updating dmaBufferDescriptorActive in i2s.cpp, and I would search for the pointer through the linked list (after doing some timing measurements - we do not want to bog the ISR), to avoid assuming the block layout.

I could prepare some draft code for that if you are interested.