Hi all.
This great forum have already helped me in various questions I had,
but now I cannot find a relevant topic
(or maybe I don't know the keywords for a decent search)
I am trying to use a class object as a library,
which is supplied by the manufacturer of a TFT Graphics controller IC (FTDI, FT800).
I am forced to use C++ as the library uses classes and templates and
it is not easy to me to port it in C.
The host microcontroller (atmega328) which controls the graphics controller (FT800) has only 32Kbytes flash,
so any byte is valuable.
In the header file FT_VM800P35.h there is a line defining a custom type
FT800IMPL_SPI which is used later for the declaration of the object
FTImpl.
FT_VM800P35.h :
1 2 3 4 5 6 7 8 9 10
|
#ifndef _FT_VM800P35_H_
#define _FT_VM800P35_H_
...
#include "libraries/FT_GC/FT_Transport_SPI/FT_Transport_SPI.h"
...
#include "libraries/FT_GC/FT800/FT800Impl.h"
...
typedef FT800Impl<FT_Transport_SPI> FT800IMPL_SPI;
#endif /* _FT_VM800P35_H_ */
|
FT800Impl.h, FT_Transport_SPI.h
are delivered by the manufacturer, as the above header file (FT_VM800P35.h).
Then, in my code file I have included the FT_VM800P35.h
and the line which declares the FTImpl using the FT800IMPL_SPI type.
1 2 3 4
|
...
#include <FT_VM800P35.h>
FT800IMPL_SPI FTImpl(FT_CS_PIN, FT_PDN_PIN, FT_INT_PIN);
...
|
When the code is one file, bellow the above lines, everything compiles and
runs smoothly, example code showing the use of FTImpl :
HMI_someGraph.cpp:
1 2 3 4 5 6 7 8 9
|
...
FTImpl.ColorRGB(120, 0, 120);
FTImpl.LineWidth(16);
FTImpl.Tag(HMI_Page_Header2);
FTImpl.Begin(FT_RECTS);
FTImpl.Vertex2f(261*16, 16);
FTImpl.Vertex2f(320*16, 25*16);
FTImpl.End();
...
|
But as the code is growing, I had to split the code to several files to
HMI_xxx.cpp and their HMI_xxx.h files.
The code in these files have to use the functions of FTImpl, but
I cannot find the way to do it.
I have tried making HMI_main.cpp and HMI_main.h files
with #include <FT_VM800P35.h> in the HMI_main.h file :
HMI_main.h :
1 2 3 4 5 6
|
#ifndef HMI_MAIN_H
#define HMI_MAIN_H
...
#include <FT_VM800P35.h>
...
#endif //HMI_MAIN_H
|
and
HMI_main.cpp :
1 2 3 4
|
#include "HMI_main.h"
...
FT800IMPL_SPI FTImpl(FT_CS_PIN, FT_PDN_PIN, FT_INT_PIN);
...
|
including #include "HMI_main.h" in the rest header files HMI_xxx.h
but with no success (" 'FTImpl' was not declared in this scope"),
for every HMI.xxx.cpp file.
and when I put
FT800IMPL_SPI FTImpl(FT_CS_PIN, FT_PDN_PIN, FT_INT_PIN);
in the HMI_main.h file
HMI_main.h :
1 2 3 4 5 6 7 8
|
#ifndef HMI_MAIN_H
#define HMI_MAIN_H
...
#include <FT_VM800P35.h>
...
FT800IMPL_SPI FTImpl(FT_CS_PIN, FT_PDN_PIN, FT_INT_PIN);
...
#endif //HMI_MAIN_H
|
again no success ("multiple definition of FTImpl")
for every HMI.xxx.cpp file that uses its functions.
The only working attempt was when I declare FTImpl as static in every HMI_xxx.cpp file.
HMI_Config.cpp :
1 2 3 4
|
#include "HMI_Config.h"
...
static FT800IMPL_SPI FTImpl(FT_CS_PIN, FT_PDN_PIN, FT_INT_PIN);
...
|
and
HMI_Config.h :
1 2 3 4 5 6
|
#ifndef HMI_CONFIG_H
#define HMI_CONFIG_H
...
#include <FT_VM800P35.h>
...
#endif // end HMI_CONFIG.H
|
But this solution seems to me it consumes so much flash, as it seems the same code is repeated in every instance / declaration of every file uses it.
Sorry for my ignorance and the wrong terminology,
but as I said I am new in C++.
Although it is chance to improve my C++ programming skills I would appreciate any help.
Thanks.