//#include "images.h"
//#include "Teensy41_Cardlike.h"
//#include "flexio_teensy_mm.c"
#include "teensy41.c"
//#define use_spi
#if defined(use_spi)
#include <SPI.h>
#include <RA8876_t3.h>
#else
//#include <RA8876_t3.h>
#include <RA8876_t41_p.h>
#endif
#include <math.h>
#if defined(use_spi)
#define RA8876_CS 10
#define RA8876_RESET 9
#define BACKLITE 7 //External backlight control connected to this Arduino pin
RA8876_t3 tft = RA8876_t3(RA8876_CS, RA8876_RESET); //Using standard SPI pins
#else
uint8_t dc = 13;
uint8_t cs = 11;
uint8_t rst = 12;
#define BACKLITE 7 //External backlight control connected to this Arduino pin
RA8876_t41_p lcd = RA8876_t41_p(dc,cs,rst); //(dc, cs, rst)
//RA8876_t3 lcd = RA8876_t3(dc,cs,rst); //(dc, cs, rst)
#endif
uint32_t start = 0;
uint32_t end = 0;
uint8_t busSpeed = 12;
uint8_t rData = 0;
uint16_t rslt = 0;
void setup() {
while (!Serial && millis() < 3000) {} //wait for Serial Monitor
Serial.printf("%c SDRAM Dev Board and RA8876 parallel 8080 mode testing (8/16)\n\n",12);
// Serial.print(CrashReport);
// pinMode(WINT, INPUT); // For XnWAIT signal if connected and used.
#if defined(use_spi)
lcd.begin();
#else
lcd.begin(busSpeed);// 20 is working in 8bit and 16bit mode on T41
#endif
// if(!lcd.begin(busSpeed)) Serial.printf("lcd.begin(busSpeed) FAILED!!!\n");
delay(100);
Serial.print("Bus speed: ");
Serial.print(busSpeed,DEC);
Serial.println(" MHZ");
Serial.print("Bus Width: ");
Serial.print(BUS_WIDTH,DEC);
Serial.println("-bits");
lcd.graphicMode(true);
lcd.fillScreen(0x0000);
lcd.setRotation(0);
}
int i=0, j=0;
void loop() {
// rData = lcd.lcdStatusRead();
// Serial.printf("rData = 0x%2.2x\n",rData);
// start = micros();
// start = millis();
// lcd.drawPixel(0x0000,0x0000,0xffff);
// for(i = 0; i < 2; i++) {
// rslt = lcd.getPixel(i,0);
// Serial.printf("rslt = 0x%4.4X\n",rslt);
// }
// lcd.pushPixels16bitAsync(teensy41_Cardlike,10,10,575,424);
// lcd.pushPixels16bitAsync(flexio_teensy_mm,0,0,480,320); // 480x320
lcd.pushPixels16bitAsync(teensy41,0,0,480,320); // 480x320
/*
for (i = 0; i < 240; i++){
for (j = 0; j < 184; j++){
lcd.drawPixel(i, j + 136, Dallas[i][j]);
}
}
for (i = 0; i < 240; i++){
for (j = 0; j < 184; j++){
lcd.drawPixel(i+250, j + 136, Salt_Lake[i][j]);
}
}
for (i = 0; i < 182; i++){
for (j = 0; j < 185; j++){
lcd.drawPixel(i + 500, j + 135, Jewish_style_building[i][j]);
}
}
for (i = 0; i < 240; i++){
for (j = 0; j < 236; j++){
lcd.drawPixel(i+746, j + 85, Flower_pattern[i][j]);
}
}
for (i = 0; i < 89; i++) {
for (j = 0; j < 92; j++) {
lcd.drawPixel(i + 31, j + 98 + 300, quarter_pattern[i][j]);
}
}
for (i = 0; i < 89; i++) {
for (j = 0; j < 92; j++) {
lcd.drawPixel(i + 120, j + 98 + 300, quarter_pattern[88 - i][j]);
}
}
for (i = 0; i < 89; i++) {
for (j = 0; j < 92; j++) {
lcd.drawPixel(i + 31, j + 190 + 300, quarter_pattern[i][91 - j]);
}
}
for (i = 0; i < 89; i++) {
for (j = 0; j < 92; j++) {
lcd.drawPixel(i + 120, j + 190 + 300, quarter_pattern[88 - i][91 - j]);
}
}
*/
// lcd.pushPixels16bitDMA(teensy41,1,1,480,320); // FLASHMEM buffer
// lcd.pushPixels16bitDMA(teensy41_Cardlike,1,1,575,424); // FLASHMEM buffer
// lcd.pushPixels16bitDMA(flexio_teensy_mm,530,260,480,320); // FLASHMEM buffer
// lcd.pushPixels16bitDMA(frameBuffer,530,260,480,320); // SDRAM buffer
// lcd.pushPixels16bitDMA(frameBuffer1,1,1,575,424); // SDRAM buffer
// lcd.writeRect(10,10,575,424,teensy41_Cardlike);
// lcd.writeRect(10,280,480,320,teensy41);
// lcd.writeRect(530,0,480,320,flexio_teensy_mm);
// end = micros() - start;
// Serial.printf("Wrote %d bytes in %dus\n\n",(575*424)+(480*320), end);
// end = millis() - start;
// Serial.printf("Wrote %d bytes in %dms\n\n",(575*424)+(480*320), end);
waitforInput();
// lcd.graphicMode(true);
// lcd.clearScreen(0x0000);
}
void waitforInput()
{
Serial.println("Press anykey to continue");
while (Serial.read() == -1) ;
while (Serial.read() != -1) ;
}