Code:
//#define USE_SPI1
/*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x
MISO: 12//Teensy3.x
SCK: 13//Teensy3.x
the rest of pin below:
*/
#ifdef USE_SPI1
#define RA8875_INT 3//any pin
#define RA8875_CS 10//restriction for Teensy3 and CS
#define RA8875_RST -1//any pin
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#define RA8875_MOSI 0
#define RA8875_MISO 1
#define RA8875_SCLK 32
#elif defined(__IMXRT1062__)
#define RA8875_MOSI 26
#define RA8875_MISO 1
#define RA8875_SCLK 27
#endif
#else
#define RA8875_INT 3//any pin
#define RA8875_CS 10//restriction for Teensy3 and CS
#define RA8875_RST 9//any pin
#define RA8875_MOSI 11
#define RA8875_MISO 12
#define RA8875_SCLK 13
#endif
RA8875 tft = RA8875(RA8875_CS, RA8875_RST, RA8875_MOSI, RA8875_SCLK, RA8875_MISO);
bool enable_layers = false;
// Converted to code with:
// http://www.rinkydinkelectronics.com/t_imageconverter565.php
//
#include "teensy40_pinout1.h" //the picture
#include "teensy40_pinout2.h" //the picture
#include "teensy40_front.h" // Try to load from DMAMEM?
#include "TD_T4_TopCard.h" // Top Dog card...
/* GIMP (https://www.gimp.org/) can also be used to export the image using the following steps:
1. File -> Export As
2. In the Export Image dialog, use 'C source code (*.c)' as filetype.
3. Press export to get the export options dialog.
4. Type the desired variable name into the 'prefixed name' box.
5. Uncheck 'GLIB types (guint8*)'
6. Check 'Save as RGB565 (16-bit)'
7. Press export to save your image.
Assuming 'image_name' was typed in the 'prefixed name' box of step 4, you can have to include the c file as above,
using the image can be done with:
tft.writeRect(0, 0, image_name.width, image_name.height, (uint16_t*)(image_name.pixel_data));
See also https://forum.pjrc.com/threads/35575-Export-for-ILI9341_t3-with-GIMP
*/
void setup() {
while (!Serial && millis() < 5000) ;
Serial.begin(115200);
DumpMemoryInfo();
Serial.printf("CS:%u RST:%u, MOSI:%u SCLK:%u MISO:%u\n", RA8875_CS, RA8875_RST, RA8875_MOSI, RA8875_SCLK, RA8875_MISO);
//
//tft.begin(RA8875_800x480);
//tft.begin(RA8875_480x272);
// tft.begin(Adafruit_800x480);
tft.begin(Adafruit_480x272);
if ((tft.width()==480) && (tft.height() == 272)) enable_layers = true; tft.setRotation(0);
Serial.printf("Screen Width:%d Height: %d\n", tft.width(), tft.height());
tft.fillWindow(RA8875_BLACK);
delay(250);
tft.fillWindow(RA8875_RED);
delay(250);
tft.fillWindow(RA8875_GREEN);
delay(250);
tft.fillWindow(RA8875_BLUE);
}
void drawImage(RA8875writes layer, uint16_t image_width, uint16_t image_height, uint16_t *image, uint16_t bgColor) {
// first lets fill in part of screen that our image does not cover
if (enable_layers) tft.writeTo(layer);
if ((tft.width() >= image_width) && (tft.height() >= image_height)) {
uint16_t start_x = (tft.width() - image_width) / 2;
uint16_t start_y = (tft.height() - image_height) / 2;
tft.fillRect(0, 0, tft.width(), start_y, bgColor); // top;
tft.fillRect(0, start_y, start_x, image_height, bgColor); // left
tft.fillRect(start_x + image_width, start_y, tft.width() - (start_x + image_width), image_height, bgColor); // right
tft.fillRect(0, start_y + image_height, tft.width(), tft.height() - (start_y + image_height), bgColor); // top;
// now lets draw out each of the lines of the image...
for (uint16_t y = start_y; y < (start_y + image_height); y++) {
tft.setY(y);
tft.drawPixels(image, image_width, start_x, y);
image += image_width;
}
} else {
// We need to rotate the image...
uint16_t start_y = (tft.height() - image_width) / 2;
uint16_t start_x = (tft.width() - image_height) / 2;
//Serial.printf("Rotated: start(%d, %d)\n", start_x, start_y);
tft.fillRect(0, 0, tft.width(), start_y, bgColor); // top;
tft.fillRect(0, start_y, start_x, image_width, bgColor); // left
tft.fillRect(start_x + image_height, start_y, tft.width() - (start_x + image_height), image_width, bgColor); // right
tft.fillRect(0, start_y + image_width, tft.width(), tft.height() - (start_y + image_width), bgColor); // top;
// now lets draw out each of the lines of the image...
static uint16_t rotated_row[800]; // max size.
// BUGBUG: need to start at end of row and work back or image inverted
image += (image_width - 1);
for (uint16_t y = start_y; y < (start_y + image_width); y++) {
uint16_t *pimage = image;
for (uint16_t i = 0; i < image_height; i++) {
rotated_row[i] = *pimage;
pimage += image_width;
}
//Serial.printf("DP %x, %d, %d %d\n", rotated_row, image_height, start_x, y);
tft.drawPixels(rotated_row, image_height, start_x, y);
image--;
}
}
if (enable_layers)tft.layerEffect((layer==L1)? LAYER1 : LAYER2);
}
void loop(void) {
Serial.print("Display Front of card ");
elapsedMillis em = 0;
drawImage(L1, 240, 320, (uint16_t*)teensy40_pinout1, RA8875_RED);
Serial.println((uint32_t)em, DEC);
delay(5000);
Serial.print("Display Back of card ");
em = 0;
drawImage(L2, 240, 320, (uint16_t*)teensy40_pinout2, RA8875_GREEN);
Serial.println((uint32_t)em, DEC);
delay(5000);
Serial.print("Display front of chip (DMAMEM?) ");
em = 0;
drawImage(L1, 240, 320, (uint16_t*)teensy40_front, RA8875_BLUE);
Serial.println((uint32_t)em, DEC);
delay(5000);
Serial.print("Display TallDog T4 Card ");
em = 0;
drawImage(L2, 400, 272, (uint16_t*)td_t4_top, RA8875_BLACK);
Serial.println((uint32_t)em, DEC);
delay(5000);
}
void DumpMemoryInfo() {
#if defined(__IMXRT1062__)
// from the linker
// extern unsigned long _stextload;
extern unsigned long _stext;
extern unsigned long _etext;
// extern unsigned long _sdataload;
extern unsigned long _sdata;
extern unsigned long _edata;
extern unsigned long _sbss;
extern unsigned long _ebss;
// extern unsigned long _flexram_bank_config;
extern unsigned long _estack;
uint32_t flexram_config = IOMUXC_GPR_GPR17;
Serial.printf("IOMUXC_GPR_GPR17:%x IOMUXC_GPR_GPR16:%x IOMUXC_GPR_GPR14:%x\n",
flexram_config, IOMUXC_GPR_GPR16, IOMUXC_GPR_GPR14);
Serial.printf("Initial Stack pointer: %x\n", &_estack);
uint32_t dtcm_size = 0;
uint32_t itcm_size = 0;
for (; flexram_config; flexram_config >>= 2) {
if ((flexram_config & 0x3) == 0x2) dtcm_size += 32768;
else if ((flexram_config & 0x3) == 0x3) itcm_size += 32768;
}
Serial.printf("ITCM allocated: %u DTCM allocated: %u\n", itcm_size, dtcm_size);
Serial.printf("ITCM init range: %x - %x Count: %u\n", &_stext, &_etext, (uint32_t)&_etext - (uint32_t)&_stext);
Serial.printf("DTCM init range: %x - %x Count: %u\n", &_sdata, &_edata, (uint32_t)&_edata - (uint32_t)&_sdata);
Serial.printf("DTCM cleared range: %x - %x Count: %u\n", &_sbss, &_ebss, (uint32_t)&_ebss - (uint32_t)&_sbss);
#endif
}
Still has the other 4 header files with the images...