marciot / esp32-dali-clock

An NTSC/PAL version of the 80s Dali Clock for the ESP32
GNU General Public License v3.0
117 stars 10 forks source link

no issue - question about composite video #9

Open BobSleigh38 opened 6 months ago

BobSleigh38 commented 6 months ago

Hello and thank you for sharing your work I understand that your code for composite video is between bitluni library (esp32lib) and ESP_8_BIT library Your demo for the clock works fine for me on a car dvd player screen However I have no image when I use any of bitluni code. Did you have the same issue than me ? How did you solve it ? Does it have something to do with bad syncing (PLL/APLL) ? I really enjoy the clock :)

marciot commented 6 months ago

Bitluni's video generation code and the one in ESP_8_BIT are very different. They both worked on the monitors I tried, but the code in ESP_8_BIT seemed superior and was more capable. I do not understand either code well enough to say why that might be.

You didn't mention why you you were looking to use Bitluni's code, but if you simply want to run his demos, I made a fork of his code and demos which have been adapted to use the video generator backend from ESP_8_BIT:

https://github.com/marciot/ESP32CompositeColorVideo

You may have better luck with that one.

BobSleigh38 commented 6 months ago

Thank you for your answer. I have no idea why Bitluni's code is not working. I actually don't need to stick to Bitluni's library but he made an incredible work on documenting his library, for example on his youtube channel, and it's nice to know how the library work instead of just adding the headers and calling the functions. I'm also exploring the Fabgl library which work for me I'm trying to have both graphics and music / sound on an esp32.

M0NWY commented 5 months ago

This took me like 3 evenings of swearing to figure out, but you need to downgrade your esp32 tool chain to the one the code was originally written for. Bitluni's code works fine for me on esp32 v1.0.1. and Arduino IDE 2.2.1(Latest).

BobSleigh38 commented 5 months ago

Hello M0NWY and thank you so much for sharing your solution. However I never compiled bitluni's examples with Expressif toolchain but with Arduino IDE Which version of toolchain worked for you ?

M0NWY commented 5 months ago

I meant the esp32 toolchain that can be integrated into the arduino IDE via the board manager and the external URL that you add in to the preferences.. V1.0.1 worked for me, even with the latest arduino IDE (v2.2.1).

On Tue, 9 Jan 2024 at 21:58, Bob Sleigh @.***> wrote:

Hello M0NWY and thank you so much for sharing your solution. However I never compiled bitluni's examples with Expressif toolchain but with Arduino IDE Which version of toolchain worked for you ?

— Reply to this email directly, view it on GitHub https://github.com/marciot/esp32-dali-clock/issues/9#issuecomment-1883863377, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACTFGWDIGWG4VFRNIVJJP2LYNW4QLAVCNFSM6AAAAABAR6RAGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBTHA3DGMZXG4 . You are receiving this because you commented.Message ID: @.***>

BobSleigh38 commented 5 months ago

Hello M0NWY, I downgraded "esp32 by espressif systems" in arduino manager from 2.0.14 to 1.0.1 as you said. It works !!! (see photo attached) Tested with arduino ide 2.2.1 too Something happened between 2.0.0 (working) and 2.0.1 (not working) they are around 80 commits between the two versions. Maybe it's possible to locate the exact code change that make this bug happens in espdif github repository but I don't know how to do this investigation as I upgrade/downgrade boards in arduino IDE. WhatsApp Image 2024-01-25 at 20 02 26

marciot commented 5 months ago

@BobSleigh38: Can you provide a link to the two commits you mentioned?

I have a hunch the problem has something to do with the initialization of the APLL hardware. If I can see what changed between the two commits, maybe I can see if anything might have affected the way the APLL hardware is initialized.

BobSleigh38 commented 5 months ago

Hi Marciot ! I don't use commits. I go to arduino IDE->tools->board->board manager From there I go to "esp32 by espressif systems" then I downgrade to 2.0.0 (working version) or 2.0.1 (not working version) Now I'm trying to identify more precisely the changes that made the code not working anymore with git tool and the repository https://github.com/espressif/arduino-esp32 It's not an easy task .... Hope it helps, and sorry for posting about Bitluni's project on your project repository but this is where I got answers :) !

BobSleigh38 commented 5 months ago

The guilty commit is here : https://github.com/espressif/arduino-esp32/commit/00214d5c2a1c2b1904f2caf6f0d5ddfe952331ff But they are so many modifications in this commit (1475 files) I'm lost !

marciot commented 5 months ago

Ah, so I searched that repo for "rtc_clk_apll_enable", which is the function I suspect might have changed, and I did not find it. It looks like the "espressif/arduino-esp32" is just the code that links the Arduino IDE to the underlying espressif code. That code we care about is this other repo:

https://github.com/espressif/esp-idf

So, now the challenge is to figure out which versions of the esp-idf introduced the change. I appears as if the arduino-esp32 repo has commits such as this one which indicate when the underlying IDF is changed:

https://github.com/espressif/arduino-esp32/pull/8943

So with this, it should theoretically be possible to cross reference to the other repo.

marciot commented 5 months ago

Okay, so here are my finding based on the information you provided:

Date arduino-esp32 esp-idf Notes
Nov 22, 2021 https://github.com/espressif/arduino-esp32/commit/a5002c86a063432ab7614fa642aef98357d137ea Mentions IDF release/v4.4 ddc44956bf
Nov 4, 2021 https://github.com/espressif/arduino-esp32/commit/418ac74be0b9b4f254aaf326641f3d2fe07918a7 Mentions IDF release/v4.4 6a7d83af19
Oct 25, 2021 https://github.com/espressif/arduino-esp32/releases/tag/2.0.1-RC1 Arduino Release
Oct 24, 2021 https://github.com/espressif/arduino-esp32/pull/5801 Mentions v4.4-dev-3544-g2720d45e71
Oct 13, 2021 https://github.com/espressif/arduino-esp32/commit/34c81be93bcbc86c4c3525029c6e203c1e0c237e https://github.com/espressif/esp-idf/commit/b86fe0c66ca17d5907ae26ecdffc9d4eb79cec07
Oct 1, 2021 https://github.com/espressif/arduino-esp32/commit/00214d5c2a1c2b1904f2caf6f0d5ddfe952331ff https://github.com/espressif/esp-idf/commit/3e370c4296247b349aa3b9a0076c05b9946d47dc Commit @BobSleigh38 identified
Aug 31, 2021 https://github.com/espressif/arduino-esp32/releases/tag/2.0.0 Arduino-ESP Release Mentions v4.4-dev-2313-gc69f0ec32
Jul 26, 2021 https://github.com/espressif/arduino-esp32/commit/6972695d95039b990008d45389baf76bbf25f0ee https://github.com/espressif/esp-idf/commit/c69f0ec3292de2b9df5554405744296333d0feb2
marciot commented 5 months ago

So, where I am at. I suspect the code in https://github.com/espressif/esp-idf/commit/c69f0ec3292de2b9df5554405744296333d0feb2 from July 26, 2021 is the last working code, which was included in arduino-esp32 2.0.0 which was released on August 31, 2021.

However, it is unclear which version of the esp-idf code is used in the October 25, 2021 release of 2.0.1 RC, as the last reference to the esp-idf repository occurs on October 13, 2021. From that point on, I cannot find valid identifiers I can cross-reference between the two repos.

marciot commented 5 months ago

So I am falling down a rabbit hole here. Here is what I don't understand. In the video code, there is a function call that configures the timers. It looks like this:

https://github.com/marciot/esp32-dali-clock/blob/7569f83f4c1842c5a734d4a893aecfb99477aa8c/esp32-dali-clock/src/gfx/CompositeColorOutput.h#L343

Notice it takes five arguments. When I search the esp-idf repo for that function, I get a much shorter version which does not have the extra arguments:

https://github.com/search?q=repo%3Aespressif%2Fesp-idf%20rtc_clk_apll_enable&type=code

I cannot locate the five argument code in the esp-idf repo, which suggests maybe it isn't the correct code.

If I randomly Google for "rtc_clk_apll_enable", I get what appears to be a fork of esp-idf that does appears to have a "rtc_clk_apll_enable" with the correct number of arguments:

https://github.com/chunhuajiang/esp-idf-zh/blob/6d673f4fa2b9335dcb9df48179bbccf3fafdc290/components/soc/esp32/rtc_clk.c#L152

So I am wondering whether at some point, those extra arguments were removed from esp-idf. Could this possibly be the reason things broke?

I wonder whether it would be possible to take the function out of chunhuajiang's repo and see if using that to initialize the APLL hardware instead of the current function would solve the problem.

BobSleigh38 commented 5 months ago

Thank you so much much for your investigation !! I will try the code in rtc_clk.c What did partially work for me is the code from FabGL. I can see the image from bitluni demo (simple composite) on the screen, but the image is not still, it's scrolling very quickly vertically. I managed to get a still image at a moment, but I'm not able to reproduce this again. It's hard to understand the code. I grabbed the lines from here : https://github.com/fdivitto/FabGL/blob/master/src/devdrivers/cvbsgenerator.cpp I2S0.conf.tx_reset = 1; I2S0.conf.tx_reset = 0; I2S0.lc_conf.in_rst = 1; I2S0.lc_conf.in_rst = 0; ... ... ...

I did add those lines in bitluni's simple composite demo, right before the hack to get the 13MHz I2S frequency. https://github.com/bitluni/ESP32CompositeVideo/blob/master/CompositeVideoSimple/CompositeOutput.h //this is the hack that enables the highest sampling rate possible ~13MHz, have fun SET_PERI_REG_BITS(I2S_CLKM_CONF_REG(0), I2S_CLKM_DIV_A_V, 1, I2S_CLKM_DIV_A_S);

Right now I'm using FabGL, but it's using a huge library only for the video part, it takes ages (and memory?) to compile. That's why I'd be happy to switch back to bare minimal code.

I'm coding a pinball game, based on fantastic 1ko js demo from this guy https://frankforce.com/lu1ky-pinball-code-deep-dive/ I'm modifying the code so that it's optimized for esp32 (pre-calculation of normals in RLE bitmaps, like old dos games ) https://gamedev.stackexchange.com/questions/43705/2d-collision-detection-for-pinball-game/43719

Thank you again :)