Merge pull request #8860 from jepler/create-sd-placeholder

supervisor: Create a file /sd/placeholder.txt with a note
This commit is contained in:
Scott Shawcroft 2024-02-02 09:54:48 -08:00 committed by GitHub
commit cd28f1d678
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 10 deletions

View file

@ -16,6 +16,7 @@ CIRCUITPY_ESP_PSRAM_FREQ = 40m
OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_CODEOP=0
# Include these Python libraries in firmware.
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel

View file

@ -64,26 +64,30 @@ inline void filesystem_tick(void) {
}
__attribute__((unused)) // this function MAY be unused
static void make_empty_file(FATFS *fatfs, const char *path) {
FIL fp;
f_open(fatfs, &fp, path, FA_WRITE | FA_CREATE_ALWAYS);
f_close(&fp);
}
#if CIRCUITPY_FULL_BUILD
#define MAKE_FILE_WITH_OPTIONAL_CONTENTS(fatfs, filename, string_literal) do { \
const byte buffer[] = string_literal; \
make_file_with_contents(fatfs, filename, buffer, sizeof(buffer) - 1); \
} while (0)
static void make_sample_code_file(FATFS *fatfs) {
#if CIRCUITPY_FULL_BUILD
static void make_file_with_contents(FATFS *fatfs, const char *filename, const byte *content, UINT size) {
FIL fs;
UINT char_written = 0;
const byte buffer[] = "print(\"Hello World!\")\n";
// Create or modify existing code.py file
f_open(fatfs, &fs, "/code.py", FA_WRITE | FA_CREATE_ALWAYS);
f_write(&fs, buffer, sizeof(buffer) - 1, &char_written);
f_open(fatfs, &fs, filename, FA_WRITE | FA_CREATE_ALWAYS);
f_write(&fs, content, size, &size);
f_close(&fs);
#else
make_empty_file(fatfs, "/code.py");
#endif
}
#else
#define MAKE_FILE_WITH_OPTIONAL_CONTENTS(fatfs, filename, string_literal) \
make_empty_file(fatfs, filename)
#endif
// we don't make this function static because it needs a lot of stack and we
// want it to be executed without using stack within main() function
@ -137,11 +141,20 @@ bool filesystem_init(bool create_allowed, bool force_create) {
// https://specifications.freedesktop.org/trash-spec/trashspec-latest.html
#endif
#if CIRCUITPY_SDCARDIO || CIRCUITPY_SDIOIO
res = f_mkdir(&vfs_fat->fatfs, "/sd");
#if CIRCUITPY_FULL_BUILD
MAKE_FILE_WITH_OPTIONAL_CONTENTS(&vfs_fat->fatfs, "/sd/placeholder.txt",
"SD cards mounted at /sd will hide this file from Python."
" SD cards are not visible via USB CIRCUITPY.\n");
#endif
#endif
#if CIRCUITPY_OS_GETENV
make_empty_file(&vfs_fat->fatfs, "/settings.toml");
#endif
// make a sample code.py file
make_sample_code_file(&vfs_fat->fatfs);
MAKE_FILE_WITH_OPTIONAL_CONTENTS(&vfs_fat->fatfs, "/code.py", "print(\"Hello World!\")\n");
// create empty lib directory
res = f_mkdir(&vfs_fat->fatfs, "/lib");