359 lines
10 KiB
C++
359 lines
10 KiB
C++
#include "Wire.h"
|
|
#include "XL9535_driver.h"
|
|
#include "pin_config.h"
|
|
#include "lvgl.h"
|
|
#include <Arduino.h>
|
|
#include <Arduino_GFX_Library.h>
|
|
#include <SPIFFS.h>
|
|
#include "current_img.h"
|
|
|
|
#include "SD_MMC.h"
|
|
#include "FS.h"
|
|
|
|
#define USING_2_1_INC_CST820 1
|
|
|
|
#define MSG_BAT_VOLT_UPDATE 1
|
|
#define MSG_TOUCH_UPDATE 2
|
|
#define MSG_WIFI_UPDATE 3
|
|
#define MSG_TOUCH_INT_UPDATE 4
|
|
#define TOUCH_MODULES_CST_SELF
|
|
|
|
|
|
struct FileInfo {
|
|
char fileName[255];
|
|
size_t fileSize;
|
|
};
|
|
|
|
typedef struct {
|
|
uint8_t cmd;
|
|
uint8_t data[16];
|
|
uint8_t databytes; // No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
|
|
} lcd_init_cmd_t;
|
|
|
|
|
|
String network, lastimg, Image_str, ssid , password;
|
|
String message_to_write = "";
|
|
String statut = "0";
|
|
uint16_t * data_image;
|
|
uint8_t touchAddress = 0;
|
|
int Size, Sizepack;
|
|
int status = 0 ;
|
|
int fileCount = 0;
|
|
const int MAX_FILES = 100;
|
|
bool click = false;
|
|
bool touchDevicesOnline = false;
|
|
|
|
XL9535 xl;
|
|
|
|
FileInfo fileInfos[MAX_FILES];
|
|
|
|
TaskHandle_t pvCreatedTask;
|
|
|
|
Arduino_ESP32RGBPanel *bus = new Arduino_ESP32RGBPanel(
|
|
-1, -1, -1, EXAMPLE_PIN_NUM_DE, EXAMPLE_PIN_NUM_VSYNC, EXAMPLE_PIN_NUM_HSYNC, EXAMPLE_PIN_NUM_PCLK,
|
|
EXAMPLE_PIN_NUM_DATA1, EXAMPLE_PIN_NUM_DATA2, EXAMPLE_PIN_NUM_DATA3, EXAMPLE_PIN_NUM_DATA4, EXAMPLE_PIN_NUM_DATA5,
|
|
EXAMPLE_PIN_NUM_DATA6, EXAMPLE_PIN_NUM_DATA7, EXAMPLE_PIN_NUM_DATA8, EXAMPLE_PIN_NUM_DATA9, EXAMPLE_PIN_NUM_DATA10, EXAMPLE_PIN_NUM_DATA11,
|
|
EXAMPLE_PIN_NUM_DATA13, EXAMPLE_PIN_NUM_DATA14, EXAMPLE_PIN_NUM_DATA15, EXAMPLE_PIN_NUM_DATA16, EXAMPLE_PIN_NUM_DATA17);
|
|
|
|
Arduino_GFX *gfx = new Arduino_ST7701_RGBPanel(bus, GFX_NOT_DEFINED, 0 /* rotation */, false /* IPS */, 480, 480,
|
|
st7701_type2_init_operations, sizeof(st7701_type2_init_operations), true,
|
|
50, 1, 30, 20, 1, 30);
|
|
|
|
DRAM_ATTR static const lcd_init_cmd_t st_init_cmds[] = {
|
|
{0xFF, {0x77, 0x01, 0x00, 0x00, 0x10}, 0x05},
|
|
{0xC0, {0x3b, 0x00}, 0x02},
|
|
{0xC1, {0x0b, 0x02}, 0x02},
|
|
{0xC2, {0x07, 0x02}, 0x02},
|
|
{0xCC, {0x10}, 0x01},
|
|
{0xCD, {0x08}, 0x01}, // 用565时屏蔽 666打开
|
|
{0xb0, {0x00, 0x11, 0x16, 0x0e, 0x11, 0x06, 0x05, 0x09, 0x08, 0x21, 0x06, 0x13, 0x10, 0x29, 0x31, 0x18}, 0x10},
|
|
{0xb1, {0x00, 0x11, 0x16, 0x0e, 0x11, 0x07, 0x05, 0x09, 0x09, 0x21, 0x05, 0x13, 0x11, 0x2a, 0x31, 0x18}, 0x10},
|
|
{0xFF, {0x77, 0x01, 0x00, 0x00, 0x11}, 0x05},
|
|
{0xb0, {0x6d}, 0x01},
|
|
{0xb1, {0x37}, 0x01},
|
|
{0xb2, {0x81}, 0x01},
|
|
{0xb3, {0x80}, 0x01},
|
|
{0xb5, {0x43}, 0x01},
|
|
{0xb7, {0x85}, 0x01},
|
|
{0xb8, {0x20}, 0x01},
|
|
{0xc1, {0x78}, 0x01},
|
|
{0xc2, {0x78}, 0x01},
|
|
{0xc3, {0x8c}, 0x01},
|
|
{0xd0, {0x88}, 0x01},
|
|
{0xe0, {0x00, 0x00, 0x02}, 0x03},
|
|
{0xe1, {0x03, 0xa0, 0x00, 0x00, 0x04, 0xa0, 0x00, 0x00, 0x00, 0x20, 0x20}, 0x0b},
|
|
{0xe2, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0x0d},
|
|
{0xe3, {0x00, 0x00, 0x11, 0x00}, 0x04},
|
|
{0xe4, {0x22, 0x00}, 0x02},
|
|
{0xe5, {0x05, 0xec, 0xa0, 0xa0, 0x07, 0xee, 0xa0, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0x10},
|
|
{0xe6, {0x00, 0x00, 0x11, 0x00}, 0x04},
|
|
{0xe7, {0x22, 0x00}, 0x02},
|
|
{0xe8, {0x06, 0xed, 0xa0, 0xa0, 0x08, 0xef, 0xa0, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0x10},
|
|
{0xeb, {0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00}, 0x07},
|
|
{0xed, {0xff, 0xff, 0xff, 0xba, 0x0a, 0xbf, 0x45, 0xff, 0xff, 0x54, 0xfb, 0xa0, 0xab, 0xff, 0xff, 0xff}, 0x10},
|
|
{0xef, {0x10, 0x0d, 0x04, 0x08, 0x3f, 0x1f}, 0x06},
|
|
{0xFF, {0x77, 0x01, 0x00, 0x00, 0x13}, 0x05},
|
|
{0xef, {0x08}, 0x01},
|
|
{0xFF, {0x77, 0x01, 0x00, 0x00, 0x00}, 0x05},
|
|
{0x36, {0x08}, 0x01},
|
|
{0x3a, {0x66}, 0x01},
|
|
{0x11, {0x00}, 0x80},
|
|
{0x29, {0x00}, 0x80},
|
|
{0, {0}, 0xff}
|
|
};
|
|
|
|
|
|
|
|
void SD_init(void);
|
|
void tft_init(void);
|
|
void lcd_cmd(const uint8_t cmd);
|
|
void lcd_data(const uint8_t *data, int len);
|
|
|
|
|
|
|
|
//===============================================================================================
|
|
|
|
// Gestionnaire de l'ecran :
|
|
|
|
//===============================================================================================
|
|
|
|
|
|
void scanDevices(void) {
|
|
byte error, address;
|
|
int nDevices = 0;
|
|
Serial.println("Scanning for I2C devices ...");
|
|
for (address = 0x01; address < 0x7f; address++) {
|
|
Wire.beginTransmission(address);
|
|
error = Wire.endTransmission();
|
|
if (error == 0) {
|
|
Serial.printf("I2C device found at address 0x%02X\n", address);
|
|
nDevices++;
|
|
} else if (error != 2) {
|
|
Serial.printf("Error %d at address 0x%02X\n", error, address);
|
|
}
|
|
}
|
|
if (nDevices == 0) {
|
|
Serial.println("No I2C devices found");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//===============================================================================================
|
|
|
|
// Gestionnaire de memoire :
|
|
|
|
//===============================================================================================
|
|
|
|
void setupSPIFFS() {
|
|
if (SPIFFS.begin()) {
|
|
Serial.println("Système de fichiers SPIFFS monté avec succès");
|
|
} else {
|
|
Serial.println("Erreur lors du montage du système de fichiers SPIFFS");
|
|
}
|
|
}
|
|
|
|
void SD_init() {
|
|
xl.digitalWrite(SD_CS_PIN, 1); // To use SDIO one-line mode, you need to pull the CS pin high
|
|
SD_MMC.setPins(SD_CLK_PIN, SD_CMD_PIN, SD_D0_PIN);
|
|
if (!SD_MMC.begin("/sdcard", true, true)) {
|
|
Serial.println("Card Mount Failed");
|
|
return;
|
|
}
|
|
uint8_t cardType = SD_MMC.cardType();
|
|
if (cardType == CARD_NONE) {
|
|
Serial.println("No SD card attached");
|
|
return;
|
|
}
|
|
Serial.print("SD Card Type: ");
|
|
if (cardType == CARD_MMC)
|
|
Serial.println("MMC");
|
|
else if (cardType == CARD_SD)
|
|
Serial.println("SDSC");
|
|
else if (cardType == CARD_SDHC)
|
|
Serial.println("SDHC");
|
|
else
|
|
Serial.println("UNKNOWN");
|
|
|
|
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
|
|
Serial.printf("SD Card Size: %lluMB\n", cardSize);
|
|
}
|
|
|
|
|
|
uint16_t* convertStringToUint16Array(String inputString, int arraySize) {
|
|
uint16_t* dataArray = new uint16_t[arraySize];
|
|
int currentIndex = 0;
|
|
int lastIndex = 0;
|
|
for (int i = 0; i < inputString.length(); i++) {
|
|
if (inputString.charAt(i) == ',' || i == inputString.length() - 1) {
|
|
String token = inputString.substring(lastIndex, i + 1);
|
|
lastIndex = i + 1;
|
|
dataArray[currentIndex] = strtol(token.c_str(), NULL, 16);
|
|
currentIndex++;
|
|
}
|
|
}
|
|
return dataArray;
|
|
}
|
|
|
|
|
|
|
|
void lecture_front(fs::FS &fs, String path) {
|
|
|
|
Serial.println("Reading file: " + path);
|
|
File file = fs.open(path);
|
|
if (!file) {
|
|
Serial.println("Failed to open file for reading");
|
|
return ;
|
|
}
|
|
Serial.println("File open");
|
|
String contentfile = file.readString();
|
|
file.close();
|
|
int len = 230400;
|
|
|
|
gfx->draw16bitRGBBitmap(0, 0, (uint16_t *)convertStringToUint16Array(contentfile, 230400), 480, 480);
|
|
contentfile = "";
|
|
return ;
|
|
}
|
|
|
|
|
|
void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
|
|
fileCount = 0;
|
|
|
|
File root = fs.open(dirname);
|
|
if (!root) {
|
|
Serial.println("Failed to open directory");
|
|
return ;
|
|
}
|
|
if (!root.isDirectory()) {
|
|
Serial.println("Not a directory");
|
|
return ;
|
|
}
|
|
File file = root.openNextFile();
|
|
while (file) {
|
|
if (file.isDirectory()) {
|
|
Serial.print(" DIR : ");
|
|
Serial.println(file.name());
|
|
if (levels) {
|
|
listDir(fs, file.path(), levels - 1);
|
|
}
|
|
} else {
|
|
if (fileCount < MAX_FILES) {
|
|
Serial.print(" FILE: ");
|
|
Serial.print(file.name());
|
|
Serial.print(" SIZE: ");
|
|
Serial.println(file.size());
|
|
}
|
|
}
|
|
file = root.openNextFile();
|
|
}
|
|
}
|
|
|
|
//===============================================================================================
|
|
|
|
// Gestionnaire de variables :
|
|
|
|
//===============================================================================================
|
|
|
|
|
|
String uint16ArrayToString(uint16_t* array, size_t length) {
|
|
String result = "";
|
|
for (size_t i = 0; i < length; i++) {
|
|
result += String(array[i]);
|
|
// Ajoutez un séparateur si nécessaire (par exemple, une virgule)
|
|
if (i < length - 1) {
|
|
result += ",";
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
pinMode(BAT_VOLT_PIN, ANALOG);
|
|
Wire.begin(IIC_SDA_PIN, IIC_SCL_PIN, (uint32_t)800000);
|
|
Serial.begin(115200);
|
|
setupSPIFFS();
|
|
SD_init();
|
|
listDir(SD_MMC, "/", 0);
|
|
xl.begin();
|
|
uint8_t pin = (1 << PWR_EN_PIN) | (1 << LCD_CS_PIN) | (1 << TP_RES_PIN) | (1 << LCD_SDA_PIN) | (1 << LCD_CLK_PIN) |
|
|
(1 << LCD_RST_PIN) | (1 << SD_CS_PIN);
|
|
xl.pinMode8(0, pin, OUTPUT);
|
|
xl.digitalWrite(PWR_EN_PIN, 1);
|
|
pinMode(EXAMPLE_PIN_NUM_BK_LIGHT, OUTPUT);
|
|
digitalWrite(EXAMPLE_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL);
|
|
gfx->begin();
|
|
tft_init();
|
|
lastimg = "image_data";
|
|
// gfx->draw16bitRGBBitmap(0, 0, (uint16_t *)image_data, 480, 480);
|
|
|
|
lecture_front(SD_MMC, "/pikachu_run_bg_480 - slim.h");
|
|
}
|
|
|
|
void loop() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_send_data(uint8_t data) {
|
|
uint8_t n;
|
|
for (n = 0; n < 8; n++) {
|
|
if (data & 0x80)
|
|
xl.digitalWrite(LCD_SDA_PIN, 1);
|
|
else
|
|
xl.digitalWrite(LCD_SDA_PIN, 0);
|
|
data <<= 1;
|
|
xl.digitalWrite(LCD_CLK_PIN, 0);
|
|
xl.digitalWrite(LCD_CLK_PIN, 1);
|
|
}
|
|
}
|
|
|
|
void lcd_cmd(const uint8_t cmd) {
|
|
xl.digitalWrite(LCD_CS_PIN, 0);
|
|
xl.digitalWrite(LCD_SDA_PIN, 0);
|
|
xl.digitalWrite(LCD_CLK_PIN, 0);
|
|
xl.digitalWrite(LCD_CLK_PIN, 1);
|
|
lcd_send_data(cmd);
|
|
xl.digitalWrite(LCD_CS_PIN, 1);
|
|
}
|
|
|
|
void lcd_data(const uint8_t *data, int len) {
|
|
uint32_t i = 0;
|
|
if (len == 0)
|
|
return; // no need to send anything
|
|
do {
|
|
xl.digitalWrite(LCD_CS_PIN, 0);
|
|
xl.digitalWrite(LCD_SDA_PIN, 1);
|
|
xl.digitalWrite(LCD_CLK_PIN, 0);
|
|
xl.digitalWrite(LCD_CLK_PIN, 1);
|
|
lcd_send_data(*(data + i));
|
|
xl.digitalWrite(LCD_CS_PIN, 1);
|
|
i++;
|
|
} while (len--);
|
|
}
|
|
|
|
void tft_init(void) {
|
|
xl.digitalWrite(LCD_CS_PIN, 1);
|
|
xl.digitalWrite(LCD_SDA_PIN, 1);
|
|
xl.digitalWrite(LCD_CLK_PIN, 1);
|
|
xl.digitalWrite(LCD_RST_PIN, 1);
|
|
vTaskDelay(200 / portTICK_PERIOD_MS);
|
|
xl.digitalWrite(LCD_RST_PIN, 0);
|
|
vTaskDelay(200 / portTICK_PERIOD_MS);
|
|
xl.digitalWrite(LCD_RST_PIN, 1);
|
|
vTaskDelay(200 / portTICK_PERIOD_MS);
|
|
int cmd = 0;
|
|
while (st_init_cmds[cmd].databytes != 0xff) {
|
|
lcd_cmd(st_init_cmds[cmd].cmd);
|
|
lcd_data(st_init_cmds[cmd].data, st_init_cmds[cmd].databytes & 0x1F);
|
|
if (st_init_cmds[cmd].databytes & 0x80) {
|
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
|
}
|
|
cmd++;
|
|
}
|
|
Serial.println("Register setup complete");
|
|
}
|