Initial commit with Waveshare ESP32-S3-LCD-1.47 demo files

This commit is contained in:
drjones
2026-06-30 01:06:03 -07:00
commit 23107b98d7
2986 changed files with 819030 additions and 0 deletions

View File

@@ -0,0 +1,235 @@
#include "Display_ST7789.h"
SPIClass LCDspi(FSPI);
#define SPI_WRITE(_dat) LCDspi.transfer(_dat)
#define SPI_WRITE_Word(_dat) LCDspi.transfer16(_dat)
void SPI_Init()
{
LCDspi.begin(EXAMPLE_PIN_NUM_SCLK,EXAMPLE_PIN_NUM_MISO,EXAMPLE_PIN_NUM_MOSI);
}
void LCD_WriteCommand(uint8_t Cmd)
{
LCDspi.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, LOW);
SPI_WRITE(Cmd);
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
LCDspi.endTransaction();
}
void LCD_WriteData(uint8_t Data)
{
LCDspi.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH);
SPI_WRITE(Data);
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
LCDspi.endTransaction();
}
void LCD_WriteData_Word(uint16_t Data)
{
LCDspi.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH);
SPI_WRITE_Word(Data);
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
LCDspi.endTransaction();
}
void LCD_WriteData_nbyte(uint8_t* SetData,uint8_t* ReadData,uint32_t Size)
{
LCDspi.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH);
LCDspi.transferBytes(SetData, ReadData, Size);
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
LCDspi.endTransaction();
}
void LCD_Reset(void)
{
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
delay(50);
digitalWrite(EXAMPLE_PIN_NUM_LCD_RST, LOW);
delay(50);
digitalWrite(EXAMPLE_PIN_NUM_LCD_RST, HIGH);
delay(50);
}
void LCD_Init(void)
{
pinMode(EXAMPLE_PIN_NUM_LCD_CS, OUTPUT);
pinMode(EXAMPLE_PIN_NUM_LCD_DC, OUTPUT);
pinMode(EXAMPLE_PIN_NUM_LCD_RST, OUTPUT);
Backlight_Init();
SPI_Init();
LCD_Reset();
//************* Start Initial Sequence **********//
LCD_WriteCommand(0x11);
delay(120);
LCD_WriteCommand(0x36);
if (HORIZONTAL)
LCD_WriteData(0x00);
else
LCD_WriteData(0x70);
LCD_WriteCommand(0x3A);
LCD_WriteData(0x05);
LCD_WriteCommand(0xB0);
LCD_WriteData(0x00);
LCD_WriteData(0xE8);
LCD_WriteCommand(0xB2);
LCD_WriteData(0x0C);
LCD_WriteData(0x0C);
LCD_WriteData(0x00);
LCD_WriteData(0x33);
LCD_WriteData(0x33);
LCD_WriteCommand(0xB7);
LCD_WriteData(0x35);
LCD_WriteCommand(0xBB);
LCD_WriteData(0x35);
LCD_WriteCommand(0xC0);
LCD_WriteData(0x2C);
LCD_WriteCommand(0xC2);
LCD_WriteData(0x01);
LCD_WriteCommand(0xC3);
LCD_WriteData(0x13);
LCD_WriteCommand(0xC4);
LCD_WriteData(0x20);
LCD_WriteCommand(0xC6);
LCD_WriteData(0x0F);
LCD_WriteCommand(0xD0);
LCD_WriteData(0xA4);
LCD_WriteData(0xA1);
LCD_WriteCommand(0xD6);
LCD_WriteData(0xA1);
LCD_WriteCommand(0xE0);
LCD_WriteData(0xF0);
LCD_WriteData(0x00);
LCD_WriteData(0x04);
LCD_WriteData(0x04);
LCD_WriteData(0x04);
LCD_WriteData(0x05);
LCD_WriteData(0x29);
LCD_WriteData(0x33);
LCD_WriteData(0x3E);
LCD_WriteData(0x38);
LCD_WriteData(0x12);
LCD_WriteData(0x12);
LCD_WriteData(0x28);
LCD_WriteData(0x30);
LCD_WriteCommand(0xE1);
LCD_WriteData(0xF0);
LCD_WriteData(0x07);
LCD_WriteData(0x0A);
LCD_WriteData(0x0D);
LCD_WriteData(0x0B);
LCD_WriteData(0x07);
LCD_WriteData(0x28);
LCD_WriteData(0x33);
LCD_WriteData(0x3E);
LCD_WriteData(0x36);
LCD_WriteData(0x14);
LCD_WriteData(0x14);
LCD_WriteData(0x29);
LCD_WriteData(0x32);
LCD_WriteCommand(0x21);
LCD_WriteCommand(0x11);
delay(120);
LCD_WriteCommand(0x29);
}
/******************************************************************************
function: Set the cursor position
parameter :
Xstart: Start uint16_t x coordinate
Ystart: Start uint16_t y coordinate
Xend : End uint16_t coordinates
Yend : End uint16_t coordinatesen
******************************************************************************/
void LCD_SetCursor(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend)
{
if (HORIZONTAL) {
// set the X coordinates
LCD_WriteCommand(0x2A);
LCD_WriteData(Xstart >> 8);
LCD_WriteData(Xstart + Offset_X);
LCD_WriteData(Xend >> 8);
LCD_WriteData(Xend + Offset_X);
// set the Y coordinates
LCD_WriteCommand(0x2B);
LCD_WriteData(Ystart >> 8);
LCD_WriteData(Ystart + Offset_Y);
LCD_WriteData(Yend >> 8);
LCD_WriteData(Yend + Offset_Y);
}
else {
// set the X coordinates
LCD_WriteCommand(0x2A);
LCD_WriteData(Ystart >> 8);
LCD_WriteData(Ystart + Offset_Y);
LCD_WriteData(Yend >> 8);
LCD_WriteData(Yend + Offset_Y);
// set the Y coordinates
LCD_WriteCommand(0x2B);
LCD_WriteData(Xstart >> 8);
LCD_WriteData(Xstart + Offset_X);
LCD_WriteData(Xend >> 8);
LCD_WriteData(Xend + Offset_X);
}
LCD_WriteCommand(0x2C);
}
/******************************************************************************
function: Refresh the image in an area
parameter :
Xstart: Start uint16_t x coordinate
Ystart: Start uint16_t y coordinate
Xend : End uint16_t coordinates
Yend : End uint16_t coordinates
color : Set the color
******************************************************************************/
void LCD_addWindow(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,uint16_t* color)
{
uint16_t Show_Width = Xend - Xstart + 1;
uint16_t Show_Height = Yend - Ystart + 1;
uint32_t numBytes = Show_Width * Show_Height * sizeof(uint16_t);
uint8_t Read_D[numBytes];
LCD_SetCursor(Xstart, Ystart, Xend, Yend);
LCD_WriteData_nbyte((uint8_t*)color, Read_D, numBytes);
}
// backlight
void Backlight_Init(void)
{
ledcAttach(EXAMPLE_PIN_NUM_BK_LIGHT, Frequency, Resolution);
ledcWrite(EXAMPLE_PIN_NUM_BK_LIGHT, 100);
}
void Set_Backlight(uint8_t Light) //
{
if(Light > 100 || Light < 0)
printf("Set Backlight parameters in the range of 0 to 100 \r\n");
else{
uint32_t Backlight = Light*10;
ledcWrite(EXAMPLE_PIN_NUM_BK_LIGHT, Backlight);
}
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include <Arduino.h>
#include <SPI.h>
#define LCD_WIDTH 172 //LCD width
#define LCD_HEIGHT 320 //LCD height
#define SPIFreq 80000000
#define EXAMPLE_PIN_NUM_MISO -1
#define EXAMPLE_PIN_NUM_MOSI 45
#define EXAMPLE_PIN_NUM_SCLK 40
#define EXAMPLE_PIN_NUM_LCD_CS 42
#define EXAMPLE_PIN_NUM_LCD_DC 41
#define EXAMPLE_PIN_NUM_LCD_RST 39
#define EXAMPLE_PIN_NUM_BK_LIGHT 48
#define Frequency 1000 // PWM frequencyconst
#define Resolution 10
#define VERTICAL 0
#define HORIZONTAL 1
#define Offset_X 34
#define Offset_Y 0
void LCD_SetCursor(uint16_t x1, uint16_t y1, uint16_t x2,uint16_t y2);
void LCD_Init(void);
void LCD_SetCursor(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend);
void LCD_addWindow(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,uint16_t* color);
void Backlight_Init(void);
void Set_Backlight(uint8_t Light);

View File

@@ -0,0 +1,125 @@
#include "LCD_Image.h"
PNG png;
File Image_file;
uint16_t Image_CNT;
char SD_Image_Name[100][100] ;
char File_Image_Name[100][100] ;
int16_t xpos = 0;
int16_t ypos = 0;
void * pngOpen(const char *filePath, int32_t *size) {
Image_file = SD_MMC.open(filePath);
*size = Image_file.size();
return &Image_file;
}
void pngClose(void *handle) {
File Image_file = *((File*)handle);
if (Image_file) Image_file.close();
}
int32_t pngRead(PNGFILE *page, uint8_t *buffer, int32_t length) {
if (!Image_file) return 0;
page = page; // Avoid warning
return Image_file.read(buffer, length);
}
int32_t pngSeek(PNGFILE *page, int32_t position) {
if (!Image_file) return 0;
page = page; // Avoid warning
return Image_file.seek(position);
}
//=========================================v==========================================
// pngDraw
//====================================================================================
// This next function will be called during decoding of the png file to
// render each image line to the TFT. If you use a different TFT library
// you will need to adapt this function to suit.
// Callback function to draw pixels to the display
static uint16_t lineBuffer[MAX_IMAGE_WIDTH];
void pngDraw(PNGDRAW *pDraw) {
png.getLineAsRGB565(pDraw, lineBuffer, PNG_RGB565_BIG_ENDIAN, 0xffffffff);
uint32_t size = pDraw->iWidth;
for (size_t i = 0; i < size; i++) {
lineBuffer[i] = (((lineBuffer[i] >> 8) & 0xFF) | ((lineBuffer[i] << 8) & 0xFF00));
}
LCD_addWindow(xpos, pDraw->y, xpos + pDraw->iWidth, ypos + pDraw->y,lineBuffer); // x_end End index on x-axis (x_end not included)
}
/////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void Search_Image(const char* directory, const char* fileExtension) {
Image_CNT = Folder_retrieval(directory,fileExtension,SD_Image_Name,100);
if(Image_CNT) {
for (int i = 0; i < Image_CNT; i++) {
strcpy(File_Image_Name[i], SD_Image_Name[i]);
remove_file_extension(File_Image_Name[i]);
}
}
}
void Show_Image(const char * filePath)
{
printf("Currently display picture %s\r\n",filePath);
int16_t ret = png.open(filePath, pngOpen, pngClose, pngRead, pngSeek, pngDraw);
if (ret == PNG_SUCCESS) {
printf("image specs: (%d x %d), %d bpp, pixel type: %d\r\n", png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType());
uint32_t dt = millis();
if (png.getWidth() > MAX_IMAGE_WIDTH) {
printf("Image too wide for allocated line buffer size!\r\n");
}
else {
ret = png.decode(NULL, 0);
png.close();
}
printf("%d ms\r\n",millis()-dt);
}
}
void Display_Image(const char* directory, const char* fileExtension, uint16_t ID)
{
Search_Image(directory,fileExtension);
if(Image_CNT) {
String FilePath;
if (String(directory) == "/") { // Handle the case when the directory is the root
FilePath = String(directory) + SD_Image_Name[ID];
} else {
FilePath = String(directory) + "/" + SD_Image_Name[ID];
}
const char* filePathCStr = FilePath.c_str(); // Convert String to c_str() for Show_Image function
printf("Show : %s \r\n", filePathCStr); // Print file path for debugging
Show_Image(filePathCStr); // Show the image using the file path
}
else
printf("No files with extension '%s' found in directory: %s\r\n", fileExtension, directory);
}
uint16_t Now_Image = 0;
void Image_Next(const char* directory, const char* fileExtension)
{
if(!digitalRead(BOOT_KEY_PIN)){
while(!digitalRead(BOOT_KEY_PIN));
Now_Image ++;
if(Now_Image == Image_CNT)
Now_Image = 0;
Display_Image(directory,fileExtension,Now_Image);
}
}
void Image_Next_Loop(const char* directory, const char* fileExtension,uint32_t NextTime)
{
static uint32_t NextTime_Now=0;
NextTime_Now++;
if(NextTime_Now == NextTime)
{
NextTime_Now = 0;
Now_Image ++;
if(Now_Image == Image_CNT)
Now_Image = 0;
Display_Image(directory,fileExtension,Now_Image);
}
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include <PNGdec.h>
#include "SD_Card.h"
#include "Display_ST7789.h"
#define BOOT_KEY_PIN 9
#define MAX_IMAGE_WIDTH 172 // Adjust for your images
void Search_Image(const char* directory, const char* fileExtension);
void Show_Image(const char * filePath);
void Display_Image(const char* directory, const char* fileExtension, uint16_t ID);
void Image_Next(const char* directory, const char* fileExtension);
void Image_Next_Loop(const char* directory, const char* fileExtension,uint32_t NextTime);

View File

@@ -0,0 +1,56 @@
/**
******************************************************************************
* @file LCD_Image.ino
* @author Yongqin Ou
* @version V1.0
* @date 2024-10-31
* @brief Setup experiment for SD card, display, and RGB lamp
* @license MIT
* @copyright Copyright (c) 2024, Waveshare
******************************************************************************
*
* Experiment Objective: Learn how to set up and use SD card for image display and control an RGB lamp.
*
* Hardware Resources and Pin Assignment:
* 1. SD Card Interface --> As configured in SD_Card.h.
* 2. Display Interface --> As configured in Display_ST7789.h.
* 3. RGB Lamp Interface --> As configured in RGB_lamp.h.
*
* Experiment Phenomenon:
* 1. Runs tests and initializes SD card, display, and sets backlight.
* 2. Continuously loops through images on the SD card and controls the RGB lamp.
*
* Notes:
* None
*
******************************************************************************
*
* Development Platform: ESP32
* Support Forum: service.waveshare.com
* Company Website: www.waveshare.com
*
******************************************************************************
*/
/*
You must copy the PNG File from the SD Card File folder to the SD card and connect the SD card to the device
*/
#include "SD_Card.h"
#include "Display_ST7789.h"
#include "LCD_Image.h"
#include "RGB_lamp.h"
void setup()
{
Flash_test();
SD_Init();
LCD_Init();
Set_Backlight(90);
}
void loop()
{
Image_Next_Loop("/",".png",300);
RGB_Lamp_Loop(2);
delay(5);
}

View File

@@ -0,0 +1,48 @@
#include "RGB_lamp.h"
uint16_t Time = 0;
uint16_t Number = 0;
uint8_t RGB_Data[192][3] = {
{64, 1, 0}, {63, 2, 0}, {62, 3, 0}, {61, 4, 0}, {60, 5, 0}, {59, 6, 0}, {58, 7, 0}, {57, 8, 0},
{56, 9, 0}, {55, 10, 0}, {54, 11, 0}, {53, 12, 0}, {52, 13, 0}, {51, 14, 0}, {50, 15, 0}, {49, 16, 0},
{48, 17, 0}, {47, 18, 0}, {46, 19, 0}, {45, 20, 0}, {44, 21, 0}, {43, 22, 0}, {42, 23, 0}, {41, 24, 0},
{40, 25, 0}, {39, 26, 0}, {38, 27, 0}, {37, 28, 0}, {36, 29, 0}, {35, 30, 0}, {34, 31, 0}, {33, 32, 0},
{32, 33, 0}, {31, 34, 0}, {30, 35, 0}, {29, 36, 0}, {28, 37, 0}, {27, 38, 0}, {26, 39, 0}, {25, 40, 0},
{24, 41, 0}, {23, 42, 0}, {22, 43, 0}, {21, 44, 0}, {20, 45, 0}, {19, 46, 0}, {18, 47, 0}, {17, 48, 0},
{16, 49, 0}, {15, 50, 0}, {14, 51, 0}, {13, 52, 0}, {12, 53, 0}, {11, 54, 0}, {10, 55, 0}, {9, 56, 0},
{8, 57, 0}, {7, 58, 0}, {6, 59, 0}, {5, 60, 0}, {4, 61, 0}, {3, 62, 0}, {2, 63, 0}, {1, 64, 0},
{0, 64, 1}, {0, 63, 2}, {0, 62, 3}, {0, 61, 4}, {0, 60, 5}, {0, 59, 6}, {0, 58, 7}, {0, 57, 8},
{0, 56, 9}, {0, 55, 10}, {0, 54, 11}, {0, 53, 12}, {0, 52, 13}, {0, 51, 14}, {0, 50, 15}, {0, 49, 16},
{0, 48, 17}, {0, 47, 18}, {0, 46, 19}, {0, 45, 20}, {0, 44, 21}, {0, 43, 22}, {0, 42, 23}, {0, 41, 24},
{0, 40, 25}, {0, 39, 26}, {0, 38, 27}, {0, 37, 28}, {0, 36, 29}, {0, 35, 30}, {0, 34, 31}, {0, 33, 32},
{0, 32, 33}, {0, 31, 34}, {0, 30, 35}, {0, 29, 36}, {0, 28, 37}, {0, 27, 38}, {0, 26, 39}, {0, 25, 40},
{0, 24, 41}, {0, 23, 42}, {0, 22, 43}, {0, 21, 44}, {0, 20, 45}, {0, 19, 46}, {0, 18, 47}, {0, 17, 48},
{0, 16, 49}, {0, 15, 50}, {0, 14, 51}, {0, 13, 52}, {0, 12, 53}, {0, 11, 54}, {0, 10, 55}, {0, 9, 56},
{0, 8, 57}, {0, 7, 58}, {0, 6, 59}, {0, 5, 60}, {0, 4, 61}, {0, 3, 62}, {0, 2, 63}, {0, 1, 64},
{1, 0, 64}, {2, 0, 63}, {3, 0, 62}, {4, 0, 61}, {5, 0, 60}, {6, 0, 59}, {7, 0, 58}, {8, 0, 57},
{9, 0, 56}, {10, 0, 55}, {11, 0, 54}, {12, 0, 53}, {13, 0, 52}, {14, 0, 51}, {15, 0, 50}, {16, 0, 49},
{17, 0, 48}, {18, 0, 47}, {19, 0, 46}, {20, 0, 45}, {21, 0, 44}, {22, 0, 43}, {23, 0, 42}, {24, 0, 41},
{25, 0, 40}, {26, 0, 39}, {27, 0, 38}, {28, 0, 37}, {29, 0, 36}, {30, 0, 35}, {31, 0, 34}, {32, 0, 33},
{33, 0, 32}, {34, 0, 31}, {35, 0, 30}, {36, 0, 29}, {37, 0, 28}, {38, 0, 27}, {39, 0, 26}, {40, 0, 25},
{41, 0, 24}, {42, 0, 23}, {43, 0, 22}, {44, 0, 21}, {45, 0, 20}, {46, 0, 19}, {47, 0, 18}, {48, 0, 17},
{49, 0, 16}, {50, 0, 15}, {51, 0, 14}, {52, 0, 13}, {53, 0, 12}, {54, 0, 11}, {55, 0, 10}, {56, 0, 9},
{57, 0, 8}, {58, 0, 7}, {59, 0, 6}, {60, 0, 5}, {61, 0, 4}, {62, 0, 3}, {63, 0, 2}, {64, 0, 1}
};
// data range -> Red:0~255 Green:0~255 Blue:0~255
void Set_Color(uint8_t Red,uint8_t Green,uint8_t Blue) // Set RGB bead color
{
neopixelWrite(PIN_NEOPIXEL, Red, Green, Blue);
}
void RGB_Lamp_Loop(uint16_t Waiting)
{
Time++;
if(Time == Waiting){
Time = 0;
Number++;
if(Number == 192)
Number = 0;
Set_Color( RGB_Data[Number][0]*3, RGB_Data[Number][1]*3, RGB_Data[Number][2]*3); // Color
}
}

View File

@@ -0,0 +1,7 @@
#pragma once
#include "Arduino.h"
#define PIN_NEOPIXEL 38
void Set_Color(uint8_t Red,uint8_t Green,uint8_t Blue); // Set RGB bead color
void RGB_Lamp_Loop(uint16_t Waiting); // The lamp beads change color in cycles

View File

@@ -0,0 +1,119 @@
#include "SD_Card.h"
bool SDCard_Flag;
bool SDCard_Finish;
uint16_t SDCard_Size;
uint16_t Flash_Size;
void SD_Init() {
// SD MMC
if(!SD_MMC.setPins(SD_CLK_PIN, SD_CMD_PIN, SD_D0_PIN, SD_D1_PIN, SD_D2_PIN, SD_D3_PIN)){
printf("SD MMC: Pin change failed!\r\n");
return;
}
if (SD_MMC.begin("/sdcard", true, true)) {
printf("SD card initialization successful!\r\n");
} else {
printf("SD card initialization failed!\r\n");
}
uint8_t cardType = SD_MMC.cardType();
if(cardType == CARD_NONE){
printf("No SD card attached\r\n");
return;
}
else{
printf("SD Card Type: ");
if(cardType == CARD_MMC){
printf("MMC\r\n");
} else if(cardType == CARD_SD){
printf("SDSC\r\n");
} else if(cardType == CARD_SDHC){
printf("SDHC\r\n");
} else {
printf("UNKNOWN\r\n");
}
uint64_t totalBytes = SD_MMC.totalBytes();
uint64_t usedBytes = SD_MMC.usedBytes();
SDCard_Size = totalBytes/(1024*1024);
printf("Total space: %llu\n", totalBytes);
printf("Used space: %llu\n", usedBytes);
printf("Free space: %llu\n", totalBytes - usedBytes);
}
}
bool File_Search(const char* directory, const char* fileName)
{
File Path = SD_MMC.open(directory);
if (!Path) {
printf("Path: <%s> does not exist\r\n",directory);
return false;
}
File file = Path.openNextFile();
while (file) {
if (strcmp(file.name(), fileName) == 0) {
if (strcmp(directory, "/") == 0)
printf("File '%s%s' found in root directory.\r\n",directory,fileName);
else
printf("File '%s/%s' found in root directory.\r\n",directory,fileName);
Path.close();
return true;
}
file = Path.openNextFile();
}
if (strcmp(directory, "/") == 0)
printf("File '%s%s' not found in root directory.\r\n",directory,fileName);
else
printf("File '%s/%s' not found in root directory.\r\n",directory,fileName);
Path.close();
return false;
}
uint16_t Folder_retrieval(const char* directory, const char* fileExtension, char File_Name[][100],uint16_t maxFiles)
{
File Path = SD_MMC.open(directory);
if (!Path) {
printf("Path: <%s> does not exist\r\n",directory);
return false;
}
uint16_t fileCount = 0;
char filePath[100];
File file = Path.openNextFile();
while (file && fileCount < maxFiles) {
if (!file.isDirectory() && strstr(file.name(), fileExtension)) {
strncpy(File_Name[fileCount], file.name(), sizeof(File_Name[fileCount]));
if (strcmp(directory, "/") == 0) {
snprintf(filePath, 100, "%s%s", directory, file.name());
} else {
snprintf(filePath, 100, "%s/%s", directory, file.name());
}
printf("File found: %s\r\n", filePath);
fileCount++;
}
file = Path.openNextFile();
}
Path.close();
if (fileCount > 0) {
printf("%d <%s> files were retrieved\r\n",fileCount,fileExtension);
return fileCount;
} else {
printf("No files with extension '%s' found in directory: %s\r\n", fileExtension, directory);
return 0;
}
}
void remove_file_extension(char *file_name) {
char *last_dot = strrchr(file_name, '.');
if (last_dot != NULL) {
*last_dot = '\0';
}
}
void Flash_test()
{
printf("/********** RAM Test**********/\r\n");
// Get Flash size
uint32_t flashSize = ESP.getFlashChipSize();
Flash_Size = flashSize/1024/1024;
printf("Flash size: %d MB \r\n", flashSize/1024/1024);
printf("/******* RAM Test Over********/\r\n\r\n");
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "Arduino.h"
#include <cstring>
#include "FS.h"
#include "SD_MMC.h"
#define SD_CLK_PIN 14
#define SD_CMD_PIN 15
#define SD_D0_PIN 16
#define SD_D1_PIN 18
#define SD_D2_PIN 17
#define SD_D3_PIN 21
extern uint16_t SDCard_Size;
extern uint16_t Flash_Size;
void SD_Init();
void Flash_test();
bool File_Search(const char* directory, const char* fileName);
uint16_t Folder_retrieval(const char* directory, const char* fileExtension, char File_Name[][100],uint16_t maxFiles);
void remove_file_extension(char *file_name);