@@ -70,20 +70,23 @@ static void make_empty_file(FATFS *fatfs, const char *path) {
70
70
f_close (& fp );
71
71
}
72
72
73
+ #if CIRCUITPY_FULL_BUILD
74
+ #define MAKE_FILE_WITH_OPTIONAL_CONTENTS (fatfs , filename , string_literal ) do { \
75
+ const byte buffer[] = string_literal; \
76
+ make_file_with_contents(fatfs, filename, buffer, sizeof(buffer) - 1); \
77
+ } while (0)
73
78
74
- static void make_sample_code_file (FATFS * fatfs ) {
75
- #if CIRCUITPY_FULL_BUILD
79
+ static void make_file_with_contents (FATFS * fatfs , const char * filename , const byte * content , UINT size ) {
76
80
FIL fs ;
77
- UINT char_written = 0 ;
78
- const byte buffer [] = "print(\"Hello World!\")\n" ;
79
81
// 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 );
82
+ f_open (fatfs , & fs , filename , FA_WRITE | FA_CREATE_ALWAYS );
83
+ f_write (& fs , content , size , & size );
82
84
f_close (& fs );
83
- #else
84
- make_empty_file (fatfs , "/code.py" );
85
- #endif
86
85
}
86
+ #else
87
+ #define MAKE_FILE_WITH_OPTIONAL_CONTENTS (fatfs , filename , string_literal ) \
88
+ make_empty_file(fatfs, filename)
89
+ #endif
87
90
88
91
// we don't make this function static because it needs a lot of stack and we
89
92
// want it to be executed without using stack within main() function
@@ -141,7 +144,7 @@ bool filesystem_init(bool create_allowed, bool force_create) {
141
144
make_empty_file (& vfs_fat -> fatfs , "/settings.toml" );
142
145
#endif
143
146
// make a sample code.py file
144
- make_sample_code_file (& vfs_fat -> fatfs );
147
+ MAKE_FILE_WITH_OPTIONAL_CONTENTS (& vfs_fat -> fatfs , "/code.py" , "print(\"Hello World!\")\n" );
145
148
146
149
// create empty lib directory
147
150
res = f_mkdir (& vfs_fat -> fatfs , "/lib" );
0 commit comments