Skip to content

Commit

Permalink
Merge recent Pipboy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Jan 30, 2025
2 parents e84e670 + 612bd3a commit 333f45c
Show file tree
Hide file tree
Showing 18 changed files with 553 additions and 158 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
XiaoBLE: Add board: Seeed XIAO BLE
nRF5x: Allow entering UF2 bootloader mode by calling E.rebootToDFU() (on boards that have such a bootloader)
Graphics: Graphics.asImage() can now take x/y/w/h options to make only part of the graphics into an image
STM32: Revert hasSystemSlept=true before _WFI that caused jsTimer to get corrupted
Pipboy: allow audio files to be played at the same time as (silent) video. add audioStopped/videoStopped events and audioStop method
Pipboy: Pip.audioStartVar(wav,{overlap:true}) can now play sounds over the top of other sounds. audioRead now doesn't stop audio playback

2v25 : ESP32C3: Get analogRead working correctly
Graphics: Adjust image alignment when rotating images to avoid cropping (fix #2535)
Expand Down
1 change: 0 additions & 1 deletion boards/PIPBOY.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
'USB' : { 'pin_vsense' : 'A9', # PA5 for v0.3, PA9 for v0.5 and later
'pin_dm' : 'A11',
'pin_dp' : 'A12' },

'JTAG' : {
'pin_MS' : 'A13',
'pin_CK' : 'A14',
Expand Down
19 changes: 12 additions & 7 deletions libs/filesystem/jswrap_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool jsfsInit() {
#endif // USE_FLASHFS
FRESULT res;

if ((res = f_mount(&jsfsFAT, "", 1)) != FR_OK) {
if ((res = f_mount(&jsfsFAT, "", 1/*immediate mount*/)) != FR_OK) {
#ifndef PIPBOY // Don't throw an error for the Pip-Boy - just return false
jsfsReportError("Unable to mount media", res);
#endif
Expand Down Expand Up @@ -204,11 +204,8 @@ static bool fileGetFromVar(JsFile *file, JsVar *parent) {
return ret;
}

/*JSON{
"type" : "kill",
"generate" : "jswrap_file_kill"
}*/
void jswrap_file_kill() {
/// Uninit all software-related SD card stuff - but don't de-init hardware
void jswrap_file_kill_sw() {
JsVar *arr = fsGetArray(false);
if (arr) {
JsvObjectIterator it;
Expand All @@ -230,6 +227,14 @@ void jswrap_file_kill() {
f_mount(0, 0, 0);
}
#endif
}

/*JSON{
"type" : "kill",
"generate" : "jswrap_file_kill"
}*/
void jswrap_file_kill() {
jswrap_file_kill_sw();
#ifdef SD_CARD_ANYWHERE
sdSPISetup(0, PIN_UNDEFINED);
#endif
Expand Down Expand Up @@ -669,7 +674,7 @@ int jswrap_E_flashFatFS(JsVar* options) {
uint8_t init=flashFatFsInit(addr, sectors);
if (init) {
if ( format ) {
uint8_t res = f_mount(&jsfsFAT, "", 0);
uint8_t res = f_mount(&jsfsFAT, "", 0/*delayed mount?*/);
jsDebug(DBG_INFO,"Formatting Flash\n");
res = f_mkfs("", 1, 0); // Super Floppy format, using all space (not partition table)
if (res != FR_OK) {
Expand Down
2 changes: 2 additions & 0 deletions libs/filesystem/jswrap_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ typedef struct JsFile {
JsFileData *data;
} PACKED_FLAGS JsFile;

/// Uninit all software-related SD card stuff - but don't de-init hardware
void jswrap_file_kill_sw();
// Called when stopping, to make sure all files are closed
void jswrap_file_kill();
bool jsfsInit();
Expand Down
102 changes: 98 additions & 4 deletions libs/filesystem/jswrap_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ JsVar *jswrap_fs_readdir(JsVar *path) {
if (!pathStr[0]) strcpy(pathStr, "."); // deal with empty readdir
#endif

FRESULT res = 0;
FRESULT res = 0; // leave readdir to return 'undefined' on PipBoy if jsfsInit fails (on other devices it'll throw an exception anyway)
if (jsfsInit()) {
#ifndef LINUX
DIR dirs;
Expand Down Expand Up @@ -299,7 +299,7 @@ bool jswrap_fs_unlink(JsVar *path) {
if (!jsfsGetPathString(pathStr, path)) return 0;

#ifndef LINUX
FRESULT res = 0;
FRESULT res = FR_DISK_ERR;
if (jsfsInit()) {
res = f_unlink(pathStr);
}
Expand Down Expand Up @@ -337,7 +337,7 @@ JsVar *jswrap_fs_stat(JsVar *path) {
if (!jsfsGetPathString(pathStr, path)) return 0;

#ifndef LINUX
FRESULT res = 0;
FRESULT res = FR_DISK_ERR;
if (jsfsInit()) {
FILINFO info;
memset(&info,0,sizeof(info));
Expand Down Expand Up @@ -378,6 +378,66 @@ JsVar *jswrap_fs_stat(JsVar *path) {
return 0;
}

/*JSON{
"type" : "staticmethod",
"class" : "fs",
"name" : "getFree",
"ifndef" : "SAVE_ON_FLASH",
"generate" : "jswrap_fs_getfree",
"params" : [
["path","JsVar","The path specifying the logical drive"]
],
"return" : ["JsVar","An object describing the drive, or undefined on failure"]
}
Get the number of free sectors on the volume. This returns an object with the following
fields:
freeSectors: the number of free sectors
totalSectors: the total number of sectors on the volume
sectorSize: the number of bytes per sector
clusterSize: the number of sectors per cluster
*/
JsVar *jswrap_fs_getfree(JsVar *path) {
char pathStr[JS_DIR_BUF_SIZE] = "";
if (!jsvIsUndefined(path))
if (!jsfsGetPathString(pathStr, path)) return 0;

#ifndef LINUX
FRESULT res = FR_DISK_ERR;
if (jsfsInit()) {
FATFS *fs;
DWORD fre_clust, fre_sect, tot_sect, sect_size;
// Get volume information and free clusters
res = f_getfree(pathStr, &fre_clust, &fs);
if (res==0 /*ok*/) {
JsVar *obj = jsvNewObject();
if (!obj) return 0;
// Get total sectors and free sectors
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
#ifndef FF_MAX_SS // compat with older fatfs
#define FF_MAX_SS _MAX_SS
#define FF_MIN_SS _MIN_SS
#endif
#if FF_MAX_SS != FF_MIN_SS
sect_size = fs->ssize;
#else
sect_size = FF_MIN_SS;
#endif
jsvObjectSetChildAndUnLock(obj, "freeSectors", jsvNewFromInteger((JsVarInt)fre_sect));
jsvObjectSetChildAndUnLock(obj, "totalSectors", jsvNewFromInteger((JsVarInt)tot_sect));
jsvObjectSetChildAndUnLock(obj, "sectorSize", jsvNewFromInteger((JsVarInt)sect_size));
jsvObjectSetChildAndUnLock(obj, "clusterSize", jsvNewFromInteger((JsVarInt)fs->csize));
return obj;
}
}
#else
// @TODO: Implement something for Linux...?
#endif

return 0;
}

/*JSON{
"type" : "staticmethod",
"class" : "fs",
Expand Down Expand Up @@ -413,7 +473,7 @@ bool jswrap_fs_mkdir(JsVar *path) {
if (!jsfsGetPathString(pathStr, path)) return 0;

#ifndef LINUX
FRESULT res = 0;
FRESULT res = FR_DISK_ERR;
if (jsfsInit()) {
res = f_mkdir(pathStr);
}
Expand All @@ -427,3 +487,37 @@ bool jswrap_fs_mkdir(JsVar *path) {
}
return true;
}

/*JSON{
"type" : "staticmethod",
"class" : "fs",
"name" : "mkfs",
"ifndef" : "SAVE_ON_FLASH",
"generate" : "jswrap_fs_mkfs",
"return" : ["bool","True on success, or false on failure"]
}
Reformat the connected media to a FAT filesystem
*/
bool jswrap_fs_mkfs() {
#ifndef LINUX
FRESULT res = FR_DISK_ERR;
// ensure hardware inited. Ignore return value as we're formatting
jsfsInit();
// de-init software (but not hardware - we need to ensure open files are closed)
jswrap_file_kill_sw();
// Reformat
uint8_t workBuffer[FF_MAX_SS];
res = f_mkfs("", NULL, workBuffer, sizeof(workBuffer));
if (res) {
jsfsReportError("mkfs error", res);
return false;
}
return jsfsInit();
#else
jsExceptionHere(JSET_ERROR, "fs.mkfs not implemented on Linux");
return false;
#endif


}

2 changes: 2 additions & 0 deletions libs/filesystem/jswrap_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ bool jswrap_fs_unlink(JsVar *path);
JsVar *jswrap_fs_stat(JsVar *path);
bool jswrap_fs_mkdir(JsVar *path);
void jswrap_fs_sync();
JsVar *jswrap_fs_getfree(JsVar *path);
bool jswrap_fs_mkfs();
2 changes: 1 addition & 1 deletion libs/graphics/lcd_arraybuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void lcdScroll_ArrayBuffer_flat8(JsGraphics *gfx, int xdir, int ydir, int x1, in
void lcdInit_ArrayBuffer(JsGraphics *gfx, JsVar *optionalBuffer) {
// create buffer
if (optionalBuffer) {
jsvAddNamedChild(gfx->graphicsVar, optionalBuffer, "buffer");
jsvUnLock(jsvAddNamedChild(gfx->graphicsVar, optionalBuffer, "buffer"));
} else {
JsVar *buf = jswrap_arraybuffer_constructor((int)graphicsGetMemoryRequired(gfx));
jsvAddNamedChildAndUnLock(gfx->graphicsVar, buf, "buffer");
Expand Down
2 changes: 1 addition & 1 deletion libs/graphics/lcd_fsmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1927,4 +1927,4 @@ void lcdFSMC_blit2Bit(JsGraphics *gfx, int x, int y, int w, int h, int scale, Js
jsvStringIteratorFree(&lastPixels);
}
lcdFSMC_blitEnd();
}
}
Loading

0 comments on commit 333f45c

Please sign in to comment.