initial commit
This commit is contained in:
245
examples/LVGL_Image/Display_ST7789.cpp
Normal file
245
examples/LVGL_Image/Display_ST7789.cpp
Normal file
@@ -0,0 +1,245 @@
|
||||
#include "Display_ST7789.h"
|
||||
|
||||
#define SPI_WRITE(_dat) SPI.transfer(_dat)
|
||||
#define SPI_WRITE_Word(_dat) SPI.transfer16(_dat)
|
||||
#define SPI_WRITE_nByte(_SetData,_ReadData,_Size) SPI.transferBytes(_SetData,_ReadData,_Size)
|
||||
void SPI_Init()
|
||||
{
|
||||
SPI.begin(EXAMPLE_PIN_NUM_SCLK,EXAMPLE_PIN_NUM_MISO,EXAMPLE_PIN_NUM_MOSI);
|
||||
}
|
||||
|
||||
void LCD_WriteCommand(uint8_t Cmd)
|
||||
{
|
||||
SPI.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);
|
||||
SPI.endTransaction();
|
||||
}
|
||||
void LCD_WriteData(uint8_t Data)
|
||||
{
|
||||
SPI.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);
|
||||
SPI.endTransaction();
|
||||
}
|
||||
|
||||
void LCD_WriteData_Word(uint16_t Data)
|
||||
{
|
||||
SPI.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);
|
||||
SPI.endTransaction();
|
||||
}
|
||||
void LCD_WriteData_nbyte(uint8_t* SetData,uint8_t* ReadData,uint32_t Size)
|
||||
{
|
||||
SPI.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH);
|
||||
SPI_WRITE_nByte(SetData, ReadData, Size);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
SPI.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 i,j;
|
||||
// LCD_SetCursor(Xstart, Ystart, Xend,Yend);
|
||||
// uint16_t Show_Width = Xend - Xstart + 1;
|
||||
// uint16_t Show_Height = Yend - Ystart + 1;
|
||||
// for(i = 0; i < Show_Height; i++){
|
||||
// for(j = 0; j < Show_Width; j++){
|
||||
// LCD_WriteData_Word(color[(i*(Show_Width))+j]);
|
||||
// }
|
||||
// }
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
31
examples/LVGL_Image/Display_ST7789.h
Normal file
31
examples/LVGL_Image/Display_ST7789.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#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 5
|
||||
#define EXAMPLE_PIN_NUM_MOSI 6
|
||||
#define EXAMPLE_PIN_NUM_SCLK 7
|
||||
#define EXAMPLE_PIN_NUM_LCD_CS 14
|
||||
#define EXAMPLE_PIN_NUM_LCD_DC 15
|
||||
#define EXAMPLE_PIN_NUM_LCD_RST 21
|
||||
#define EXAMPLE_PIN_NUM_BK_LIGHT 22
|
||||
#define Frequency 1000
|
||||
#define Resolution 10
|
||||
|
||||
#define VERTICAL 0
|
||||
#define HORIZONTAL 1
|
||||
|
||||
#define Offset_X 34
|
||||
#define Offset_Y 0
|
||||
|
||||
void SPI_Init();
|
||||
|
||||
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);
|
||||
124
examples/LVGL_Image/LCD_Image.cpp
Normal file
124
examples/LVGL_Image/LCD_Image.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
#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.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 + 1,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);
|
||||
}
|
||||
}
|
||||
14
examples/LVGL_Image/LCD_Image.h
Normal file
14
examples/LVGL_Image/LCD_Image.h
Normal 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);
|
||||
19
examples/LVGL_Image/LVGL_Image.ino
Normal file
19
examples/LVGL_Image/LVGL_Image.ino
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "SD_Card.h"
|
||||
#include "Display_ST7789.h"
|
||||
#include "LCD_Image.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
Flash_test();
|
||||
LCD_Init();
|
||||
SD_Init();
|
||||
Display_Image("/",".png", 0);
|
||||
pinMode(BOOT_KEY_PIN, INPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Image_Next_Loop("/",".png",300);
|
||||
delay(5);
|
||||
}
|
||||
113
examples/LVGL_Image/SD_Card.cpp
Normal file
113
examples/LVGL_Image/SD_Card.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "SD_Card.h"
|
||||
|
||||
uint16_t SDCard_Size;
|
||||
uint16_t Flash_Size;
|
||||
|
||||
void SD_Init() {
|
||||
// SD
|
||||
if (SD.begin(SD_CS, SPI, 80000000, "/sd", 5, true)) {
|
||||
printf("SD card initialization successful!\r\n");
|
||||
} else {
|
||||
printf("SD card initialization failed!\r\n");
|
||||
}
|
||||
uint8_t cardType = SD.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.totalBytes();
|
||||
uint64_t usedBytes = SD.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.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.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");
|
||||
}
|
||||
19
examples/LVGL_Image/SD_Card.h
Normal file
19
examples/LVGL_Image/SD_Card.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "Arduino.h"
|
||||
#include <cstring>
|
||||
#include "Display_ST7789.h"
|
||||
#include "SD.h"
|
||||
#include "FS.h"
|
||||
|
||||
// Digital I/O used
|
||||
#define SD_CS 4 // SD_D3:
|
||||
|
||||
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);
|
||||
Reference in New Issue
Block a user