Skip to content

Commit cd28f1d

Browse files
authored
Merge pull request adafruit#8860 from jepler/create-sd-placeholder
supervisor: Create a file /sd/placeholder.txt with a note
2 parents 8e3e953 + 221af87 commit cd28f1d

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

ports/espressif/boards/lolin_s3_mini/mpconfigboard.mk

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CIRCUITPY_ESP_PSRAM_FREQ = 40m
1616
OPTIMIZATION_FLAGS = -Os
1717
CIRCUITPY_ESPCAMERA = 0
1818
CIRCUITPY_BITMAPFILTER = 0
19+
CIRCUITPY_CODEOP=0
1920

2021
# Include these Python libraries in firmware.
2122
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel

supervisor/shared/filesystem.c

+23-10
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,30 @@ inline void filesystem_tick(void) {
6464
}
6565

6666

67+
__attribute__((unused)) // this function MAY be unused
6768
static void make_empty_file(FATFS *fatfs, const char *path) {
6869
FIL fp;
6970
f_open(fatfs, &fp, path, FA_WRITE | FA_CREATE_ALWAYS);
7071
f_close(&fp);
7172
}
7273

74+
#if CIRCUITPY_FULL_BUILD
75+
#define MAKE_FILE_WITH_OPTIONAL_CONTENTS(fatfs, filename, string_literal) do { \
76+
const byte buffer[] = string_literal; \
77+
make_file_with_contents(fatfs, filename, buffer, sizeof(buffer) - 1); \
78+
} while (0)
7379

74-
static void make_sample_code_file(FATFS *fatfs) {
75-
#if CIRCUITPY_FULL_BUILD
80+
static void make_file_with_contents(FATFS *fatfs, const char *filename, const byte *content, UINT size) {
7681
FIL fs;
77-
UINT char_written = 0;
78-
const byte buffer[] = "print(\"Hello World!\")\n";
7982
// Create or modify existing code.py file
80-
f_open(fatfs, &fs, "/code.py", FA_WRITE | FA_CREATE_ALWAYS);
81-
f_write(&fs, buffer, sizeof(buffer) - 1, &char_written);
83+
f_open(fatfs, &fs, filename, FA_WRITE | FA_CREATE_ALWAYS);
84+
f_write(&fs, content, size, &size);
8285
f_close(&fs);
83-
#else
84-
make_empty_file(fatfs, "/code.py");
85-
#endif
8686
}
87+
#else
88+
#define MAKE_FILE_WITH_OPTIONAL_CONTENTS(fatfs, filename, string_literal) \
89+
make_empty_file(fatfs, filename)
90+
#endif
8791

8892
// we don't make this function static because it needs a lot of stack and we
8993
// want it to be executed without using stack within main() function
@@ -137,11 +141,20 @@ bool filesystem_init(bool create_allowed, bool force_create) {
137141
// https://specifications.freedesktop.org/trash-spec/trashspec-latest.html
138142
#endif
139143

144+
#if CIRCUITPY_SDCARDIO || CIRCUITPY_SDIOIO
145+
res = f_mkdir(&vfs_fat->fatfs, "/sd");
146+
#if CIRCUITPY_FULL_BUILD
147+
MAKE_FILE_WITH_OPTIONAL_CONTENTS(&vfs_fat->fatfs, "/sd/placeholder.txt",
148+
"SD cards mounted at /sd will hide this file from Python."
149+
" SD cards are not visible via USB CIRCUITPY.\n");
150+
#endif
151+
#endif
152+
140153
#if CIRCUITPY_OS_GETENV
141154
make_empty_file(&vfs_fat->fatfs, "/settings.toml");
142155
#endif
143156
// make a sample code.py file
144-
make_sample_code_file(&vfs_fat->fatfs);
157+
MAKE_FILE_WITH_OPTIONAL_CONTENTS(&vfs_fat->fatfs, "/code.py", "print(\"Hello World!\")\n");
145158

146159
// create empty lib directory
147160
res = f_mkdir(&vfs_fat->fatfs, "/lib");

0 commit comments

Comments
 (0)