Teensy 4.1 DMA programming for video conversion

steady2025

New member
Hi everyone đź‘‹

I'm considering creating a video converter similar to this one https://github.com/AlexEkb4ever/ZX_RGBI2VGA-HDMI, but with Teensy and tailored to a specific model of a retro PC. The converter is necessary because the frequencies and video resolutions of the incoming and outgoing signals differ. For example, retro PC produces 320x192 pixels at 50Hz video, while VGA has 640x480 at 60Hz mode. Therefore, some scaling, padding, centring and buffering is needed.

I'm looking for information or examples of DMA programming and the usage of voltage comparators with Teensy 4.1 and C++/assembly.
The project requires reading the output R,G,B,SYNC signals into a frame buffer using DMA or a similar technology and simultaneously have a second DMA sending data from the buffer to a VGA R,G,B and SYNC pins.
Therefore, the minimal implementation requires two DMA-like processes with ISRs running at around 25 Mhz speed each.
Additionally, it would be great if Teensy is capable of performing voltage comparison and converting the incoming signal into digital values. For example, RGB pins of the retro PC can have 0V - for black, 1.8V - normal colour level, and 3.3V - bright version of the colour. If Teensy could convert these levels into digital representation, it would be great. Otherwise, some circuitry will be needed to split normal/bright colour levels and supply only HIGH/LOW values to two separate input pins of Teensy for each of the R, G and B signals.

Any links on DMA programming with ISRs and minimalistic high-speed ADC, or hints on how my task could be achieved, are highly appreciated.
Thanks!
 
Have you looked at using the PXP for image format conversion + scaling?
Yes, but the tricky part is what buffers and memory layout DMA/FlexIO will require, and whether these buffers are PXP-friendly.
I saw this thread https://forum.pjrc.com/index.php?threads/t4-pixel-pipeline-library.64860/ in which you actively contributed, and it was quite helpful in understanding PXP.

My main problem at this point is how to decode R, G, B, HS and VS signals on Teensy pins into a buffer in memory.
The ideal option is to have 2 bits per color and then have 6 bits for RGB and 2 bits for HS and VS.
With this approach, each pixel will also have HS/VS bits, but that's the price to pay for reading the entire line with DMA.

I'm not sure if PXP will be happy with such layouts.
Also, it could be that I can scale the image on-the-fly while receiving data, just by writing 2 bytes of the same color instead of 1 into a buffer.
This will automatically produce 320 -> 640 conversion. Or this could be done during output by sending the same color twice.
Padding and centring can also be done by changing the starting offset within the frame buffer.
I should also consider the output process. It may also require a specific buffer layout.

This project https://github.com/Jean-MarcHarvengt/VGA_t4 and this library https://github.com/Jean-MarcHarvengt/VGA_t4/blob/master/VGA_t4.cpp are awesome and helpful in understanding how the output can be implemented.
However, the project contains this remark
Please compile the sketches at 600MHz else some interferences will be visible.
and it makes me think that both capturing and outputting to VGA using this library could be too heavy task for CPU capacity.
 
Back
Top