adafruit compatible wrapper added
This commit is contained in:
parent
22e4aae491
commit
c17d11ac9c
|
@ -0,0 +1,339 @@
|
|||
/**
|
||||
* STM32F429 Discovery onboard display example
|
||||
*
|
||||
* Uses LTDC, see AN4861 for more information.
|
||||
*
|
||||
* Import the Adafruit GFX library
|
||||
* Sketch=>Include Libraries=>Manage Libraries=>Adafruit GFX
|
||||
*
|
||||
*/
|
||||
|
||||
#include "TFT_F429_Discovery.h"
|
||||
|
||||
TFT_F429_Discovery tft;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("LTDC Test!");
|
||||
|
||||
tft.begin();
|
||||
|
||||
Serial.println(F("Benchmark Time (microseconds)"));
|
||||
delay(10);
|
||||
Serial.print(F("Screen fill "));
|
||||
Serial.println(testFillScreen());
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Text "));
|
||||
Serial.println(testText());
|
||||
delay(3000);
|
||||
|
||||
Serial.print(F("Lines "));
|
||||
Serial.println(testLines(LTDC_CYAN));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Horiz/Vert Lines "));
|
||||
Serial.println(testFastLines(LTDC_RED, LTDC_BLUE));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Rectangles (outline) "));
|
||||
Serial.println(testRects(LTDC_GREEN));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Rectangles (filled) "));
|
||||
Serial.println(testFilledRects(LTDC_YELLOW, LTDC_MAGENTA));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Circles (filled) "));
|
||||
Serial.println(testFilledCircles(10, LTDC_MAGENTA));
|
||||
|
||||
Serial.print(F("Circles (outline) "));
|
||||
Serial.println(testCircles(10, LTDC_WHITE));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Triangles (outline) "));
|
||||
Serial.println(testTriangles());
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Triangles (filled) "));
|
||||
Serial.println(testFilledTriangles());
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Rounded rects (outline) "));
|
||||
Serial.println(testRoundRects());
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Rounded rects (filled) "));
|
||||
Serial.println(testFilledRoundRects());
|
||||
delay(500);
|
||||
|
||||
Serial.println(F("Done!"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop(void) {
|
||||
for(uint8_t rotation=0; rotation<4; rotation++) {
|
||||
tft.setRotation(rotation);
|
||||
testText();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long testFillScreen() {
|
||||
unsigned long start = micros();
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
yield();
|
||||
tft.fillScreen(LTDC_RED);
|
||||
yield();
|
||||
tft.fillScreen(LTDC_GREEN);
|
||||
yield();
|
||||
tft.fillScreen(LTDC_BLUE);
|
||||
yield();
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
yield();
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testText() {
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
unsigned long start = micros();
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextColor(LTDC_WHITE); tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(LTDC_YELLOW); tft.setTextSize(2);
|
||||
tft.println(1234.56);
|
||||
tft.setTextColor(LTDC_RED); tft.setTextSize(3);
|
||||
tft.println(0xDEADBEEF, HEX);
|
||||
tft.println();
|
||||
tft.setTextColor(LTDC_GREEN);
|
||||
tft.setTextSize(5);
|
||||
tft.println("Groop");
|
||||
tft.setTextSize(2);
|
||||
tft.println("I implore thee,");
|
||||
tft.setTextSize(1);
|
||||
tft.println("my foonting turlingdromes.");
|
||||
tft.println("And hooptiously drangle me");
|
||||
tft.println("with crinkly bindlewurdles,");
|
||||
tft.println("Or I will rend thee");
|
||||
tft.println("in the gobberwarts");
|
||||
tft.println("with my blurglecruncheon,");
|
||||
tft.println("see if I don't!");
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testLines(uint16_t color) {
|
||||
unsigned long start, t;
|
||||
int x1, y1, x2, y2,
|
||||
w = tft.width(),
|
||||
h = tft.height();
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
yield();
|
||||
|
||||
x1 = y1 = 0;
|
||||
y2 = h - 1;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = w - 1;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t = micros() - start; // fillScreen doesn't count against timing
|
||||
|
||||
yield();
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
yield();
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = 0;
|
||||
y2 = h - 1;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = 0;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t += micros() - start;
|
||||
|
||||
yield();
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
yield();
|
||||
|
||||
x1 = 0;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = w - 1;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t += micros() - start;
|
||||
|
||||
yield();
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
yield();
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = 0;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
|
||||
yield();
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFastLines(uint16_t color1, uint16_t color2) {
|
||||
unsigned long start;
|
||||
int x, y, w = tft.width(), h = tft.height();
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
start = micros();
|
||||
for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
|
||||
for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testRects(uint16_t color) {
|
||||
unsigned long start;
|
||||
int n, i, i2,
|
||||
cx = tft.width() / 2,
|
||||
cy = tft.height() / 2;
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
start = micros();
|
||||
for(i=2; i<n; i+=6) {
|
||||
i2 = i / 2;
|
||||
tft.drawRect(cx-i2, cy-i2, i, i, color);
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
|
||||
unsigned long start, t = 0;
|
||||
int n, i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
for(i=n; i>0; i-=6) {
|
||||
|
||||
i2 = i / 2;
|
||||
start = micros();
|
||||
tft.fillRect(cx-i2, cy-i2, i, i, color1);
|
||||
t += micros() - start;
|
||||
// Outlines are not included in timing results
|
||||
tft.drawRect(cx-i2, cy-i2, i, i, color2);
|
||||
yield();
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
|
||||
unsigned long start;
|
||||
int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
start = micros();
|
||||
for(x=radius; x<w; x+=r2) {
|
||||
for(y=radius; y<h; y+=r2) {
|
||||
tft.fillCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testCircles(uint8_t radius, uint16_t color) {
|
||||
unsigned long start;
|
||||
int x, y, r2 = radius * 2,
|
||||
w = tft.width() + radius,
|
||||
h = tft.height() + radius;
|
||||
|
||||
// Screen is not cleared for this one -- this is
|
||||
// intentional and does not affect the reported time.
|
||||
start = micros();
|
||||
for(x=0; x<w; x+=r2) {
|
||||
for(y=0; y<h; y+=r2) {
|
||||
tft.drawCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testTriangles() {
|
||||
unsigned long start;
|
||||
int n, i, cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
n = min(cx, cy);
|
||||
start = micros();
|
||||
for(i=0; i<n; i+=5) {
|
||||
tft.drawTriangle(
|
||||
cx , cy - i, // peak
|
||||
cx - i, cy + i, // bottom left
|
||||
cx + i, cy + i, // bottom right
|
||||
tft.color565(i, i, i));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledTriangles() {
|
||||
unsigned long start, t = 0;
|
||||
int i, cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
start = micros();
|
||||
for(i=min(cx,cy); i>10; i-=5) {
|
||||
start = micros();
|
||||
tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(0, i*10, i*10));
|
||||
t += micros() - start;
|
||||
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(i*10, i*10, 0));
|
||||
yield();
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned long testRoundRects() {
|
||||
unsigned long start;
|
||||
int w, i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
w = min(tft.width(), tft.height());
|
||||
start = micros();
|
||||
for(i=0; i<w; i+=6) {
|
||||
i2 = i / 2;
|
||||
tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledRoundRects() {
|
||||
unsigned long start;
|
||||
int i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(LTDC_BLACK);
|
||||
start = micros();
|
||||
for(i=min(tft.width(), tft.height()); i>20; i-=6) {
|
||||
i2 = i / 2;
|
||||
tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
|
||||
yield();
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
Wrapper for STM LTDC to Adafruit GFX driver
|
||||
|
||||
What is LTDC?
|
||||
http://www.st.com/content/ccc/resource/technical/document/application_note/group0/25/ca/f9/b4/ae/fc/4e/1e/DM00287603/files/DM00287603.pdf/jcr:content/translations/en.DM00287603.pdf
|
||||
|
||||
2017,ChrisMicro
|
||||
|
||||
|
||||
To be done: replase this by a faster direct
|
||||
display driver.
|
||||
|
||||
*/
|
||||
#ifndef _TFT_F429_DISCOVERY_
|
||||
#define _TFT_F429_DISCOVERY_
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "BSP_f429i_discovery.h"
|
||||
|
||||
#define LTDC_BLACK 0x0000 /* 0, 0, 0 */
|
||||
#define LTDC_NAVY 0x000F /* 0, 0, 128 */
|
||||
#define LTDC_DARKGREEN 0x03E0 /* 0, 128, 0 */
|
||||
#define LTDC_DARKCYAN 0x03EF /* 0, 128, 128 */
|
||||
#define LTDC_MAROON 0x7800 /* 128, 0, 0 */
|
||||
#define LTDC_PURPLE 0x780F /* 128, 0, 128 */
|
||||
#define LTDC_OLIVE 0x7BE0 /* 128, 128, 0 */
|
||||
#define LTDC_LIGHTGREY 0xC618 /* 192, 192, 192 */
|
||||
#define LTDC_DARKGREY 0x7BEF /* 128, 128, 128 */
|
||||
#define LTDC_BLUE 0x001F /* 0, 0, 255 */
|
||||
#define LTDC_GREEN 0x07E0 /* 0, 255, 0 */
|
||||
#define LTDC_CYAN 0x07FF /* 0, 255, 255 */
|
||||
#define LTDC_RED 0xF800 /* 255, 0, 0 */
|
||||
#define LTDC_MAGENTA 0xF81F /* 255, 0, 255 */
|
||||
#define LTDC_YELLOW 0xFFE0 /* 255, 255, 0 */
|
||||
#define LTDC_WHITE 0xFFFF /* 255, 255, 255 */
|
||||
#define LTDC_ORANGE 0xFD20 /* 255, 165, 0 */
|
||||
#define LTDC_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
|
||||
#define LTDC_PINK 0xF81F
|
||||
|
||||
|
||||
class TFT_F429_Discovery : public Adafruit_GFX {
|
||||
public:
|
||||
TFT_F429_Discovery(): Adafruit_GFX((int16_t) 240, (int16_t) 320)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
void begin()
|
||||
{
|
||||
BSP_LCD_Init();
|
||||
BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER);
|
||||
BSP_LCD_SelectLayer(1);
|
||||
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
|
||||
|
||||
BSP_LCD_SetTransparency(1, 255);
|
||||
|
||||
/* Clear the LCD */
|
||||
BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
|
||||
BSP_LCD_Clear(LCD_COLOR_WHITE);
|
||||
|
||||
};
|
||||
|
||||
uint32_t RGB565TORGB8888(int16_t RGB565)
|
||||
{
|
||||
int color = RGB565;
|
||||
uint8_t r = ((color >> 11) & 0x1F) << 3;
|
||||
uint8_t g = ((color >> 5) & 0x3F) << 2;
|
||||
uint8_t b = (color & 0x1F) << 3;
|
||||
uint32_t RGB8888 = 0XFF000000 | r << 16 | g << 8 | b;
|
||||
|
||||
return RGB8888;
|
||||
}
|
||||
|
||||
void setColor(int16_t RGB565)
|
||||
{
|
||||
BSP_LCD_SetTextColor(RGB565TORGB8888(RGB565));
|
||||
}
|
||||
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color)
|
||||
{
|
||||
BSP_LCD_DrawPixel(x, y, RGB565TORGB8888(color));
|
||||
};
|
||||
|
||||
void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
|
||||
{
|
||||
setColor(color);
|
||||
BSP_LCD_DrawHLine(x, y, w);
|
||||
};
|
||||
|
||||
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
|
||||
{
|
||||
setColor(color);
|
||||
BSP_LCD_DrawVLine(x, y, h);
|
||||
};
|
||||
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
|
||||
{
|
||||
setColor(color);
|
||||
BSP_LCD_DrawHLine(x, y, w);
|
||||
};
|
||||
|
||||
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
|
||||
{
|
||||
|
||||
//BSP_LCD_SetColorKeying(0, color); // keine Farbänderung
|
||||
|
||||
setColor(color);
|
||||
BSP_LCD_FillRect(x, y, w, h); // Rechteck bleibt schwarz
|
||||
};
|
||||
|
||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3);
|
||||
}
|
||||
|
||||
};
|
||||
#endif // TFT_F429_DISCOVERY
|
|
@ -1310,6 +1310,7 @@ void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
|
|||
{
|
||||
/* Write data value to all SDRAM memory */
|
||||
*(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
|
||||
//*(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue