B4R=true
Group=Default Group
ModulesStructureVersion=1
Type=StaticCode
Version=3
@EndOfDesignText@
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Private FormatStatus As Boolean
Public CardSize As Double
End Sub
Public Sub DoSDFormat() As Boolean
FormatStatus=False
RunNative("DoFormat",Null)
Return FormatStatus
End Sub
#if c
static SPIClass SPI_2(2);
uint32_t cardSectorCount = 0;
uint8_t sectorBuffer[512];
SdCardFactory cardFactory;
SdCard* m_card = nullptr;
uint32_t const ERASE_SIZE = 262144L;
bool formatCard()
{
ExFatFormatter exFatFormatter;
FatFormatter fatFormatter;
bool rtn = cardSectorCount > 67108864 ?
exFatFormatter.format(m_card, sectorBuffer, &Serial) :
fatFormatter.format(m_card, sectorBuffer, &Serial);
return rtn;
}
void DoFormat(B4R::Object* O)
{
m_card = cardFactory.newCard(SdSpiConfig(PB12, DEDICATED_SPI, SD_SCK_MHZ(18), &SPI_2));
if (!m_card || m_card->errorCode()) {
b4r_sdcardformat::_formatstatus=false;
return;
}
cardSectorCount = m_card->sectorCount();
if (!cardSectorCount) {
b4r_sdcardformat::_formatstatus=false;
return;
}
b4r_sdcardformat::_cardsize=cardSectorCount/2097152.0;
b4r_sdcardformat::_formatstatus=formatCard();
}
#End If