Code:
int x=0; int y=0; int width=90; int height=100;
String text="HELLO"
int length = text.length();
for (int l = 0; l < length; l++)
{
tft.setWindow(x+(l*width), y, x+(l*width) + width - 1, y + height - 1);
uint32_t charpos = (text.charAt(l) - (int)61) * width * height * 3);
byte *startbyte= binarray+charpos;
vspi->writeBytes((uint8_t*)startbyte, width * height * 3);
}
Complete Code:
#include "FS.h"
//#include "SPIFFS.h"
#include <TFT_eSPI.h>
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI();
#define SPI2_NSS_PIN 28
static const int spiClk = 40000000; // 1 MHz
//SPIClass * vspi = NULL;
int CS_PIN =5;
unsigned long bgstart = 675000UL;
void setup() {
Serial.begin(115200);
if (!SPIFFS.begin(true)) {
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
btStop();
//vspi = new SPIClass(VSPI);
SPI.begin();
Serial.begin(115200);
tft.begin();
tft.setRotation(1); // landscape
tft.fillScreen(TFT_BLACK);
//Background
bigImage(702000, 702000, 0, 0, 480, 320, 0xFFFFFF);
//void DrawString( uint32_t check, int x, int y, int width, int height, String text, bool compare, bool transp,int asciioffset)
DrawString( 0 , 0, 0, 90, 100, "HELLO", false, false, 65);
DrawString( 0 , 0, 100, 90, 100, "ITS", false, false, 65);
DrawString( 0 , 0, 200, 90, 100, "FUN", false, false, 65);
}
void loop() {
}
void DrawString( uint32_t check, int x, int y, int width, int height, String text, bool compare, bool transp, uint32_t asciioffset) {
int lengthl = text.length();
for (int l = 0; l < lengthl; l++)
{
uint32_t charpos = ((uint32_t)((uint32_t)text.charAt(l) - (uint32_t)asciioffset) * (uint32_t)width * height * 3);
//void transparentImage(uint32_t startpic, uint32_t startbackground, int x, int y, int width, int height, uint32_t tcolor)
transparentImage( check + charpos, 702000, x + ( l * width), y, width, height, 0xFFFFFF);
Serial.println(charpos);
}
}
void transparentImage(uint32_t startpic, uint32_t startbackground, int x, int y, int width, int height, uint32_t tcolor) {
tft.setWindow(x, y, x + width - 1, y + height - 1);
//read background clipping
File f = SPIFFS.open( "/test.bin", "r");
char *buf = (char*)malloc(width * height * 3);
char *temp = (char*)malloc(width * 3);
unsigned long offset = 0;
for (int i = 0; i < height; i++) {
// unsigned long offset = startbackground + (x * width*3 - (width*3 - (width-y*3)) + (i * width * 3));
unsigned long offsetbg = startbackground + ((y + i) * 480 * 3 ) + (x * 3) ;
f.seek(offsetbg, SeekSet);
f.readBytes((char*)temp, width * 3) ;
memcpy( buf + (i * width * 3), temp, (width * 3) );
}
for (int i = 0; i < height; i++) {
unsigned long offset = startpic + i * width * 3;
f.seek(offset, SeekSet);
f.readBytes((char*)temp, width * 3) ;
for (int h = 0; h < width * 3; h = h + 3)
{
uint32_t bp = temp[ h];
bp = (bp << 8) | temp[h + 1];
bp = (bp << 16) | temp[ h + 2];
if (bp >= 0x111111 || y + i > 300) {
buf[width * i * 3 + h] = temp[h];
buf[width * i * 3 + h + 1] = temp[h + 1];
buf[width * i * 3 + h + 2] = temp[h + 2];
}
}
}
SPI.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(CS_PIN, LOW); //pull SS slow to prep other end for transfer
SPI.writeBytes((uint8_t*)buf, width * height * 3);
digitalWrite(CS_PIN, HIGH); //pull ss high to signify end of data transfer
SPI.endTransaction();
f.close();
Serial.println("test");
free(buf);
free(temp);
}
void bigImage(uint32_t startpic, uint32_t startbackground, int x, int y, int width, int height, uint32_t tcolor) {
tft.setWindow(x, y, x + width - 1, y + height - 1);
//read background clipping
File f = SPIFFS.open( "/test.bin", "r");
char *buf = (char*)malloc(width * height * 3);
char *temp = (char*)malloc(width * 3);
unsigned long offset = 0;
SPI.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(CS_PIN, LOW); //pull SS slow to prep other end for transfer
for (int i = 0; i < height; i++) {
unsigned long offset = startbackground + (i * width * 3);
f.seek(offset, SeekSet);
f.readBytes((char*)temp, width * 3) ;
SPI.writeBytes((uint8_t*)temp, width * 3);
}
digitalWrite(CS_PIN, HIGH); //pull ss high to signify end of data transfer
SPI.endTransaction();
f.close();
free(buf);
free(temp);
}