Hi guys,
I have a problem and I would ask you for help.
I have the following scenario:
I built a small software for Mega2560 compatible board.
Now, I want to switch to a Due compatible board.
In order to use the DMA of the Due I have to switch also the display library. The display controller is not the same.
I though using the PIMPL idiom would be good to “hide” the actual hardware dependent implementation.
I created first the wrapper UI.h
#ifndef UI_H
#define UI_H
#include <SPI.h>
#define TFT_RST 10
#define TFT_DC 7
#define TFT_CS 9
class UI
{
public:
UI();
~UI();
void begin();
void reset();
void drawSth();
private:
struct Impl;
Impl* _impl;
};
#endif
Then, I have the UI.cpp file:
#include “UI.h”
#if Is_Atmel
#include "UI_ILI9341.cpp"
#else
#include "UI_ILI9325.cpp"
#endif
At this point, I want to change the implementation based on a build_flag defined in the environments of the platformio.ini
And last but not least the real implementation for the hardware:
#ifndef UI_ILI9341_H
#define UI_ILI9341_H
#include "UI.h"
#include "ILI9341_due_config.h"
#include "ILI9341_due.h"
#include "allFonts.h"
#include "allIcons.h"
struct UI::Impl
{
ILI9341_due tft = ILI9341_due(TFT_CS, TFT_DC, TFT_RST);
void begin()
{
tft.begin();
tft.setRotation(iliRotation90);
reset();
}
void reset()
{
tft.fillScreen(ILI9341_WHITE);
}
void drawSth()
{
tft.fillRectangle(0, 0, 20, 20, ILI9341_BLACK);
}
}
UI::UI()
{
_impl = new Impl();
}
UI::~UI()
{
delete _impl;
}
void UI::begin()
{
_impl->begin();
}
void UI::reset()
{
_impl->reset();
}
void UI::drawSth()
{
_impl->drawSth();
}
#endif
In addition, there is of course an implementation for the other display and the Atmega2560.
But for now, the implementation is completely empty. The public methods are available, but empty.
When I am trying to compile the whole thing for the Atmega2560 I am getting the following error:
In file included from C:\Users\phoef.platformio\packages\framework-arduinoavr\cores\arduino/Arduino.h:28:0,
from C:\Users\phoef.platformio\packages\framework-arduinoavr\libraries_cores_\arduino\SPI\src/SPI.h:17,
from lib\UI\UI.h:4,
from lib\UI\UI_ILI9341.cpp:4:
lib\Fonts/ArialRounded34.h:48:33: error: variable ‘ArialRounded34’ must be const in order to be put into read-only section by means of 'attribute((progmem))'
static uint8_t ArialRounded34[] PROGMEM = {
^
lib\Fonts/Arial29.h:48:26: error: variable ‘Arial29’ must be const in order to be put into read-only section by means of 'attribute((progmem))'
static uint8_t Arial29[] PROGMEM = {
^
*** [.pioenvs\megaatmega2560\libf9d\UI\UI_ILI9341.o] Error 1
I was hoping, that the LDF would ignore the not included file.
I guess it is not, because I am including the cpp file?
Any ideas how to achieve a hardware independent interface based on environments?
Thanks