Skip to content

Commit 09e7e3f

Browse files
committed
Merge branch 'esp8266' of https://github.com/ficeto/Arduino into ficeto-esp8266
2 parents 0d376cb + bf427f1 commit 09e7e3f

28 files changed

+7299
-60
lines changed

arduino-core/src/processing/app/debug/Compiler.java

+7
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ private PreferencesMap createBuildPreferences(String _buildPath,
460460
p.put("build.path", _buildPath);
461461
p.put("build.project_name", _primaryClassName);
462462
p.put("build.arch", targetPlatform.getId().toUpperCase());
463+
File sketch_data = sketch.getDataFolder();
464+
if(sketch_data.exists()){
465+
p.put("build.sketch_data", sketch_data.getAbsolutePath());
466+
} else {
467+
p.put("build.sketch_data", "");
468+
}
469+
463470

464471
// Platform.txt should define its own compiler.path. For
465472
// compatibility with earlier 1.5 versions, we define a (ugly,

hardware/esp8266com/esp8266/cores/esp8266/Arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern "C" {
3838
#include "pgmspace.h"
3939
#include "esp8266_peri.h"
4040
#include "twi.h"
41+
#include "spiffs/spiffs.h"
4142

4243
void yield(void);
4344

@@ -211,6 +212,7 @@ void loop(void);
211212
#include "WString.h"
212213

213214
#include "HardwareSerial.h"
215+
#include "FileSystem.h"
214216
#include "Esp.h"
215217

216218
uint16_t makeWord(uint16_t w);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/****
2+
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3+
* Created 2015 by Skurydin Alexey
4+
* http://github.com/anakod/Sming
5+
* All files of the Sming Core are provided under the LGPL v3 license.
6+
****/
7+
8+
#include "FileSystem.h"
9+
#include "WString.h"
10+
11+
file_t fileOpen(const String name, FileOpenFlags flags)
12+
{
13+
int repeats = 0;
14+
bool notExist;
15+
bool canRecreate = (flags & eFO_CreateIfNotExist) == eFO_CreateIfNotExist;
16+
int res;
17+
18+
do
19+
{
20+
notExist = false;
21+
res = SPIFFS_open(&_filesystemStorageHandle, name.c_str(), (spiffs_flags)flags, 0);
22+
int code = SPIFFS_errno(&_filesystemStorageHandle);
23+
if (res < 0)
24+
{
25+
debugf("open errno %d\n", code);
26+
notExist = (code == SPIFFS_ERR_NOT_FOUND || code == SPIFFS_ERR_DELETED || code == SPIFFS_ERR_FILE_DELETED || code == SPIFFS_ERR_IS_FREE);
27+
//debugf("recreate? %d %d %d", notExist, canRecreate, (repeats < 3));
28+
if (notExist && canRecreate)
29+
fileDelete(name); // fix for deleted files
30+
}
31+
} while (notExist && canRecreate && repeats++ < 3);
32+
33+
return res;
34+
}
35+
36+
void fileClose(file_t file)
37+
{
38+
SPIFFS_close(&_filesystemStorageHandle, file);
39+
}
40+
41+
size_t fileWrite(file_t file, const void* data, size_t size)
42+
{
43+
int res = SPIFFS_write(&_filesystemStorageHandle, file, (void *)data, size);
44+
if (res < 0)
45+
{
46+
debugf("write errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
47+
return res;
48+
}
49+
return res;
50+
}
51+
52+
size_t fileRead(file_t file, void* data, size_t size)
53+
{
54+
int res = SPIFFS_read(&_filesystemStorageHandle, file, data, size);
55+
if (res < 0)
56+
{
57+
debugf("read errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
58+
return res;
59+
}
60+
return res;
61+
}
62+
63+
int fileSeek(file_t file, int offset, SeekOriginFlags origin)
64+
{
65+
return SPIFFS_lseek(&_filesystemStorageHandle, file, offset, origin);
66+
}
67+
68+
bool fileIsEOF(file_t file)
69+
{
70+
return SPIFFS_eof(&_filesystemStorageHandle, file);
71+
}
72+
73+
int32_t fileTell(file_t file)
74+
{
75+
return SPIFFS_tell(&_filesystemStorageHandle, file);
76+
}
77+
78+
int fileFlush(file_t file)
79+
{
80+
return SPIFFS_fflush(&_filesystemStorageHandle, file);
81+
}
82+
83+
int fileStats(const String name, spiffs_stat *stat)
84+
{
85+
return SPIFFS_stat(&_filesystemStorageHandle, name.c_str(), stat);
86+
}
87+
88+
int fileStats(file_t file, spiffs_stat *stat)
89+
{
90+
return SPIFFS_fstat(&_filesystemStorageHandle, file, stat);
91+
}
92+
93+
void fileDelete(const String name)
94+
{
95+
SPIFFS_remove(&_filesystemStorageHandle, name.c_str());
96+
}
97+
98+
void fileDelete(file_t file)
99+
{
100+
SPIFFS_fremove(&_filesystemStorageHandle, file);
101+
}
102+
103+
bool fileExist(const String name)
104+
{
105+
spiffs_stat stat = {0};
106+
if (fileStats(name.c_str(), &stat) < 0) return false;
107+
return stat.name[0] != '\0';
108+
}
109+
110+
111+
int fileLastError(file_t fd)
112+
{
113+
return SPIFFS_errno(&_filesystemStorageHandle);
114+
}
115+
116+
void fileClearLastError(file_t fd)
117+
{
118+
_filesystemStorageHandle.errno = SPIFFS_OK;
119+
}
120+
121+
void fileSetContent(const String fileName, const char *content)
122+
{
123+
file_t file = fileOpen(fileName.c_str(), eFO_CreateNewAlways | eFO_WriteOnly);
124+
fileWrite(file, content, os_strlen(content));
125+
fileClose(file);
126+
}
127+
128+
uint32_t fileGetSize(const String fileName)
129+
{
130+
file_t file = fileOpen(fileName.c_str(), eFO_ReadOnly);
131+
// Get size
132+
fileSeek(file, 0, eSO_FileEnd);
133+
int size = fileTell(file);
134+
fileClose(file);
135+
return size;
136+
}
137+
138+
String fileGetContent(const String fileName)
139+
{
140+
file_t file = fileOpen(fileName.c_str(), eFO_ReadOnly);
141+
// Get size
142+
fileSeek(file, 0, eSO_FileEnd);
143+
int size = fileTell(file);
144+
if (size <= 0)
145+
{
146+
fileClose(file);
147+
return "";
148+
}
149+
fileSeek(file, 0, eSO_FileStart);
150+
char* buffer = new char[size + 1];
151+
buffer[size] = 0;
152+
fileRead(file, buffer, size);
153+
fileClose(file);
154+
String res = buffer;
155+
delete[] buffer;
156+
return res;
157+
}
158+
159+
int fileGetContent(const String fileName, char* buffer, int bufSize)
160+
{
161+
if (buffer == NULL || bufSize == 0) return 0;
162+
*buffer = 0;
163+
164+
file_t file = fileOpen(fileName.c_str(), eFO_ReadOnly);
165+
// Get size
166+
fileSeek(file, 0, eSO_FileEnd);
167+
int size = fileTell(file);
168+
if (size <= 0 || bufSize <= size)
169+
{
170+
fileClose(file);
171+
return 0;
172+
}
173+
buffer[size] = 0;
174+
fileSeek(file, 0, eSO_FileStart);
175+
fileRead(file, buffer, size);
176+
fileClose(file);
177+
return size;
178+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/****
2+
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3+
* Created 2015 by Skurydin Alexey
4+
* http://github.com/anakod/Sming
5+
* All files of the Sming Core are provided under the LGPL v3 license.
6+
****/
7+
8+
#ifndef _SMING_CORE_FILESYSTEM_H_
9+
#define _SMING_CORE_FILESYSTEM_H_
10+
11+
#include "spiffs/spiffs.h"
12+
class String;
13+
14+
enum FileOpenFlags
15+
{
16+
eFO_ReadOnly = SPIFFS_RDONLY,
17+
eFO_WriteOnly = SPIFFS_WRONLY,
18+
eFO_ReadWrite = eFO_ReadOnly | eFO_WriteOnly,
19+
eFO_CreateIfNotExist = SPIFFS_CREAT,
20+
eFO_Append = SPIFFS_APPEND,
21+
eFO_Truncate = SPIFFS_TRUNC,
22+
eFO_CreateNewAlways = eFO_CreateIfNotExist | eFO_Truncate
23+
};
24+
25+
static FileOpenFlags operator|(FileOpenFlags lhs, FileOpenFlags rhs)
26+
{
27+
return (FileOpenFlags) ((int)lhs| (int)rhs);
28+
}
29+
30+
typedef enum
31+
{
32+
eSO_FileStart = SPIFFS_SEEK_SET,
33+
eSO_CurrentPos = SPIFFS_SEEK_CUR,
34+
eSO_FileEnd = SPIFFS_SEEK_END
35+
} SeekOriginFlags;
36+
37+
file_t fileOpen(const String name, FileOpenFlags flags);
38+
void fileClose(file_t file);
39+
size_t fileWrite(file_t file, const void* data, size_t size);
40+
size_t fileRead(file_t file, void* data, size_t size);
41+
int fileSeek(file_t file, int offset, SeekOriginFlags origin);
42+
bool fileIsEOF(file_t file);
43+
int32_t fileTell(file_t file);
44+
int fileFlush(file_t file);
45+
int fileLastError(file_t fd);
46+
void fileClearLastError(file_t fd);
47+
void fileSetContent(const String fileName, const char *content);
48+
uint32_t fileGetSize(const String fileName);
49+
String fileGetContent(const String fileName);
50+
int fileGetContent(const String fileName, char* buffer, int bufSize);
51+
52+
53+
int fileStats(const String name, spiffs_stat *stat);
54+
int fileStats(file_t file, spiffs_stat *stat);
55+
void fileDelete(const String name);
56+
void fileDelete(file_t file);
57+
bool fileExist(const String name);
58+
59+
#endif /* _SMING_CORE_FILESYSTEM_H_ */

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring.c

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void delayMicroseconds(unsigned int us) {
7676
void init() {
7777
initPins();
7878
timer1_isr_init();
79+
//spiffs_mount();
7980
os_timer_setfn(&micros_overflow_timer, (os_timer_func_t*) &micros_overflow_tick, 0);
8081
os_timer_arm(&micros_overflow_timer, 60000, REPEAT);
8182
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013-2015 Peter Andersson (pelleplutt1976<at>gmail.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
#############################################################
3+
# Required variables for each makefile
4+
# Discard this section from all parent makefiles
5+
# Expected variables (with automatic defaults):
6+
# CSRCS (all "C" files in the dir)
7+
# SUBDIRS (all subdirs with a Makefile)
8+
# GEN_LIBS - list of libs to be generated ()
9+
# GEN_IMAGES - list of images to be generated ()
10+
# COMPONENTS_xxx - a list of libs/objs in the form
11+
# subdir/lib to be extracted and rolled up into
12+
# a generated lib/image xxx.a ()
13+
#
14+
ifndef PDIR
15+
GEN_LIBS = spiffs.a
16+
endif
17+
18+
#############################################################
19+
# Configuration i.e. compile options etc.
20+
# Target specific stuff (defines etc.) goes in here!
21+
# Generally values applying to a tree are captured in the
22+
# makefile at its root level - these are then overridden
23+
# for a subtree within the makefile rooted therein
24+
#
25+
#DEFINES +=
26+
27+
#############################################################
28+
# Recursion Magic - Don't touch this!!
29+
#
30+
# Each subtree potentially has an include directory
31+
# corresponding to the common APIs applicable to modules
32+
# rooted at that subtree. Accordingly, the INCLUDE PATH
33+
# of a module can only contain the include directories up
34+
# its parent path, and not its siblings
35+
#
36+
# Required for each makefile to inherit from the parent
37+
#
38+
39+
INCLUDES := $(INCLUDES) -I $(PDIR)include
40+
INCLUDES += -I ./
41+
INCLUDES += -I ../libc
42+
INCLUDES += -I ../platform
43+
PDIR := ../$(PDIR)
44+
sinclude $(PDIR)Makefile

hardware/esp8266com/esp8266/cores/esp8266/spiffs/docs/IMPLEMENTING

Whitespace-only changes.

0 commit comments

Comments
 (0)