Initial commit

This commit is contained in:
2026-03-31 13:17:21 +02:00
commit 7eeecff042
6821 changed files with 3514215 additions and 0 deletions

View File

@@ -0,0 +1,174 @@
#include "FileHandler.h"
FileHandler::FileHandler() {
// Initialisez vos membres de classe ici si nécessaire
}
FileInfo* FileHandler::listDir(fs::FS &fs, const char *dirname, uint8_t levels, int &fileCount) {
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
fileCount = 0;
return nullptr;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
fileCount = 0;
return nullptr;
}
File file = root.openNextFile();
FileInfo* fileInfo = nullptr;
int count = 0;
while (file) {
FileInfo* newFileInfo = (FileInfo*)malloc(sizeof(FileInfo));
newFileInfo->name = file.name();
newFileInfo->size = file.size();
FileInfo* temp = (FileInfo*)realloc(fileInfo, (count + 1) * sizeof(FileInfo));
if (temp == nullptr) {
// Échec de réallocation, libérer la mémoire précédemment allouée
freeFileInfo(fileInfo);
fileCount = 0;
return nullptr;
}
fileInfo = temp;
fileInfo[count] = *newFileInfo;
free(newFileInfo);
count++;
if (file.isDirectory() && levels) {
FileInfo* subDirFiles = listDir(fs, file.path(), levels - 1, fileCount);
if (subDirFiles) {
for (int i = 0; i < fileCount; i++) {
FileInfo* newFileInfo = (FileInfo*)malloc(sizeof(FileInfo));
newFileInfo->name = subDirFiles[i].name;
newFileInfo->size = subDirFiles[i].size;
FileInfo* temp = (FileInfo*)realloc(fileInfo, (count + 1) * sizeof(FileInfo));
if (temp == nullptr) {
// Échec de réallocation, libérer la mémoire précédemment allouée
freeFileInfo(fileInfo);
fileCount = 0;
return nullptr;
}
fileInfo = temp;
fileInfo[count] = *newFileInfo;
free(newFileInfo);
count++;
}
freeFileInfo(subDirFiles);
}
}
file = root.openNextFile();
}
fileCount = count;
return fileInfo;
}
void FileHandler::freeFileInfo(FileInfo* fileInfo) {
if (fileInfo) {
free(fileInfo);
}
}
bool FileHandler::createDir(fs::FS &fs, const char *path) {
Serial.printf("Creating Dir: %s\n", path);
if (fs.mkdir(path)) {
Serial.println("Dir created");
return true;
} else {
Serial.println("mkdir failed");
return false;
}
}
bool FileHandler::removeDir(fs::FS &fs, const char *path) {
Serial.printf("Removing Dir: %s\n", path);
if (fs.rmdir(path)) {
Serial.println("Dir removed");
return true;
} else {
Serial.println("rmdir failed");
return false;
}
}
bool FileHandler::readFile(fs::FS &fs, const char *path) {
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return false;
}
Serial.print("Read from file: ");
while (file.available()) {
Serial.write(file.read());
}
return true;
}
bool FileHandler::writeFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return false;
}
if (file.print(message)) {
Serial.println("File written");
return true;
} else {
Serial.println("Write failed");
return false;
}
}
bool FileHandler::appendFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Appending to file: %s\n", path);
File file = fs.open(path, FILE_APPEND);
if (!file) {
Serial.println("Failed to open file for appending");
return false;
}
if (file.print(message)) {
Serial.println("Message appended");
return true;
} else {
Serial.println("Append failed");
return false;
}
}
bool FileHandler::renameFile(fs::FS &fs, const char *path1, const char *path2) {
Serial.printf("Renaming file %s to %s\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("File renamed");
return true;
} else {
Serial.println("Rename failed");
return false;
}
}
bool FileHandler::deleteFile(fs::FS &fs, const char *path) {
Serial.printf("Deleting file: %s\n", path);
if (fs.remove(path)) {
Serial.println("File deleted");
return true;
} else {
Serial.println("Delete failed");
return false;
}
}

View File

@@ -0,0 +1,26 @@
#ifndef FileHandler_h
#define FileHandler_h
#include <Arduino.h> // Inclure Arduino.h pour utiliser String
#include <FS.h> // Inclure la bibliothèque FS (ou la bibliothèque appropriée)
struct FileInfo {
String name;
size_t size;
};
class FileHandler {
public:
FileHandler();
FileInfo* listDir(fs::FS &fs, const char *dirname, uint8_t levels, int &fileCount);
void freeFileInfo(FileInfo* fileInfo);
bool createDir(fs::FS &fs, const char *path);
bool removeDir(fs::FS &fs, const char *path);
bool readFile(fs::FS &fs, const char *path);
bool writeFile(fs::FS &fs, const char *path, const char *message);
bool appendFile(fs::FS &fs, const char *path, const char *message);
bool renameFile(fs::FS &fs, const char *path1, const char *path2);
bool deleteFile(fs::FS &fs, const char *path);
};
#endif

View File

@@ -0,0 +1,92 @@
#include "SD_MMC.h"
#include "Wire.h"
#include "XL9535_driver.h"
#include "pin_config.h"
#include "FileHandler.h"
#include <FS.h>
#include <Arduino.h>
XL9535 xl;
FileHandler fileHandler;
void setup() {
Serial.begin(115200);
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);
FileInfo* files = nullptr;
int fileCount = 0;
// Utilisation de la bibliothèque FileHandler pour gérer les fichiers et les répertoires
files = fileHandler.listDir(SD_MMC, "/", 0, fileCount);
for (int i = 0; i < fileCount; i++) {
Serial.print("File: ");
Serial.print(files[i].name);
Serial.print(" Size: ");
Serial.println(files[i].size);
}
fileHandler.createDir(SD_MMC, "/");
files = fileHandler.listDir(SD_MMC, "/", 0, fileCount);
for (int i = 0; i < fileCount; i++) {
Serial.print("File: ");
Serial.print(files[i].name);
Serial.print(" Size: ");
Serial.println(files[i].size);
}
fileHandler.removeDir(SD_MMC, "/");
files = fileHandler.listDir(SD_MMC, "/", 2, fileCount);
for (int i = 0; i < fileCount; i++) {
Serial.print("File: ");
Serial.print(files[i].name);
Serial.print(" Size: ");
Serial.println(files[i].size);
}
fileHandler.writeFile(SD_MMC, "/hello.txt", "Hello ");
fileHandler.appendFile(SD_MMC, "/hello.txt", "World!\n");
fileHandler.readFile(SD_MMC, "/hello.txt");
fileHandler.deleteFile(SD_MMC, "/foo.txt");
fileHandler.renameFile(SD_MMC, "/hello.txt", "/foo.txt");
fileHandler.readFile(SD_MMC, "/foo.txt");
fileHandler.freeFileInfo(files);
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
}
void loop() {
delay(10000);
}

View File

@@ -0,0 +1,117 @@
#include "XL9535_driver.h"
#include "Wire.h"
void XL9535::writeRegister(uint8_t reg, uint8_t *data, uint8_t len) {
_wire->beginTransmission(_address);
_wire->write(reg);
for (uint8_t i = 0; i < len; i++) {
_wire->write(data[i]);
}
_wire->endTransmission();
}
uint8_t XL9535::readRegister(uint8_t reg, uint8_t *data, uint8_t len) {
_wire->beginTransmission(_address);
_wire->write(reg);
_wire->endTransmission();
_wire->requestFrom(_address, len);
uint8_t index = 0;
while (index < len)
data[index++] = _wire->read();
return 0;
}
void XL9535::begin(bool A0, bool A1, bool A2, TwoWire *wire) {
_address = XL9535_IIC_ADDRESS | (A2 << 3) | (A1 << 2) | (A0 << 1);
_wire = wire;
is_found = true;
_wire->beginTransmission(_address);
if (!_wire->endTransmission()) {
Serial.println("Found xl9535");
} else {
Serial.println("xl9535 not found");
is_found = false;
}
}
void XL9535::pinMode(uint8_t pin, uint8_t mode) {
if (is_found) {
uint8_t port = 0;
if (pin > 7) {
readRegister(XL9535_CONFIG_PORT_1_REG, &port, 1);
if (mode == OUTPUT) {
port = port & (~(1 << (pin - 10)));
} else {
port = port | (1 << (pin - 10));
}
writeRegister(XL9535_CONFIG_PORT_1_REG, &port, 1);
} else {
readRegister(XL9535_CONFIG_PORT_0_REG, &port, 1);
if (mode == OUTPUT) {
port = port & (~(1 << pin));
} else {
port = port | (1 << pin);
}
writeRegister(XL9535_CONFIG_PORT_0_REG, &port, 1);
}
} else {
Serial.println("xl9535 not found");
}
}
void XL9535::pinMode8(uint8_t port, uint8_t pin, uint8_t mode) {
if (is_found) {
uint8_t _pin = (mode != OUTPUT) ? pin : ~pin;
if (port) {
writeRegister(XL9535_CONFIG_PORT_1_REG, &_pin, 1);
} else {
writeRegister(XL9535_CONFIG_PORT_0_REG, &_pin, 1);
}
} else {
Serial.println("xl9535 not found");
}
}
void XL9535::digitalWrite(uint8_t pin, uint8_t val) {
if (is_found) {
uint8_t port = 0;
uint8_t reg_data = 0;
if (pin > 7) {
readRegister(XL9535_OUTPUT_PORT_1_REG, &reg_data, 1);
reg_data = reg_data & (~(1 << (pin - 10)));
port = reg_data | val << (pin - 10);
writeRegister(XL9535_OUTPUT_PORT_1_REG, &port, 1);
} else {
readRegister(XL9535_OUTPUT_PORT_0_REG, &reg_data, 1);
reg_data = reg_data & (~(1 << pin));
port = reg_data | val << pin;
writeRegister(XL9535_OUTPUT_PORT_0_REG, &port, 1);
}
} else {
Serial.println("xl9535 not found");
}
}
int XL9535::digitalRead(uint8_t pin) {
if (is_found) {
int state = 0;
uint8_t port = 0;
if (pin > 7) {
readRegister(XL9535_INPUT_PORT_1_REG, &port, 1);
state = port & (pin - 10) ? 1 : 0;
} else {
readRegister(XL9535_INPUT_PORT_0_REG, &port, 1);
state = port & pin ? 1 : 0;
}
return state;
} else {
Serial.println("xl9535 not found");
}
return 0;
}
void XL9535::read_all_reg() {
uint8_t data;
for (uint8_t i = 0; i < 8; i++) {
readRegister(i, &data, 1);
Serial.printf("0x%02x : 0x%02X \r\n", i, data);
}
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include "Arduino.h"
#include "Wire.h"
#define XL9535_IIC_ADDRESS 0X20
#define XL9535_INPUT_PORT_0_REG 0X00
#define XL9535_INPUT_PORT_1_REG 0X01
#define XL9535_OUTPUT_PORT_0_REG 0X02
#define XL9535_OUTPUT_PORT_1_REG 0X03
#define XL9535_INVERSION_PORT_0_REG 0X04
#define XL9535_INVERSION_PORT_1_REG 0X05
#define XL9535_CONFIG_PORT_0_REG 0X06
#define XL9535_CONFIG_PORT_1_REG 0X07
class XL9535 {
public:
XL9535(){};
~XL9535(){};
void begin(bool A0 = 0, bool A1 = 0, bool A2 = 0, TwoWire *wire = &Wire);
void pinMode(uint8_t pin, uint8_t mode);
void pinMode8(uint8_t port, uint8_t pin, uint8_t mode);
void digitalWrite(uint8_t pin, uint8_t val);
int digitalRead(uint8_t pin);
void read_all_reg();
protected:
void writeRegister(uint8_t reg, uint8_t *data, uint8_t len);
uint8_t readRegister(uint8_t reg, uint8_t *data, uint8_t len);
uint8_t _address;
TwoWire *_wire;
bool is_found;
};

View File

@@ -0,0 +1,57 @@
#pragma once
#define WIFI_SSID "xinyuandianzi"
#define WIFI_PASSWORD "AA15994823428"
#define EXAMPLE_LCD_PIXEL_CLOCK_HZ (8 * 1000 * 1000)
#define EXAMPLE_LCD_BK_LIGHT_ON_LEVEL 1
#define EXAMPLE_LCD_BK_LIGHT_OFF_LEVEL !EXAMPLE_LCD_BK_LIGHT_ON_LEVEL
#define EXAMPLE_PIN_NUM_BK_LIGHT 46
#define EXAMPLE_PIN_NUM_HSYNC 47
#define EXAMPLE_PIN_NUM_VSYNC 41
#define EXAMPLE_PIN_NUM_DE 45
#define EXAMPLE_PIN_NUM_PCLK 42
// #define EXAMPLE_PIN_NUM_DATA0 44
#define EXAMPLE_PIN_NUM_DATA1 21
#define EXAMPLE_PIN_NUM_DATA2 18
#define EXAMPLE_PIN_NUM_DATA3 17
#define EXAMPLE_PIN_NUM_DATA4 16
#define EXAMPLE_PIN_NUM_DATA5 15
#define EXAMPLE_PIN_NUM_DATA6 14
#define EXAMPLE_PIN_NUM_DATA7 13
#define EXAMPLE_PIN_NUM_DATA8 12
#define EXAMPLE_PIN_NUM_DATA9 11
#define EXAMPLE_PIN_NUM_DATA10 10
#define EXAMPLE_PIN_NUM_DATA11 9
// #define EXAMPLE_PIN_NUM_DATA12 43
#define EXAMPLE_PIN_NUM_DATA13 7
#define EXAMPLE_PIN_NUM_DATA14 6
#define EXAMPLE_PIN_NUM_DATA15 5
#define EXAMPLE_PIN_NUM_DATA16 3
#define EXAMPLE_PIN_NUM_DATA17 2
#define EXAMPLE_PIN_NUM_DISP_EN -1
// The pixel number in horizontal and vertical
#define EXAMPLE_LCD_H_RES 480
#define EXAMPLE_LCD_V_RES 480
#define IIC_SCL_PIN 48
#define IIC_SDA_PIN 8
#define SD_CLK_PIN 39
#define SD_CMD_PIN 40
#define SD_D0_PIN 38
#define BAT_VOLT_PIN 4
#define TP_INT_PIN 1
#define BOOT_BTN_PIN 0
/* XL9535 --- PIN - P0*/
#define TP_RES_PIN 1
#define PWR_EN_PIN 2
#define LCD_CS_PIN 3
#define LCD_SDA_PIN 4
#define LCD_CLK_PIN 5
#define LCD_RST_PIN 6
#define SD_CS_PIN 7