Monsters691 2021-10-14 22:29 采纳率: 50%
浏览 62
已结题

Arduino的esp32使用tft显示屏渲染出来的画面错位怎么办


#include <TFT_eSPI.h>
#include <SPI.h>
#include <Wire.h>
#include "bmp.h"
 
#ifndef TFT_DISPOFF
#define TFT_DISPOFF 0x28
#endif
 
#ifndef TFT_SLPIN
#define TFT_SLPIN   0x10
#endif
 
#define TFT_BL 17
 
TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke custom library
 
void showImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data);
 
void setup()
{
    Serial.begin(9600);
    Serial.println("Start");
    tft.init();
    tft.setRotation(1);
    tft.fillScreen(TFT_BLACK);
    tft.setTextSize(2);
    tft.setTextColor(TFT_MAGENTA);
    tft.setCursor(0, 0);
    tft.setTextDatum(MC_DATUM);
    tft.setTextSize(1);
 
//    if (TFT_BL > 0) { // TFT_BL has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h
//         //显示屏背光
//      ledcSetup(10, 5000/*freq*/, 10 /*resolution*/);
//      ledcAttachPin(TFT_BL, 10);
//      analogReadResolution(10);
//      ledcWrite(10,512);
//    }
}
 
void loop()
{
    tft.fillScreen(TFT_WHITE);
    tft.setSwapBytes(true);
    showImage(50, 50,  32, 32, bmp2);
    showImage(90, 90,  32, 32, bmp3);
    delay(1000);
}
 
#define PI_BUF_SIZE 128
void showImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data){
  int32_t dx = 0;
  int32_t dy = 0;
  int32_t dw = w;
  int32_t dh = h*2;
 
  if (x < 0) { dw += x; dx = -x; x = 0; }
  if (y < 0) { dh += y; dy = -y; y = 0; }
 
  if (dw < 1 || dh < 1) return;
 
  CS_L;
 
  data += dx + dy *w ;
 
  uint16_t  buffer[PI_BUF_SIZE];
  uint16_t* pix_buffer = buffer;
  uint16_t  high,low;
 
  tft.setWindow(x, y, x + dw - 1 , y + dh -1);
 
  // Work out the number whole buffers to send
  uint16_t nb = (dw * dh) / (2 * PI_BUF_SIZE) ;
 
  // Fill and send "nb" buffers to TFT
  //  第一个for是纵向渲染图片
  for (int32_t i = 0; i < nb; i++) {
    for (int32_t j = 0; j < PI_BUF_SIZE ; j++) {
      high = pgm_read_word(&data[(i * 2 * PI_BUF_SIZE) + 2 * j - 1]);
      low = pgm_read_word(&data[(i * 2 * PI_BUF_SIZE) + 2 * j ]);
      pix_buffer[j] = (high<<8)+low;
    }
    tft.pushPixels(pix_buffer, PI_BUF_SIZE);
  }
 
  // Work out number of pixels not yet sent
  uint16_t np = (dw * dh) % (2 * PI_BUF_SIZE);
 
  // Send any partial buffer left over
  if (np) {
    for (int32_t i = 0; i < np; i++)
    {
      high = pgm_read_word(&data[(nb * 2 * PI_BUF_SIZE) + 2 * i -1]);
      low = pgm_read_word(&data[(nb * 2 * PI_BUF_SIZE) + 2 * i ]);
      pix_buffer[i] = (high<<8)+low;
    }
    tft.pushPixels(pix_buffer, np);
  }
 
  CS_H;
}

img

这么弄在线等急!
我感觉是数组的问题渲染歪了但是不知道改哪里

  • 写回答

1条回答 默认 最新

  • 「已注销」 2021-10-15 08:46
    关注

    没有渲染成功,对吗

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月1日
  • 创建了问题 10月14日

悬赏问题

  • ¥20 escpos打印到CUPS打印机
  • ¥15 MATLAB读取TXT,并添加度分秒
  • ¥15 excel提示内存不足
  • ¥15 软件安装包用的是openinstall 在普通路由上有一些限速,怎么提速
  • ¥15 msgeq7根据音乐控制电机
  • ¥15 51单片机PN532刷卡原理图代码
  • ¥15 matlab如何不显示绘图而保存为能打开的fig图片?
  • ¥15 oracle数据库备份、
  • ¥15 关于Finetune模型,CUDA error: device-side assert triggered 报错
  • ¥15 能将阿里云上多个设备的信息能上传给小程序吗