Skip to content

Commit

Permalink
Change the partition format to FATFS, compatible with Arduino IDE #241
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jun 12, 2024
1 parent 1308206 commit 157ea89
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
- examples/peripheral/PMU_ADC/PMU_ADC.ino
- examples/peripheral/PMU_Interrupt/PMU_Interrupt.ino
- examples/peripheral/PlayMusicFromPROGMEM/PlayMusicFromPROGMEM.ino
- examples/peripheral/PlayMusicFromSPIFFS/PlayMusicFromSPIFFS.ino
- examples/peripheral/PlayMusicFromFATFS/PlayMusicFromFATFS.ino
- examples/peripheral/RTC_AlarmByUnits/RTC_AlarmByUnits.ino
- examples/peripheral/RTC_TimeLib/RTC_TimeLib.ino
- examples/peripheral/RTC_TimeSynchronization/RTC_TimeSynchronization.ino
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
- examples/peripheral/PMU_ADC
- examples/peripheral/PMU_Interrupt
- examples/peripheral/PlayMusicFromPROGMEM
- examples/peripheral/PlayMusicFromSPIFFS
- examples/peripheral/PlayMusicFromFATFS
- examples/peripheral/RTC_AlarmByUnits
- examples/peripheral/RTC_TimeLib
- examples/peripheral/RTC_TimeSynchronization
Expand Down
14 changes: 7 additions & 7 deletions examples/demo/LilyGoGui/LilyGoGui.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ IRsend irsend(BOARD_IR_PIN);
#include <AudioGeneratorMP3.h>
#include <AudioGeneratorWAV.h>
#include <AudioOutputI2S.h>
#include <AudioFileSourceSPIFFS.h>
#include <AudioFileSourceFATFS.h>
#include <AudioFileSourceFunction.h>
#include <AudioGeneratorFLAC.h>
#include <AudioGeneratorAAC.h>
Expand All @@ -61,7 +61,7 @@ SX1280 radio = newModule();

extern const unsigned char mp3_array[16509];
extern unsigned char mp3_ring_setup[86144];
AudioFileSourceSPIFFS *file_fs;
AudioFileSourceFATFS *file_fs;
AudioGeneratorWAV *wav = NULL;
AudioFileSourcePROGMEM *file = NULL;
AudioOutputI2S *out = NULL;
Expand Down Expand Up @@ -933,7 +933,7 @@ void wav_task(void *param)
// if (!audio->isRunning()) {
mp3->stop();
suspend_playMP3Handler();
//mp3->connecttoFS(SPIFFS, "/ring_1.mp3");
//mp3->connecttoFS(FFat, "/ring_1.mp3");
// Serial.println("play \"/ring_1.mp3\"");
is_pause = false;
// }
Expand Down Expand Up @@ -1279,7 +1279,7 @@ void settingPlayer()
mp3 = new AudioGeneratorMP3();
mp3->begin(id3, out);

file_fs = new AudioFileSourceSPIFFS();
file_fs = new AudioFileSourceFATFS();
wav = new AudioGeneratorWAV();
player_task_cb = playMP3;

Expand Down Expand Up @@ -1317,7 +1317,7 @@ static bool CreateWAV(const char *song_name, uint32_t duration, uint16_t num_cha
// data size in bytes - > this amount of data should be recorded from microphone later
uint32_t data_size = sampling_rate * num_channels * bits_per_sample * duration / 8;

File new_audio_file = SPIFFS.open(song_name, FILE_WRITE);
File new_audio_file = FFat.open(song_name, FILE_WRITE);
if (!new_audio_file) {
Serial.println("Failed to create file");
return false;
Expand Down Expand Up @@ -1603,7 +1603,7 @@ static void PDM_Record(const char *song_name, uint32_t duration)
}

// Open created .wav file in append+binary mode to add PCM data
File audio_file = SPIFFS.open(song_name, FILE_APPEND);
File audio_file = FFat.open(song_name, FILE_APPEND);
if (!audio_file) {
Serial.println("Failed to create file");
return;
Expand Down Expand Up @@ -1640,7 +1640,7 @@ static void PDM_Record(const char *song_name, uint32_t duration)
if (bytes_written != BUFFER_SIZE) {
Serial.println("Bytes written error");
}
// Save data to SPIFFS
// Save data to FFat
audio_file.write( buf, BUFFER_SIZE);
// Increment the counter
counter += BUFFER_SIZE;
Expand Down
46 changes: 31 additions & 15 deletions examples/demo/factory/factory.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@
* @license MIT
* @copyright Copyright (c) 2023 Shenzhen Xinyuan Electronic Technology Co., Ltd
* @date 2023-04-05
* @note Arduino Setting
* @note Arduino esp version 2.0.9 Setting , not support esp 3.x
* Tools ->
* Board:"ESP32S3 Dev Module"
* USB CDC On Boot:"Enable"
* USB DFU On Boot:"Disable"
* Flash Size : "16MB(128Mb)"
* Flash Mode"QIO 80MHz
* Partition Scheme:"16M Flash(3M APP/9.9MB FATFS)"
* PSRAM:"OPI PSRAM"
* Upload Mode:"UART0/Hardware CDC"
* USB Mode:"Hardware CDC and JTAG"
* CPU Frequency: "240MHz (WiFi)"
* Core Debug Level: "Verbose"
* USB DFU On Boot: "Disabled"
* Erase All Flash Before Sketch Upload: "Disabled"
* Events Run On: "Core 1"
* Flash Mode: "QI0 80MHz"
* Flash Size: "16MB (128Mb)"
* JTAG Adapter: "Disabled"
* Arduino Runs On: "Core 1"
* USB Firmware MSC On Boot: "Disabled"
* Partition Scheme: "16M Flash (3MB APP/9.9MB FATFS)"
* PSRAM: "OPI PSRAM"
* Upload Mode: "UART0/Hardware CDC"
* Upload Speed: "921600"
* USB Mode: "Hardware CDC and JTAG"
* Programmer: "Esptool"
*/


//! Two transceivers, SX1262 and SX1280, are defined based on the actual model
// #define USE_RADIO_SX1280
#define USE_RADIO_SX1262
Expand Down Expand Up @@ -49,14 +59,14 @@ IRsend irsend(BOARD_IR_PIN);
#include <AudioGeneratorMP3.h>
#include <AudioGeneratorWAV.h>
#include <AudioOutputI2S.h>
#include <AudioFileSourceSPIFFS.h>
#include <AudioFileSourceFATFS.h>

AudioGeneratorMP3 *mp3;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;
AudioFileSourceID3 *id3;
AudioGeneratorWAV *wav;
AudioFileSourceSPIFFS *file_fs;
AudioFileSourceFATFS *file_fs;

extern const uint8_t boot_music[4365];
#endif
Expand Down Expand Up @@ -452,7 +462,13 @@ static void charge_anim_cb(void *obj, int32_t v)
if (last_check_inteval < millis()) {
battery_percent = watch.getBatteryPercent();
lv_obj_t *label_percent = (lv_obj_t *)lv_obj_get_user_data(arc);
lv_label_set_text_fmt(label_percent, "%d%%", battery_percent);
if (battery_percent != - 1) {
lv_label_set_text_fmt(label_percent, "%d%%", battery_percent);
} else {
lv_label_set_long_mode(label_percent,LV_LABEL_LONG_WRAP);
lv_obj_set_width(label_percent,lv_pct(90));
lv_label_set_text(label_percent, "Please turn the battery switch to ON");
}
if (battery_percent == 100) {
lv_obj_t *img = (lv_obj_t *)lv_obj_get_user_data(label_percent);
lv_anim_del(arc, charge_anim_cb);
Expand Down Expand Up @@ -2533,7 +2549,7 @@ void settingPlayer()
mp3 = new AudioGeneratorMP3();
mp3->begin(id3, out);

file_fs = new AudioFileSourceSPIFFS();
file_fs = new AudioFileSourceFATFS();
wav = new AudioGeneratorWAV();
player_task_cb = playMP3;

Expand Down Expand Up @@ -2574,7 +2590,7 @@ static bool CreateWAV(const char *song_name, uint32_t duration, uint16_t num_cha
// data size in bytes - > this amount of data should be recorded from microphone later
uint32_t data_size = sampling_rate * num_channels * bits_per_sample * duration / 8;

File new_audio_file = SPIFFS.open(song_name, FILE_WRITE);
File new_audio_file = FFat.open(song_name, FILE_WRITE);
if (!new_audio_file) {
Serial.println("Failed to create file");
return false;
Expand Down Expand Up @@ -2677,7 +2693,7 @@ static void PDM_Record(const char *song_name, uint32_t duration)
}

// Open created .wav file in append+binary mode to add PCM data
File audio_file = SPIFFS.open(song_name, FILE_APPEND);
File audio_file = FFat.open(song_name, FILE_APPEND);
if (!audio_file) {
Serial.println("Failed to create file");
return;
Expand Down Expand Up @@ -2716,7 +2732,7 @@ static void PDM_Record(const char *song_name, uint32_t duration)
Serial.println("Bytes written error");
}

// Save data to SPIFFS
// Save data to FFat
audio_file.write( buf, BUFFER_SIZE);

// Increment the counter
Expand Down
6 changes: 3 additions & 3 deletions examples/lvgl/third_party/ImageDecoder/ImageDecoder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
* @copyright Copyright (c) 2023 Shenzhen Xinyuan Electronic Technology Co., Ltd
* @date 2023-05-01
* @Note You need to upload the files from the data file to the SPIFFS
* @Note You need to upload the files from the data file to the FFat
* file system before using this example
* @note platfromio user use <pio run -t uploadfs> ,
* * Note that you need to place the sample data folder in the same level directory as <platformio. ini>
Expand All @@ -31,9 +31,9 @@ void setup(void)
beginLvglHelper();

String file = String("/") + filename[0];
if (!SPIFFS.exists(file)) {
if (!FFat.exists(file)) {
while (1) {
Serial.println("You need to upload the files from the data file to the SPIFFS file system before using this example");
Serial.println("You need to upload the files from the data file to the FFat file system before using this example");
delay(1000);
}
}
Expand Down
10 changes: 5 additions & 5 deletions examples/peripheral/PDM_Recording/PDM_Recording.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include <LV_Helper.h>

#include <AudioOutputI2S.h>
#include <AudioFileSourceSPIFFS.h>
#include <AudioFileSourceFATFS.h>
#include "AudioGeneratorWAV.h"
#include "AudioFileSourceFunction.h"


AudioGeneratorWAV *wav;
AudioFileSourceSPIFFS *file;
AudioFileSourceFATFS *file;
AudioOutputI2S *out;

void microphone_record(const char *song_name, uint32_t duration);
Expand All @@ -43,7 +43,7 @@ void setup(void)

out = new AudioOutputI2S(1, AudioOutputI2S::EXTERNAL_I2S);
out->SetPinout(BOARD_DAC_IIS_BCK, BOARD_DAC_IIS_WS, BOARD_DAC_IIS_DOUT);
file = new AudioFileSourceSPIFFS("/rec.wav");
file = new AudioFileSourceFATFS("/rec.wav");
wav = new AudioGeneratorWAV();
wav->begin(file, out);

Expand Down Expand Up @@ -73,7 +73,7 @@ bool create_wav_file(const char *song_name, uint32_t duration, uint16_t num_chan
// data size in bytes - > this amount of data should be recorded from microphone later
uint32_t data_size = sampling_rate * num_channels * bits_per_sample * duration / 8;

File new_audio_file = SPIFFS.open(song_name, FILE_WRITE);
File new_audio_file = FFat.open(song_name, FILE_WRITE);
if (new_audio_file == NULL) {
Serial.println("Failed to create file");
return false;
Expand Down Expand Up @@ -148,7 +148,7 @@ void microphone_record(const char *song_name, uint32_t duration)
}

// Open created .wav file in append+binary mode to add PCM data
File audio_file = SPIFFS.open(song_name, FILE_APPEND);
File audio_file = FFat.open(song_name, FILE_APPEND);
if (!audio_file) {
Serial.println("Failed to create file");
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file PlayMusicFromSPIFFS.ino
* @file PlayMusicFromFATFS.ino
* @author Lewis He (lewishe@outlook.com)
* @license MIT
* @copyright Copyright (c) 2023 Shenzhen Xinyuan Electronic Technology Co., Ltd
Expand All @@ -9,7 +9,7 @@
#include <LilyGoLib.h>
#include <LV_Helper.h>
#include <AudioOutputI2S.h>
#include <AudioFileSourceSPIFFS.h>
#include <AudioFileSourceFATFS.h>
#include <AudioGeneratorWAV.h>
#include <AudioFileSourceFunction.h>
#include <AudioGeneratorFLAC.h>
Expand All @@ -23,7 +23,7 @@
const uint8_t i2sPort = 1;

AudioGeneratorWAV *wav = NULL;
AudioFileSourceSPIFFS *file = NULL;
AudioFileSourceFATFS *file = NULL;
AudioOutputI2S *out = NULL;
AudioGeneratorMP3 *mp3 = NULL;
AudioFileSourceID3 *id3 = NULL;
Expand Down Expand Up @@ -157,7 +157,7 @@ void setup(void)
Serial.begin(115200);

// When initializing the watch,
// SPIFFS has already been initialized internally
// FFat has already been initialized internally
watch.begin();

beginLvglHelper();
Expand All @@ -172,7 +172,7 @@ void setup(void)
lv_obj_t *label;

label = lv_label_create(cont);
lv_label_set_text(label, "PlayMusicFromSPIFFS");
lv_label_set_text(label, "PlayMusicFromFFat");

//Play wav Button
lv_obj_t *btn1 = lv_btn_create(cont);
Expand Down Expand Up @@ -210,7 +210,7 @@ void setup(void)
lv_label_set_text(label, "Play AAC");
lv_obj_center(label);

file = new AudioFileSourceSPIFFS();
file = new AudioFileSourceFATFS();

// Set up the use of an external decoder
out = new AudioOutputI2S(i2sPort, AudioOutputI2S::EXTERNAL_I2S);
Expand Down
6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
; src_dir = examples/peripheral/PMU_ADC
; src_dir = examples/peripheral/PMU_Interrupt
; src_dir = examples/peripheral/PlayMusicFromPROGMEM
; src_dir = examples/peripheral/PlayMusicFromSPIFFS
; src_dir = examples/peripheral/PlayMusicFromFATFS
; src_dir = examples/peripheral/GPSFullExample
; src_dir = examples/peripheral/GPSFactory

Expand Down Expand Up @@ -153,8 +153,8 @@ boards_dir = ./board/LilyGoWatch-S3
lib_extra_dirs = .
upload_speed = 921600
monitor_speed = 115200
board_build.filesystem = spiffs
board_build.partitions = default_16MB.csv
board_build.filesystem = fatfs
board_build.partitions = app3M_fat9M_16MB.csv

[env:twatch-s3]
platform = espressif32@6.3.0
Expand Down
8 changes: 4 additions & 4 deletions src/LilyGoLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ bool LilyGoLib::begin(Stream *stream)
setTextFont(2);
fillScreen(TFT_BLACK);

log_println("Init SPIFFS");
if (!SPIFFS.begin()) {
log_println("Init FFat");
if (!FFat.begin()) {

if (bootDisplay) {
setBrightness(50);
drawString("Format SPIFFS...", 120, 120);
drawString("Format FFat...", 120, 120);
}
SPIFFS.format();
FFat.format();
}

if (bootDisplay) {
Expand Down
2 changes: 1 addition & 1 deletion src/LilyGoLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#error "Please manually update and install Arduino Core ESP32 to the latest version, how to update, please see here https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#windows-manual-installation"
#endif

#include <SPIFFS.h>
#include <FFat.h>
#include <FS.h>
#include <Wire.h>
#include <TFT_eSPI.h>
Expand Down
2 changes: 1 addition & 1 deletion src/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ e.g. "stm32f7xx.h" or "stm32f4xx.h"*/
#define LV_USE_FS_POSIX 1
#if LV_USE_FS_POSIX
#define LV_FS_POSIX_LETTER 'A' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_POSIX_PATH "/spiffs" /*Set the working directory. File/directory paths will be appended to it.*/
#define LV_FS_POSIX_PATH "/ffat" /*Set the working directory. File/directory paths will be appended to it.*/
#define LV_FS_POSIX_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
#endif

Expand Down

0 comments on commit 157ea89

Please sign in to comment.