Using Espressif Components in Arduino IDE

Hi, I am reading this:

and wondering how I can use in the Arduino IDE please?

Thanks

No guarantees, but you can get the source code from the repository and try to compile it. You may find that there are dependencies that you'll need to track down.

That's the link I posted for the IDF CMake env no!?
Are you saying you can just bang out a lib from it... Again, any explanation?

No, it's not the link you posted. It's the GitHub page containing the component's source code. You can try to create an Arduino code incorporating the source files. There's an example that you can use as a guide.

Converting it to an actual Arduino library is one approach. I got it to compile by adding the source to a sketch. The backend (arduino-cli) will compile all sources under the sketch's src directory, and any subdirectories. You'll need to save the sketch to reliably add files to it.

  • my_sketch/
    • my_sketch.ino
    • src/

There's a "download archive" link on that registry page. The archive contains a folder named esp_jpeg. So move that under src. You'll also want to delete the examples and test_apps directories, so the backend won't try to compile those. You end up with

  • my_sketch/
    • my_sketch.ino
    • src/
      • esp_jpeg/
        • CMakeLists.txt
        • Kconfig
        • jpeg_decoder.c
        • include/
          • jpeg_decoder.h
        • tjpgd/
          • tjpgd.h

and a few other files. In the .ino file, add the library header

#include "src/esp_jpeg/include/jpeg_decoder.h"

Just to be sure the compiler is not trying to outsmart you, you can also add a function call. In setup or loop, add

  esp_jpeg_decode(nullptr, nullptr);  //TODO remove

Don't actually try to run the sketch -- it will end badly. This is just to see if the build is working.

Next, a few minor adjustments to jpeg_decoder.c. Normally, the build system will configure the include paths. This is done in the CMakeLists.txt file; but we're not using CMake. Only two changes (here's a diff with the line numbers), adding the actual paths

14c14
< #include "jpeg_decoder.h"
---
> #include "include/jpeg_decoder.h"
28c28
< #include "tjpgd.h"
---
> #include "tjpgd/tjpgd.h"

Finally, there are some flags for tjpgd. Normally this is done with Kconfig, with the same-name file. Apparently it's a tool that reads the file and displays prompts, to generate a file named sdkconfig.h. There is such a file baked into the board platform, but it doesn't have the flags needed here. And you don't want to obscure those existing flags, which are needed elsewhere. So create src/esp_jpeg/tjpgd/sdkconfig.h:

#pragma once
#define CONFIG_JD_SZBUF 512
#define CONFIG_JD_FORMAT 1  // RGB565 (instead of RGB888)
#define CONFIG_JD_FASTDECODE 1 // 32BIT

That's a minimal set, with default values. Read that Kconfig file to see the other options.

So that built for me. Hope I didn't forget a step. And be sure to remove that call with the nullptrs. There is mention of having some of the functionality in the ROM of certain MCUs, in which case it may make sense to use that by having CONFIG_JD_USE_ROM set to y: a can of worms, if you choose to accept it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.