|
tft.startWrite()是TFT_eSPI库(已使用)中的代码但报错是exit status 1 class Adafruit_ST7735' has no member named 'startWrite'; did you mean 'spiwrite'?
感觉没有扫描到我引用的TFT_eSPI,一直说Adafruit_ST7735中没有tft.startWrite()
源代码如下,求求各位大神帮帮孩子吧。
//接线方式https://blog.csdn.net/moshanghuaw/article/details/122037124
#include <TFT_eSPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SD.h>
#include <SPI.h>
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
//TFT显示屏和SD卡将共享硬件SPI接口。
//硬件SPI引脚特定于Arduino板类型
//无法重新映射到备用接点。对于Arduino Uno,
//Duemilanove等,引脚11=MOSI,引脚12=MISO,引脚13=SCK。
#define SD_CS 4 // Chip select line for SD card
#define TFT_CS 10 // Chip select line for TFT display
#define TFT_DC 9 // Data/command line for TFT
#define TFT_RST 8 // Reset line for TFT (or connect to +5V)
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define BUFFPIXEL 20
void bmpDraw(char *filename, uint8_t x, uint8_t y)
{
File bmpFile;
int bmpWidth, bmpHeight; // W+H(以像素为单位)
uint8_t bmpDepth; // 位深度(当前必须为24)
uint32_t bmpImageoffset; // 文件中图像数据的开始
uint32_t rowSize; // 不总是=bmpWidth;可能有填充
uint8_t sdbuffer[3*BUFFPIXEL]; // 像素缓冲区(每个像素R+G+B)
uint8_t buffidx = sizeof(sdbuffer); // sdbuffer中的当前位置
boolean goodBmp = false; // 在有效的标头分析时设置为true
boolean flip = true; // BMP自下而上存储
int w, h, row, col;
uint8_t r, g, b;
uint32_t pos = 0, startTime = millis();
if((x >= tft.width()) || (y >= tft.height())) return;
// 在SD卡上打开请求的文件
if ((bmpFile = SD.open(filename)) == NULL)
{
return;
}
// 分析BMP标头,二进制BMP文件以0x4D42开头
if(read16(bmpFile) == 0x4D42)
{ // BMP签名
Serial.print("File size: ");
Serial.println(read32(bmpFile));
(void)read32(bmpFile); // 读取并忽略创建者字节
bmpImageoffset = read32(bmpFile); // 图像数据的开始
// 读取DIB标题
Serial.print("Header size: ");
Serial.println(read32(bmpFile));
bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile);
if(read16(bmpFile) == 1)
{ // # planes -- must be '1'
bmpDepth = read16(bmpFile); // 每像素位
if((bmpDepth == 24) && (read32(bmpFile) == 0))
{ // 0 = uncompressed
goodBmp = true; // 支持的BMP格式--继续!
// BMP行填充(如果需要)到4字节边界
rowSize = (bmpWidth * 3 + 3) & ~3;
//若bmpHeight为负数,则图像按自上而下的顺序排列。
//这不是标准,而是在野外观察到的。
if(bmpHeight < 0) {
bmpHeight = -bmpHeight;
flip = false;
}
// 要装载的作物区域
w = bmpWidth;
h = bmpHeight;
if((x+w-1) >= tft.width()) w = tft.width() - x;
if((y+h-1) >= tft.height()) h = tft.height() - y;
// 将TFT地址窗口设置为剪切图像边界
tft.startWrite();
tft.setAddrWindow(x, y, w, h);
for (row=0; row<h; row++)
{ //对于每条扫描线。。。
//寻找扫描线的起点。这可能看起来很吃力
//每一行都要这么做,但这
//这种方法涵盖了很多细节,比如裁剪
//以及扫描线填充。此外,搜索只需要
//如果文件位置确实需要更改,则放置
//(避免了SD库中的大量集群数学)。
if(flip) // 位图按自下而上的顺序存储(普通BMP)
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
else // 位图自上而下存储
pos = bmpImageoffset + row * rowSize;
if(bmpFile.position() != pos) { // 需要寻求?
tft.endWrite();
bmpFile.seek(pos);
buffidx = sizeof(sdbuffer); // 强制重新加载缓冲区
}
for (col=0; col<w; col++)
{ // 对于每个像素。。。
// 是时候读取更多像素数据了吗?
if (buffidx >= sizeof(sdbuffer)) { // 的确
bmpFile.read(sdbuffer, sizeof(sdbuffer));
buffidx = 0; // 将索引设置为开头
tft.startWrite();
}
// 将像素从BMP转换为TFT格式,按键显示
r = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
b = sdbuffer[buffidx++];
tft.pushColor(tft.color565(r,g,b));
} // end pixel
} // end scanline
tft.endWrite();
} // end goodBmp
}
}
bmpFile.close();
if(!goodBmp) Serial.println("BMP format not recognized.");
}
//这些从SD卡文件中读取16位和32位类型。
//BMP数据存储为小端序,Arduino也是小端序。
//如果移植到其他地方,可能需要颠倒下标顺序。
uint16_t read16(File f) {
uint16_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read(); // MSB
return result;
}
uint32_t read32(File f) {
uint32_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read();
((uint8_t *)&result)[2] = f.read();
((uint8_t *)&result)[3] = f.read(); // MSB
return result;
}
void setup(void) {
pinMode(12,INPUT); // 设置SD的MISO IO状态,非常重要!
Serial.begin(9600);
// Initialize 1.8" TFT
tft.initR(INITR_REDTAB); // (已解决)显示部分图像128X128,其余部分为花边,复位断电重连无用,图片一侧随RX灯的闪动而变色,使用tft.initR(INITR_BLACKTAB)后显示完整其余不变,复位后不变断电重连后症状恢复
//tft.initR(INITR_HALLOWING); // 解决方法 在Adafuit_ST7735.h的第13行将INITR_144GRENTAB更改为0x03,例如#define INITR_14GRENTAB 0x03
//tft.initR(INITR_144GREENTAB); // 同上
//tft.initR(INITR_BLACKTAB); // 图片全部显示,色调不对,无闪动变色现象
tft.setRotation(3);
tft.fillScreen(ST7735_BLACK);
}
void loop() {
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS))
{
Serial.println("failed!");
tft.setTextSize(2);
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ST7735_BLUE);
tft.print("SD Card init error!");
return;
}
bmpDraw("x.bmp", 0, 0);
}
|
|