DMA and Camera input - a notion about 16bit input data
Posted: Thu Jul 27, 2017 3:11 am
I've been studying the OV7670 camera and the I2S support in ESP32. Specifically, I've been studying the DMA support provided by the I2S peripheral. As I understand the story, the OV7670 presents data in 8bit units each camera clock cycle. The camera becomes the master and the ESP32 becomes the DMA slave. Each time the camera transitions a pixel clock, a new 8 bits of data becomes available.
Now I start to get hazy ... my understanding is that the ESP32 MUST read 16bits of data as a unit. In our samples, we don't configure the upper 8 bits so only read 8 bits of data into each 16 bit sample from the bus that is then written to RAM.
For example, if I am going to read 160 pixels where each pixel is transmitted as 2 clock cycles giving the 1st 8bits of pixel data and then the 2nd 8 bits of pixel data ... then my desire is to ingest 320 bytes. However, because the data is presented as 2 cycles of 8 bits each rather than 1 cycle of 16 bits, then I need to allocate 640 bytes. The data then written to RAM will be
P0L 00 P0H 00 P1L 00 P1H 00 P2L 00 P2H 00 P3L 00 P3H 00 ...
where:
PxL = pixel num Low
PxH = pixel num High
And now the notion that I have in mind. What if we used some simple digital electronics between the camera and the ESP32. Specifically, what if we use a divide/2 counter on the clock so that only every other clock pulse from the camera is sent to the ESP32 and in addition, an 8 bit data latch.
The result would then be that we could present a full 16 bits of data to the ESP32 for each DMA read.
Even clock pulses from the camera would load the 8 bit data latch while odd clock pulses would be passed through to the ESP32 so that it could read 8 bits directly from the camera and 8 bits from the previously latched data.
My electronic skills aren't super great but I believe that these components exist and are cheap. The result would be data in RAM that would consist of:
P0L P0H P1L P1H P2L P2H P3L P3H ....
and hence no wasted RAM space and 1/2 the load on DMA processing.
Again, these are just musings on my part but happy to discuss.
Now I start to get hazy ... my understanding is that the ESP32 MUST read 16bits of data as a unit. In our samples, we don't configure the upper 8 bits so only read 8 bits of data into each 16 bit sample from the bus that is then written to RAM.
For example, if I am going to read 160 pixels where each pixel is transmitted as 2 clock cycles giving the 1st 8bits of pixel data and then the 2nd 8 bits of pixel data ... then my desire is to ingest 320 bytes. However, because the data is presented as 2 cycles of 8 bits each rather than 1 cycle of 16 bits, then I need to allocate 640 bytes. The data then written to RAM will be
P0L 00 P0H 00 P1L 00 P1H 00 P2L 00 P2H 00 P3L 00 P3H 00 ...
where:
PxL = pixel num Low
PxH = pixel num High
And now the notion that I have in mind. What if we used some simple digital electronics between the camera and the ESP32. Specifically, what if we use a divide/2 counter on the clock so that only every other clock pulse from the camera is sent to the ESP32 and in addition, an 8 bit data latch.
The result would then be that we could present a full 16 bits of data to the ESP32 for each DMA read.
Even clock pulses from the camera would load the 8 bit data latch while odd clock pulses would be passed through to the ESP32 so that it could read 8 bits directly from the camera and 8 bits from the previously latched data.
My electronic skills aren't super great but I believe that these components exist and are cheap. The result would be data in RAM that would consist of:
P0L P0H P1L P1H P2L P2H P3L P3H ....
and hence no wasted RAM space and 1/2 the load on DMA processing.
Again, these are just musings on my part but happy to discuss.