osc ili9341 control stm32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************** | |
This is our GFX example for the Adafruit ILI9341 Breakout and Shield | |
----> http://www.adafruit.com/products/1651 | |
Check out the links above for our tutorials and wiring diagrams | |
These displays use SPI to communicate, 4 or 5 pins are required to | |
interface (RST is optional) | |
Adafruit invests time and resources providing this open source code, | |
please support Adafruit and open-source hardware by purchasing | |
products from Adafruit! | |
Written by Limor Fried/Ladyada for Adafruit Industries. | |
MIT license, all text above must be included in any redistribution | |
****************************************************/ | |
#include <OSCBundle.h> | |
#include <SLIPEncodedSerial.h> | |
#include <OSCMessage.h> | |
SLIPEncodedSerial SLIPSerial(Serial); | |
#include "SPI.h" | |
#include "Adafruit_GFX_AS.h" | |
#include "Adafruit_ILI9341_STM.h" | |
#define TFT_DC PA12 | |
#define TFT_CS PA4 | |
#define TFT_RST PA11 | |
Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC, TFT_RST); | |
void setup() { | |
Serial.begin(115200); | |
Serial.setTimeout(50); | |
tft.begin(); | |
tft.fillScreen(ILI9341_BLACK); | |
tft.setRotation(1); | |
} | |
void loop(void) { | |
while(1) | |
{ | |
getOSC(); | |
} | |
} | |
void getOSC() | |
{ | |
OSCMessage msgIn; //declares buffer | |
uint32_t size = SLIPSerial.available(); | |
while ((!SLIPSerial.endofPacket()) && (size > 0)) | |
{ | |
uint32_t size = SLIPSerial.available(); | |
while (size--) | |
{ | |
msgIn.fill(SLIPSerial.read()); | |
} | |
} | |
if (!msgIn.hasError()) | |
{ | |
msgIn.dispatch("/bgfill", bgfill, 0); | |
msgIn.dispatch("/invert", invertarea, 0); | |
//msgIn.dispatch("/activelow", activeLow, 0); | |
msgIn.dispatch("/waveform",waveform,0); | |
msgIn.dispatch("/line",line,0); | |
msgIn.dispatch("/text", text,0); | |
msgIn.dispatch("/hello", hello, 0); | |
msgIn.dispatch("/setcursor", setcursor,0); | |
msgIn.empty(); | |
} | |
else { | |
msgIn.empty(); | |
} | |
} | |
void waveform(OSCMessage &msg)//send 240 ints to the screen | |
{ | |
int x; | |
for (x = 0; x < 239; x++) | |
{ | |
tft.drawPixel(x,msg.getInt(x)); | |
} | |
} | |
void invertarea(OSCMessage &msg) | |
{ | |
//tft.invertDisplay(1); | |
uint16_t y,x,tmp,startx,starty,endx,endy; | |
startx = msg.getInt(0); | |
starty = msg.getInt(1); | |
endx = msg.getInt(2); | |
endy = msg.getInt(3); | |
uint16_t len = (endx-startx+1)*(endy-starty+1); | |
uint16_t buf[len]; | |
readPixels(startx,starty,endx,endy,buf); | |
for (y = starty; y < endy; y++) | |
{ | |
for (x = startx; x<endx; x++) | |
{ | |
tft.drawPixel(x,y,~buf[y+x]); | |
} | |
} | |
} | |
void readarea(OSCMessage &msg) | |
{ | |
uint16_t pbuf[100]; | |
tft.readPixels(0,0,10,10,pbuf); | |
int i = 0; | |
for (i = 0; i< 100;i++) | |
{ | |
Serial.print(pbuf[i]); | |
} | |
Serial.println(); | |
} | |
void line(OSCMessage &msg) | |
{ | |
int x,y,xend,yend,color; | |
x = msg.getInt(0); | |
y = msg.getInt(1); | |
xend = msg.getInt(2); | |
yend = msg.getInt(3); | |
color = msg.getInt(4); | |
tft.drawLine(x,y,xend,yend,color); | |
} | |
void setcursor(OSCMessage &msg) | |
{ | |
int val1, val2; | |
val1 = msg.getInt(0); | |
Serial.print(val1); | |
Serial.println(); | |
val2 = msg.getInt(1); | |
Serial.print(val2); | |
Serial.println(); | |
tft.setCursor(val1, val2); | |
//Serial.println(color); | |
} | |
void hello(OSCMessage &msg) | |
{ | |
OSCMessage hello("/hello"); | |
hello.add((int32_t) 1); | |
SLIPSerial.beginPacket(); | |
hello.send(SLIPSerial); | |
SLIPSerial.endPacket(); | |
hello.empty(); | |
} | |
void text(OSCMessage &msg) | |
{ | |
//tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2); | |
tft.setTextSize(2); | |
if (msg.isInt(0)) | |
{ | |
int tmp =msg.getInt(0); | |
tft.setTextColor(tmp); | |
Serial.print(tmp); | |
Serial.println(); | |
} | |
if (msg.isString(1)) | |
{ | |
int length = msg.getDataLength(1); | |
char str[length]; | |
msg.getString(1,str,length); | |
tft.println(str); | |
Serial.println(str); | |
Serial.println(length); | |
} | |
} | |
void bgfill(OSCMessage &msg) | |
{ | |
int color; | |
color = msg.getInt(0); | |
tft.fillScreen(color); | |
Serial.println(color); | |
} | |
unsigned long testFillScreen() { | |
unsigned long start = micros(); | |
tft.fillScreen(ILI9341_BLACK); | |
tft.fillScreen(ILI9341_RED); | |
tft.fillScreen(ILI9341_GREEN); | |
tft.fillScreen(ILI9341_BLUE); | |
tft.fillScreen(ILI9341_BLACK); | |
return micros() - start; | |
} | |
unsigned long testText() { | |
// tft.fillScreen(ILI9341_BLACK); | |
unsigned long start = micros(); | |
tft.setCursor(0, 0); | |
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); | |
tft.println("Hello World!aaaaaaaaaaaaaaaaaa"); | |
tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2); | |
tft.println(1234.5644444444444444444); | |
tft.setTextColor(ILI9341_RED); tft.setTextSize(3); | |
tft.println(0xDEADBEEFAAAAA, HEX); | |
tft.println(); | |
tft.setTextColor(ILI9341_GREEN); | |
tft.setTextSize(5); | |
tft.println("GroopGROO"); | |
tft.setTextSize(2); | |
tft.println("I implore thee,aaaaaaaaaaaaaaaaaa"); | |
tft.setTextSize(1); | |
tft.println("my foonting turlingdromesaaaaaaaaaaaaaaaaaa."); | |
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 testFastLines(uint16_t color1, uint16_t color2) { | |
unsigned long start; | |
int x, y, w = tft.width(), h = tft.height(); | |
tft.fillScreen(ILI9341_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(ILI9341_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(ILI9341_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); | |
} | |
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(ILI9341_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(ILI9341_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(0, 0, 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(ILI9341_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, i)); | |
t += micros() - start; | |
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, | |
tft.color565(i, i, 0)); | |
} | |
return t; | |
} | |
unsigned long testRoundRects() { | |
unsigned long start; | |
int w, i, i2, | |
cx = tft.width() / 2 - 1, | |
cy = tft.height() / 2 - 1; | |
tft.fillScreen(ILI9341_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(ILI9341_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)); | |
} | |
return micros() - start; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment