Example #1
0
bool jsfsInit() {
#ifndef LINUX
    if (!fat_initialised) {
#ifdef SD_CARD_ANYWHERE
        if (!isSdSPISetup()) {
#ifdef SD_SPI
            const char *deviceStr = jshGetDeviceString(SD_SPI);
            JsVar *spi = jsvSkipNameAndUnLock(jspGetNamedVariable(deviceStr));
            JshSPIInfo inf;
            jshSPIInitInfo(&inf);
            inf.pinMISO = SD_DO_PIN;
            inf.pinMOSI = SD_DI_PIN;
            inf.pinSCK = SD_CLK_PIN;
            jshSPISetup(SD_SPI, &inf);
            sdSPISetup(spi, SD_CS_PIN);
            jsvUnLock(spi);
#else
            jsError("SD card must be setup with E.connectSDCard first");
            return false;
#endif
        }
#endif

        FRESULT res;
        if ((res = f_mount(&jsfsFAT, "", 1/*immediate*/)) != FR_OK) {
            jsfsReportError("Unable to mount SD card", res);
            return false;
        }
        fat_initialised = true;
    }
#endif
    return true;
}
Example #2
0
bool jsfsInit() {
   
#ifndef LINUX
  if (!fat_initialised) {
#ifndef USE_FLASHFS  
#ifdef SD_CARD_ANYWHERE
    if (!isSdSPISetup()) {
#ifdef SD_SPI
      const char *deviceStr = jshGetDeviceString(SD_SPI);
      JsVar *spi = jsvSkipNameAndUnLock(jspGetNamedVariable(deviceStr));
      JshSPIInfo inf;
      jshSPIInitInfo(&inf);
      inf.baudRate = 4000000; // 4Mhz bit rate for onboard SD cards
      inf.pinMISO = SD_DO_PIN;
      inf.pinMOSI = SD_DI_PIN;
      inf.pinSCK = SD_CLK_PIN;
      jshSPISetup(SD_SPI, &inf);
      sdSPISetup(spi, SD_CS_PIN);
      jsvUnLock(spi);
#else
      jsExceptionHere(JSET_ERROR,"SD card must be setup with E.connectSDCard first");
      return false;
#endif // SD_SPI
    }
#endif // SD_CARD_ANYWHER
#endif // USE_FLASHFS 
    FRESULT res;

    if ((res = f_mount(&jsfsFAT, "", 1)) != FR_OK) {
       jsfsReportError("Unable to mount media", res);
       return false;
    }
    fat_initialised = true;
  }
#endif // LINUX
  return true;
}