I am working on an embedded project that uses this hardware driver. I wrote a wrapper module (C++ as C, no objects) around this library to easily integrate it with my project. However, to make things simpler, I compiled my C wrapper code as C++ to side-step the issue of calling C++ from C.
Essentially what I tried to do was have an init function that initializes the driver code and keeps a static handle around for the other functions to use from within the same translation unit. I am by no means a C++ expert, but I am puzzled surrounding my current problem.
Here is an example of what I am doing:
static ILI9341_t3 *tft;
void display_init(void){
ILI9341_t3 _tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
_tft.begin();
_tft.fillScreen(ILI9341_BLACK);
_tft.setTextColor(ILI9341_YELLOW);
tft = &_tft;
}
void display_clear(void){
tft->fillScreen(ILI9341_BLACK);
}
This code compiles without issue, but any interaction with the screen after display_init is fruitless. Is this usage undefined in C++? What might be causing the object to become ineffective after leaving the scope of the init function?
This code seems to work if I put the entire object initialization in a static context, but I am not convinced this is the best path to take.