Tweak pushColors() for SAMD51, add non-DMA option to wobble example

This commit is contained in:
Phillip Burgess
2018-06-21 18:40:57 -07:00
parent c542e168f3
commit bdcfb20734
3 changed files with 26 additions and 3 deletions
+4
View File
@@ -875,7 +875,11 @@ void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color) {
// externally by BMP examples. Assumes that setWindowAddr() has
// previously been set to define the bounds. Max 255 pixels at
// a time (BMP examples read in small chunks due to limited RAM).
#if defined(__SAMD51__)
void Adafruit_TFTLCD::pushColors(uint16_t *data, uint16_t len, boolean first) {
#else
void Adafruit_TFTLCD::pushColors(uint16_t *data, uint8_t len, boolean first) {
#endif
uint16_t color;
uint8_t hi, lo;
CS_ACTIVE;
+4
View File
@@ -38,7 +38,11 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
void setRotation(uint8_t x);
// These methods are public in order for BMP examples to work:
void setAddrWindow(int x1, int y1, int x2, int y2);
#if defined(__SAMD51__)
void pushColors(uint16_t *data, uint16_t len, boolean first);
#else
void pushColors(uint16_t *data, uint8_t len, boolean first);
#endif
void pushColorsDMA(uint32_t totalBytes, uint8_t *buffer,
uint16_t bufSize, void (*callback)(uint8_t *dest, uint16_t len));
+18 -3
View File
@@ -9,6 +9,8 @@
#define LCD_RESET A4 // Alternately just connect to Arduino's reset pin
#define DMA_SELECT A1 // Hi/lo chooses DMA vs non-DMA effect
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define DMALINES 16
@@ -23,6 +25,8 @@ void setup()
Serial.begin(9600);
while(!Serial);
pinMode(DMA_SELECT, INPUT_PULLUP);
// Initialize pixel buffer with alternating red and white bands,
// 32 pixels wide. 0x00F8 is 16-bit red (0xF800) endian-swapped
// so bytes can be copied directly to screen.
@@ -62,7 +66,7 @@ void setup()
int lineNum;
int frame = 0;
// pushColorsDMA() callback function -- fills one scanline with
// pushColorsDMA() callback function -- fills DMALINES scanlines with
// data from pixels[] array.
void myCallback(uint8_t *dest, uint16_t len) {
for(int i=0; i<DMALINES; i++) {
@@ -72,14 +76,25 @@ void myCallback(uint8_t *dest, uint16_t len) {
if((lineNum + frame/8) & 32) offset = (offset + 32) % 63;
memcpy(dest, &pixels[offset], len / DMALINES);
lineNum++;
dest += 320 * 2; // Next scanline
dest += 320 * 2; // Offset to next scanline (2 bytes/pixel)
}
}
void loop() {
tft.setAddrWindow(0, 0, tft.width() - 1, tft.height() - 1);
lineNum = 0;
tft.pushColorsDMA(tft.width() * tft.height() * 2, dmabuf, tft.width() * DMALINES * 2, myCallback);
if(digitalRead(DMA_SELECT)) {
tft.pushColorsDMA(tft.width() * tft.height() * 2, dmabuf, tft.width() * DMALINES * 2, myCallback);
} else {
bool first = true;
while(lineNum < tft.height()) {
// Fill the DMA buffer, but don't issue it
myCallback(dmabuf, tft.width() * DMALINES * 2);
// Then send it using non-DMA function:
tft.pushColors((uint16_t *)dmabuf, tft.width() * DMALINES, first);
first = false;
}
}
frame++;
uint32_t elapsed = (millis() - startTime) / 1000;
if(elapsed > 0) {