Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Inspirati
Copy link
Contributor

Initial preview of development work towards an esp32 compatible port.

Several issues to address, starting with how to manage disparate requirements of CMakeLists.txt

Initial development being tested on an esp32dev board with toolchain ESP-IDF v5.4.1-dirty

Primary goal is to achieve little impact on the existing codebase.

Review feedback welcome.

Initial preview of development work towards an esp32 compatible port.

Several issues to address, starting with how to manage disparate requirements of CMakeLists.txt

Initial development being tested on an esp32dev board with toolchain ESP-IDF v5.4.1-dirty

Primary goal is to achieve little impact on the existing codebase.

Review feedback welcome.
The secondary esp32 uart is configured for the tcli console, with the primary uart still utilised for diagnostics.
@gkoh
Copy link
Owner

gkoh commented Jun 17, 2025

@Inspirati thank you very much for the preview, I have taken a bit of time to review and consider.

Primary goal is to achieve little impact on the existing codebase.

I fully support this, the code is reasonably portable with only the timer and flash APIs being specific (and easily ported to other MCUs).

However, I do have some pause and concern with this particular approach.
Specifically, directly importing the esp32 code (lib/espidf) makes me uneasy. I'm unsure of the maintenance burden this may (or may not) entail.

A significant chunk of this effort has been splicing in the espidf framework with further work needed to manage and integrate the build to support both rp2040 and esp32.
This means we are creating our own multi-platform build system, something which is likely to become more complicated as more platforms are desired.

Perhaps an alternative to this effort (which I have already been idly entertaining), port the project to Zephyr.
In theory this would allow many more platforms to be supported, but especially rp2040 and esp32 support seems adequate for our needs.
Furthermore, platform support should be 'just' a device tree file configuration.

Zephyr also provides functionality that would supersede some of the custom work here, especially:

Of course, this is more effort, but I believe has longer term benefit.

Regardless of the outcome, thank you @Inspirati for your interest, I appreciate it.

@Inspirati
Copy link
Contributor Author

G'day gkoh, I appreciate your timely response.

Primary goal is to achieve little impact on the existing codebase.

Preliminary proof of concept would ideally not make a mess of your current art, such that #if/#endif is apt to do.

I fully support this, the code is reasonably portable with only the timer and flash APIs being specific (and easily ported to other MCUs).

Thankfully I found the code easily portable, unlike many other projects I have worked with. I only came here looking to glean the interrupt driven cec decoder, however have found myself venturing far beyond..

However, I do have some pause and concern with this particular approach.
Specifically, directly importing the esp32 code (lib/espidf) makes me uneasy. I'm unsure of the maintenance burden this may (or may not) entail.

This is only the pathway, and not an intended destination. 'tis only meant as a means to achieving my objective of evaluating the desired routines in an esp environment.

A significant chunk of this effort has been splicing in the espidf framework with further work needed to manage and integrate the build to support both rp2040 and esp32.
This means we are creating our own multi-platform build system, something which is likely to become more complicated as more platforms are desired.

I am a make (makefile) aficionado myself, having never taken favourably to cmake. This recent experience is only reinforcing such. A brief attempt at coercing cmake to do what is required, with both the esp-idf and pi vscode extensions in mind, has proven frustratingly futile.

Perhaps an alternative to this effort (which I have already been idly entertaining), port the project to Zephyr.

Not familiar with Zephyr so shall take a look. However upon initialy noting it is an rtos unto itself, my hopes are not high. The entire espressif ecosystem seems to be very much tightly coupled to freertos. Indeed, the freertos scheduler is already running before main (or rather app_main) is invoked. My guess is this would prove more challenging than the multi-platform build dilemma. But trying to run Zephyr within a freertos task could be fun, until it aint.

In theory this would allow many more platforms to be supported, but especially rp2040 and esp32 support seems adequate for our needs.
Furthermore, platform support should be 'just' a device tree file configuration.

I feel like your quotation marks around 'just' are justified. Rarely such is the case with such things.

Zephyr also provides functionality that would supersede some of the custom work here, especially:

shell/cli (https://docs.zephyrproject.org/latest/services/shell/index.html)

I quite like the shell, and have now got it coupled with a relative minimum of effort. Abstracting it for ready extension may be a another story, so I probably won't be taking it away with me.

USB HID (https://docs.zephyrproject.org/latest/connectivity/usb/device/usb_device.html#usb-human-interface-devices-hid-support)
logging (https://docs.zephyrproject.org/latest/services/logging/index.html)

As per above (re cec interrupt algorithm), I am not planning on going there, and would leave this functionality to the next guy.

Of course, this is more effort, but I believe has longer term benefit.

Let's see what I make (intended) of Zephyr.

If you could please report back any regressions with the pico build, such would be a great help. I'm not exactly set-up, nor familiar enough with it, to be at all thorough. My basic philosophy being that if I don't touch it, it shouldn't break?

Minor changes to structure and modification of several function prototypes to official parameter types & names.
In order to improve namespace clarity utilised git mv to change name of a couple of port support modules.
@gkoh
Copy link
Owner

gkoh commented Jun 19, 2025

G'day gkoh, I appreciate your timely response.
@Inspirati You are most welcome.

Primary goal is to achieve little impact on the existing codebase.

Preliminary proof of concept would ideally not make a mess of your current art, such that #if/#endif is apt to do.

Based on #49 I think we can minimise #{if,endif} macro hell.
Specifically, if we refactor hdmi-link accurately, it should be the only place platform specific code needs to occur.
Using this PR, it could almost be the build system just including the right source files, eg. there would be a hdmi_link_rp2040.c and hdmi_link_esp32.c, the disparate CMakeLists.txt would use the desired one.

I fully support this, the code is reasonably portable with only the timer and flash APIs being specific (and easily ported to other MCUs).

Thankfully I found the code easily portable, unlike many other projects I have worked with. I only came here looking to glean the interrupt driven cec decoder, however have found myself venturing far beyond..

Excellent, I did spend some time refactoring things so they were clean.
Of course, I didn't go far enough.

However, I do have some pause and concern with this particular approach.
Specifically, directly importing the esp32 code (lib/espidf) makes me uneasy. I'm unsure of the maintenance burden this may (or may not) entail.

This is only the pathway, and not an intended destination. 'tis only meant as a means to achieving my objective of evaluating the desired routines in an esp environment.

At a minimum, I would be fine with this being a staged approach, I recall that "perfect is the enemy of done".

A significant chunk of this effort has been splicing in the espidf framework with further work needed to manage and integrate the build to support both rp2040 and esp32.
This means we are creating our own multi-platform build system, something which is likely to become more complicated as more platforms are desired.

I am a make (makefile) aficionado myself, having never taken favourably to cmake. This recent experience is only reinforcing such. A brief attempt at coercing cmake to do what is required, with both the esp-idf and pi vscode extensions in mind, has proven frustratingly futile.

Aha, a fellow Makefile zealot 🙂
Thankfully, CMake is unlikely to completely supplant make itself, it still relies on it for the actual build process.

Perhaps an alternative to this effort (which I have already been idly entertaining), port the project to Zephyr.

Not familiar with Zephyr so shall take a look. However upon initialy noting it is an rtos unto itself, my hopes are not high. The entire espressif ecosystem seems to be very much tightly coupled to freertos. Indeed, the freertos scheduler is already running before main (or rather app_main) is invoked. My guess is this would prove more challenging than the multi-platform build dilemma. But trying to run Zephyr within a freertos task could be fun, until it aint.

My suggestion here would be to completely replace FreeRTOS with Zephyr, not integrate the two.
There is increasing support for ESP32 from Espressif themselves, thus this landscape is continuously changing (and perhaps improving).

In theory this would allow many more platforms to be supported, but especially rp2040 and esp32 support seems adequate for our needs.
Furthermore, platform support should be 'just' a device tree file configuration.

I feel like your quotation marks around 'just' are justified. Rarely such is the case with such things.

Yes, I'm wary of what is advertised vs what is true.
When I find some time, I will give Zephyr's build framework 'west' a trial.

Zephyr also provides functionality that would supersede some of the custom work here, especially:

shell/cli (https://docs.zephyrproject.org/latest/services/shell/index.html)

I quite like the shell, and have now got it coupled with a relative minimum of effort. Abstracting it for ready extension may be a another story, so I probably won't be taking it away with me.

tclie is indeed quite nice.
I did find some issues if you nest the regex too deep, it just 'got stuck' (which I suspect was a stack overflow, but never proved).

USB HID (https://docs.zephyrproject.org/latest/connectivity/usb/device/usb_device.html#usb-human-interface-devices-hid-support)
logging (https://docs.zephyrproject.org/latest/services/logging/index.html)

As per above (re cec interrupt algorithm), I am not planning on going there, and would leave this functionality to the next guy.

Of course, this is more effort, but I believe has longer term benefit.

Let's see what I make (intended) of Zephyr.

If you could please report back any regressions with the pico build, such would be a great help. I'm not exactly set-up, nor familiar enough with it, to be at all thorough. My basic philosophy being that if I don't touch it, it shouldn't break?

As noted in #49, I regard clang-format a requirement to ensure merges are as clean and minimal as possible.
If you are able to do that, the CI will check the builds for you.
Furthermore, I can do actual device testing as needed.

Significant progress along with major cleanup of the port code.

Also successfully build tested the pico target. Requires replacing CMakeFiles.txt with the accompanying CMakeFiles.pico

More work to come with renaming a few modules as discussed in the refactoring pull request.
Commit the rest of the update.
Mostly to quiet the format checker, but a few fixes addressing issues found during an independent build test.
@gkoh
Copy link
Owner

gkoh commented Jun 24, 2025

@Inspirati Might be better to exclude the imported sources from clang-format.
It's in the workflow here:

exclude-regex: '(crc\/.+|FreeRTOS-Kernel\/.+|pico-sdk\/.+|tcli\/.+)'

Note I exclude the cloned into external libraries (FreeRTOS-Kernel, crc, tcli, etc).

@gkoh
Copy link
Owner

gkoh commented Jun 24, 2025

@Inspirati Might be better to exclude the imported sources from clang-format. It's in the workflow here:

exclude-regex: '(crc\/.+|FreeRTOS-Kernel\/.+|pico-sdk\/.+|tcli\/.+)'

Note I exclude the cloned into external libraries (FreeRTOS-Kernel, crc, tcli, etc).

I went ahead and did this to help move things along.

Inspirati added 15 commits June 26, 2025 19:11
Both the legacy and new esp-idf i2c driver models are optionally supported. The former requires no change to the mainline source, the later requires a single processor conditional.
Significant cleanup preparing for a merge candidate.

As yet no run-time test conducted on pico hardware.

Proposed solution to disparate requirements for CMakeLists.txt is to require the user to copy one of the template versions as provided.

Now includes I2C (DDC) support, with options to try both new and legacy esp-idf i2c drivers.

Two potential methods to facilitate pico-sdk header inclusion - either with dummy (empty) headers in a replicated directory structure (to satisfy the C pre-processor), or by including all required headers in a common include. Both approaches can be trialled via use of the USE_PORTABLE define in CMakeFiles.txt
Builds and runs nicely on both esp32 and pico-pi.

With the addition of several new diagnostic features, RX_ABORTS have seemingly been eliminated.

Additional feature allows asynchronous sending of cec messages from external tasks.
Significant progress towards a fully functional esp32 port, with support for USB HID with target board esp32s3.

CEC modules decoupled from main application and moved to lib directory, for portability to other projects.

CEC driver now supports ability to asynchronously inject transmit messages from external tasks.

Includes numerous additional cec bus diagnostic features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants