atmel-samd: Default to code.txt instead of main.py (main.py will still work on its own.)
This commit is contained in:
parent
3b1109c47b
commit
575d2e7998
@ -52,20 +52,14 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
|
||||
// TODO(tannewt): Remove these default files in favor a very simple README with
|
||||
// a url to all of the files that ship on boards.
|
||||
|
||||
static const char fresh_boot_py[] =
|
||||
"# boot.py -- run on boot-up\r\n"
|
||||
"# can run arbitrary Python, but best to keep it minimal\r\n"
|
||||
"\r\n"
|
||||
;
|
||||
|
||||
static const char fresh_main_py[] =
|
||||
"# main.py -- put your code here!\r\n"
|
||||
static const char fresh_code_txt[] =
|
||||
"# code.txt -- put your code here!\r\n"
|
||||
;
|
||||
|
||||
static const char fresh_readme_txt[] =
|
||||
"This is a MicroPython board\r\n"
|
||||
"This is an Adafruit MicroPython board\r\n"
|
||||
"\r\n"
|
||||
"You can get started right away by writing your Python code in 'main.py'.\r\n"
|
||||
"You can get started right away by writing your Python code in 'code.txt'.\r\n"
|
||||
"\r\n"
|
||||
"For a serial prompt:\r\n"
|
||||
" - Windows: you need to go to 'Device manager', right click on the unknown device,\r\n"
|
||||
@ -74,7 +68,7 @@ static const char fresh_readme_txt[] =
|
||||
" - Mac OS X: use the command: screen /dev/tty.usbmodem*\r\n"
|
||||
" - Linux: use the command: screen /dev/ttyACM0\r\n"
|
||||
"\r\n"
|
||||
"Please visit http://micropython.org/help/ for further help.\r\n"
|
||||
"Please visit https://learn.adafruit.com/category/micropython for further help.\r\n"
|
||||
;
|
||||
|
||||
extern void flash_init_vfs(fs_user_mount_t *vfs);
|
||||
@ -115,11 +109,11 @@ void init_flash_fs(void) {
|
||||
// set label
|
||||
f_setlabel("MICROPYTHON");
|
||||
|
||||
// create empty main.py
|
||||
// create empty code.txt
|
||||
FIL fp;
|
||||
f_open(&fp, "/flash/main.py", FA_WRITE | FA_CREATE_ALWAYS);
|
||||
f_open(&fp, "/flash/code.txt", FA_WRITE | FA_CREATE_ALWAYS);
|
||||
UINT n;
|
||||
f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n);
|
||||
f_write(&fp, fresh_code_txt, sizeof(fresh_code_txt) - 1 /* don't count null terminator */, &n);
|
||||
f_close(&fp);
|
||||
|
||||
// TODO(tannewt): Create an .inf driver file for Windows.
|
||||
@ -129,29 +123,6 @@ void init_flash_fs(void) {
|
||||
f_write(&fp, fresh_readme_txt, sizeof(fresh_readme_txt) - 1 /* don't count null terminator */, &n);
|
||||
f_close(&fp);
|
||||
|
||||
// Make sure we have a /flash/boot.py. Create it if needed.
|
||||
FILINFO fno;
|
||||
#if _USE_LFN
|
||||
fno.lfname = NULL;
|
||||
fno.lfsize = 0;
|
||||
#endif
|
||||
res = f_stat("/flash/boot.py", &fno);
|
||||
if (res == FR_OK) {
|
||||
if (fno.fattrib & AM_DIR) {
|
||||
// exists as a directory
|
||||
// TODO handle this case
|
||||
// see http://elm-chan.org/fsw/ff/img/app2.c for a "rm -rf" implementation
|
||||
} else {
|
||||
// exists as a file, good!
|
||||
}
|
||||
} else {
|
||||
// doesn't exist, create fresh file
|
||||
|
||||
f_open(&fp, "/flash/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
|
||||
f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n);
|
||||
// TODO check we could write n bytes
|
||||
f_close(&fp);
|
||||
}
|
||||
if (usb_writeable) {
|
||||
vfs->flags |= FSUSER_USB_WRITEABLE;
|
||||
}
|
||||
@ -210,6 +181,22 @@ void reset_samd21(void) {
|
||||
// TODO(tannewt): Reset all of the pins too.
|
||||
}
|
||||
|
||||
bool maybe_run(const char* filename, int* ret) {
|
||||
FILINFO fno;
|
||||
#if _USE_LFN
|
||||
fno.lfname = NULL;
|
||||
fno.lfsize = 0;
|
||||
#endif
|
||||
FRESULT res = f_stat(filename, &fno);
|
||||
if (res != FR_OK || fno.fattrib & AM_DIR) {
|
||||
return false;
|
||||
}
|
||||
mp_hal_stdout_tx_str(filename);
|
||||
mp_hal_stdout_tx_str(" output:\r\n");
|
||||
*ret = pyexec_file(filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
void start_mp(void) {
|
||||
#ifdef AUTORESET_DELAY_MS
|
||||
mp_hal_stdout_tx_str("\r\n");
|
||||
@ -218,15 +205,20 @@ void start_mp(void) {
|
||||
#endif
|
||||
|
||||
new_status_color(0x00, 0x00, 0x8f);
|
||||
mp_hal_stdout_tx_str("boot.py output:\r\n");
|
||||
int ret = pyexec_file("boot.py");
|
||||
if (ret & PYEXEC_FORCED_EXIT) {
|
||||
int ret = 0;
|
||||
bool found_boot = maybe_run("settings.txt", &ret) ||
|
||||
maybe_run("settings.py", &ret) ||
|
||||
maybe_run("boot.py", &ret) ||
|
||||
maybe_run("boot.txt", &ret);
|
||||
if (found_boot && ret & PYEXEC_FORCED_EXIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
new_status_color(0x00, 0x8f, 0x00);
|
||||
mp_hal_stdout_tx_str("\r\nmain.py output:\r\n");
|
||||
pyexec_file("main.py");
|
||||
maybe_run("code.txt", &ret) ||
|
||||
maybe_run("code.py", &ret) ||
|
||||
maybe_run("main.py", &ret) ||
|
||||
maybe_run("main.txt", &ret);
|
||||
}
|
||||
|
||||
#ifdef UART_REPL
|
||||
|
Loading…
x
Reference in New Issue
Block a user