基于clion ide和paltformio插件,在arduino框架下,实现投屏
常见的都是使用spi串口屏,但是为了提高刷新速度,这里希望通过使用并口屏实现屏幕的驱动。
完整程序代码如下:https://github.com/OULIHONG1999/esp32s3_tcp_screencpy.git
代码仓库连接
库文件
1. TFT_eSPI
2. TJpg_Decoder
其中主要是修改了User_Setup.h中的文件配置,并在main文件的setup()函数中,取消原来使用DMA方式的初始化,以及在绘制屏幕画面时,取消了DMA发送数据,绘制屏幕的方式
部分代码展示
- main.cpp文件
#include <Arduino.h>
#include <TFT_eSPI.h>
#include <SPI.h>
#include <WiFi.h>
#include <TJpg_Decoder.h>
#include <pgmspace.h>
#include <esp_lcd_panel_ops.h>
// 从32改为128,增加缓存,增加速度
uint16_t PROGMEM dmaBuffer1[128 * 128]; // Toggle buffer for 32*32 MCU block, 1024bytes
uint16_t PROGMEM dmaBuffer2[128 * 128]; // Toggle buffer for 32*32 MCU block, 1024bytes
uint16_t *dmaBufferPtr = dmaBuffer1;
bool dmaBufferSel = 0;
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite clk = TFT_eSprite(&tft);
char *ssid = "CMCC-ABCD"; //填写你的wifi名字
char *password = "66668888"; //填写你的wifi密码
int httpPort = 8081; //设置监听端口
WiFiServer server; //初始化一个服务端对象
uint8_t buff[7000] PROGMEM = {
0};//每一帧的临时缓存
uint8_t img_buff[50000] PROGMEM = {
0};//用于存储tcp传过来的图片
uint16_t size_count = 0;//计算一帧的字节大小
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap) {
if (y >= tft.height()) return 0;
// Double buffering is used, the bitmap is copied to the buffer by pushImageDMA() the
// bitmap can then be updated by the jpeg decoder while DMA is in progress
if (dmaBufferSel) dmaBufferPtr = dmaBuffer2;
else dmaBufferPtr = dmaBuffer1;
dmaBufferSel = !dmaBufferSel; // Toggle buffer selection
// pushImageDMA() will clip the image block at screen boundaries before initiating DMA
// tft.pushImageDMA(x, y, w, h, bitmap, dmaBufferPtr); // Initiate DMA - blocking only if last DMA is not complete // 不使用,注释掉
tft.pushImage(x, y, w, h, bitmap); // 使用其他的绘制函数
return 1;
}
byte loadNum = 6;
void loading(byte delayTime) {
//启动动画
clk.setColorDepth(8);
clk.createSprite(200, 50