Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • avn/swd/third-party/mxgui
1 result
Select Git revision
Show changes
Showing
with 826 additions and 50 deletions
......@@ -33,14 +33,14 @@
#ifndef MXGUI_SETTINGS_H
#define MXGUI_SETTINGS_H
#define MXGUI_SETTINGS_VERSION 101
#define MXGUI_SETTINGS_VERSION 102
// Before you can compile mxgui you have to configure it by editing this
// file. After that, comment out this line to disable the reminder error.
// The PARSING_FROM_IDE is because Netbeans gets confused by this, it is never
// defined when compiling the code.
#ifndef PARSING_FROM_IDE
#error This error is a reminder that you have not edited mxgui_settings.h yet.
// #error This error is a reminder that you have not edited mxgui_settings.h yet.
#endif //PARSING_FROM_IDE
namespace mxgui {
......@@ -84,6 +84,13 @@ static const unsigned int level2MaxNumApps=4;
//#define MXGUI_ORIENTATION_VERTICAL_MIRRORED
//#define MXGUI_ORIENTATION_HORIZONTAL_MIRRORED
///
/// Invert touch screen Y coordinate.
/// Required on some boards as the touchscreen sensor is mounted with an
/// inverted vertical coordinate with respect to the display's one.
///
//#define MXGUI_TOUCH_INVERT_Y
///
/// Select which fonts are required. Choose one or more
///
......@@ -93,6 +100,9 @@ static const unsigned int level2MaxNumApps=4;
#define MXGUI_FONT_TAHOMA
#define MXGUI_ENABLE_BOLD_FONTS
//Default font
#define defaultFont droid11
#else //_MIOSIX
// Enable or disable level 2.
......@@ -144,6 +154,9 @@ static const unsigned int SIMULATOR_BGCOLOR=0;
#define MXGUI_FONT_TAHOMA
#define MXGUI_ENABLE_BOLD_FONTS
//Default font
#define defaultFont droid11
#endif //_MIOSIX
} //namespace mxgui
......
......@@ -29,7 +29,7 @@
#include "misc_inst.h"
#include "pthread_lock.h"
#if MXGUI_SETTINGS_VERSION != 101
#if MXGUI_SETTINGS_VERSION != 102
#error Wrong mxgui_settings.h version. You need to upgrade it.
#endif
......@@ -70,7 +70,7 @@ DisplayManager::DisplayManager()
// class Display
//
Display::Display() : isDisplayOn(true), font(miscFixed)
Display::Display() : isDisplayOn(true), font(defaultFont)
{
pthread_mutexattr_t temp;
pthread_mutexattr_init(&temp);
......
......@@ -114,6 +114,9 @@ void registerDisplayHook(DisplayManager& dm)
// class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
static DisplayImpl instance;
......@@ -266,7 +269,6 @@ DisplayImpl::~DisplayImpl()
DisplayImpl::DisplayImpl(): buffer(0), last()
{
setFont(miscFixed);
setTextColor(make_pair(Color(black),Color(white)));
{
FastInterruptDisableLock dLock;
......
......@@ -43,6 +43,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// Class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -356,7 +358,6 @@ DisplayImpl::DisplayImpl(): buffer(0)
//Power up sequence -- end
//
setFont(droid11);
setTextColor(make_pair(Color(0xffff),Color(0x0000)));
clear(black);
}
......
......@@ -91,6 +91,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// Class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -483,7 +485,6 @@ DisplayImpl::DisplayImpl()
sendCommand8(0x23,0x00);
sendCommand8(0x26,0xa0);
setFont(droid21);
setTextColor(make_pair(Color(0xffff),Color(0x0000)));
clear(black);
doTurnOn();
......
......@@ -45,6 +45,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -243,7 +245,6 @@ DisplayImpl::~DisplayImpl()
DisplayImpl::DisplayImpl(): buffer(0), last(), beginPixelCalled(false),
backend(QTBackend::instance())
{
setFont(droid11);
setTextColor(make_pair(Color(SIMULATOR_FGCOLOR),Color(SIMULATOR_BGCOLOR)));
}
......
......@@ -48,6 +48,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// Class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -289,7 +291,6 @@ DisplayImpl::DisplayImpl(): buffer(0)
writeReg(0x004f,0);
writeReg(0x004e,0);
//Fill display
setFont(droid11);
setTextColor(make_pair(white, black));
clear(black);
}
......
......@@ -74,6 +74,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// Class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -373,7 +375,6 @@ DisplayImpl::~DisplayImpl() {}
DisplayImpl::DisplayImpl(): which(0)
{
doTurnOn();
setFont(droid11);
setTextColor(make_pair(Color(0xffff),Color(0x0000)));
}
......
/***************************************************************************
* Copyright (C) 2014 by Terraneo Federico *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or use *
* macros or inline functions from this file, or you compile this file *
* and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with the GNU General *
* Public License. This exception does not invalidate any other reasons *
* why a work based on this file might be covered by the GNU General *
* Public License. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#ifdef _BOARD_STM32F415VG_ST25DVDISCOVERY
#include "display_st25dvdiscovery.h"
#include "miosix.h"
#include "misc_inst.h"
#include "line.h"
#include <cstdarg>
using namespace std;
using namespace miosix;
namespace mxgui {
//Control interface
typedef Gpio<GPIOB_BASE,13> scl; //SPI SCK
typedef Gpio<GPIOC_BASE, 3> sda; //SPI MOSI
typedef Gpio<GPIOC_BASE, 0> dcx; //Data/command
typedef Gpio<GPIOB_BASE,12> csx; //SPI CS
/**
* Send and receive a byte through SPI2
* \param c byte to send
* \return byte received
*/
static unsigned char spi2sendRev(unsigned char c=0)
{
SPI2->DR=c;
while((SPI2->SR & SPI_SR_RXNE)==0) ;
return SPI2->DR;
}
void sendCmd(unsigned char cmd, int len, ...)
{
// Send Command
dcx::low();
csx::low();
spi2sendRev(cmd);
delayUs(1);
dcx::high();
// Send Arguments
va_list arg;
va_start(arg,len);
for(int i=0;i<len;i++)
{
spi2sendRev(va_arg(arg,int));
delayUs(1);
}
va_end(arg);
csx::high();
}
Transaction::Transaction(unsigned char cmd)
{
dcx::low();
csx::low();
spi2sendRev(cmd);
delayUs(1);
dcx::high();
}
void Transaction::write(unsigned char c)
{
spi2sendRev(c);
delayUs(1);
}
Transaction::~Transaction()
{
csx::high();
}
void registerDisplayHook(DisplayManager& dm)
{
dm.registerDisplay(&DisplayImpl::instance());
}
DisplayImpl& DisplayImpl::instance()
{
static DisplayImpl instance;
return instance;
}
void DisplayImpl::doTurnOn()
{
sendCmd(0x29,0); //LCD_DISPLAY_ON
}
void DisplayImpl::doTurnOff()
{
sendCmd(0x28,0); //LCD_DISPLAY_ON
}
void DisplayImpl::doSetBrightness(int brt)
{
//TODO - Can be set by 0x51h
}
pair<short int, short int> DisplayImpl::doGetSize() const
{
return make_pair(height,width);
}
void DisplayImpl::write(Point p, const char *text)
{
font.draw(*this, textColor, p, text);
}
void DisplayImpl::clippedWrite(Point p, Point a, Point b, const char *text)
{
font.clippedDraw(*this, textColor, p, a, b, text);
}
void DisplayImpl::clear(Color color)
{
clear(Point(0,0), Point(width-1,height-1), color);
}
void DisplayImpl::clear(Point p1, Point p2, Color color)
{
unsigned char lsb = color & 0xFF;
unsigned char msb = (color >> 8) & 0xFF;
imageWindow(p1, p2);
int numPixels = (p2.x() - p1.x() + 1) * (p2.y() - p1.y() + 1);
Transaction t(0x2c);
//Send data to write on GRAM
for(int i=0; i < numPixels; i++)
{
t.write(msb);
t.write(lsb);
}
}
void DisplayImpl::beginPixel() {}
void DisplayImpl::setPixel(Point p, Color color)
{
unsigned char lsb = color & 0xFF;
unsigned char msb = (color >> 8) & 0xFF;
sendCmd(0x2c,2,msb,lsb); // RAMWR
}
void DisplayImpl::line(Point a, Point b, Color color)
{
// TODO - Horizontal line optimization
Line::draw(*this, a, b, color);
}
void DisplayImpl::scanLine(Point p, const Color *colors, unsigned short length)
{
imageWindow(p,Point(width-1,p.y()));
unsigned char lsb = 0x00;
unsigned char msb = 0x00;
Transaction t(0x2c); // RAMWR
for (int i = 0; i < length; i++)
{
lsb = colors[i] & 0xFF;
msb = (colors[i] >> 8) & 0xFF;
t.write(msb);
t.write(lsb);
}
}
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;
short int yEnd = p.y() + img.getHeight() - 1;
if(xEnd >= width || yEnd >= height) { return; }
const unsigned short *imgData = img.getData();
if(imgData != 0)
{
unsigned char lsb = 0x00;
unsigned char msb = 0x00;
//Optimized version for memory-loaded images
imageWindow(p, Point(xEnd, yEnd));
int numPixels = img.getHeight() * img.getWidth();
Transaction t(0x2c); // RAMWR
for(int i=0; i <= numPixels; i++)
{
lsb = imgData[i] & 0xFF;
msb = (imgData[i] >> 8) & 0xFF;
t.write(msb);
t.write(lsb);
}
}
else img.draw(*this,p);
}
void DisplayImpl::clippedDrawImage(Point p, Point a, Point b, const ImageBase& img)
{
img.clippedDraw(*this,p,a,b);
}
void DisplayImpl::drawRectangle(Point a, Point b, Color c)
{
line(a,Point(b.x(), a.y()), c);
line(Point(b.x(), a.y()), b, c);
line(b,Point(a.x(), b.y()), c);
line(Point(a.x(), b.y()), a, c);
}
DisplayImpl::pixel_iterator DisplayImpl::begin(Point p1, Point p2, IteratorDirection d)
{
if(p1.x()<0 || p1.y()<0 || p2.x()<0 || p2.y()<0)
{
return pixel_iterator();
}
if(p1.x() >= width || p1.y() >= height || p2.x() >= width || p2.y() >= height)
{
return pixel_iterator();
}
if(p2.x() < p1.x() || p2.y() < p1.y())
{
return pixel_iterator();
}
if(d==DR) textWindow(p1,p2);
else imageWindow(p1,p2);
unsigned int numPixels=(p2.x()-p1.x()+1)*(p2.y()-p1.y()+1);
return pixel_iterator(numPixels);
}
DisplayImpl::DisplayImpl() : buffer(0)
{
// TODO - RCC Sequence needed for PLLSAI? There is no PLLSAI for this MCU
// SPI2 Configuration
{
FastInterruptDisableLock dLock;
scl::mode(Mode::ALTERNATE); scl::alternateFunction(5); //SPI5
sda::mode(Mode::ALTERNATE); sda::alternateFunction(5);
csx::mode(Mode::OUTPUT); csx::high();
dcx::mode(Mode::OUTPUT);
RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
RCC_SYNC();
}
SPI2->CR1=SPI_CR1_SSM //Sowtware CS
| SPI_CR1_SSI //Software CS high
| SPI_CR1_SPE //SPI enabled
| (3<<3) //Divide input clock by 16: 84/16=5.25MHz
| SPI_CR1_MSTR; //Master mode
Thread::sleep(1);
// ILI9341 Configuration
sendCmd(0xca,3,0xc3,0x08,0x50); //undocumented command
sendCmd(0xcf,3,0x00,0xc1,0x30); //LCD_POWERB
sendCmd(0xed,4,0x64,0x03,0x12,0x81); //LCD_POWER_SEQ
sendCmd(0xe8,3,0x85,0x00,0x78); //LCD_DTCA
sendCmd(0xcb,5,0x39,0x2c,0x00,0x34,0x02); //LCD_POWERA
sendCmd(0xf7,1,0x20); //LCD_PRC
sendCmd(0xea,2,0x00,0x00); //LCD_DTCB
sendCmd(0xb1,2,0x00,0x1b); //LCD_FRMCTR1
sendCmd(0xb6,2,0x0a,0xa2); //LCD_DFC
sendCmd(0xc0,1,0x10); //LCD_POWER1
sendCmd(0xc1,1,0x10); //LCD_POWER2
sendCmd(0xc5,2,0x45,0x15); //LCD_VCOM1
sendCmd(0xc7,1,0x90); //LCD_VCOM2
sendCmd(0x36,1,0x08); //LCD_MAC
sendCmd(0xf2,1,0x00); //LCD_3GAMMA_EN
sendCmd(0xb6,4,0x0a,0xa7,0x27,0x04); //LCD_DFC
sendCmd(0x2a,4,0x00,0x00,0x00,0xef); //LCD_COLUMN_ADDR
sendCmd(0x2b,4,0x00,0x00,0x01,0x3f); //LCD_PAGE_ADDR
sendCmd(0xf6,3,0x01,0x00,0x00); //LCD_INTERFACE
sendCmd(0x3a,1,0x05);
sendCmd(0x2c,0); //LCD_GRAM
Thread::sleep(200);
sendCmd(0x26,1,0x01); //LCD_GAMMA
sendCmd(0xe0,15,0x0f,0x29,0x24,0x0c,0x0e,0x09,0x4e,0x78,0x3c,0x09,0x13,
0x05,0x17,0x11,0x00); //LCD_PGAMMA
sendCmd(0xe1,15,0x00,0x16,0x1b,0x04,0x11,0x07,0x31,0x33,0x42,0x05,0x0c,
0x0a,0x28,0x2f,0x0f); //LCD_NGAMMA
sendCmd(0x11,0); //LCD_SLEEP_OUT
Thread::sleep(500);
sendCmd(0x29,0); //LCD_DISPLAY_ON
sendCmd(0x2c,0); //LCD_GRAM
imageWindow(Point(0,0), Point(width-1,height-1));
};
DisplayImpl::~DisplayImpl()
{
if (buffer) delete[] buffer;
}
}
#endif //_BOARD_STM32F415VG_ST25DVDISCOVERY
/***************************************************************************
* Copyright (C) 2014 by Terraneo Federico *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or use *
* macros or inline functions from this file, or you compile this file *
* and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with the GNU General *
* Public License. This exception does not invalidate any other reasons *
* why a work based on this file might be covered by the GNU General *
* Public License. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#ifndef MXGUI_LIBRARY
#error "This is header is private, it can be used only within mxgui."
#error "If your code depends on a private header, it IS broken."
#endif //MXGUI_LIBRARY
#ifndef DISPLAY_ST25DVDISCOVERY_H
#define DISPLAY_ST25DVDISCOVERY_H
#ifdef _BOARD_STM32F415VG_ST25DVDISCOVERY
#include "display.h"
#include "color.h"
#include "point.h"
namespace mxgui {
//This display is 16 bit per pixel, check that the color depth is properly
//configured
#ifndef MXGUI_COLOR_DEPTH_16_BIT
#error The ILI9341 driver requires a color depth of 16bit per pixel
#endif
/**
* Send a command to the ILI9341 display controller
* \param cmd command
* \param len length of the (optional) argument, or 0 for commands without
* arguments.
*/
void sendCmd(unsigned char cmd, int len, ...);
/**
* Simply another flavour of sending data to Display
* Useful for sending dynamically sized data
*/
class Transaction
{
public:
Transaction(unsigned char cmd);
void write(unsigned char c);
~Transaction();
Transaction(const Transaction&)=delete;
Transaction& operator=(const Transaction&)=delete;
};
class DisplayImpl : public Display
{
public:
/**
* \return an instance to this class (singleton)
*/
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) override;
/**
* Write part of text to the display
* \param p point of the upper left corner where the text will be drawn.
* Negative coordinates are allowed, as long as the clipped view has
* positive or zero coordinates
* \param a Upper left corner of clipping rectangle
* \param b Lower right corner of clipping rectangle
* \param text text to write
*/
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) override;
/**
* Clear an area of the screen
* \param p1 upper left corner of area to clear
* \param p2 lower right corner of area to clear
* \param color fill color
*/
void clear(Point p1, Point p2, Color color) override;
/**
* This member function is used on some target displays to reset the
* drawing window to its default value. You have to call beginPixel() once
* before calling setPixel(). You can then make any number of calls to
* setPixel() without calling beginPixel() again, as long as you don't
* call any other member function in this class. If you call another
* member function, for example line(), you have to call beginPixel() again
* before calling setPixel().
*/
void beginPixel() override;
/**
* Draw a pixel with desired color. You have to call beginPixel() once
* before calling setPixel()
* \param p point where to draw pixel
* \param color pixel color
*/
void setPixel(Point p, Color color) override;
/**
* Draw a line between point a and point b, with color c
* \param a first point
* \param b second point
* \param c line color
*/
void line(Point a, Point b, Color color) override;
/**
* Draw an horizontal line on screen.
* Instead of line(), this member function takes an array of colors to be
* able to individually set pixel colors of a line.
* \param p starting point of the line
* \param colors an array of pixel colors whoase size must be b.x()-a.x()+1
* \param length length of colors array.
* p.x()+length must be <= display.width()
*/
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() override;
/**
* Draw the content of the last getScanLineBuffer() on an horizontal line
* on the screen.
* \param p starting point of the line
* \param length length of colors array.
* p.x()+length must be <= display.width()
*/
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) override;
/**
* Draw part of an image on the screen
* \param p point of the upper left corner where the image will be drawn.
* Negative coordinates are allowed, as long as the clipped view has
* positive or zero coordinates
* \param a Upper left corner of clipping rectangle
* \param b Lower right corner of clipping rectangle
* \param i Image to draw
*/
void clippedDrawImage(Point p, Point a, Point b, const ImageBase& img) override;
/**
* Draw a rectangle (not filled) with the desired color
* \param a upper left corner of the rectangle
* \param b lower right corner of the rectangle
* \param c color of the line
*/
void drawRectangle(Point a, Point b, Color c) override;
class pixel_iterator
{
public:
/**
* Default constructor, results in an invalid iterator.
*/
pixel_iterator(): pixelLeft(0), wr(nullptr) {}
/**
* Set a pixel and move the pointer to the next one
* \param color color to set the current pixel
* \return a reference to this
*/
pixel_iterator& operator= (Color color)
{
pixelLeft--;
unsigned char lsb = color & 0xFF;
unsigned char msb = (color >> 8) & 0xFF;
wr->write(msb);
wr->write(lsb);
return *this;
}
/**
* Compare two pixel_iterators for equality.
* They are equal if they point to the same location.
*/
bool operator== (const pixel_iterator& itr)
{
return this->pixelLeft==itr.pixelLeft;
}
/**
* Compare two pixel_iterators for inequality.
* They different if they point to different locations.
*/
bool operator!= (const pixel_iterator& itr)
{
return this->pixelLeft!=itr.pixelLeft;
}
/**
* \return a reference to this.
*/
pixel_iterator& operator* () { return *this; }
/**
* \return a reference to this. Does not increment pixel pointer.
*/
pixel_iterator& operator++ () { return *this; }
/**
* \return a reference to this. Does not increment pixel pointer.
*/
pixel_iterator& operator++ (int) { return *this; }
/**
* Must be called if not all pixels of the required window are going
* to be written.
*/
void invalidate() {}
~pixel_iterator()
{
if(wr) delete wr;
}
private:
/**
* Constructor
* \param pixelLeft number of remaining pixels
*/
pixel_iterator(unsigned int pixelLeft): pixelLeft(pixelLeft)
{
wr = new Transaction(0x2c);
}
unsigned int pixelLeft; ///< How many pixels are left to draw
Transaction* wr;
friend class DisplayImpl;
};
/**
* Specify a window on screen and return an object that allows to write
* its pixels.
* Note: a call to begin() will invalidate any previous iterator.
* \param p1 upper left corner of window
* \param p2 lower right corner (included)
* \param d increment direction
* \return a pixel iterator
*/
pixel_iterator begin(Point p1, Point p2, IteratorDirection d);
/**
* \return an iterator which is one past the last pixel in the pixel
* specified by begin. Behaviour is undefined if called before calling
* begin()
*/
pixel_iterator end() const
{
// Default ctor: pixelLeft is zero
return pixel_iterator();
}
/**
* Destructor
*/
~DisplayImpl() override;
private:
/**
* Constructor.
* Do not instantiate objects of this type directly from application code.
*/
DisplayImpl();
#if defined MXGUI_ORIENTATION_VERTICAL
static const short int width=240;
static const short int height=320;
#elif defined MXGUI_ORIENTATION_HORIZONTAL || \
defined MXGUI_ORIENTATION_VERTICAL_MIRRORED || \
defined MXGUI_ORIENTATION_HORIZONTAL_MIRRORED
#error unsupported orientation
#else
#error No orientation defined
#endif
Color* buffer; ///< For scanLineBuffer
/**
* This member function is used to set the cursor stored in memory, as well as
* the SC,SP,EC,EP counters of display driver.
* \param p1 top-left point of the rectangle
* \param p2 bottom-right point of the rectangle
*/
static inline void window(Point p1, Point p2)
{
int SC[] = {p1.x() & 0xff, (p1.x() >> 8) & 0xff};
int EC[] = {p2.x() & 0xff, (p2.x() >> 8) & 0xff};
int SP[] = {p1.y() & 0xff, (p1.y() >> 8) & 0xff};
int EP[] = {p2.y() & 0xff, (p2.y() >> 8) & 0xff};
sendCmd(0x2a,4,SC[1],SC[0],EC[1],EC[0]); //LCD_COLUMN_ADDR
sendCmd(0x2b,4,SP[1],SP[0],EP[1],EP[0]); //LCD_PAGE_ADDR
sendCmd(0x2c,0); //LCD_RAMWR
}
/**
* Set a hardware window on the screen, optimized for writing text.
* The GRAM increment will be set to up-to-down first, then left-to-right which
* is the correct increment to draw fonts
* \param p1 upper left corner of the window
* \param p2 lower right corner of the window
*/
static inline void textWindow(Point p1, Point p2)
{
#ifdef MXGUI_ORIENTATION_VERTICAL
// p3 is p2 transposed relative to p1. So that the column and page addresses exchanges
Point p3(p1.x()+p2.y()-p1.y(),p1.y()+p2.x()-p1.x());
window(p1,p3);
sendCmd(0x36,1,0x28); //LCD_MAC
#elif defined MXGUI_ORIENTATION_HORIZONTAL
#error Not implemented
#elif defined MXGUI_ORIENTATION_VERTICAL_MIRRORED
#error Not implemented
#else //MXGUI_ORIENTATION_HORIZONTAL_MIRRORED
#error Not implemented
#endif
}
/**
* Set a hardware window on the screen, optimized for drawing images.
* The GRAM increment will be set to left-to-right first, then up-to-down which
* is the correct increment to draw images
* \param p1 upper left corner of the window
* \param p2 lower right corner of the window
*/
static inline void imageWindow(Point p1, Point p2)
{
#ifdef MXGUI_ORIENTATION_VERTICAL
window(p1,p2);
sendCmd(0x36,1,0x08); //LCD_MAC
#elif defined MXGUI_ORIENTATION_HORIZONTAL
#error Not implemented
#elif defined MXGUI_ORIENTATION_VERTICAL_MIRRORED
#error Not implemented
#else //MXGUI_ORIENTATION_HORIZONTAL_MIRRORED
#error Not implemented
#endif
}
};
} //namespace mxgui
#endif //_BOARD_STM32F415VG_ST25DVDISCOVERY
#endif //DISPLAY_ST25DVDISCOVERY_H
......@@ -31,6 +31,9 @@
#include "misc_inst.h"
#include "line.h"
//The ST7735 driver requires a color depth 16 per pixel
#ifdef MXGUI_COLOR_DEPTH_16_BIT
using namespace std;
using namespace miosix;
......@@ -63,6 +66,9 @@ const unsigned char initST7735b[] = {
0x00
};
const short int DisplayGenericST7735::width;
const short int DisplayGenericST7735::height;
/**
* Class DisplayGenericST7735
*/
......@@ -327,7 +333,6 @@ void DisplayGenericST7735::initialize() {
sendCmds(initST7735b);
doTurnOn();
setFont(droid11);
setTextColor(make_pair(white, black));
}
......@@ -346,3 +351,5 @@ void DisplayGenericST7735::sendCmds(const unsigned char *cmds) {
}
} //mxgui
#endif //MXGUI_COLOR_DEPTH_16_BIT
......@@ -39,9 +39,8 @@
namespace mxgui {
#ifndef MXGUI_COLOR_DEPTH_16_BIT
#error The ST7735 driver requires a color depth 16 per pixel
#endif
//The ST7735 driver requires a color depth 16 per pixel
#ifdef MXGUI_COLOR_DEPTH_16_BIT
//Used to transiently pull low either the csx or dcx pin
class Transaction
......@@ -329,14 +328,12 @@ protected:
private:
#if defined MXGUI_ORIENTATION_VERTICAL
#ifdef MXGUI_ORIENTATION_VERTICAL
static const short int width = 128;
static const short int height = 160;
#elif defined MXGUI_ORIENTATION_HORIZONTAL
#else //MXGUI_ORIENTATION_HORIZONTAL
static const short int width = 160;
static const short int height = 128;
#else
#error Orientation not defined
#endif
/**
......@@ -440,4 +437,6 @@ private:
Color *buffer; ///< For scanLineBuffer
};
#endif //MXGUI_COLOR_DEPTH_16_BIT
} //namespace mxgui
......@@ -51,6 +51,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -288,7 +290,6 @@ DisplayImpl::DisplayImpl(): buffer(0), displayType(UNKNOWN)
break;
}
setFont(droid11);
setTextColor(make_pair(Color(0xffff),Color(0x0000)));
clear(black);
}
......
......@@ -114,6 +114,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -467,7 +469,6 @@ DisplayImpl::DisplayImpl()
| 0 //no dithering
| LTDC_GCR_LTDCEN; //Display enabled
setFont(droid11);
setTextColor(make_pair(Color(0xffff),Color(0x0000)));
clear(black);
}
......@@ -561,6 +562,9 @@ void registerDisplayHook(DisplayManager& dm)
// class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
static DisplayImpl instance;
......@@ -1312,7 +1316,6 @@ DisplayImpl::DisplayImpl()
// Update the display
DSI->WCR |= DSI_WCR_LTDCEN;
setFont(droid11);
setTextColor(make_pair(Color(0xffff), Color(0x0000)));
clear(black);
}
......
......@@ -140,6 +140,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// Class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -477,7 +479,6 @@ DisplayImpl::DisplayImpl(): buffer(0)
writeReg(0x07, D0 | D1 |DTE | GON | BASEE);
//Fill display
setFont(droid11);
setTextColor(make_pair(white, black));
clear(black);
}
......
......@@ -45,6 +45,8 @@ void registerDisplayHook(DisplayManager& dm)
//
// class DisplayImpl
//
const short int DisplayImpl::width;
const short int DisplayImpl::height;
DisplayImpl& DisplayImpl::instance()
{
......@@ -248,7 +250,6 @@ DisplayImpl::DisplayImpl():
beginPixelCalled(false),
backend(WinBackend::instance())
{
setFont(droid11);
setTextColor(make_pair(Color(0xffff), Color(0x0000)));
}
......
......@@ -188,6 +188,9 @@ static Point getTouchData()
int x=static_cast<int>(tsData[0])<<4 | tsData[1]>>4;
int y=((static_cast<int>(tsData[1]) & 0xf)<<8) | tsData[2];
x=4095-x; //X is swapped
#ifdef MXGUI_TOUCH_INVERT_Y
y=4095-y; //On some boards Y is swapped too
#endif
//Calibration values. May vary from unit to unit
const int xMin=300;
const int xMax=3770;
......@@ -198,7 +201,11 @@ static Point getTouchData()
y=((y-yMin)*320)/(yMax-yMin);
x=min(239,max(0,x));
y=min(319,max(0,y));
#ifdef MXGUI_ORIENTATION_HORIZONTAL
return Point(319-y,x);
#else
return Point(x,y);
#endif
}
}
......
......@@ -37,18 +37,6 @@ namespace mxgui {
// Class Font
//
Font::Font(unsigned char startChar, unsigned char endChar, unsigned char height,
unsigned char width, unsigned char dataSize, bool antialiased,
const void *data): startChar(startChar), endChar(endChar),
height(height), width(width), dataSize(dataSize),
antialiased(antialiased), widths(0), offset(0), data(data) {}
Font::Font(unsigned char startChar, unsigned char endChar, unsigned char height,
unsigned char dataSize, bool antialiased, const unsigned char *widths,
const unsigned short *offset, const void *data): startChar(startChar),
endChar(endChar), height(height), width(0), dataSize(dataSize),
antialiased(antialiased), widths(widths), offset(offset), data(data) {}
short int Font::calculateLength(const char *s) const
{
if(isFixedWidth())
......
......@@ -56,9 +56,11 @@ public:
* \param data pinter to the font data. This must point to a static array
* so that no memeory leak problems occur
*/
Font(unsigned char startChar, unsigned char endChar, unsigned char height,
constexpr Font(unsigned char startChar, unsigned char endChar, unsigned char height,
unsigned char width, unsigned char dataSize, bool antialiased,
const void *data);
const void *data): startChar(startChar), endChar(endChar),
height(height), width(width), dataSize(dataSize),
antialiased(antialiased), widths(0), offset(0), data(data) {}
/**
* Creates a variable width font.
* \param startChar the first character available, example ' ' (ASCII space)
......@@ -74,9 +76,11 @@ public:
* \param data pinter to the font data. This must point to a static array
* so that no memeory leak problems occur
*/
Font(unsigned char startChar, unsigned char endChar, unsigned char height,
constexpr Font(unsigned char startChar, unsigned char endChar, unsigned char height,
unsigned char dataSize, bool antialiased, const unsigned char *widths,
const unsigned short *offset, const void *data);
const unsigned short *offset, const void *data): startChar(startChar),
endChar(endChar), height(height), width(0), dataSize(dataSize),
antialiased(antialiased), widths(widths), offset(offset), data(data) {}
/**
* Draw a string on a surface.
......
......@@ -67,17 +67,7 @@ Drawable::~Drawable()
// class Window
//
Window::Window() : prefs(white,black,
#ifdef MXGUI_FONT_DROID11
droid11),
#elif defined(MXGUI_FONT_TAHOMA)
tahoma),
#elif defined(MXGUI_FONT_MISCFIXED)
miscFixed),
#else
#error "Need a font"
#endif
redrawNeeded(false)
Window::Window() : prefs(white,black,defaultFont), redrawNeeded(false)
{
pthread_mutex_init(&mutex,NULL);
pthread_cond_init(&cond,NULL);
......