Skip to content

Using CalEPD in a C project

Martin F edited this page Mar 10, 2023 · 1 revision

via D1sconnected, he asked this in a CalEPD issue and found a nice way to do it. Since the Issue is closed, in order to make the solution available to everyone, I decided to add it here in the WiKi. Background info: You are working in a C project but you want to use a C++ component like CalEPD. What is the right step? Should I update all my code to C++?

If that's the not the right answer for you then keep on reading!

In D1sconnected own words here is his explanation on how to do it.

Steps to integrate it

  1. I left my entire code-base in C language with no changes
  2. Create additional cpp wrapper component, where placed CalEPD functions and left all cpp-related includes in cpp file
  3. Include wrapper header in main.c, function declaration has extern C directive

This works just fine. ESP32 Cmake pretty "smart" and there is no need to add any additional build steps.

And I suppose that the main issue was that I forget to remove cpp includes from header, which I tried to include in main.c.

main.c

#include <eink_interface.h>

eink_interface.h

#ifdef __cplusplus
extern "C"
#endif 
void EinkInterface_Demo(void);

eink_interface.cpp

#include "eink_interface.h"
#include "goodisplay/gdey0154d67.h"
#include <Fonts/ubuntu/Ubuntu_M8pt8b.h>

EpdSpi io;
Gdey0154d67 display(io);

void EinkInterface_Demo(void)
{
   display.init(false);
   display.setCursor(10, 40);
   display.setFont(&Ubuntu_M8pt8b);
   display.println("CalEPD display test\n");
   display.update();
}

CMakeLists.txt

set(component_srcs "eink_interface.cpp")

idf_component_register(SRCS "${component_srcs}"
                       REQUIRES freertos  driver CalEPD
                       INCLUDE_DIRS ".")

And here is stackoverflow topic, which perfectly describes what's going on. https://stackoverflow.com/a/20325642

Clone this wiki locally