diff --git a/drivers/display_bitsboard.cpp b/drivers/display_bitsboard.cpp
index d0cd269c77d778d88357539b3aa17335265b1658..200891cccf5fad60a5f8c0f40069316ad499f7bd 100644
--- a/drivers/display_bitsboard.cpp
+++ b/drivers/display_bitsboard.cpp
@@ -105,64 +105,36 @@ void TIM7_IRQHandler()
namespace mxgui {
+void registerDisplayHook(DisplayManager& dm)
+{
+ dm.registerDisplay(&DisplayImpl::instance());
+}
+
//
// class DisplayImpl
//
-DisplayImpl::DisplayImpl(): buffer(0), textColor(), font(miscFixed), last()
+DisplayImpl& DisplayImpl::instance()
{
- setTextColor(Color(black),Color(white));
- {
- FastInterruptDisableLock dLock;
- RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;
- RCC->APB1ENR |= RCC_APB1ENR_SPI2EN | RCC_APB1ENR_TIM7EN;
- sck::mode(Mode::ALTERNATE_OD);
- sck::alternateFunction(5);
- mosi::mode(Mode::ALTERNATE_OD);
- mosi::alternateFunction(5);
- dres::mode(Mode::OPEN_DRAIN);
- nflm::mode(Mode::OPEN_DRAIN);
- nm::mode(Mode::OPEN_DRAIN);
- dispoff::mode(Mode::OPEN_DRAIN);
- }
-
- nflm::high();
- nm::high();
- dispoff::high();
-
- dres::high();
- delayUs(10);
- dres::low();
- delayUs(10);
-
- framebuffer=new unsigned short[2048]; //256*128/16=2048
- unsigned int bba=(reinterpret_cast<unsigned>(framebuffer)-0x20000000)*32;
- framebufferBitBandAlias=reinterpret_cast<unsigned int*>(0x22000000+bba);
- memset(framebuffer,0,4096);
+ static DisplayImpl instance;
+ return instance;
+}
- TIM7->CR1=TIM_CR1_OPM;
- TIM7->DIER=TIM_DIER_UIE;
- TIM7->PSC=84-1; //84MHz/84=1MHz (1us resolution)
- TIM7->CNT=0;
+void DisplayImpl::doTurnOn()
+{
+ dispoff::low();
+}
- dmaRefill();
- NVIC_SetPriority(DMA1_Stream4_IRQn,2);//High priority for DMA
- NVIC_EnableIRQ(DMA1_Stream4_IRQn);
- NVIC_SetPriority(TIM7_IRQn,3);//High priority for TIM7
- NVIC_EnableIRQ(TIM7_IRQn);
+void DisplayImpl::doTurnOff()
+{
+ dispoff::high();
+}
- SPI2->CR2=SPI_CR2_TXDMAEN;
- SPI2->CR1=SPI_CR1_DFF | //16bit mode
- SPI_CR1_SSM | //SS pin not connected to SPI
- SPI_CR1_SSI | //Internal SS signal pulled high
- SPI_CR1_LSBFIRST | //Send LSB first
- SPI_CR1_MSTR | //Master mode
- SPI_CR1_SPE | //SPI enabled, master mode
- SPI_CR1_BR_0 |
- SPI_CR1_BR_1; //42MHz/16=2.625MHz (/4 by the 4094)=0.66MHz
+void DisplayImpl::doSetBrightness(int brt) {}
- Thread::sleep(500);
- dispoff::low();
+pair<short int, short int> DisplayImpl::doGetSize() const
+{
+ return make_pair(height,width);
}
void DisplayImpl::write(Point p, const char *text)
@@ -195,6 +167,21 @@ void DisplayImpl::clear(Point p1, Point p2, Color color)
while(it!=end()) *it=color;
}
+void DisplayImpl::beginPixel() {}
+
+void DisplayImpl::setPixel(Point p, Color color)
+{
+ //if(p.x()<0 || p.y()<0 || p.x()>=width || p.y()>=height) return;
+ unsigned short x=p.x();
+ unsigned short y=p.y();
+ if(y>=64)
+ {
+ y-=64;
+ x+=256;
+ }
+ framebufferBitBandAlias[512*y+x]= color ? 0 : 1;
+}
+
void DisplayImpl::line(Point a, Point b, Color color)
{
if(a.x()<0 || a.y()<0 || b.x()<0 || b.y()<0) return;
@@ -212,6 +199,17 @@ void DisplayImpl::scanLine(Point p, const Color *colors, unsigned short length)
for(int i=0;i<length;i++) *it=colors[i];
}
+Color *DisplayImpl::getScanLineBuffer()
+{
+ if(buffer==0) buffer=new Color[getWidth()];
+ return buffer;
+}
+
+void DisplayImpl::scanLineBuffer(Point p, unsigned short length)
+{
+ scanLine(p,buffer,length);
+}
+
void DisplayImpl::drawImage(Point p, const ImageBase& img)
{
short int xEnd=p.x()+img.getWidth()-1;
@@ -241,25 +239,21 @@ void DisplayImpl::drawRectangle(Point a, Point b, Color c)
line(Point(a.x(),b.y()),a,c);
}
-void DisplayImpl::turnOn()
+void DisplayImpl::setTextColor(pair<Color,Color> colors)
{
- dispoff::low();
+ Font::generatePalette(textColor,colors.first,colors.second);
}
-void DisplayImpl::turnOff()
+pair<Color,Color> DisplayImpl::getTextColor() const
{
- dispoff::high();
+ return make_pair(textColor[3],textColor[0]);
}
-void DisplayImpl::setTextColor(Color fgcolor, Color bgcolor)
-{
- Font::generatePalette(textColor,fgcolor,bgcolor);
-}
+void DisplayImpl::setFont(const Font& font) { this->font=font; }
-void DisplayImpl::setFont(const Font& font)
-{
- this->font=font;
-}
+Font DisplayImpl::getFont() const { return font; }
+
+void DisplayImpl::update() {}
DisplayImpl::pixel_iterator DisplayImpl::begin(Point p1, Point p2, IteratorDirection d)
{
@@ -281,6 +275,67 @@ DisplayImpl::pixel_iterator DisplayImpl::begin(Point p1, Point p2, IteratorDirec
return pixel_iterator(p1,p2,d,this);
}
+DisplayImpl::~DisplayImpl()
+{
+ if(buffer) delete[] buffer;
+}
+
+DisplayImpl::DisplayImpl(): buffer(0), textColor(), font(miscFixed), last()
+{
+ setTextColor(make_pair(Color(black),Color(white)));
+ {
+ FastInterruptDisableLock dLock;
+ RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;
+ RCC->APB1ENR |= RCC_APB1ENR_SPI2EN | RCC_APB1ENR_TIM7EN;
+ sck::mode(Mode::ALTERNATE_OD);
+ sck::alternateFunction(5);
+ mosi::mode(Mode::ALTERNATE_OD);
+ mosi::alternateFunction(5);
+ dres::mode(Mode::OPEN_DRAIN);
+ nflm::mode(Mode::OPEN_DRAIN);
+ nm::mode(Mode::OPEN_DRAIN);
+ dispoff::mode(Mode::OPEN_DRAIN);
+ }
+
+ nflm::high();
+ nm::high();
+ dispoff::high();
+
+ dres::high();
+ delayUs(10);
+ dres::low();
+ delayUs(10);
+
+ framebuffer=new unsigned short[2048]; //256*128/16=2048
+ unsigned int bba=(reinterpret_cast<unsigned>(framebuffer)-0x20000000)*32;
+ framebufferBitBandAlias=reinterpret_cast<unsigned int*>(0x22000000+bba);
+ memset(framebuffer,0,4096);
+
+ TIM7->CR1=TIM_CR1_OPM;
+ TIM7->DIER=TIM_DIER_UIE;
+ TIM7->PSC=84-1; //84MHz/84=1MHz (1us resolution)
+ TIM7->CNT=0;
+
+ dmaRefill();
+ NVIC_SetPriority(DMA1_Stream4_IRQn,2);//High priority for DMA
+ NVIC_EnableIRQ(DMA1_Stream4_IRQn);
+ NVIC_SetPriority(TIM7_IRQn,3);//High priority for TIM7
+ NVIC_EnableIRQ(TIM7_IRQn);
+
+ SPI2->CR2=SPI_CR2_TXDMAEN;
+ SPI2->CR1=SPI_CR1_DFF | //16bit mode
+ SPI_CR1_SSM | //SS pin not connected to SPI
+ SPI_CR1_SSI | //Internal SS signal pulled high
+ SPI_CR1_LSBFIRST | //Send LSB first
+ SPI_CR1_MSTR | //Master mode
+ SPI_CR1_SPE | //SPI enabled, master mode
+ SPI_CR1_BR_0 |
+ SPI_CR1_BR_1; //42MHz/16=2.625MHz (/4 by the 4094)=0.66MHz
+
+ Thread::sleep(500);
+ dispoff::low();
+}
+
} //namespace mxgui
#endif //_BOARD_BITSBOARD
diff --git a/drivers/display_bitsboard.h b/drivers/display_bitsboard.h
index e27a8d065a282d37d30049ea5f4f22271bff1597..168ff71c651ec8432b0d50132e22102d71e1f315 100644
--- a/drivers/display_bitsboard.h
+++ b/drivers/display_bitsboard.h
@@ -36,6 +36,7 @@
#ifdef _BOARD_BITSBOARD
#include <config/mxgui_settings.h>
+#include "display.h"
#include "point.h"
#include "color.h"
#include "font.h"
@@ -52,22 +53,43 @@
namespace mxgui {
-class DisplayImpl
+class DisplayImpl : public Display
{
public:
/**
- * Constructor.
- * Do not instantiate objects of this type directly from application code,
- * use Display::instance() instead.
+ * \return an instance to this class (singleton)
*/
- DisplayImpl();
+ static DisplayImpl& instance();
+
+ /**
+ * Turn the display On after it has been turned Off.
+ * Display initial state is On.
+ */
+ void doTurnOn() override;
+
+ /**
+ * Turn the display Off. It can be later turned back On.
+ */
+ void doTurnOff() override;
+
+ /**
+ * Set display brightness. Depending on the underlying driver,
+ * may do nothing.
+ * \param brt from 0 to 100
+ */
+ void doSetBrightness(int brt) override;
+
+ /**
+ * \return a pair with the display height and width
+ */
+ std::pair<short int, short int> doGetSize() const override;
/**
* Write text to the display. If text is too long it will be truncated
* \param p point where the upper left corner of the text will be printed
* \param text, text to print.
*/
- void write(Point p, const char *text);
+ void write(Point p, const char *text) override;
/**
* Write part of text to the display
@@ -78,13 +100,13 @@ public:
* \param b Lower right corner of clipping rectangle
* \param text text to write
*/
- void clippedWrite(Point p, Point a, Point b, const char *text);
+ void clippedWrite(Point p, Point a, Point b, const char *text) override;
/**
* Clear the Display. The screen will be filled with the desired color
* \param color fill color
*/
- void clear(Color color);
+ void clear(Color color) override;
/**
* Clear an area of the screen
@@ -92,7 +114,7 @@ public:
* \param p2 lower right corner of area to clear
* \param color fill color
*/
- void clear(Point p1, Point p2, Color color);
+ void clear(Point p1, Point p2, Color color) override;
/**
* This member function is used on some target displays to reset the
@@ -103,7 +125,7 @@ public:
* member function, for example line(), you have to call beginPixel() again
* before calling setPixel().
*/
- void beginPixel() {}
+ void beginPixel() override;
/**
* Draw a pixel with desired color. You have to call beginPixel() once
@@ -111,18 +133,7 @@ public:
* \param p point where to draw pixel
* \param color pixel color
*/
- void setPixel(Point p, Color color)
- {
- //if(p.x()<0 || p.y()<0 || p.x()>=width || p.y()>=height) return;
- unsigned short x=p.x();
- unsigned short y=p.y();
- if(y>=64)
- {
- y-=64;
- x+=256;
- }
- framebufferBitBandAlias[512*y+x]= color ? 0 : 1;
- }
+ void setPixel(Point p, Color color) override;
/**
* Draw a line between point a and point b, with color c
@@ -130,7 +141,7 @@ public:
* \param b second point
* \param c line color
*/
- void line(Point a, Point b, Color color);
+ void line(Point a, Point b, Color color) override;
/**
* Draw an horizontal line on screen.
@@ -141,17 +152,13 @@ public:
* \param length length of colors array.
* p.x()+length must be <= display.width()
*/
- void scanLine(Point p, const Color *colors, unsigned short length);
+ void scanLine(Point p, const Color *colors, unsigned short length) override;
/**
* \return a buffer of length equal to this->getWidth() that can be used to
* render a scanline.
*/
- Color *getScanLineBuffer()
- {
- if(buffer==0) buffer=new Color[getWidth()];
- return buffer;
- }
+ Color *getScanLineBuffer() override;
/**
* Draw the content of the last getScanLineBuffer() on an horizontal line
@@ -160,17 +167,14 @@ public:
* \param length length of colors array.
* p.x()+length must be <= display.width()
*/
- void scanLineBuffer(Point p, unsigned short length)
- {
- scanLine(p,buffer,length);
- }
+ void scanLineBuffer(Point p, unsigned short length) override;
/**
* Draw an image on the screen
* \param p point of the upper left corner where the image will be drawn
* \param i image to draw
*/
- void drawImage(Point p, const ImageBase& img);
+ void drawImage(Point p, const ImageBase& img) override;
/**
* Draw part of an image on the screen
@@ -181,7 +185,7 @@ public:
* \param b Lower right corner of clipping rectangle
* \param i Image to draw
*/
- void clippedDrawImage(Point p, Point a, Point b, const ImageBase& img);
+ void clippedDrawImage(Point p, Point a, Point b, const ImageBase& img) override;
/**
* Draw a rectangle (not filled) with the desired color
@@ -189,71 +193,37 @@ public:
* \param b lower right corner of the rectangle
* \param c color of the line
*/
- void drawRectangle(Point a, Point b, Color c);
-
- /**
- * \return the display's height
- */
- short int getHeight() const { return height; }
-
- /**
- * \return the display's width
- */
- short int getWidth() const { return width; }
-
- /**
- * Turn the display On after it has been turned Off.
- * Display initial state is On.
- */
- void turnOn();
-
- /**
- * Turn the display Off. It can be later turned back On.
- */
- void turnOff();
-
- /**
- * Set display brightness. Depending on the underlying driver,
- * may do nothing.
- * \param brt from 0 to 100
- */
- void setBrightness(int brt) {}
+ void drawRectangle(Point a, Point b, Color c) override;
/**
* Set colors used for writing text
* \param fgcolor text color
* \param bgcolor background color
*/
- void setTextColor(Color fgcolor, Color bgcolor);
-
- /**
- * \return the current foreground color.
- * The foreground color is used to draw text on screen
- */
- Color getForeground() const { return textColor[3]; }
+ void setTextColor(std::pair<Color,Color> colors) override;
- /**
- * \return the current background color.
- * The foreground color is used to draw text on screen
+ /**
+ * \return a pair with the foreground and background colors.
+ * Those colors are used to draw text on screen
*/
- Color getBackground() const { return textColor[0]; }
+ std::pair<Color,Color> getTextColor() const override;
/**
* Set the font used for writing text
* \param font new font
*/
- void setFont(const Font& font);
+ void setFont(const Font& font) override;
/**
* \return the current font used to draw text
*/
- Font getFont() const { return font; }
+ Font getFont() const override;
/**
* Make all changes done to the display since the last call to update()
- * visible. This backends require it.
+ * visible. This backends does not require it, so it is empty.
*/
- void update() {}
+ void update() override;
/**
* Pixel iterator. A pixel iterator is an output iterator that allows to
@@ -427,12 +397,15 @@ public:
/**
* Destructor
*/
- ~DisplayImpl()
- {
- if(buffer) delete[] buffer;
- }
+ ~DisplayImpl() override;
private:
+ /**
+ * Constructor.
+ * Do not instantiate objects of this type directly from application code.
+ */
+ DisplayImpl();
+
#if defined MXGUI_ORIENTATION_VERTICAL || \
defined MXGUI_ORIENTATION_VERTICAL_MIRRORED
static const short int width=128;