10000 Thu Dec 8 19:58:11 CST 2016 · programmer131/esp32-snippets@2322f80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2322f80

Browse files
author
kolban
committed
Thu Dec 8 19:58:11 CST 2016
1 parent 9ce7bdd commit 2322f80

File tree

7 files changed

+278
-1
lines changed

7 files changed

+278
-1
lines changed

.cproject

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
<folderInfo id="0.1585648564." name="/" resourcePath="">
1919
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.858258150" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
2020
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.858258150.1918542150" name=""/>
21-
<builder id="org.eclipse.cdt.build.core.settings.default.builder.473998174" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
21+
<builder id="org.eclipse.cdt.build.core.settings.default.builder.473998174" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder">
22+
<outputEntries>
23+
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name=""/>
24+
</outputEntries>
25+
</builder>
2226
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.354998465" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
2327
<tool id="org.eclipse.cdt.build.core.settings.holder.360963571" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
2428
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.916191028" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
2529
<listOptionValue builtIn="false" value="/opt/xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/4.8.5/include"/>
2630
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/vfs/include&quot;"/>
31+
<listOptionValue builtIn="false" value="/opt/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/4.8.5"/>
32+
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/spi_flash/include&quot;"/>
2733
</option>
2834
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1400544808" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
2935
</tool>
@@ -41,6 +47,7 @@
4147
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/myapp/build/include}&quot;"/>
4248
<listOptionValue builtIn="false" value="/opt/xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/4.8.5/include"/>
4349
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/vfs/include&quot;"/>
50+
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/spi_flash/include&quot;"/>
4451
</option>
4552
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1608399615" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
4653
</tool>
@@ -55,7 +62,9 @@
5562
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/tcpip_adapter/include&quot;"/>
5663
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/lwip/include/lwip&quot;"/>
5764
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/vfs/include&quot;"/>
65+
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/spi_flash/include&quot;"/>
5866
<listOptionValue builtIn="false" value="/opt/xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/4.8.5/include"/>
67+
<listOptionValue builtIn="false" value="/opt/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/4.8.5"/>
5968
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/myapp/build/include}&quot;"/>
6069
</option>
6170
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.30884209" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>

mongoose/webserver/main/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ char *mongoose_eventToString(int ev) {
4646
return "MG_EV_RECV";
4747
case MG_EV_HTTP_REQUEST:
4848
return "MG_EV_HTTP_REQUEST";
49+
case MG_EV_HTTP_REPLY:
50+
return "MG_EV_HTTP_REPLY";
4951
case MG_EV_MQTT_CONNACK:
5052
return "MG_EV_MQTT_CONNACK";
5153
case MG_EV_MQTT_CONNACK_ACCEPTED:
Lines changed: 56 additions & 0 deletions
26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <esp_partition.h>
2+
3+
const char *partitionSubtypeToString(esp_partition_subtype_t subtype) {
4+
switch(subtype) {
5+
case ESP_PARTITION_SUBTYPE_APP_FACTORY:
6+
return "APP_FACTORY";
7+
case ESP_PARTITION_SUBTYPE_APP_OTA_0:
8+
return "APP_OTA_0";
9+
case ESP_PARTITION_SUBTYPE_APP_OTA_1:
10+
return "APP_OTA_1";
11+
case ESP_PARTITION_SUBTYPE_APP_OTA_10:
12+
return "APP_OTA_10";
13+
case ESP_PARTITION_SUBTYPE_APP_OTA_11:
14+
return "APP_OTA_11";
15+
case ESP_PARTITION_SUBTYPE_APP_OTA_12:
16+
return "APP_OTA_12";
17+
case ESP_PARTITION_SUBTYPE_APP_OTA_13:
18+
return "APP_OTA_13";
19+
case ESP_PARTITION_SUBTYPE_APP_OTA_14:
20+
return "APP_OTA_14";
21+
case ESP_PARTITION_SUBTYPE_APP_OTA_15:
22+
return "APP_OTA_15";
23+
case ESP_PARTITION_SUBTYPE_APP_OTA_2:
24+
return "APP_OTA_2";
25+
case ESP_PARTITION_SUBTYPE_APP_OTA_3:
+
return "APP_OTA_3";
27+
case ESP_PARTITION_SUBTYPE_APP_OTA_4:
28+
return "APP_OTA_4";
29+
case ESP_PARTITION_SUBTYPE_APP_OTA_5:
30+
return "APP_OTA_5";
31+
case ESP_PARTITION_SUBTYPE_APP_OTA_6:
32+
return "APP_OTA_6";
33+
case ESP_PARTITION_SUBTYPE_APP_OTA_7:
34+
return "APP_OTA_7";
35+
case ESP_PARTITION_SUBTYPE_APP_OTA_8:
36+
return "APP_OTA_8";
37+
case ESP_PARTITION_SUBTYPE_APP_OTA_9:
38+
return "APP_OTA_9";
39+
case ESP_PARTITION_SUBTYPE_APP_TEST:
40+
return "APP_TEST";
41+
case ESP_PARTITION_SUBTYPE_DATA_ESPHTTPD:
42+
return "DATA_ESPHTTPD";
43+
case ESP_PARTITION_SUBTYPE_DATA_FAT:
44+
return "DATA_FAT";
45+
case ESP_PARTITION_SUBTYPE_DATA_NVS:
46+
return "DATA_NVS";
47+
case ESP_PARTITION_SUBTYPE_DATA_OTA:
48+
return "DATA_OTA";
49+
case ESP_PARTITION_SUBTYPE_DATA_PHY:
50+
return "DATA_PHY";
51+
case ESP_PARTITION_SUBTYPE_DATA_SPIFFS:
52+
return "DATA_SPIFFS";
53+
default:
54+
return "Unknown";
55+
}
56+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <esp_partition.h>
2+
3+
const char *partitionTypeToString(esp_partition_type_t type) {
4+
switch(type) {
5+
case ESP_PARTITION_TYPE_APP:
6+
return "APP";
7+
case ESP_PARTITION_TYPE_DATA:
8+
return "DATA";
9+
default:
10+
return "Unknown";
11+
}
12+
}

vfs/spiffs/spiffs_vfs.c

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#include "spiffs.h"
2+
#include <esp_vfs.h>
3+
#include <esp_log.h>
4+
#include <fcntl.h>
5+
#include <errno.h>
6+
#include "spiffs.h"
7+
#include "sdkconfig.h"
8+
9+
static char tag[] = "spiffs_vfs";
10+
11+
/*
12+
static int spiffsErrMap(spiffs *fs) {
13+
int errorCode = SPIFFS_errno(fs);
14+
switch (errorCode) {
15+
case SPIFFS_ERR_FULL:
16+
return ENOSPC;
17+
case SPIFFS_ERR_NOT_FOUND:
18+
return ENOENT;
19+
case SPIFFS_ERR_FILE_EXISTS:
20+
return EEXIST;
21+
case SPIFFS_ERR_NOT_A_FILE:
22+
return EBADF;
23+
case SPIFFS_ERR_OUT_OF_FILE_DESCS:
24+
return ENFILE;
25+
default: {
26+
ESP_LOGE(tag, "We received SPIFFs error code %d but didn't know how to map to an errno", errorCode);
27+
return ENOMSG;
28+
}
29+
}
30+
} // spiffsErrMap
31+
*/
32+
33+
34+
/**
35+
* Log the flags that are specified in an open() call.
36+
*/
37+
static void logFlags(int flags) {
38+
ESP_LOGD(tag, "flags:");
39+
if (flags & O_APPEND) {
40+
ESP_LOGD(tag, "- O_APPEND");
41+
}
42+
if (flags & O_CREAT) {
43+
ESP_LOGD(tag, "- O_CREAT");
44+
}
45+
if (flags & O_TRUNC) {
46+
ESP_LOGD(tag, "- O_TRUNC");
47+
}
48+
if (flags & O_RDONLY) {
49+
ESP_LOGD(tag, "- O_RDONLY");
50+
}
51+
if (flags & O_WRONLY) {
52+
ESP_LOGD(tag, "- O_WRONLY");
53+
}
54+
if (flags & O_RDWR) {
55+
ESP_LOGD(tag, "- O_RDWR");
56+
}
57+
} // End of logFlags
58+
59+
60+
static size_t vfs_write(void *ctx, int fd, const void *data, size_t size) {
61+
ESP_LOGI(tag, ">> write fd=%d, data=0x%lx, size=%d", fd, (unsigned long)data, size);
62+
spiffs *fs = (spiffs *)ctx;
63+
size_t retSize = SPIFFS_write(fs, (spiffs_file)fd, (void *)data, size);
64+
return retSize;
65+
} // vfs_write
66+
67+
68+
static off_t vfs_lseek(void *ctx, int fd, off_t offset, int whence) {
69+
ESP_LOGI(tag, ">> lseek fd=%d, offset=%d, whence=%d", fd, (int)offset, whence);
70+
return 0;
71+
} // vfs_lseek
72+
73+
74+
static ssize_t vfs_read(void *ctx, int fd, void *dst, size_t size) {
75+
ESP_LOGI(tag, ">> read fd=%d, dst=0x%lx, size=%d", fd, (unsigned long)dst, size);
76+
spiffs *fs = (spiffs *)ctx;
77+
ssize_t retSize = SPIFFS_read(fs, (spiffs_file)fd, dst, size);
78+
return retSize;
79+
} // vfs_read
80+
81+
82+
/**
83+
* Open the file specified by path. The flags contain the instructions
84+
* on how the file is to be opened. For example:
85+
*
86+
* O_CREAT - Create the named file.
87+
* O_TRUNC - Truncate (empty) the file.
88+
* O_RDONLY - Open the file for reading only.
89+
* O_WRONLY - Open the file for writing only.
90+
* O_RDWR - Open the file for reading and writing.
91+
* O_APPEND - Append to the file.
92+
*
93+
* The mode are access mode flags.
94+
*/
95+
static int vfs_open(void *ctx, const char *path, int flags, int accessMode) {
96+
ESP_LOGI(tag, ">> open path=%s, flags=0x%x, accessMode=0x%x", path, flags, accessMode);
97+
logFlags(flags);
98+
spiffs *fs = (spiffs *)ctx;
99+
int spiffsFlags = 0;
100+
if (flags & O_CREAT) {
101+
spiffsFlags |= SPIFFS_O_CREAT;
102+
}
103+
if (flags & O_TRUNC) {
104+
spiffsFlags |= SPIFFS_O_TRUNC;
105+
}
106+
if (flags & O_RDONLY) {
107+
spiffsFlags |= SPIFFS_O_RDONLY;
108+
}
109+
if (flags & O_WRONLY) {
110+
spiffsFlags |= SPIFFS_O_WRONLY;
111+
}
112+
if (flags & O_RDWR) {
113+
spiffsFlags |= SPIFFS_O_RDWR;
114+
}
115+
if (flags & O_APPEND) {
116+
spiffsFlags |= SPIFFS_O_APPEND;
117+
}
118+
int rc = SPIFFS_open(fs, path, spiffsFlags, accessMode);
119+
return rc;
120+
} // vfs_open
121+
122+
123+
static int vfs_close(void *ctx, int fd) {
124+
ESP_LOGI(tag, ">> close fd=%d", fd);
125+
spiffs *fs = (spiffs *)ctx;
126+
int rc = SPIFFS_close(fs, (spiffs_file)fd);
127+
return rc;
128+
} // vfs_close
129+
130+
131+
static int vfs_fstat(void *ctx, int fd, struct stat *st) {
132+
ESP_LOGI(tag, ">> fstat fd=%d", fd);
133+
return 0;
134+
} // vfs_fstat
135+
136+
137+
static int vfs_stat(void *ctx, const char *path, struct stat *st) {
138+
ESP_LOGI(tag, ">> stat path=%s", path);
139+
return 0;
140+
} // vfs_stat
141+
142+
143+
static int vfs_link(void *ctx, const char *oldPath, const char *newPath) {
144+
ESP_LOGI(tag, ">> link oldPath=%s, newPath=%s", oldPath, newPath);
145+
return 0;
146+
} // vfs_link
147+
148+
149+
static int vfs_rename(void *ctx, const char *oldPath, const char *newPath) {
150+
ESP_LOGI(tag, ">> rename oldPath=%s, newPath=%s", oldPath, newPath);
151+
spiffs *fs = (spiffs *)ctx;
152+
int rc = SPIFFS_rename(fs, oldPath, newPath);
153+
return rc;
154+
} // vfs_rename
155+
156+
157+
/**
158+
* Register the VFS at the specified mount point.
159+
* The callback functions are registered to handle the
160+
* different functions that may be requested against the
161+
* VFS.
162+
*/
163+
void spiffs_registerVFS(char *mountPoint, spiffs *fs) {
164+
esp_vfs_t vfs;
165+
esp_err_t err;
166+
167+
vfs.fd_offset = 0;
168+
vfs.flags = ESP_VFS_FLAG_CONTEXT_PTR;
169+
vfs.write_p = vfs_write;
170+
vfs.lseek_p = vfs_lseek;
171+
vfs.read_p = vfs_read;
172+
vfs.open_p = vfs_open;
173+
vfs.close_p = vfs_close;
174+
vfs.fstat_p = vfs_fstat;
175+
vfs.stat_p = vfs_stat;
176+
vfs.link_p = vfs_link;
177+
vfs.rename_p = vfs_rename;
178+
179+
err = esp_vfs_register(mountPoint, &vfs, (void *)fs);
180+
if (err != ESP_OK) {
181+
ESP_LOGE(tag, "esp_vfs_register: err=%d", err);
182+
}
183+
} // spiffs_registerVFS

vfs/spiffs/spiffs_vfs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* spiffs_vfs.h
3+
*
4+
* Created on: Dec 3, 2016
5+
* Author: kolban
6+
*/
7+
8+
#ifndef MAIN_SPIFFS_VFS_H_
9+
#define MAIN_SPIFFS_VFS_H_
10+
#include "spiffs.h"
11+
void spiffs_registerVFS(char *mountPoint, spiffs *fs);
12+
13+
14+
#endif /* MAIN_SPIFFS_VFS_H_ */

vfs/vfs-skeleton/main/vfsTest.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static ssize_t vfs_read(int fd, void *dst, size_t size) {
7272
* O_RDONLY - Open the file for reading only.
7373
* O_WRONLY - Open the file for writing only.
7474
* O_RDWR - Open the file for reading and writing.
75+
* O_APPEND - Open the file in append mode.
7576
*
7677
* The mode are access mode flags.
7778
*/

0 commit comments

Comments
 (0)
0