Bläddra i källkod

Detect the core and IDF revision during compile time.

lorol 4 år sedan
förälder
incheckning
173cb863f1

+ 12 - 9
README.md

@@ -1,6 +1,6 @@
 # LittleFS_esp32
 
-### ***Notice: The Library is been integrated to [Arduino esp32 core idf-release/v4.2 branch](https://github.com/espressif/arduino-esp32/tree/idf-release/v4.2 ) for future major core release.***
+#### ***Notice: The Library is been integrated to [Arduino esp32 core idf-release/v4.2 branch](https://github.com/espressif/arduino-esp32/tree/idf-release/v4.2 ) for future major core release. On built-in library, #define tweaks below will be unavailable.***
 
 
 ## LittleFS library for arduino-esp32
@@ -8,8 +8,8 @@
 - A LittleFS wrapper for Arduino ESP32 of [littlefs-project](https://github.com/littlefs-project/littlefs)
 - Based on [ESP-IDF port of joltwallet/esp_littlefs](https://github.com/joltwallet/esp_littlefs) , thank you Brian!
 - As a reference, see [LillteFS library for ESP8266 core](https://github.com/esp8266/Arduino/tree/master/libraries/LittleFS)
-- [PR at esp32 core development](https://github.com/espressif/arduino-esp32/pull/4096) 
-- [PR at esp-idf development](https://github.com/espressif/esp-idf/pull/5469)
+- [PR](https://github.com/espressif/arduino-esp32/pull/4096) and [merge](https://github.com/espressif/arduino-esp32/pull/4483) at esp32 core development
+- [PR](https://github.com/espressif/esp-idf/pull/5469) at esp-idf development
 - The functionality is similar to SPIFFS
 
 ### Installation
@@ -18,13 +18,14 @@
 - Or download / use **git** to have latest repository of **LITTLEFS** added to Arduino IDE **/libraries** folder  
 (File > Preferences > Sketchbook location).
 - See ``` #define CONFIG_LITTLEFS_FOR_IDF_3_2 ``` in **esp_littlefs.c**.  
-When defined, code builds with any IDF 3.2 - 4.x.  
-On IDF newer than 3.2, it **can** be commented to enable file timestamp feature.
+Now it is defined / undefined automatically by detecting the IDF version and core version.
+When defined, the library works with old and new IDFs 3.2 - 4.x but file timestamp feature is removed.
 See LITTLEFS_time example.
 - See ``` #define CONFIG_LITTLEFS_SPIFFS_COMPAT ``` in **esp_littlefs.c**.  
 When set to 1, folders are recursively created or deleted if empty on creating/deleting a new file like SPIFFS. Default is 0.
 - The other ``` #define CONFIG_LITTLEFS_xxxxx ``` are set to optimal default values.  
-Read [here](https://github.com/joltwallet/esp_littlefs/blob/master/Kconfig) and [here](https://github.com/ARMmbed/littlefs/blob/master/README.md) if you want to modify.
+Read [here](https://github.com/joltwallet/esp_littlefs/blob/master/Kconfig) and [here](https://github.com/littlefs-project//littlefs/blob/master/README.md) if you want to modify.
+- For low-level default error reporting modifications, see the defines at beginning of the **lfs.c** here.
 
 ### Usage
 
@@ -42,16 +43,17 @@ Read [here](https://github.com/joltwallet/esp_littlefs/blob/master/Kconfig) and
 #endif 
  ```
  - Note, this may not work if your sketch uses other libraries that use SPIFFS themselves.
- - See also [esp_partition.h](https://github.com/espressif/esp-idf/blob/master/components/spi_flash/include/esp_partition.h) . LITTLEFS re-uses same type and subtype.
+ - See also [esp_partition.h](https://github.com/espressif/esp-idf/blob/master/components/spi_flash/include/esp_partition.h) . LITTLEFS re-uses same type and subtype as SPIFFS
 
 ### Differences with SPIFFS 
 
-- LittleFS has folders, you need to iterate files in folders or set  ``` #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1 ```  
+- LittleFS has folders, you need to iterate files in folders unless you set  ``` #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1 ```  
 - At root a "/folder" = "folder"
 - Requires a label for mount point, NULL will not work. Recommended is to use default LITTLEFS.begin()
 - maxOpenFiles parameter is unused, kept for compatibility
 - LITTLEFS.mkdir(path) and LITTLEFS.rmdir(path) are available
 - file.seek() behaves like on FFat see [more details](https://github.com/lorol/LITTLEFS/issues/11)
+- file.write() and file.print() when partition space is ending may return different than really written bytes (on other FS is also inconsistent).
 - Speed comparison based on **LittleFS_test.ino** sketch (for a file 1048576 bytes):
 
 |Filesystem|Read time [ms]|Write time [ms]|
@@ -98,4 +100,5 @@ Read [here](https://github.com/joltwallet/esp_littlefs/blob/master/Kconfig) and
     - [recursive folders auto creation](https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60) when a new file is created at non-existing path
     - [recursive folders auto deletion](https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149) on "last file" deletion (SPIFFS cannot have "folder w/o file")
     - review other differences: opendir(), rmdir(), unlink()
-  - [x] Follow-up / retire this library if LittleFS gets implemented through IDF / esp32 Arduino core.
+  - [ ] Retire this library when released by esp32 Arduino core
+  - [ ] Cleanup examples 

+ 1 - 3
examples/LITTLEFS_PlatformIO/src/main.cpp

@@ -144,9 +144,8 @@ void deleteFile(fs::FS &fs, const char * path){
     }
 }
 
-// SPIFFS-like write and delete file
+// SPIFFS-like write and delete file, better use #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1
 
-// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60
 void writeFile2(fs::FS &fs, const char * path, const char * message){
     if(!fs.exists(path)){
 		if (strchr(path, '/')) {
@@ -179,7 +178,6 @@ void writeFile2(fs::FS &fs, const char * path, const char * message){
     file.close();
 }
 
-// See:  https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149
 void deleteFile2(fs::FS &fs, const char * path){
     Serial.printf("Deleting file and empty folders on path: %s\r\n", path);
 

+ 1 - 3
examples/LittleFS_test/LittleFS_test.ino

@@ -123,9 +123,8 @@ void deleteFile(fs::FS &fs, const char * path){
     }
 }
 
-// SPIFFS-like write and delete file
+// SPIFFS-like write and delete file, better use #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1
 
-// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60
 void writeFile2(fs::FS &fs, const char * path, const char * message){
     if(!fs.exists(path)){
 		if (strchr(path, '/')) {
@@ -158,7 +157,6 @@ void writeFile2(fs::FS &fs, const char * path, const char * message){
     file.close();
 }
 
-// See:  https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149
 void deleteFile2(fs::FS &fs, const char * path){
     Serial.printf("Deleting file and empty folders on path: %s\r\n", path);
 

+ 2 - 2
library.properties

@@ -2,8 +2,8 @@ name=LittleFS_esp32
 version=1.0.5
 author=lorol
 maintainer=lorol
-sentence=LittleFS for esp32 based on esp_littlefs IDF component. Use esp32 core-provided LITTLEFS library instead this one (when it gets available)
-paragraph=. See littlefs.c #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1 and #define CONFIG_LITTLEFS_FOR_IDF_3_2 to adjust for best SPIFFS and for older core releases compatibility.
+sentence=LittleFS for esp32 based on esp_littlefs IDF component. Use esp32 core-provided LITTLEFS library instead of this one when available in future core releases.
+paragraph= For esp32 core 1.0.4 release, use #define CONFIG_LITTLEFS_FOR_IDF_3_2 and for more SPIFFS compatibility, set #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1
 category=Data Storage
 url=https://github.com/lorol/LITTLEFS
 architectures=esp32

+ 7 - 0
src/LICENSE

@@ -0,0 +1,7 @@
+Copyright 2020 Brian Pugh
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 24 - 0
src/LICENSE.md

@@ -0,0 +1,24 @@
+Copyright (c) 2017, Arm Limited. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+-  Redistributions of source code must retain the above copyright notice, this
+   list of conditions and the following disclaimer.
+-  Redistributions in binary form must reproduce the above copyright notice, this
+   list of conditions and the following disclaimer in the documentation and/or
+   other materials provided with the distribution.
+-  Neither the name of ARM nor the names of its contributors may be used to
+   endorse or promote products derived from this software without specific prior
+   written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 24 - 3
src/esp_littlefs.c

@@ -12,7 +12,26 @@
  */
 
 //#define LOG_LOCAL_LEVEL 5
-//#define CONFIG_LITTLEFS_FOR_IDF_3_2      /* For old IDF 3.2 compatibility, core release 1.0.4 - no timestamps */
+
+#if __has_include("esp_arduino_version.h")
+#include "esp_arduino_version.h"
+#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
+#warning("Use the built-in LITTLEFS library")
+#endif
+#else
+//#warning("LITTLEFS: no esp_arduino_version.h file, likely 1.0.x")
+#endif
+
+#if __has_include("esp_idf_version.h")
+#include "esp_idf_version.h"
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(3, 3, 0)
+//#warning("IDF is 3.3 or later, LittleFS file timestamps are enabled")
+#endif
+#else
+#define CONFIG_LITTLEFS_FOR_IDF_3_2      /* For old IDF 3.2 compatibility, core release 1.0.4 - no timestamps */
+//#warning("IDF < 3.3, no LittleFS file timestamps")
+#endif
+
 //#define CONFIG_LITTLEFS_USE_ONLY_HASH
 #define CONFIG_LITTLEFS_HUMAN_READABLE 0   /* Use 1 for verbose errors */
 #define CONFIG_LITTLEFS_SPIFFS_COMPAT 0    /* Use 1 for better drop-in replacement of SPIFFS */
@@ -44,9 +63,11 @@
 #include <sys/lock.h>
 #include <sys/param.h>
 
-#if __has_include("esp32/rom/spi_flash.h") 
+#if __has_include("esp32/rom/spi_flash.h")
+//#warning("LITTLEFS: IDF 4, spi_flash.h file location different from IDF 3")
 #include "esp32/rom/spi_flash.h"
-#else 
+#else
+//#warning("LITTLEFS: IDF 3")
 #include "rom/spi_flash.h"
 #endif
 

+ 6 - 1
src/lfs.c

@@ -3,7 +3,12 @@
  *
  * Copyright (c) 2017, Arm Limited. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * @note Modified and used by lorol for Arduino esp32 core tests
  */
+
+//#define LFS_NO_ERROR   /* Change default error reporting level: LFS_NO_DEBUG, LFS_NO_WARN,  LFS_NO_ERROR,  LFS_YES_TRACE */
+
 #include "lfs.h"
 #include "lfs_util.h"
 
@@ -459,7 +464,7 @@ static void lfs_alloc_ack(lfs_t *lfs) {
 // Invalidate the lookahead buffer. This is done during mounting and
 // failed traversals
 static void lfs_alloc_reset(lfs_t *lfs) {
-    lfs->free.off = lfs->seed % lfs->cfg->block_size;
+    lfs->free.off = lfs->seed % lfs->cfg->block_count; //lfs->free.off = lfs->seed % lfs->cfg->block_size;
     lfs->free.size = 0;
     lfs->free.i = 0;
     lfs_alloc_ack(lfs);