71 files changed
+1094
-27493
No files matched your search
@@ -7,9 +7,6 @@
|
||||
*.app
|
||||
|
||||
*.pyc
|
||||
/tools/nrfutil-0.5.2/build/
|
||||
/tools/nrfutil-0.5.2/dist/
|
||||
/tools/nrfutil-0.5.2/nrfutil.egg-info/
|
||||
/tools/.idea/
|
||||
/tools/midi_tests/node_modules
|
||||
|
||||
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
# Adafruit nRF52 Arduino Core Changelog
|
||||
|
||||
# 0.10.5
|
||||
# 0.11.0
|
||||
|
||||
- Fixed Feather nRF52840 Express's qspi driver to work with on-board flash device
|
||||
- Rework USB driver using Adafruit_TinyUSB library
|
||||
- Added Metro nRF52840 Express
|
||||
- Update bootloader binaries to 0.2.11
|
||||
|
||||
@@ -82,11 +82,6 @@ int Adafruit_USBD_CDC::read(void)
|
||||
return (int) tud_cdc_read_char();
|
||||
}
|
||||
|
||||
size_t Adafruit_USBD_CDC::readBytes(char *buffer, size_t length)
|
||||
{
|
||||
return tud_cdc_read(buffer, length);
|
||||
}
|
||||
|
||||
void Adafruit_USBD_CDC::flush(void)
|
||||
{
|
||||
tud_cdc_write_flush();
|
||||
@@ -106,11 +101,8 @@ size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size)
|
||||
remain -= wrcount;
|
||||
buffer += wrcount;
|
||||
|
||||
// Write FIFO is full, flush and re-try
|
||||
if ( remain )
|
||||
{
|
||||
tud_cdc_write_flush();
|
||||
}
|
||||
// Write FIFO is full, run usb background to flush
|
||||
if ( remain ) yield();
|
||||
}
|
||||
|
||||
return size - remain;
|
||||
|
||||
@@ -51,9 +51,6 @@ public:
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
operator bool();
|
||||
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
size_t readBytes(uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||
};
|
||||
|
||||
extern Adafruit_USBD_CDC Serial;
|
||||
|
||||
@@ -164,7 +164,8 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
return USBDevice._desc_cfg;
|
||||
}
|
||||
|
||||
static uint16_t _desc_str[32];
|
||||
// up to 32 unicode characters (header make it 33)
|
||||
static uint16_t _desc_str[33];
|
||||
|
||||
// Invoked when received GET STRING DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
@@ -187,7 +188,7 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index)
|
||||
|
||||
// cap at max char
|
||||
chr_count = strlen(str);
|
||||
if ( chr_count > 31 ) chr_count = 31;
|
||||
if ( chr_count > 32 ) chr_count = 32;
|
||||
|
||||
for(uint8_t i=0; i<chr_count; i++)
|
||||
{
|
||||
|
||||
@@ -73,23 +73,21 @@ typedef struct
|
||||
//--------------------------------------------------------------------+
|
||||
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
|
||||
|
||||
// TODO will be replaced by dcd_edpt_busy()
|
||||
bool pending_read_from_host;
|
||||
//bool pending_read_from_host; TODO remove
|
||||
static void _prep_out_transaction (uint8_t itf)
|
||||
{
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
|
||||
// skip if previous transfer not complete
|
||||
// dcd_edpt_busy() doesn't work, probably transfer is complete but not properly handled by the stack
|
||||
// if ( dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
|
||||
if (pending_read_from_host) return;
|
||||
if ( usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
|
||||
//if (pending_read_from_host) return;
|
||||
|
||||
// Prepare for incoming data but only allow what we can store in the ring buffer.
|
||||
uint16_t max_read = tu_fifo_remaining(&p_cdc->rx_ff);
|
||||
if ( max_read >= CFG_TUD_CDC_EPSIZE )
|
||||
{
|
||||
dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
|
||||
pending_read_from_host = true;
|
||||
usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
|
||||
// pending_read_from_host = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,13 +181,13 @@ uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize)
|
||||
bool tud_cdc_n_write_flush (uint8_t itf)
|
||||
{
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
TU_VERIFY( !dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
|
||||
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
|
||||
|
||||
uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epin_buf, CFG_TUD_CDC_EPSIZE);
|
||||
if ( count )
|
||||
{
|
||||
TU_VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected
|
||||
TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count) );
|
||||
TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count) );
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -298,7 +296,7 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
|
||||
}
|
||||
|
||||
// Prepare for incoming data
|
||||
pending_read_from_host = false;
|
||||
// pending_read_from_host = false;
|
||||
_prep_out_transaction(cdc_id);
|
||||
|
||||
return true;
|
||||
@@ -394,7 +392,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
|
||||
|
||||
// prepare for OUT transaction
|
||||
pending_read_from_host = false;
|
||||
// pending_read_from_host = false;
|
||||
_prep_out_transaction(itf);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,28 +73,31 @@ bool tud_hid_ready(void)
|
||||
{
|
||||
uint8_t itf = 0;
|
||||
uint8_t const ep_in = _hidd_itf[itf].ep_in;
|
||||
return tud_ready() && (ep_in != 0) && !dcd_edpt_busy(TUD_OPT_RHPORT, ep_in);
|
||||
return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
|
||||
}
|
||||
|
||||
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
||||
{
|
||||
TU_VERIFY( tud_hid_ready() && (len < CFG_TUD_HID_BUFSIZE) );
|
||||
TU_VERIFY( tud_hid_ready() );
|
||||
|
||||
uint8_t itf = 0;
|
||||
hidd_interface_t * p_hid = &_hidd_itf[itf];
|
||||
|
||||
// If report id = 0, skip ID field
|
||||
if (report_id)
|
||||
{
|
||||
len = tu_min8(len, CFG_TUD_HID_BUFSIZE-1);
|
||||
|
||||
p_hid->epin_buf[0] = report_id;
|
||||
memcpy(p_hid->epin_buf+1, report, len);
|
||||
len++;
|
||||
}else
|
||||
{
|
||||
// If report id = 0, skip ID field
|
||||
len = tu_min8(len, CFG_TUD_HID_BUFSIZE);
|
||||
memcpy(p_hid->epin_buf, report, len);
|
||||
}
|
||||
|
||||
return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
|
||||
return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
|
||||
}
|
||||
|
||||
bool tud_hid_boot_mode(void)
|
||||
@@ -180,7 +183,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
|
||||
*p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
// Prepare for output endpoint
|
||||
if (p_hid->ep_out) TU_ASSERT(dcd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
|
||||
if (p_hid->ep_out) TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -303,7 +306,7 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
if (ep_addr == p_hid->ep_out)
|
||||
{
|
||||
tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
|
||||
TU_ASSERT(dcd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
|
||||
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -139,7 +139,7 @@ bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
|
||||
(*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
// Prepare for Command Block Wrapper
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -394,7 +394,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
if ( (p_cbw->total_bytes > 0 ) && !tu_bit_test(p_cbw->dir, 7) )
|
||||
{
|
||||
// queue transfer
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
|
||||
}else
|
||||
{
|
||||
int32_t resplen;
|
||||
@@ -428,7 +428,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
if (p_msc->total_len)
|
||||
{
|
||||
TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len ); // cannot return more than host expect
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) );
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) );
|
||||
}else
|
||||
{
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
@@ -543,7 +543,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
p_msc->stage = MSC_STAGE_CMD;
|
||||
|
||||
// Send SCSI Status
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
|
||||
|
||||
// Invoke complete callback if defined
|
||||
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
|
||||
@@ -560,7 +560,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
}
|
||||
|
||||
// Queue for the next CBW
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
}
|
||||
else
|
||||
{
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, nbytes), );
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, nbytes), );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,7 +627,7 @@ static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
|
||||
|
||||
// Write10 callback will be called later when usb transfer complete
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -71,6 +71,35 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
|
||||
return true;
|
||||
}
|
||||
|
||||
// retrieve data from fifo
|
||||
static void _tu_ff_pull(tu_fifo_t* f, void * buffer)
|
||||
{
|
||||
memcpy(buffer,
|
||||
f->buffer + (f->rd_idx * f->item_size),
|
||||
f->item_size);
|
||||
|
||||
f->rd_idx = (f->rd_idx + 1) % f->depth;
|
||||
f->count--;
|
||||
}
|
||||
|
||||
// send data to fifo
|
||||
static void _tu_ff_push(tu_fifo_t* f, void const * data)
|
||||
{
|
||||
memcpy( f->buffer + (f->wr_idx * f->item_size),
|
||||
data,
|
||||
f->item_size);
|
||||
|
||||
f->wr_idx = (f->wr_idx + 1) % f->depth;
|
||||
|
||||
if (tu_fifo_full(f))
|
||||
{
|
||||
f->rd_idx = f->wr_idx; // keep the full state (rd == wr && len = size)
|
||||
}
|
||||
else
|
||||
{
|
||||
f->count++;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@@ -82,23 +111,19 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] p_buffer
|
||||
@param[in] buffer
|
||||
Pointer to the place holder for data read from the buffer
|
||||
|
||||
@returns TRUE if the queue is not empty
|
||||
*/
|
||||
/******************************************************************************/
|
||||
bool tu_fifo_read(tu_fifo_t* f, void * p_buffer)
|
||||
bool tu_fifo_read(tu_fifo_t* f, void * buffer)
|
||||
{
|
||||
if( tu_fifo_empty(f) ) return false;
|
||||
|
||||
tu_fifo_lock(f);
|
||||
|
||||
memcpy(p_buffer,
|
||||
f->buffer + (f->rd_idx * f->item_size),
|
||||
f->item_size);
|
||||
f->rd_idx = (f->rd_idx + 1) % f->depth;
|
||||
f->count--;
|
||||
_tu_ff_pull(f, buffer);
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
@@ -113,7 +138,7 @@ bool tu_fifo_read(tu_fifo_t* f, void * p_buffer)
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] p_data
|
||||
@param[in] buffer
|
||||
The pointer to data location
|
||||
@param[in] count
|
||||
Number of element that buffer can afford
|
||||
@@ -121,27 +146,28 @@ bool tu_fifo_read(tu_fifo_t* f, void * p_buffer)
|
||||
@returns number of items read from the FIFO
|
||||
*/
|
||||
/******************************************************************************/
|
||||
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t count)
|
||||
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * buffer, uint16_t count)
|
||||
{
|
||||
if( tu_fifo_empty(f) ) return 0;
|
||||
|
||||
tu_fifo_lock(f);
|
||||
|
||||
/* Limit up to fifo's count */
|
||||
if ( count > f->count ) count = f->count;
|
||||
|
||||
/* Could copy up to 2 portions marked as 'x' if queue is wrapped around
|
||||
* case 1: ....RxxxxW.......
|
||||
* case 2: xxxxxW....Rxxxxxx
|
||||
*/
|
||||
// uint16_t index2upper = tu_min16(count, f->count-f->rd_idx);
|
||||
|
||||
uint8_t* p_buf = (uint8_t*) p_buffer;
|
||||
uint8_t* buf8 = (uint8_t*) buffer;
|
||||
uint16_t len = 0;
|
||||
while( (len < count) && tu_fifo_read(f, p_buf) )
|
||||
|
||||
while (len < count)
|
||||
{
|
||||
_tu_ff_pull(f, buf8);
|
||||
|
||||
len++;
|
||||
p_buf += f->item_size;
|
||||
buf8 += f->item_size;
|
||||
}
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -182,33 +208,20 @@ bool tu_fifo_peek_at(tu_fifo_t* f, uint16_t pos, void * p_buffer)
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] p_data
|
||||
@param[in] data
|
||||
The byte to add to the FIFO
|
||||
|
||||
@returns TRUE if the data was written to the FIFO (overwrittable
|
||||
FIFO will always return TRUE)
|
||||
*/
|
||||
/******************************************************************************/
|
||||
bool tu_fifo_write (tu_fifo_t* f, const void * p_data)
|
||||
bool tu_fifo_write (tu_fifo_t* f, const void * data)
|
||||
{
|
||||
if ( tu_fifo_full(f) && !f->overwritable ) return false;
|
||||
|
||||
tu_fifo_lock(f);
|
||||
|
||||
memcpy( f->buffer + (f->wr_idx * f->item_size),
|
||||
p_data,
|
||||
f->item_size);
|
||||
|
||||
f->wr_idx = (f->wr_idx + 1) % f->depth;
|
||||
|
||||
if (tu_fifo_full(f))
|
||||
{
|
||||
f->rd_idx = f->wr_idx; // keep the full state (rd == wr && len = size)
|
||||
}
|
||||
else
|
||||
{
|
||||
f->count++;
|
||||
}
|
||||
_tu_ff_push(f, data);
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
@@ -223,26 +236,35 @@ bool tu_fifo_write (tu_fifo_t* f, const void * p_data)
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] p_data
|
||||
@param[in] data
|
||||
The pointer to data to add to the FIFO
|
||||
@param[in] count
|
||||
Number of element
|
||||
@return Number of written elements
|
||||
*/
|
||||
/******************************************************************************/
|
||||
uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * p_data, uint16_t count)
|
||||
uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * data, uint16_t count)
|
||||
{
|
||||
if ( count == 0 ) return 0;
|
||||
|
||||
uint8_t const* p_buf = (uint8_t const*) p_data;
|
||||
tu_fifo_lock(f);
|
||||
|
||||
// Not overwritable limit up to full
|
||||
if (!f->overwritable) count = tu_min16(count, tu_fifo_remaining(f));
|
||||
|
||||
uint8_t const* buf8 = (uint8_t const*) data;
|
||||
uint16_t len = 0;
|
||||
while( (len < count) && tu_fifo_write(f, p_buf) )
|
||||
|
||||
while (len < count)
|
||||
{
|
||||
_tu_ff_push(f, buf8);
|
||||
|
||||
len++;
|
||||
p_buf += f->item_size;
|
||||
buf8 += f->item_size;
|
||||
}
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,25 +100,28 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num);
|
||||
// Wake up host
|
||||
void dcd_remote_wakeup(uint8_t rhport);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Endpoint API
|
||||
* - open : Configure endpoint's registers
|
||||
* - xfer : Submit a transfer. When complete dcd_event_xfer_complete
|
||||
* must be called to notify the stack
|
||||
* - busy : Check if endpoint transferring is complete (TODO remove)
|
||||
* - stall : stall endpoint
|
||||
* - clear_stall : clear stall, data toggle is also reset to DATA0
|
||||
*------------------------------------------------------------------*/
|
||||
//--------------------------------------------------------------------+
|
||||
// Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Configure endpoint's registers according to descriptor
|
||||
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
|
||||
|
||||
// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
|
||||
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
||||
|
||||
// Check if endpoint transferring is complete (TODO remove)
|
||||
bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
// Stall endpoint
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
// clear stall, data toggle is also reset to DATA0
|
||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Event Function
|
||||
* Called by DCD to notify USBD
|
||||
* Called by DCD to notify device stack
|
||||
*------------------------------------------------------------------*/
|
||||
void dcd_event_handler(dcd_event_t const * event, bool in_isr);
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ typedef struct {
|
||||
uint8_t self_powered : 1; // configuration descriptor's attribute
|
||||
};
|
||||
|
||||
// uint8_t ep_busy_mask[2]; // bit mask for busy endpoint
|
||||
uint8_t ep_stall_mask[2]; // bit mask for stalled endpoint
|
||||
uint8_t ep_busy_map[2]; // bit mask for busy endpoint
|
||||
uint8_t ep_stall_map[2]; // bit map for stalled endpoint
|
||||
|
||||
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
|
||||
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
|
||||
@@ -287,6 +287,10 @@ void tud_task (void)
|
||||
{
|
||||
// Invoke the class callback associated with the endpoint address
|
||||
uint8_t const ep_addr = event.xfer_complete.ep_addr;
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
_usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
|
||||
if ( 0 == tu_edpt_number(ep_addr) )
|
||||
{
|
||||
@@ -621,7 +625,7 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr)
|
||||
|
||||
case DCD_EVENT_SUSPEND:
|
||||
// NOTE: When plugging/unplugging device, the D+/D- state are unstable and can accidentally meet the
|
||||
// SUSPEND condition ( Idle for 3ms ). Some MCUs such as samd don't distinguish suspend vs disconnect as well.
|
||||
// SUSPEND condition ( Idle for 3ms ). Some MCUs such as SAMD doesn't distinguish suspend vs disconnect as well.
|
||||
// We will skip handling SUSPEND/RESUME event if not currently connected
|
||||
if ( _usbd_dev.connected )
|
||||
{
|
||||
@@ -643,7 +647,8 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr)
|
||||
break;
|
||||
|
||||
case DCD_EVENT_XFER_COMPLETE:
|
||||
// skip zero-length control status complete event, should dcd notifies us.
|
||||
// skip zero-length control status complete event, should DCD notify us.
|
||||
// TODO could cause issue with actual zero length data used by class such as DFU
|
||||
if ( (0 == tu_edpt_number(event->xfer_complete.ep_addr)) && (event->xfer_complete.len == 0) ) break;
|
||||
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
@@ -733,13 +738,37 @@ void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr)
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
TU_VERIFY( dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes) );
|
||||
|
||||
_usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
return tu_bit_test(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
}
|
||||
|
||||
|
||||
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_stall(rhport, ep_addr);
|
||||
_usbd_dev.ep_stall_mask[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_mask[dir], epnum);
|
||||
_usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
}
|
||||
|
||||
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
@@ -748,7 +777,7 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_clear_stall(rhport, ep_addr);
|
||||
_usbd_dev.ep_stall_mask[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_mask[dir], epnum);
|
||||
_usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
}
|
||||
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
|
||||
@@ -758,7 +787,7 @@ bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
return tu_bit_test(_usbd_dev.ep_stall_mask[dir], epnum);
|
||||
return tu_bit_test(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -33,11 +33,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL API for stack management
|
||||
//--------------------------------------------------------------------+
|
||||
bool usbd_init (void);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Carry out Data and Status stage of control transfer
|
||||
// - If len = 0, it is equivalent to sending status only
|
||||
// - If len > wLength : it will be truncated
|
||||
@@ -46,6 +47,12 @@ bool usbd_control_xfer(uint8_t rhport, tusb_control_request_t const * request, v
|
||||
// Send STATUS (zero length) packet
|
||||
bool usbd_control_status(uint8_t rhport, tusb_control_request_t const * request);
|
||||
|
||||
// Submit a usb transfer
|
||||
bool usbd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
||||
|
||||
// Check if endpoint transferring is complete
|
||||
bool usbd_edpt_busy (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
@@ -35,6 +35,7 @@ int Stream::timedRead()
|
||||
do {
|
||||
c = read();
|
||||
if (c >= 0) return c;
|
||||
yield(); // running TinyUSB task
|
||||
} while(millis() - _startMillis < _timeout);
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
@@ -47,6 +48,7 @@ int Stream::timedPeek()
|
||||
do {
|
||||
c = peek();
|
||||
if (c >= 0) return c;
|
||||
yield(); // running TinyUSB task
|
||||
} while(millis() - _startMillis < _timeout);
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef FLASH_DEVICES_H_
|
||||
#define FLASH_DEVICES_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint32_t total_size;
|
||||
|
||||
// Response bytes to 0x90 JEDEC REMS ID command.
|
||||
uint8_t manufacturer_id;
|
||||
uint8_t device_id;
|
||||
|
||||
// Status register value to enable quad mode
|
||||
uint16_t status_quad_enable;
|
||||
|
||||
// Working frequency
|
||||
uint8_t freq;
|
||||
|
||||
} qspi_flash_device_t;
|
||||
|
||||
// Settings for the Gigadevice GD25Q16C 2MiB SPI flash.
|
||||
// Datasheet: http://www.gigadevice.com/datasheet/gd25q16c/
|
||||
// Can only work reliably with nrf5x at 10 Mhz, even though it should work up to 104 MHz
|
||||
#define GD25Q16C {\
|
||||
.total_size = 2*1024*1024, \
|
||||
.manufacturer_id = 0xc8, \
|
||||
.device_id = 0x14, \
|
||||
.status_quad_enable = (1 << 9),\
|
||||
.freq = NRF_QSPI_FREQ_32MDIV3 \
|
||||
}
|
||||
|
||||
#define MX25R6435F {\
|
||||
.total_size = 8*1024*1024, \
|
||||
.manufacturer_id = 0xc2, \
|
||||
.device_id = 0x17, \
|
||||
.status_quad_enable = (1 << 6),\
|
||||
.freq = NRF_QSPI_FREQ_32MDIV1 \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FLASH_DEVICES_H_ */
|
||||
@@ -1,254 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#ifdef EXTERNAL_FLASH_DEVICES
|
||||
|
||||
#include "flash_devices.h"
|
||||
#include "flash_qspi.h"
|
||||
#include "flash_cache.h"
|
||||
#include "nrfx_qspi.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
enum
|
||||
{
|
||||
QSPI_CMD_RSTEN = 0x66,
|
||||
QSPI_CMD_RST = 0x99,
|
||||
QSPI_CMD_WRSR = 0x01,
|
||||
QSPI_CMD_REMS = 0x90,
|
||||
};
|
||||
|
||||
const qspi_flash_device_t _flash_devices_arr[] = { EXTERNAL_FLASH_DEVICES };
|
||||
enum { FLASH_DEVICE_COUNT = arrcount(_flash_devices_arr) };
|
||||
|
||||
const qspi_flash_device_t* _flash_dev = NULL;
|
||||
|
||||
// Flash Abstraction Layer
|
||||
static bool fal_qspi_erase (uint32_t addr);
|
||||
static uint32_t fal_qspi_program (uint32_t dst, void const * src, uint32_t len);
|
||||
static uint32_t fal_qspi_read (void* dst, uint32_t src, uint32_t len);
|
||||
static bool fal_qspi_verify (uint32_t addr, void const * buf, uint32_t len);
|
||||
|
||||
static uint8_t _cache_buffer[FLASH_CACHE_SIZE] __attribute__((aligned(4)));
|
||||
|
||||
static flash_cache_t _cache = {
|
||||
.erase = fal_qspi_erase,
|
||||
.program = fal_qspi_program,
|
||||
.read = fal_qspi_read,
|
||||
.verify = fal_qspi_verify,
|
||||
.cache_addr = FLASH_CACHE_INVALID_ADDR,
|
||||
.cache_buf = _cache_buffer
|
||||
};
|
||||
|
||||
static SemaphoreHandle_t _qspi_mutex;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API
|
||||
//--------------------------------------------------------------------+
|
||||
uint32_t flash_qspi_size (void)
|
||||
{
|
||||
VERIFY(_flash_dev, 0);
|
||||
return _flash_dev->total_size;
|
||||
}
|
||||
|
||||
uint32_t flash_qspi_write (uint32_t dst, void const * src, uint32_t len)
|
||||
{
|
||||
VERIFY(_flash_dev, 0);
|
||||
|
||||
xSemaphoreTake(_qspi_mutex, portMAX_DELAY);
|
||||
uint32_t res = flash_cache_write(&_cache, dst, src, len);
|
||||
xSemaphoreGive(_qspi_mutex);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
uint32_t flash_qspi_read (void* dst, uint32_t src, uint32_t len)
|
||||
{
|
||||
VERIFY(_flash_dev, 0);
|
||||
|
||||
// xSemaphoreTake(_qspi_mutex, portMAX_DELAY);
|
||||
flash_cache_read(&_cache, dst, src, len);
|
||||
// xSemaphoreGive(_qspi_mutex);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void flash_qspi_flush (void)
|
||||
{
|
||||
VERIFY(_flash_dev,);
|
||||
|
||||
xSemaphoreTake(_qspi_mutex, portMAX_DELAY);
|
||||
flash_cache_flush(&_cache);
|
||||
xSemaphoreGive(_qspi_mutex);
|
||||
}
|
||||
|
||||
bool flash_qspi_chiperase (void)
|
||||
{
|
||||
VERIFY(_flash_dev);
|
||||
|
||||
xSemaphoreTake(_qspi_mutex, portMAX_DELAY);
|
||||
VERIFY(NRFX_SUCCESS == nrfx_qspi_erase(NRF_QSPI_ERASE_LEN_ALL, 0));
|
||||
xSemaphoreGive(_qspi_mutex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void flash_qspi_init (void)
|
||||
{
|
||||
// Init QSPI flash
|
||||
nrfx_qspi_config_t qspi_cfg = {
|
||||
.xip_offset = 0,
|
||||
.pins = {
|
||||
.sck_pin = g_ADigitalPinMap[PIN_QSPI_SCK],
|
||||
.csn_pin = g_ADigitalPinMap[PIN_QSPI_CS],
|
||||
.io0_pin = g_ADigitalPinMap[PIN_QSPI_IO0],
|
||||
.io1_pin = g_ADigitalPinMap[PIN_QSPI_IO1],
|
||||
.io2_pin = g_ADigitalPinMap[PIN_QSPI_IO2],
|
||||
.io3_pin = g_ADigitalPinMap[PIN_QSPI_IO3],
|
||||
},
|
||||
.prot_if = {
|
||||
.readoc = NRF_QSPI_READOC_READ4IO,
|
||||
.writeoc = NRF_QSPI_WRITEOC_PP4O,
|
||||
.addrmode = NRF_QSPI_ADDRMODE_24BIT,
|
||||
.dpmconfig = false
|
||||
},
|
||||
.phy_if = {
|
||||
.sck_freq = NRF_QSPI_FREQ_32MDIV16, // start with low 2 Mhz speed
|
||||
.sck_delay = 10, // min time CS must stay high before going low again. in unit of 62.5 ns
|
||||
.spi_mode = NRF_QSPI_MODE_0,
|
||||
.dpmen = false
|
||||
},
|
||||
.irq_priority = 7,
|
||||
};
|
||||
|
||||
// No callback for blocking API
|
||||
nrfx_qspi_init(&qspi_cfg, NULL, NULL);
|
||||
|
||||
nrf_qspi_cinstr_conf_t cinstr_cfg = {
|
||||
.opcode = 0,
|
||||
.length = 0,
|
||||
.io2_level = true,
|
||||
.io3_level = true,
|
||||
.wipwait = false,
|
||||
.wren = false
|
||||
};
|
||||
|
||||
// Send reset enable
|
||||
cinstr_cfg.opcode = QSPI_CMD_RSTEN;
|
||||
cinstr_cfg.length = 1;
|
||||
nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
|
||||
|
||||
// Send reset command
|
||||
cinstr_cfg.opcode = QSPI_CMD_RST;
|
||||
cinstr_cfg.length = 1;
|
||||
nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
|
||||
|
||||
NRFX_DELAY_US(100); // wait for flash device to reset
|
||||
|
||||
// Send (Read ID + 3 dummy bytes) + Receive 2 bytes of (Manufacture + Device ID)
|
||||
uint8_t dummy[5] = { 0 };
|
||||
uint8_t id_resp[5] = { 0 };
|
||||
cinstr_cfg.opcode = QSPI_CMD_REMS;
|
||||
cinstr_cfg.length = 6;
|
||||
|
||||
nrfx_qspi_cinstr_xfer(&cinstr_cfg, dummy, id_resp);
|
||||
|
||||
uint8_t const mfgr_id = id_resp[3];
|
||||
uint8_t const dev_id = id_resp[4];
|
||||
|
||||
// Debug
|
||||
// printf("qspi mfgr id : 0x%02X\n", mfgr_id);
|
||||
// printf("qspi device id: 0x%02X\n", dev_id);
|
||||
// PRINT_BUFFER(id_resp, sizeof(id_resp));
|
||||
|
||||
// Look up the flash device in supported array
|
||||
for ( uint32_t i = 0; i < FLASH_DEVICE_COUNT; i++ )
|
||||
{
|
||||
// Match ID
|
||||
if ( _flash_devices_arr[i].manufacturer_id == mfgr_id && _flash_devices_arr[i].device_id == dev_id )
|
||||
{
|
||||
_flash_dev = &_flash_devices_arr[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( _flash_dev )
|
||||
{
|
||||
// Enable quad mode
|
||||
cinstr_cfg.opcode = QSPI_CMD_WRSR;
|
||||
cinstr_cfg.length = 3;
|
||||
cinstr_cfg.wipwait = cinstr_cfg.wren = true;
|
||||
nrfx_qspi_cinstr_xfer(&cinstr_cfg, &_flash_dev->status_quad_enable, NULL);
|
||||
|
||||
// Speed up frequency
|
||||
nrf_qspi_phy_conf_t phy_if = {
|
||||
.sck_freq = _flash_dev->freq,
|
||||
.sck_delay = 10,
|
||||
.spi_mode = NRF_QSPI_MODE_0,
|
||||
.dpmen = false
|
||||
};
|
||||
nrf_qspi_ifconfig1_set(NRF_QSPI, &phy_if);
|
||||
|
||||
// create mutex
|
||||
_qspi_mutex = xSemaphoreCreateMutex();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HAL for caching
|
||||
//--------------------------------------------------------------------+
|
||||
static bool fal_qspi_erase (uint32_t addr)
|
||||
{
|
||||
VERIFY(_flash_dev);
|
||||
VERIFY(NRFX_SUCCESS == nrfx_qspi_erase(NRF_QSPI_ERASE_LEN_4KB, addr));
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t fal_qspi_program (uint32_t dst, void const * src, uint32_t len)
|
||||
{
|
||||
VERIFY(_flash_dev, 0);
|
||||
VERIFY(NRFX_SUCCESS == nrfx_qspi_write(src, len, dst));
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint32_t fal_qspi_read (void* dst, uint32_t src, uint32_t len)
|
||||
{
|
||||
VERIFY(_flash_dev, 0);
|
||||
VERIFY(NRFX_SUCCESS == nrfx_qspi_read(dst, len, src));
|
||||
return len;
|
||||
}
|
||||
|
||||
static bool fal_qspi_verify (uint32_t addr, void const * buf, uint32_t len)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // external flash
|
||||
#endif // nrf52840
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef FLASH_QSPI_H_
|
||||
#define FLASH_QSPI_H_
|
||||
|
||||
#include "common_inc.h"
|
||||
|
||||
#define FLASH_QSPI_PAGE_SIZE 4096
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void flash_qspi_init (void);
|
||||
uint32_t flash_qspi_size (void);
|
||||
void flash_qspi_flush (void);
|
||||
bool flash_qspi_erase (uint32_t addr);
|
||||
bool flash_qspi_chiperase (void);
|
||||
|
||||
uint32_t flash_qspi_write (uint32_t dst, void const * src, uint32_t len);
|
||||
uint32_t flash_qspi_read (void* dst, uint32_t src, uint32_t len);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Write helper
|
||||
//--------------------------------------------------------------------+
|
||||
static inline uint32_t flash_qspi_write8 (uint32_t dst, uint8_t num)
|
||||
{
|
||||
flash_qspi_write(dst, &num, sizeof(num));
|
||||
return sizeof(num);
|
||||
}
|
||||
|
||||
static inline uint32_t flash_qspi_write16 (uint32_t dst, uint8_t num)
|
||||
{
|
||||
flash_qspi_write(dst, &num, sizeof(num));
|
||||
return sizeof(num);
|
||||
}
|
||||
static inline uint32_t flash_qspi_write32 (uint32_t dst, uint8_t num)
|
||||
{
|
||||
flash_qspi_write(dst, &num, sizeof(num));
|
||||
return sizeof(num);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Read helper
|
||||
//--------------------------------------------------------------------+
|
||||
static inline uint8_t flash_qspi_read8 (uint32_t src)
|
||||
{
|
||||
uint8_t num;
|
||||
flash_qspi_read(&num, src, sizeof(num));
|
||||
return num;
|
||||
}
|
||||
|
||||
static inline uint16_t flash_qspi_read16 (uint32_t src)
|
||||
{
|
||||
uint16_t num;
|
||||
flash_qspi_read(&num, src, sizeof(num));
|
||||
return num;
|
||||
}
|
||||
|
||||
static inline uint16_t flash_qspi_read32 (uint32_t src)
|
||||
{
|
||||
uint32_t num;
|
||||
flash_qspi_read(&num, src, sizeof(num));
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* FLASH_QSPI_H_ */
|
||||
+1
-4
@@ -56,10 +56,7 @@ static void loop_task(void* arg)
|
||||
while (1)
|
||||
{
|
||||
loop();
|
||||
|
||||
#ifdef USE_TINYUSB
|
||||
tud_cdc_write_flush();
|
||||
#endif
|
||||
yield(); // yield run usb background task
|
||||
|
||||
// Serial events
|
||||
if (serialEvent && serialEventRun) serialEventRun();
|
||||
|
||||
+10
-6
@@ -38,11 +38,6 @@
|
||||
|
||||
SchedulerRTOS Scheduler;
|
||||
|
||||
void yield(void)
|
||||
{
|
||||
taskYIELD();
|
||||
}
|
||||
|
||||
static void _redirect_task(void* arg)
|
||||
{
|
||||
SchedulerRTOS::taskfunc_t taskfunc = (SchedulerRTOS::taskfunc_t) arg;
|
||||
@@ -81,12 +76,21 @@ bool SchedulerRTOS::startLoop(taskfunc_t task, const char* name, uint32_t stack_
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// FreeRTOS Hooks
|
||||
// Hooks
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void yield(void)
|
||||
{
|
||||
#ifdef USE_TINYUSB
|
||||
tud_cdc_write_flush();
|
||||
#endif
|
||||
|
||||
taskYIELD();
|
||||
}
|
||||
|
||||
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
|
||||
{
|
||||
LOG_LV1("RTOS", "%s Stack Overflow !!!", pcTaskName);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
name=Adafruit Little File System Libraries
|
||||
version=0.11.0
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for ARM Little File System
|
||||
paragraph=Arduino library for ARM Little File System
|
||||
category=Data Storage
|
||||
url=https://github.com/adafruit/Adafruit_nRF52_Arduino
|
||||
architectures=*
|
||||
includes=Adafruit_LittleFS.h
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <string.h>
|
||||
#include "Adafruit_LittleFS.h"
|
||||
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Implementation
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
Adafruit_LittleFS::Adafruit_LittleFS (void)
|
||||
: Adafruit_LittleFS(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Adafruit_LittleFS::Adafruit_LittleFS (struct lfs_config* cfg)
|
||||
{
|
||||
varclr(&_lfs);
|
||||
_lfs_cfg = cfg;
|
||||
_mounted = false;
|
||||
}
|
||||
|
||||
Adafruit_LittleFS::~Adafruit_LittleFS ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Initialize and mount the file system
|
||||
// Return true if mounted successfully else probably corrupted.
|
||||
// User should format the disk and try again
|
||||
bool Adafruit_LittleFS::begin (struct lfs_config * cfg)
|
||||
{
|
||||
if ( _mounted ) return true;
|
||||
|
||||
if (cfg) _lfs_cfg = cfg;
|
||||
if (!_lfs_cfg) return false;
|
||||
|
||||
VERIFY_LFS(lfs_mount(&_lfs, _lfs_cfg), false);
|
||||
_mounted = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Tear down and unmount file system
|
||||
void Adafruit_LittleFS::end(void)
|
||||
{
|
||||
if (!_mounted) return;
|
||||
|
||||
_mounted = false;
|
||||
VERIFY_LFS(lfs_unmount(&_lfs), );
|
||||
}
|
||||
|
||||
bool Adafruit_LittleFS::format (void)
|
||||
{
|
||||
// if already mounted: umount -> format -> remount
|
||||
if(_mounted) VERIFY_LFS(lfs_unmount(&_lfs), false);
|
||||
|
||||
VERIFY_LFS(lfs_format(&_lfs, _lfs_cfg), false);
|
||||
|
||||
if (_mounted) VERIFY_LFS(lfs_mount(&_lfs, _lfs_cfg), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Open a file or folder
|
||||
Adafruit_LittleFS_Namespace::File Adafruit_LittleFS::open (char const *filepath, uint8_t mode)
|
||||
{
|
||||
return Adafruit_LittleFS_Namespace::File(filepath, mode, *this);
|
||||
}
|
||||
|
||||
// Check if file or folder exists
|
||||
bool Adafruit_LittleFS::exists (char const *filepath)
|
||||
{
|
||||
struct lfs_info info;
|
||||
return 0 == lfs_stat(&_lfs, filepath, &info);
|
||||
}
|
||||
|
||||
// Create a directory, create intermediate parent if needed
|
||||
bool Adafruit_LittleFS::mkdir (char const *filepath)
|
||||
{
|
||||
const char* slash = filepath;
|
||||
if ( slash[0] == '/' ) slash++; // skip root '/'
|
||||
|
||||
while ( NULL != (slash = strchr(slash, '/')) )
|
||||
{
|
||||
char parent[slash - filepath + 1] = { 0 };
|
||||
memcpy(parent, filepath, slash - filepath);
|
||||
|
||||
// make intermediate parent
|
||||
int rc = lfs_mkdir(&_lfs, parent);
|
||||
if ( rc != LFS_ERR_OK && rc != LFS_ERR_EXIST )
|
||||
{
|
||||
PRINT_LFS_ERR(rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
slash++;
|
||||
}
|
||||
|
||||
int rc = lfs_mkdir(&_lfs, filepath);
|
||||
if ( rc != LFS_ERR_OK && rc != LFS_ERR_EXIST )
|
||||
{
|
||||
PRINT_LFS_ERR(rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove a file
|
||||
bool Adafruit_LittleFS::remove (char const *filepath)
|
||||
{
|
||||
VERIFY_LFS(lfs_remove(&_lfs, filepath), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove a folder
|
||||
bool Adafruit_LittleFS::rmdir (char const *filepath)
|
||||
{
|
||||
VERIFY_LFS(lfs_remove(&_lfs, filepath));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove a folder recursively
|
||||
bool Adafruit_LittleFS::rmdir_r (char const *filepath)
|
||||
{
|
||||
/* adafruit: lfs is modified to remove non-empty folder,
|
||||
According to below issue, comment these 2 line won't corrupt filesystem
|
||||
https://github.com/ARMmbed/littlefs/issues/43 */
|
||||
VERIFY_LFS(lfs_remove(&_lfs, filepath));
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------- Debug -------------//
|
||||
#if CFG_DEBUG
|
||||
|
||||
const char* dbg_strerr_lfs (int32_t err)
|
||||
{
|
||||
switch ( err )
|
||||
{
|
||||
case LFS_ERR_OK : return "LFS_ERR_OK";
|
||||
case LFS_ERR_IO : return "LFS_ERR_IO";
|
||||
case LFS_ERR_CORRUPT : return "LFS_ERR_CORRUPT";
|
||||
case LFS_ERR_NOENT : return "LFS_ERR_NOENT";
|
||||
case LFS_ERR_EXIST : return "LFS_ERR_EXIST";
|
||||
case LFS_ERR_NOTDIR : return "LFS_ERR_NOTDIR";
|
||||
case LFS_ERR_ISDIR : return "LFS_ERR_ISDIR";
|
||||
case LFS_ERR_NOTEMPTY : return "LFS_ERR_NOTEMPTY";
|
||||
case LFS_ERR_BADF : return "LFS_ERR_BADF";
|
||||
case LFS_ERR_INVAL : return "LFS_ERR_INVAL";
|
||||
case LFS_ERR_NOSPC : return "LFS_ERR_NOSPC";
|
||||
case LFS_ERR_NOMEM : return "LFS_ERR_NOMEM";
|
||||
|
||||
default:
|
||||
static char errcode[10];
|
||||
sprintf(errcode, "%d", err);
|
||||
return errcode;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUIT_LITTLEFS_H_
|
||||
#define ADAFRUIT_LITTLEFS_H_
|
||||
|
||||
#include <Stream.h>
|
||||
|
||||
// Internal Flash uses ARM Little FileSystem
|
||||
// https://github.com/ARMmbed/littlefs
|
||||
#include "littlefs/lfs.h"
|
||||
|
||||
#include "Adafruit_LittleFS_File.h"
|
||||
|
||||
class Adafruit_LittleFS
|
||||
{
|
||||
public:
|
||||
Adafruit_LittleFS (void);
|
||||
Adafruit_LittleFS (struct lfs_config* cfg);
|
||||
virtual ~Adafruit_LittleFS ();
|
||||
|
||||
bool begin(struct lfs_config * cfg = NULL);
|
||||
void end(void);
|
||||
|
||||
// Open the specified file/directory with the supplied mode (e.g. read or
|
||||
// write, etc). Returns a File object for interacting with the file.
|
||||
// Note that currently only one file can be open at a time.
|
||||
Adafruit_LittleFS_Namespace::File open (char const *filename, uint8_t mode = Adafruit_LittleFS_Namespace::FILE_O_READ);
|
||||
|
||||
// Methods to determine if the requested file path exists.
|
||||
bool exists (char const *filepath);
|
||||
|
||||
// Create the requested directory hierarchy--if intermediate directories
|
||||
// do not exist they will be created.
|
||||
bool mkdir (char const *filepath);
|
||||
|
||||
// Delete the file.
|
||||
bool remove (char const *filepath);
|
||||
|
||||
// Delete a folder (must be empty)
|
||||
bool rmdir (char const *filepath);
|
||||
|
||||
// Delete a folder (recursively)
|
||||
bool rmdir_r (char const *filepath);
|
||||
|
||||
// format file system
|
||||
bool format (void);
|
||||
|
||||
lfs_t* getFS(void)
|
||||
{
|
||||
return &_lfs;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool _mounted;
|
||||
struct lfs_config* _lfs_cfg;
|
||||
lfs_t _lfs;
|
||||
};
|
||||
|
||||
#if !CFG_DEBUG
|
||||
#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, NULL)
|
||||
#define PRINT_LFS_ERR(_err)
|
||||
#else
|
||||
#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, dbg_strerr_lfs)
|
||||
#define PRINT_LFS_ERR(_err) VERIFY_MESS(_err, dbg_strerr_lfs)
|
||||
|
||||
const char* dbg_strerr_lfs (int32_t err);
|
||||
#endif
|
||||
|
||||
#endif /* ADAFRUIT_LITTLEFS_H_ */
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Adafruit_LittleFS.h"
|
||||
#include "littlefs/lfs.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
File::File (Adafruit_LittleFS &fs)
|
||||
{
|
||||
_fs = &fs;
|
||||
_is_dir = false;
|
||||
_name[0] = 0;
|
||||
_dir_path = NULL;
|
||||
|
||||
_dir = NULL;
|
||||
_file = NULL;
|
||||
}
|
||||
|
||||
File::File (char const *filename, uint8_t mode, Adafruit_LittleFS &fs)
|
||||
: File(fs)
|
||||
{
|
||||
this->open(filename, mode);
|
||||
}
|
||||
|
||||
bool File::_open_file (char const *filepath, uint8_t mode)
|
||||
{
|
||||
int flags = (mode == FILE_O_READ) ? LFS_O_RDONLY :
|
||||
(mode == FILE_O_WRITE) ? (LFS_O_RDWR | LFS_O_CREAT) : 0;
|
||||
|
||||
if ( flags )
|
||||
{
|
||||
_file = (lfs_file_t*) rtos_malloc(sizeof(lfs_file_t));
|
||||
if (!_file) return false;
|
||||
|
||||
int rc = lfs_file_open(_fs->getFS(), _file, filepath, flags);
|
||||
|
||||
if ( rc )
|
||||
{
|
||||
// failed to open
|
||||
PRINT_LFS_ERR(rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
// move to end of file
|
||||
if ( mode == FILE_O_WRITE ) lfs_file_seek(_fs->getFS(), _file, 0, LFS_SEEK_END);
|
||||
|
||||
_is_dir = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool File::_open_dir (char const *filepath)
|
||||
{
|
||||
_dir = (lfs_dir_t*) rtos_malloc(sizeof(lfs_dir_t));
|
||||
if (!_dir) return false;
|
||||
|
||||
int rc = lfs_dir_open(_fs->getFS(), _dir, filepath);
|
||||
|
||||
if ( rc )
|
||||
{
|
||||
// failed to open
|
||||
PRINT_LFS_ERR(rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
_is_dir = true;
|
||||
|
||||
_dir_path = (char*) rtos_malloc(strlen(filepath) + 1);
|
||||
strcpy(_dir_path, filepath);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool File::open (char const *filepath, uint8_t mode)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
// close if currently opened
|
||||
if ( (*this) ) close();
|
||||
|
||||
struct lfs_info info;
|
||||
int rc = lfs_stat(_fs->getFS(), filepath, &info);
|
||||
|
||||
if ( LFS_ERR_OK == rc )
|
||||
{
|
||||
// file existed, open file or directory accordingly
|
||||
ret = (info.type == LFS_TYPE_REG) ? _open_file(filepath, mode) : _open_dir(filepath);
|
||||
}
|
||||
else if ( LFS_ERR_NOENT == rc )
|
||||
{
|
||||
// file not existed, only proceed with FILE_O_WRITE mode
|
||||
if ( mode == FILE_O_WRITE ) ret = _open_file(filepath, mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_LFS_ERR(rc);
|
||||
}
|
||||
|
||||
// save bare file name
|
||||
if (ret)
|
||||
{
|
||||
char const* splash = strrchr(filepath, '/');
|
||||
strncpy(_name, splash ? (splash + 1) : filepath, LFS_NAME_MAX);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t File::write (uint8_t ch)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return write(&ch, 1);
|
||||
}
|
||||
|
||||
size_t File::write (uint8_t const *buf, size_t size)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
|
||||
lfs_ssize_t wrcount = lfs_file_write(_fs->getFS(), _file, buf, size);
|
||||
VERIFY(wrcount > 0, 0);
|
||||
return wrcount;
|
||||
}
|
||||
|
||||
int File::read (void)
|
||||
{
|
||||
VERIFY(!_is_dir, -1);
|
||||
uint8_t ch;
|
||||
return (read(&ch, 1) > 0) ? ch : -1;
|
||||
}
|
||||
|
||||
int File::read (void *buf, uint16_t nbyte)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return lfs_file_read(_fs->getFS(), _file, buf, nbyte);
|
||||
}
|
||||
|
||||
int File::peek (void)
|
||||
{
|
||||
VERIFY(!_is_dir, -1);
|
||||
|
||||
int ch = read();
|
||||
uint32_t pos = position();
|
||||
seek((pos > 0) ? (pos - 1) : 0);
|
||||
return ch;
|
||||
}
|
||||
|
||||
int File::available (void)
|
||||
{
|
||||
return size() - position();
|
||||
}
|
||||
|
||||
bool File::seek (uint32_t pos)
|
||||
{
|
||||
VERIFY(!_is_dir, false);
|
||||
return lfs_file_seek(_fs->getFS(), _file, pos, LFS_SEEK_SET) >= 0;
|
||||
}
|
||||
|
||||
uint32_t File::position (void)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return lfs_file_tell(_fs->getFS(), _file);
|
||||
}
|
||||
|
||||
uint32_t File::size (void)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return lfs_file_size(_fs->getFS(), _file);
|
||||
}
|
||||
|
||||
void File::flush (void)
|
||||
{
|
||||
VERIFY(!_is_dir,);
|
||||
lfs_file_sync(_fs->getFS(), _file);
|
||||
}
|
||||
|
||||
void File::close (void)
|
||||
{
|
||||
if ( (*this) )
|
||||
{
|
||||
if ( _is_dir )
|
||||
{
|
||||
lfs_dir_close(_fs->getFS(), _dir);
|
||||
rtos_free(_dir);
|
||||
_dir = NULL;
|
||||
|
||||
if ( _dir_path ) rtos_free(_dir_path);
|
||||
_dir_path = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
lfs_file_close(_fs->getFS(), _file);
|
||||
rtos_free(_file);
|
||||
_file = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File::operator bool (void)
|
||||
{
|
||||
return (_file != NULL) || (_dir != NULL);
|
||||
}
|
||||
|
||||
char const* File::name (void)
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
bool File::isDirectory (void)
|
||||
{
|
||||
return _is_dir;
|
||||
}
|
||||
|
||||
File File::openNextFile (uint8_t mode)
|
||||
{
|
||||
File file(*_fs);
|
||||
|
||||
if ( !_is_dir ) return file;
|
||||
|
||||
struct lfs_info info;
|
||||
|
||||
int rc;
|
||||
|
||||
// lfs_dir_read return 0 when reaching end of directory, 1 if found an entry
|
||||
// skip "." and ".." entries
|
||||
do
|
||||
{
|
||||
rc = lfs_dir_read(_fs->getFS(), _dir, &info);
|
||||
} while ( rc == 1 && (!strcmp(".", info.name) || !strcmp("..", info.name)) );
|
||||
|
||||
if ( rc == 1 )
|
||||
{
|
||||
// string cat name with current folder
|
||||
char filepath[strlen(_dir_path) + 1 + strlen(info.name) + 1];
|
||||
|
||||
strcpy(filepath, _dir_path);
|
||||
if ( !(_dir_path[0] == '/' && _dir_path[1] == 0) ) strcat(filepath, "/"); // only add '/' if cwd is not root
|
||||
strcat(filepath, info.name);
|
||||
|
||||
file.open(filepath, mode);
|
||||
}
|
||||
else if ( rc < 0 )
|
||||
{
|
||||
PRINT_LFS_ERR(rc);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void File::rewindDirectory (void)
|
||||
{
|
||||
VERIFY_LFS(lfs_dir_rewind(_fs->getFS(), _dir),);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUIT_LITTLEFS_FILE_H_
|
||||
#define ADAFRUIT_LITTLEFS_FILE_H_
|
||||
|
||||
// Forward declaration
|
||||
class Adafruit_LittleFS;
|
||||
|
||||
namespace Adafruit_LittleFS_Namespace
|
||||
{
|
||||
|
||||
// avoid conflict with other FileSystem FILE_READ/FILE_WRITE
|
||||
enum
|
||||
{
|
||||
FILE_O_READ = 0,
|
||||
FILE_O_WRITE = 1,
|
||||
};
|
||||
|
||||
class File : public Stream
|
||||
{
|
||||
public:
|
||||
File (Adafruit_LittleFS &fs);
|
||||
File (char const *filename, uint8_t mode, Adafruit_LittleFS &fs);
|
||||
|
||||
bool open (char const *filename, uint8_t mode);
|
||||
|
||||
//------------- Stream API -------------//
|
||||
virtual size_t write (uint8_t ch);
|
||||
virtual size_t write (uint8_t const *buf, size_t size);
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
virtual int read (void);
|
||||
int read (void *buf, uint16_t nbyte);
|
||||
|
||||
virtual int peek (void);
|
||||
virtual int available (void);
|
||||
virtual void flush (void);
|
||||
|
||||
bool seek (uint32_t pos);
|
||||
uint32_t position (void);
|
||||
uint32_t size (void);
|
||||
|
||||
void close (void);
|
||||
operator bool (void);
|
||||
char const* name (void);
|
||||
|
||||
bool isDirectory (void);
|
||||
File openNextFile (uint8_t mode = FILE_O_READ);
|
||||
void rewindDirectory (void);
|
||||
|
||||
private:
|
||||
Adafruit_LittleFS* _fs;
|
||||
|
||||
bool _is_dir;
|
||||
|
||||
union {
|
||||
lfs_file_t* _file;
|
||||
lfs_dir_t* _dir;
|
||||
};
|
||||
|
||||
char* _dir_path;
|
||||
char _name[LFS_NAME_MAX+1];
|
||||
|
||||
bool _open_file(char const *filepath, uint8_t mode);
|
||||
bool _open_dir (char const *filepath);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* ADAFRUIT_LITTLEFS_FILE_H_ */
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -13,7 +13,8 @@
|
||||
//#include <pstorage.h>
|
||||
//#include <app_scheduler.h>
|
||||
#include <nrf_soc.h>
|
||||
#include "Bluefruit_FileIO.h"
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
#include "utility/debug.h"
|
||||
|
||||
#include "rtos.h"
|
||||
@@ -21,6 +22,8 @@
|
||||
|
||||
#include "crypto.h"
|
||||
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
#define CRYPTO_INSTANCE 2 // Change this to force key regeneration on next run
|
||||
|
||||
crypto_keys_t crypto_keys;
|
||||
@@ -108,7 +111,7 @@ static uint8_t crypto_loadKeys(void)
|
||||
|
||||
uint32_t keylen = sizeof(keys);
|
||||
|
||||
File file(CRYPTO_KEYFILE, FILE_READ, InternalFS);
|
||||
File file(CRYPTO_KEYFILE, FILE_O_READ, InternalFS);
|
||||
VERIFY(file, 0);
|
||||
|
||||
keylen = file.read(&keys, keylen);
|
||||
@@ -162,7 +165,7 @@ void crypto_storeKeys(void)
|
||||
keys.valid0 = 0x55;
|
||||
keys.valid1 = 0xAA;
|
||||
|
||||
File file(CRYPTO_KEYFILE, FILE_WRITE, InternalFS);
|
||||
File file(CRYPTO_KEYFILE, FILE_O_WRITE, InternalFS);
|
||||
VERIFY(file,);
|
||||
|
||||
file.write(&keys, sizeof(keys));
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
#include <bluefruit.h>
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
|
||||
// BLE Service
|
||||
BLEDfu bledfu; // OTA DFU service
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ void setup()
|
||||
Bluefruit.setName("Bluefruit52");
|
||||
|
||||
//InternalFS.remove(CRYPTO_KEYFILE);
|
||||
//File file(CRYPTO_KEYFILE, FILE_WRITE, InternalFS);
|
||||
//File file(CRYPTO_KEYFILE, FILE_O_WRITE, InternalFS);
|
||||
//file.write(&test_keys, sizeof(test_keys));
|
||||
//file.close();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=Adafruit Bluefruit nRF52 Libraries
|
||||
version=0.10.5
|
||||
version=0.11.0
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for nRF52-based Adafruit Bluefruit LE modules
|
||||
|
||||
@@ -35,10 +35,14 @@
|
||||
/**************************************************************************/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Bluefruit_FileIO.h"
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
|
||||
#include "bonding.h"
|
||||
#include "bluefruit.h"
|
||||
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
#define BOND_DEBUG 0
|
||||
|
||||
#if (CFG_DEBUG == 1 && BOND_DEBUG == 1) || (CFG_DEBUG >= 2)
|
||||
@@ -100,7 +104,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t* bk
|
||||
// delete if file already exists
|
||||
if ( InternalFS.exists(filename) ) InternalFS.remove(filename);
|
||||
|
||||
File file(filename, FILE_WRITE, InternalFS);
|
||||
File file(filename, FILE_O_WRITE, InternalFS);
|
||||
VERIFY(file,);
|
||||
|
||||
//------------- save keys -------------//
|
||||
@@ -137,7 +141,7 @@ bool bond_load_keys(uint8_t role, uint16_t ediv, bond_keys_t* bkeys)
|
||||
char filename[BOND_FNAME_LEN];
|
||||
get_fname(filename, role, ediv);
|
||||
|
||||
File file(filename, FILE_READ, InternalFS);
|
||||
File file(filename, FILE_O_READ, InternalFS);
|
||||
VERIFY(file);
|
||||
|
||||
int keylen = file.read();
|
||||
@@ -167,7 +171,7 @@ static void bond_save_cccd_dfr (uint8_t role, uint16_t conn_hdl, uint16_t ediv)
|
||||
char filename[BOND_FNAME_LEN];
|
||||
get_fname(filename, role, ediv);
|
||||
|
||||
File file(filename, FILE_WRITE, InternalFS);
|
||||
File file(filename, FILE_O_WRITE, InternalFS);
|
||||
VERIFY(file,);
|
||||
|
||||
file.seek(0); // write mode start at the end, seek to beginning
|
||||
@@ -200,7 +204,7 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, uint16_t ediv)
|
||||
char filename[BOND_FNAME_LEN];
|
||||
get_fname(filename, role, ediv);
|
||||
|
||||
File file(filename, FILE_READ, InternalFS);
|
||||
File file(filename, FILE_O_READ, InternalFS);
|
||||
|
||||
if ( file )
|
||||
{
|
||||
@@ -237,10 +241,10 @@ void bond_print_list(uint8_t role)
|
||||
{
|
||||
char const * dpath = (role == BLE_GAP_ROLE_PERIPH ? BOND_DIR_PRPH : BOND_DIR_CNTR);
|
||||
|
||||
File dir(dpath, FILE_READ, InternalFS);
|
||||
File dir(dpath, FILE_O_READ, InternalFS);
|
||||
File file(InternalFS);
|
||||
|
||||
while ( (file = dir.openNextFile(FILE_READ)) )
|
||||
while ( (file = dir.openNextFile(FILE_O_READ)) )
|
||||
{
|
||||
if ( !file.isDirectory() && bdata_skip_field(&file) ) // skip key
|
||||
{
|
||||
@@ -268,10 +272,10 @@ bool bond_find_cntr(ble_gap_addr_t const * addr, bond_keys_t* bkeys)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
File dir(BOND_DIR_CNTR, FILE_READ, InternalFS);
|
||||
File dir(BOND_DIR_CNTR, FILE_O_READ, InternalFS);
|
||||
File file(InternalFS);
|
||||
|
||||
while ( (file = dir.openNextFile(FILE_READ)) )
|
||||
while ( (file = dir.openNextFile(FILE_O_READ)) )
|
||||
{
|
||||
// Read bond data of each stored file
|
||||
int keylen = file.read();
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF52 based Bluefruit LE modules
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <Bluefruit_FileIO.h>
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
|
||||
Serial.println("ExternalFS Format Example");
|
||||
Serial.println();
|
||||
|
||||
// Wait for user input to run.
|
||||
Serial.println("This sketch will destroy all of your data in External Flash!");
|
||||
Serial.print("Enter any keys to continue:");
|
||||
while ( !Serial.available() ) delay(10);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// Initialize Internal File System
|
||||
ExternalFS.begin();
|
||||
|
||||
Serial.print("Formating ...");
|
||||
|
||||
// Format without erase
|
||||
// Pass true for full external flash erasing (take time)
|
||||
ExternalFS.format(false);
|
||||
|
||||
Serial.println("Done");
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF52 based Bluefruit LE modules
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include "flash/flash_qspi.h"
|
||||
#include <bluefruit.h>
|
||||
#include "Adafruit_TinyUSB.h"
|
||||
#include <Bluefruit_FileIO.h>
|
||||
|
||||
/* This example print out External Flash contents up to
|
||||
* MAX_LEVEL level of directories (including root)
|
||||
* WARNING: This example uses recursive call to print out directory tree
|
||||
* be extra careful, high number of MAX_LEVEL can cause memory overflow
|
||||
*/
|
||||
#define MAX_LEVEL 2
|
||||
|
||||
Adafruit_USBD_MSC usbmsc;
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup()
|
||||
{
|
||||
// block count and size are defined in variant.h
|
||||
usbmsc.setCapacity(USB_MSC_BLOCK_COUNT, USB_MSC_BLOCK_SIZE);
|
||||
usbmsc.setCallback(fl_read_cb, fl_write_cb, fl_flush_cb);
|
||||
usbmsc.begin();
|
||||
|
||||
Serial.begin(115200);
|
||||
while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
|
||||
Serial.println("ExternalFS List Files Example");
|
||||
|
||||
// Initialize Internal File System
|
||||
ExternalFS.begin();
|
||||
|
||||
// Print whole directory tree of root whose level is 0
|
||||
printTreeDir("/", 0);
|
||||
|
||||
// Print prompt
|
||||
Serial.println();
|
||||
Serial.println("Enter anything to print directory tree (again):");
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop()
|
||||
{
|
||||
if ( Serial.available() )
|
||||
{
|
||||
delay(10); // delay for all input arrived
|
||||
while( Serial.available() ) Serial.read();
|
||||
|
||||
printTreeDir("/", 0);
|
||||
|
||||
// Print prompt
|
||||
Serial.println();
|
||||
Serial.println("Enter anything to print directory tree (again):");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t fl_read_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
(void) lun;
|
||||
return flash_qspi_read(buffer, lba * USB_MSC_BLOCK_SIZE + offset, bufsize);
|
||||
}
|
||||
|
||||
int32_t fl_write_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize)
|
||||
{
|
||||
(void) lun;
|
||||
|
||||
uint32_t wrcount = flash_qspi_write(lba * USB_MSC_BLOCK_SIZE + offset, buffer, bufsize);
|
||||
|
||||
// update ExternalFS cache since USB write it out of its awareness
|
||||
ExternalFS.updateCache(lba, buffer, bufsize);
|
||||
|
||||
return wrcount;
|
||||
}
|
||||
|
||||
void fl_flush_cb (uint8_t lun)
|
||||
{
|
||||
(void) lun;
|
||||
flash_qspi_flush();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Print out whole directory tree of an folder
|
||||
until the level reach MAX_LEVEL
|
||||
|
||||
@note Recursive call
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void printTreeDir(const char* cwd, uint8_t level)
|
||||
{
|
||||
// Open the input folder
|
||||
File dir(cwd, FILE_READ, ExternalFS);
|
||||
|
||||
// Print root
|
||||
if (level == 0) Serial.println("root");
|
||||
|
||||
// File within folder
|
||||
File item(ExternalFS);
|
||||
|
||||
// Loop through the directory
|
||||
while( (item = dir.openNextFile(FILE_READ)) )
|
||||
{
|
||||
// Indentation according to dir level
|
||||
for(int i=0; i<level; i++) Serial.print("| ");
|
||||
|
||||
Serial.print("|_ ");
|
||||
Serial.print( item.name() );
|
||||
|
||||
if ( item.isDirectory() )
|
||||
{
|
||||
Serial.println("/");
|
||||
|
||||
// ATTENTION recursive call to print sub folder with level+1 !!!!!!!!
|
||||
// High number of MAX_LEVEL can cause memory overflow
|
||||
if ( level < MAX_LEVEL )
|
||||
{
|
||||
printTreeDir( item.path(), level+1 );
|
||||
}
|
||||
}else
|
||||
{
|
||||
// Print file size starting from position 30
|
||||
int pos = level*3 + 3 + strlen(item.name());
|
||||
|
||||
// Print padding
|
||||
for (int i=pos; i<30; i++) Serial.print(' ');
|
||||
|
||||
// Print at least one extra space in case current position > 50
|
||||
Serial.print(' ');
|
||||
|
||||
Serial.print( item.size() );
|
||||
Serial.println( " Bytes");
|
||||
}
|
||||
|
||||
item.close();
|
||||
}
|
||||
|
||||
dir.close();
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF52 based Bluefruit LE modules
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <Bluefruit_FileIO.h>
|
||||
|
||||
#define FILENAME "/adafruit.txt"
|
||||
|
||||
#define CONTENTS "Bluefruit Feather52's file contents"
|
||||
|
||||
File file (ExternalFS);
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
|
||||
Serial.println("External Read Write File Example");
|
||||
Serial.println();
|
||||
|
||||
// Wait for user input to run. Otherwise the code will
|
||||
// always run immediately after flash and create the FILENAME in advance
|
||||
Serial.print("Enter to any keys to continue:");
|
||||
while ( !Serial.available() )
|
||||
{
|
||||
delay(1);
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// Initialize Internal File System
|
||||
ExternalFS.begin();
|
||||
|
||||
file.open(FILENAME, FILE_READ);
|
||||
|
||||
// file existed
|
||||
if ( file )
|
||||
{
|
||||
Serial.println(FILENAME " file exists");
|
||||
|
||||
uint32_t readlen;
|
||||
char buffer[64] = { 0 };
|
||||
readlen = file.read(buffer, sizeof(buffer));
|
||||
|
||||
buffer[readlen] = 0;
|
||||
Serial.println(buffer);
|
||||
file.close();
|
||||
}else
|
||||
{
|
||||
Serial.print("Open " FILENAME " file to write ... ");
|
||||
|
||||
if( file.open(FILENAME, FILE_WRITE) )
|
||||
{
|
||||
Serial.println("OK");
|
||||
file.write(CONTENTS, strlen(CONTENTS));
|
||||
file.close();
|
||||
}else
|
||||
{
|
||||
Serial.println("Failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
name=Adafruit File System Libraries
|
||||
version=0.10.5
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for nRF52-based Adafruit Bluefruit LE modules
|
||||
paragraph=Arduino library for nRF52-based Adafruit Bluefruit LE modules
|
||||
category=Communication
|
||||
url=https://github.com/adafruit/Adafruit_nRF52_Arduino
|
||||
architectures=nrf52
|
||||
includes=Bluefruit_FileIO.h
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Bluefruit_FileIO.h"
|
||||
|
||||
namespace BluefruitFS
|
||||
{
|
||||
|
||||
File::File (FileSystemClass &fs)
|
||||
{
|
||||
_fs = &fs;
|
||||
_hdl = NULL;
|
||||
_path = NULL;
|
||||
_is_dir = false;
|
||||
}
|
||||
|
||||
File::File (char const *filename, uint8_t mode, FileSystemClass &fs)
|
||||
{
|
||||
_fs = &fs;
|
||||
_hdl = NULL;
|
||||
_path = NULL;
|
||||
_is_dir = false;
|
||||
|
||||
open(filename, mode);
|
||||
}
|
||||
|
||||
File& File::operator = (const File &rhs)
|
||||
{
|
||||
// close if currently opened
|
||||
if ( _hdl ) close();
|
||||
memcpy(this, &rhs, sizeof(File));
|
||||
return *this;
|
||||
}
|
||||
|
||||
File::~File ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool File::open (char const *filename, uint8_t mode)
|
||||
{
|
||||
// close if currently opened
|
||||
if ( _hdl ) close();
|
||||
|
||||
*this = _fs->open(filename, mode);
|
||||
return _hdl != NULL;
|
||||
}
|
||||
|
||||
size_t File::write (uint8_t ch)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return write(&ch, 1);
|
||||
}
|
||||
|
||||
size_t File::write (uint8_t const *buf, size_t size)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return _fs->_f_write(_hdl, buf, size);
|
||||
}
|
||||
|
||||
int File::read (void)
|
||||
{
|
||||
VERIFY(!_is_dir, -1);
|
||||
uint8_t ch;
|
||||
return (read(&ch, 1) > 0) ? ch : -1;
|
||||
}
|
||||
|
||||
int File::read (void *buf, uint16_t nbyte)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return _fs->_f_read(_hdl, buf, nbyte);
|
||||
}
|
||||
|
||||
int File::peek (void)
|
||||
{
|
||||
VERIFY(!_is_dir, -1);
|
||||
|
||||
int ch = read();
|
||||
uint32_t pos = position();
|
||||
seek((pos > 0) ? (pos - 1) : 0);
|
||||
return ch;
|
||||
}
|
||||
|
||||
int File::available (void)
|
||||
{
|
||||
return size() - position();
|
||||
}
|
||||
|
||||
bool File::seek (uint32_t pos)
|
||||
{
|
||||
VERIFY(!_is_dir, false);
|
||||
return _fs->_f_seek(_hdl, pos);
|
||||
}
|
||||
|
||||
uint32_t File::position (void)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return _fs->_f_position(_hdl);
|
||||
}
|
||||
|
||||
uint32_t File::size (void)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return _fs->_f_size(_hdl);
|
||||
}
|
||||
|
||||
void File::flush (void)
|
||||
{
|
||||
VERIFY(!_is_dir,);
|
||||
_fs->_f_flush(_hdl);
|
||||
}
|
||||
|
||||
void File::close (void)
|
||||
{
|
||||
if ( _hdl )
|
||||
{
|
||||
_fs->_f_close(_hdl, _is_dir);
|
||||
rtos_free(_hdl);
|
||||
}
|
||||
|
||||
if ( _path ) rtos_free(_path);
|
||||
|
||||
_hdl = NULL;
|
||||
_path = NULL;
|
||||
}
|
||||
|
||||
File::operator bool (void)
|
||||
{
|
||||
return _hdl != NULL;
|
||||
}
|
||||
|
||||
char const* File::name (void)
|
||||
{
|
||||
// return barename only
|
||||
char* barename = strrchr(_path, '/');
|
||||
return barename ? (barename + 1) : _path;
|
||||
}
|
||||
|
||||
char const* File::path (void)
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
bool File::isDirectory (void)
|
||||
{
|
||||
return _is_dir;
|
||||
}
|
||||
|
||||
File File::openNextFile (uint8_t mode)
|
||||
{
|
||||
if ( !_is_dir ) return File(*_fs);
|
||||
return _fs->_f_openNextFile(_hdl, _path, mode);
|
||||
}
|
||||
|
||||
void File::rewindDirectory (void)
|
||||
{
|
||||
_fs->_f_rewindDirectory(_hdl);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2013 Arduino LLC. All right reserved.
|
||||
Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __FILEIO_H__
|
||||
#define __FILEIO_H__
|
||||
|
||||
#include <Stream.h>
|
||||
|
||||
#define FILE_READ 0
|
||||
#define FILE_WRITE 1
|
||||
|
||||
#define FILE_NAME_MAX 255
|
||||
|
||||
class LittleFS;
|
||||
class FatFS;
|
||||
|
||||
namespace BluefruitFS
|
||||
{
|
||||
|
||||
class FileSystemClass;
|
||||
|
||||
class File: public Stream
|
||||
{
|
||||
public:
|
||||
File (FileSystemClass &fs);
|
||||
File (char const *filename, uint8_t mode, FileSystemClass &fs);
|
||||
File & operator = (const File &rhs);
|
||||
virtual ~File ();
|
||||
|
||||
bool open (char const *filename, uint8_t mode);
|
||||
|
||||
virtual size_t write (uint8_t ch);
|
||||
virtual size_t write (uint8_t const *buf, size_t size);
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
virtual int read (void);
|
||||
int read (void *buf, uint16_t nbyte);
|
||||
|
||||
virtual int peek (void);
|
||||
virtual int available (void);
|
||||
virtual void flush (void);
|
||||
|
||||
bool seek (uint32_t pos);
|
||||
uint32_t position (void);
|
||||
uint32_t size (void);
|
||||
|
||||
void close (void);
|
||||
operator bool (void);
|
||||
char const* name (void);
|
||||
char const* path (void);
|
||||
|
||||
bool isDirectory (void);
|
||||
File openNextFile (uint8_t mode = FILE_READ);
|
||||
void rewindDirectory (void);
|
||||
|
||||
private:
|
||||
FileSystemClass* _fs;
|
||||
void* _hdl;
|
||||
char* _path;
|
||||
bool _is_dir;
|
||||
|
||||
friend class ::LittleFS;
|
||||
friend class ::FatFS;
|
||||
};
|
||||
|
||||
// Abstract Interface Class
|
||||
class FileSystemClass
|
||||
{
|
||||
public:
|
||||
virtual bool begin () = 0;
|
||||
|
||||
// Open the specified file/directory with the supplied mode (e.g. read or
|
||||
// write, etc). Returns a File object for interacting with the file.
|
||||
// Note that currently only one file can be open at a time.
|
||||
virtual File open (char const *filename, uint8_t mode) = 0;
|
||||
|
||||
// Methods to determine if the requested file path exists.
|
||||
virtual bool exists (char const *filepath) = 0;
|
||||
|
||||
// Create the requested directory hierarchy--if intermediate directories
|
||||
// do not exist they will be created.
|
||||
virtual bool mkdir (char const *filepath) = 0;
|
||||
|
||||
// Delete the file.
|
||||
virtual bool remove (char const *filepath) = 0;
|
||||
|
||||
// Delete a folder (must be empty)
|
||||
virtual bool rmdir (char const *filepath) = 0;
|
||||
|
||||
// Delete a folder (recursively)
|
||||
virtual bool rmdir_r (char const *filepath) = 0;
|
||||
|
||||
// format whole file system
|
||||
virtual bool format (bool eraseall);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal API, shouldn't call directly
|
||||
//--------------------------------------------------------------------+
|
||||
virtual size_t _f_write (void* fhdl, uint8_t const *buf, size_t size) = 0;
|
||||
virtual int _f_read (void* fhdl, void *buf, uint16_t nbyte) = 0;
|
||||
virtual void _f_flush (void* fhdl) = 0;
|
||||
virtual void _f_close (void* fhdl, bool is_dir) = 0;
|
||||
|
||||
virtual bool _f_seek (void* fhdl, uint32_t pos) = 0;
|
||||
virtual uint32_t _f_position (void* fhdl) = 0;
|
||||
virtual uint32_t _f_size (void* fhdl) = 0;
|
||||
|
||||
virtual File _f_openNextFile (void* fhdl, char const* cwd, uint8_t mode) = 0;
|
||||
virtual void _f_rewindDirectory (void* fhdl) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// We enclose File and FileSystem classes in namespace BluefruitFS to avoid
|
||||
// conflicts with legacy SD library.
|
||||
|
||||
// This ensure compatibility with older sketches that uses only Bridge lib
|
||||
// (the user can still use File instead of BridgeFile)
|
||||
using namespace BluefruitFS;
|
||||
|
||||
// This allows sketches to use BluefruitFS::File together with SD library
|
||||
// (you must use BridgeFile instead of File when needed to disambiguate)
|
||||
typedef BluefruitFS::File BluefruitFile;
|
||||
|
||||
#include "InternalFS.h"
|
||||
#include "ExternalFS.h"
|
||||
|
||||
#endif
|
||||
@@ -1,377 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <string.h>
|
||||
#include "ExternalFS.h"
|
||||
#include "flash/flash_qspi.h"
|
||||
|
||||
// up to 11 characters
|
||||
#define VOLUME_LABEL "BLUEFRUIT"
|
||||
const char README_CONTENT[] =
|
||||
"This drive can be used to add or remove files to the on-board \r\n"
|
||||
"SPI flash IC on the Adafruit Bluefruit nRF52 Feather.\r\n"
|
||||
"\r\n"
|
||||
"For information on how to use the Bluefruit nRF52 Feather, see the following links:\r\n"
|
||||
"\r\n"
|
||||
"Adafruit Bluefruit nRF52 Feather Learning Guide:\r\n"
|
||||
"https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide\r\n"
|
||||
"\r\n"
|
||||
"Adafruit Bluefruit nRF52 Feather Product Page:\r\n"
|
||||
"- https://www.adafruit.com/product/4062\r\n";
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
#if !CFG_DEBUG
|
||||
|
||||
#define VERIFY_FAT(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, NULL)
|
||||
#define PRINT_FAT_ERR(_err)
|
||||
|
||||
#else
|
||||
|
||||
#define VERIFY_FAT(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, dbg_strerr_fat)
|
||||
#define PRINT_FAT_ERR(_err) VERIFY_MESS(_err, dbg_strerr_fat)
|
||||
|
||||
static const char* dbg_strerr_fat (int32_t err)
|
||||
{
|
||||
switch ( err )
|
||||
{
|
||||
case FR_DISK_ERR:
|
||||
return "FR_DISK_ERR";
|
||||
case FR_INT_ERR:
|
||||
return "FR_INT_ERR";
|
||||
case FR_NOT_READY:
|
||||
return "FR_NOT_READY";
|
||||
case FR_NO_FILE:
|
||||
return "FR_NO_FILE";
|
||||
case FR_NO_PATH:
|
||||
return "FR_NO_PATH";
|
||||
case FR_INVALID_NAME:
|
||||
return "FR_INVALID_NAME";
|
||||
case FR_DENIED:
|
||||
return "FR_DENIED";
|
||||
case FR_EXIST:
|
||||
return "FR_EXIST";
|
||||
case FR_INVALID_OBJECT:
|
||||
return "FR_INVALID_OBJECT";
|
||||
case FR_WRITE_PROTECTED:
|
||||
return "FR_WRITE_PROTECTED";
|
||||
case FR_INVALID_DRIVE:
|
||||
return "FR_INVALID_DRIVE";
|
||||
case FR_NOT_ENABLED:
|
||||
return "FR_NOT_ENABLED";
|
||||
case FR_NO_FILESYSTEM:
|
||||
return "FR_NO_FILESYSTEM";
|
||||
case FR_MKFS_ABORTED:
|
||||
return "FR_MKFS_ABORTED";
|
||||
case FR_TIMEOUT:
|
||||
return "FR_TIMEOUT";
|
||||
case FR_LOCKED:
|
||||
return "FR_LOCKED";
|
||||
case FR_NOT_ENOUGH_CORE:
|
||||
return "FR_NOT_ENOUGH_CORE";
|
||||
case FR_TOO_MANY_OPEN_FILES:
|
||||
return "FR_TOO_MANY_OPEN_FILES";
|
||||
case FR_INVALID_PARAMETER:
|
||||
return "FR_INVALID_PARAMETER";
|
||||
default:
|
||||
return "Unlikely Error";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
FatFS ExternalFS;
|
||||
|
||||
FatFS::FatFS ()
|
||||
{
|
||||
_fs = NULL;
|
||||
_begun = false;
|
||||
}
|
||||
|
||||
FatFS::~FatFS ()
|
||||
{
|
||||
}
|
||||
|
||||
bool FatFS::begin (void)
|
||||
{
|
||||
if ( _begun ) return true;
|
||||
_begun = true;
|
||||
|
||||
if ( !_fs ) _fs = (FATFS*) rtos_malloc(sizeof(FATFS));
|
||||
VERIFY(_fs);
|
||||
|
||||
// Mount file system
|
||||
uint32_t err = f_mount(_fs, "", 1);
|
||||
|
||||
// If FileSystem is not available, format it
|
||||
if ( FR_NO_FILESYSTEM == err )
|
||||
{
|
||||
LOG_LV1("FATFS", "No file system, format it");
|
||||
this->format(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
VERIFY_FAT(err, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FatFS::format (bool eraseall)
|
||||
{
|
||||
if ( eraseall )
|
||||
{
|
||||
LOG_LV2("EFLASH", "full erasing");
|
||||
VERIFY(flash_qspi_chiperase());
|
||||
}
|
||||
|
||||
uint8_t workbuf[FF_MAX_SS];
|
||||
VERIFY_FAT(f_mkfs("", FM_FAT | FM_SFD, 4096, workbuf, FF_MAX_SS), false);
|
||||
VERIFY_FAT(f_setlabel(VOLUME_LABEL), false);
|
||||
VERIFY_FAT(f_mount(_fs, "", 1), false);
|
||||
|
||||
// Always create README file when format
|
||||
File readme("README.TXT", FILE_WRITE, *this);
|
||||
readme.write(README_CONTENT);
|
||||
readme.close();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
File FatFS::_open_file (char const *filepath, uint8_t mode)
|
||||
{
|
||||
BluefruitFS::File file(*this);
|
||||
|
||||
int flags = (mode == FILE_READ) ? FA_READ :
|
||||
(mode == FILE_WRITE) ? (FA_READ | FA_WRITE | FA_OPEN_APPEND) : 0;
|
||||
|
||||
if ( flags )
|
||||
{
|
||||
FIL* fhdl = (FIL*) rtos_malloc(sizeof(FIL));
|
||||
int rc = f_open(fhdl, filepath, flags);
|
||||
|
||||
if ( rc )
|
||||
{
|
||||
rtos_free(fhdl);
|
||||
PRINT_FAT_ERR(rc);
|
||||
}
|
||||
else
|
||||
{
|
||||
file._hdl = fhdl;
|
||||
file._is_dir = false;
|
||||
|
||||
file._path = (char*) rtos_malloc(strlen(filepath) + 1);
|
||||
strcpy(file._path, filepath);
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
File FatFS::_open_dir (char const *filepath)
|
||||
{
|
||||
BluefruitFS::File file(*this);
|
||||
|
||||
DIR* fhdl = (DIR*) rtos_malloc(sizeof(DIR));
|
||||
int rc = f_opendir(fhdl, filepath);
|
||||
|
||||
if ( rc )
|
||||
{
|
||||
rtos_free(fhdl);
|
||||
PRINT_FAT_ERR(rc);
|
||||
}
|
||||
else
|
||||
{
|
||||
file._hdl = fhdl;
|
||||
file._is_dir = true;
|
||||
|
||||
file._path = (char*) rtos_malloc(strlen(filepath) + 1);
|
||||
strcpy(file._path, filepath);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
File FatFS::open (char const *filepath, uint8_t mode)
|
||||
{
|
||||
BluefruitFS::File file(*this);
|
||||
|
||||
FILINFO fno;
|
||||
FRESULT rc = FR_OK;
|
||||
bool is_root = (filepath[0] == '/' && filepath[1] == 0);
|
||||
|
||||
// f_stat return FR_INVALID_NAME for root
|
||||
if ( !is_root ) rc = f_stat(filepath, &fno);
|
||||
|
||||
if ( FR_OK == rc )
|
||||
{
|
||||
// file existed, open file or directory accordingly
|
||||
file = (is_root || (fno.fattrib & AM_DIR)) ? _open_dir(filepath) : _open_file(filepath, mode);
|
||||
}
|
||||
else if ( FR_NO_FILE == rc )
|
||||
{
|
||||
// file not existed, only proceed with FILE_WRITE mode
|
||||
if ( mode == FILE_WRITE ) file = _open_file(filepath, mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_STR(filepath);
|
||||
PRINT_FAT_ERR(rc);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
bool FatFS::exists (char const *filepath)
|
||||
{
|
||||
if ( filepath[0] == '/' && filepath[1] == 0 ) return true; // root always exists
|
||||
|
||||
FILINFO fno;
|
||||
return FR_OK == f_stat(filepath, &fno);
|
||||
}
|
||||
|
||||
bool FatFS::mkdir (char const *filepath)
|
||||
{
|
||||
VERIFY_FAT(f_mkdir(filepath), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FatFS::remove (char const *filepath)
|
||||
{
|
||||
VERIFY_FAT(f_unlink(filepath), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FatFS::rmdir (char const *filepath)
|
||||
{
|
||||
VERIFY_FAT(f_unlink(filepath), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FatFS::rmdir_r (char const *filepath)
|
||||
{
|
||||
// not supported yet
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t FatFS::_f_write (void* fhdl, uint8_t const *buf, size_t size)
|
||||
{
|
||||
UINT byte_write = 0;
|
||||
VERIFY_FAT(f_write((FIL* ) fhdl, buf, size, &byte_write), byte_write);
|
||||
return byte_write;
|
||||
}
|
||||
|
||||
int FatFS::_f_read (void* fhdl, void *buf, uint16_t nbyte)
|
||||
{
|
||||
UINT byte_read = 0;
|
||||
VERIFY_FAT(f_read((FIL* ) fhdl, buf, nbyte, &byte_read), byte_read);
|
||||
return byte_read;
|
||||
}
|
||||
|
||||
void FatFS::_f_flush (void* fhdl)
|
||||
{
|
||||
VERIFY_FAT(f_sync((FIL* ) fhdl),);
|
||||
}
|
||||
|
||||
void FatFS::_f_close (void* fhdl, bool is_dir)
|
||||
{
|
||||
if ( is_dir )
|
||||
{
|
||||
VERIFY_FAT(f_closedir((DIR* ) fhdl),);
|
||||
}
|
||||
else
|
||||
{
|
||||
VERIFY_FAT(f_close((FIL* ) fhdl),);
|
||||
}
|
||||
}
|
||||
|
||||
bool FatFS::_f_seek (void* fhdl, uint32_t pos)
|
||||
{
|
||||
VERIFY_FAT(f_lseek((FIL* ) fhdl, pos), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t FatFS::_f_position (void* fhdl)
|
||||
{
|
||||
return f_tell((FIL* ) fhdl);
|
||||
}
|
||||
|
||||
uint32_t FatFS::_f_size (void* fhdl)
|
||||
{
|
||||
return f_size((FIL* ) fhdl);
|
||||
}
|
||||
|
||||
File FatFS::_f_openNextFile (void* fhdl, char const* cwd, uint8_t mode)
|
||||
{
|
||||
BluefruitFS::File file(*this);
|
||||
|
||||
FILINFO fno;
|
||||
FRESULT rc;
|
||||
|
||||
// f_readdir return FR_OK if there is no error. If there is no more entry,
|
||||
// fno.fname will be set to NUL string
|
||||
VERIFY_FAT(f_readdir((DIR * ) fhdl, &fno), file);
|
||||
|
||||
if ( fno.fname[0] != 0 )
|
||||
{
|
||||
// string cat name with current folder
|
||||
char filepath[strlen(cwd) + 1 + strlen(fno.fname) + 1];
|
||||
|
||||
strcpy(filepath, cwd);
|
||||
if ( !(cwd[0] == '/' && cwd[1] == 0) ) strcat(filepath, "/"); // only add '/' if cwd is not root
|
||||
strcat(filepath, fno.fname);
|
||||
|
||||
file = (fno.fattrib & AM_DIR) ? _open_dir(filepath) : _open_file(filepath, mode);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void FatFS::_f_rewindDirectory (void* fhdl)
|
||||
{
|
||||
VERIFY_FAT(f_rewinddir((DIR * ) fhdl),);
|
||||
}
|
||||
|
||||
// for USB MSC to check and update fatfs sector cache
|
||||
void FatFS::updateCache (uint32_t lba, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
VERIFY(_fs,);
|
||||
if ( (lba <= _fs->winsect) && (_fs->winsect < (lba + bufsize / FF_MAX_SS)) )
|
||||
{
|
||||
memcpy(_fs->win, buffer + FF_MAX_SS * (_fs->winsect - lba), FF_MAX_SS);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef EXTERNALFS_H_
|
||||
#define EXTERNALFS_H_
|
||||
|
||||
#include "Bluefruit_FileIO.h"
|
||||
|
||||
// External Flash uses Fat FS as file system
|
||||
// http://elm-chan.org/fsw/ff/00index_e.html
|
||||
#include "fatfs/source/ff.h"
|
||||
|
||||
class FatFS: public BluefruitFS::FileSystemClass
|
||||
{
|
||||
public:
|
||||
FatFS ();
|
||||
virtual ~FatFS ();
|
||||
|
||||
bool begin (void);
|
||||
BluefruitFS::File open (char const *filepath, uint8_t mode = FILE_READ);
|
||||
bool exists (char const *filepath);
|
||||
bool mkdir (char const *filepath);
|
||||
bool remove (char const *filepath);
|
||||
bool rmdir (char const *filepath);
|
||||
bool rmdir_r (char const *filepath);
|
||||
bool format (bool eraseall);
|
||||
|
||||
// Internal API: shouldn't be used by Arduino sketch
|
||||
virtual size_t _f_write (void* fhdl, uint8_t const *buf, size_t size);
|
||||
virtual int _f_read (void* fhdl, void *buf, uint16_t nbyte);
|
||||
virtual void _f_flush (void* fhdl);
|
||||
virtual void _f_close (void* fhdl, bool is_dir);
|
||||
virtual bool _f_seek (void* fhdl, uint32_t pos);
|
||||
virtual uint32_t _f_position (void* fhdl);
|
||||
virtual uint32_t _f_size (void* fhdl);
|
||||
|
||||
virtual BluefruitFS::File _f_openNextFile (void* fhdl, char const* cwd, uint8_t mode);
|
||||
virtual void _f_rewindDirectory (void* fhdl);
|
||||
|
||||
// Should call when flash contents is changed out of the awareness of ExternalFS such as USB MSC write
|
||||
void updateCache (uint32_t lba, void const* buffer, uint32_t bufsize);
|
||||
|
||||
private:
|
||||
FATFS* _fs;
|
||||
bool _begun;
|
||||
|
||||
BluefruitFS::File _open_file (char const *filepath, uint8_t mode);
|
||||
BluefruitFS::File _open_dir (char const *filepath);
|
||||
};
|
||||
|
||||
extern FatFS ExternalFS;
|
||||
|
||||
#endif /* EXTERNALFS_H_ */
|
||||
@@ -1,488 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <string.h>
|
||||
#include "InternalFS.h"
|
||||
#include "flash/flash_nrf5x.h"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
#define LFS_FLASH_ADDR 0xED000
|
||||
#else
|
||||
#define LFS_FLASH_ADDR 0x6D000
|
||||
#endif
|
||||
|
||||
#define LFS_FLASH_TOTAL_SIZE (7*FLASH_NRF52_PAGE_SIZE)
|
||||
#define LFS_BLOCK_SIZE 128
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// LFS Disk IO
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if !CFG_DEBUG
|
||||
|
||||
#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, NULL)
|
||||
#define PRINT_LFS_ERR(_err)
|
||||
|
||||
#else
|
||||
|
||||
#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, dbg_strerr_lfs)
|
||||
#define PRINT_LFS_ERR(_err) VERIFY_MESS(_err, dbg_strerr_lfs)
|
||||
|
||||
static const char* dbg_strerr_lfs (int32_t err)
|
||||
{
|
||||
switch ( err )
|
||||
{
|
||||
case LFS_ERR_OK:
|
||||
return "LFS_ERR_OK";
|
||||
|
||||
case LFS_ERR_IO:
|
||||
return "LFS_ERR_IO";
|
||||
|
||||
case LFS_ERR_CORRUPT:
|
||||
return "LFS_ERR_CORRUPT";
|
||||
|
||||
case LFS_ERR_NOENT:
|
||||
return "LFS_ERR_NOENT";
|
||||
|
||||
case LFS_ERR_EXIST:
|
||||
return "LFS_ERR_EXIST";
|
||||
|
||||
case LFS_ERR_NOTDIR:
|
||||
return "LFS_ERR_NOTDIR";
|
||||
|
||||
case LFS_ERR_ISDIR:
|
||||
return "LFS_ERR_ISDIR";
|
||||
|
||||
case LFS_ERR_NOTEMPTY:
|
||||
return "LFS_ERR_NOTEMPTY";
|
||||
|
||||
case LFS_ERR_BADF:
|
||||
return "LFS_ERR_BADF";
|
||||
|
||||
case LFS_ERR_INVAL:
|
||||
return "LFS_ERR_INVAL";
|
||||
|
||||
case LFS_ERR_NOSPC:
|
||||
return "LFS_ERR_NOSPC";
|
||||
|
||||
case LFS_ERR_NOMEM:
|
||||
return "LFS_ERR_NOMEM";
|
||||
|
||||
default:
|
||||
{
|
||||
static char errcode[10];
|
||||
sprintf(errcode, "%d", err);
|
||||
return errcode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static inline uint32_t lba2addr(uint32_t block)
|
||||
{
|
||||
return ((uint32_t) LFS_FLASH_ADDR) + block * LFS_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Implementation
|
||||
//--------------------------------------------------------------------+
|
||||
LittleFS InternalFS;
|
||||
|
||||
LittleFS::LittleFS (void) :
|
||||
LittleFS( LFS_BLOCK_SIZE, LFS_BLOCK_SIZE, LFS_BLOCK_SIZE, LFS_FLASH_TOTAL_SIZE / LFS_BLOCK_SIZE, 128)
|
||||
{
|
||||
}
|
||||
|
||||
LittleFS::LittleFS (lfs_size_t read_size, lfs_size_t prog_size, lfs_size_t block_size, lfs_size_t block_count, lfs_size_t lookahead)
|
||||
{
|
||||
varclr(&_lfs_cfg);
|
||||
_lfs_cfg.context = this;
|
||||
_lfs_cfg.read = _iflash_read;
|
||||
_lfs_cfg.prog = _iflash_prog;
|
||||
_lfs_cfg.erase = _iflash_erase;
|
||||
_lfs_cfg.sync = _iflash_sync;
|
||||
|
||||
_lfs_cfg.read_size = read_size;
|
||||
_lfs_cfg.prog_size = prog_size;
|
||||
_lfs_cfg.block_size = block_size;
|
||||
_lfs_cfg.block_count = block_count;
|
||||
_lfs_cfg.lookahead = lookahead;
|
||||
|
||||
_begun = false;
|
||||
_mounted = false;
|
||||
}
|
||||
|
||||
LittleFS::~LittleFS ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool LittleFS::begin (void)
|
||||
{
|
||||
if ( _begun ) return true;
|
||||
_begun = true;
|
||||
|
||||
int err = lfs_mount(&_lfs, &_lfs_cfg);
|
||||
|
||||
// reformat if we can't mount the filesystem
|
||||
if ( LFS_ERR_CORRUPT == err )
|
||||
{
|
||||
LOG_LV1("IFLASH", "Format internal file system");
|
||||
this->format(false);
|
||||
} else {
|
||||
_mounted = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LittleFS::format (bool eraseall)
|
||||
{
|
||||
if ( eraseall ) {
|
||||
_flash_erase_all();
|
||||
}
|
||||
if(_mounted) {
|
||||
VERIFY_LFS(lfs_unmount(&_lfs), false);
|
||||
}
|
||||
VERIFY_LFS(lfs_format(&_lfs, &_lfs_cfg), false);
|
||||
VERIFY_LFS(lfs_mount(&_lfs, &_lfs_cfg), false);
|
||||
|
||||
_mounted = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BluefruitFS::File LittleFS::_open_file (char const *filepath, uint8_t mode)
|
||||
{
|
||||
BluefruitFS::File file(*this);
|
||||
|
||||
int flags = (mode == FILE_READ) ? LFS_O_RDONLY :
|
||||
(mode == FILE_WRITE) ? (LFS_O_RDWR | LFS_O_CREAT) : 0;
|
||||
|
||||
if ( flags )
|
||||
{
|
||||
lfs_file_t* fhdl = (lfs_file_t*) rtos_malloc(sizeof(lfs_file_t));
|
||||
VERIFY(fhdl, file);
|
||||
|
||||
int rc = lfs_file_open(&_lfs, fhdl, filepath, flags);
|
||||
|
||||
if ( rc )
|
||||
{
|
||||
rtos_free(fhdl);
|
||||
PRINT_LFS_ERR(rc);
|
||||
}
|
||||
else
|
||||
{
|
||||
// move to end of file
|
||||
if ( mode == FILE_WRITE ) lfs_file_seek(&_lfs, fhdl, 0, LFS_SEEK_END);
|
||||
|
||||
file._hdl = fhdl;
|
||||
file._is_dir = false;
|
||||
|
||||
file._path = (char*) rtos_malloc(strlen(filepath) + 1);
|
||||
strcpy(file._path, filepath);
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
BluefruitFS::File LittleFS::_open_dir (char const *filepath)
|
||||
{
|
||||
BluefruitFS::File file(*this);
|
||||
|
||||
lfs_dir_t* fhdl = (lfs_dir_t*) rtos_malloc(sizeof(lfs_dir_t));
|
||||
int rc = lfs_dir_open(&_lfs, fhdl, filepath);
|
||||
|
||||
if ( rc )
|
||||
{
|
||||
rtos_free(fhdl);
|
||||
PRINT_LFS_ERR(rc);
|
||||
}
|
||||
else
|
||||
{
|
||||
file._hdl = fhdl;
|
||||
file._is_dir = true;
|
||||
|
||||
file._path = (char*) rtos_malloc(strlen(filepath) + 1);
|
||||
strcpy(file._path, filepath);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
BluefruitFS::File LittleFS::open (char const *filepath, uint8_t mode)
|
||||
{
|
||||
BluefruitFS::File file(*this);
|
||||
struct lfs_info info;
|
||||
|
||||
int rc = lfs_stat(&_lfs, filepath, &info);
|
||||
if ( LFS_ERR_OK == rc )
|
||||
{
|
||||
// file existed, open file or directory accordingly
|
||||
file = (info.type == LFS_TYPE_REG) ? _open_file(filepath, mode) : _open_dir(filepath);
|
||||
}
|
||||
else if ( LFS_ERR_NOENT == rc )
|
||||
{
|
||||
// file not existed, only proceed with FILE_WRITE mode
|
||||
if ( mode == FILE_WRITE ) file = _open_file(filepath, mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_LFS_ERR(rc);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
bool LittleFS::exists (char const *filepath)
|
||||
{
|
||||
struct lfs_info info;
|
||||
return 0 == lfs_stat(&_lfs, filepath, &info);
|
||||
}
|
||||
|
||||
bool LittleFS::mkdir (char const *filepath)
|
||||
{
|
||||
const char* slash = filepath;
|
||||
if ( slash[0] == '/' ) slash++; // skip root '/'
|
||||
|
||||
while ( NULL != (slash = strchr(slash, '/')) )
|
||||
{
|
||||
char parent[slash - filepath + 1] = { 0 };
|
||||
memcpy(parent, filepath, slash - filepath);
|
||||
|
||||
// make intermediate parent
|
||||
int rc = lfs_mkdir(&_lfs, parent);
|
||||
if ( rc != LFS_ERR_OK && rc != LFS_ERR_EXIST )
|
||||
{
|
||||
PRINT_LFS_ERR(rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
slash++;
|
||||
}
|
||||
|
||||
int rc = lfs_mkdir(&_lfs, filepath);
|
||||
if ( rc != LFS_ERR_OK && rc != LFS_ERR_EXIST )
|
||||
{
|
||||
PRINT_LFS_ERR(rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LittleFS::remove (char const *filepath)
|
||||
{
|
||||
VERIFY_LFS(lfs_remove(&_lfs, filepath), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LittleFS::rmdir (char const *filepath)
|
||||
{
|
||||
VERIFY_LFS(lfs_remove(&_lfs, filepath));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LittleFS::rmdir_r (char const *filepath)
|
||||
{
|
||||
/* adafruit: lfs is modified to remove non-empty folder,
|
||||
According to below issue, comment these 2 line won't corrupt filesystem
|
||||
https://github.com/ARMmbed/littlefs/issues/43 */
|
||||
VERIFY_LFS(lfs_remove(&_lfs, filepath));
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// FILE API
|
||||
//--------------------------------------------------------------------+
|
||||
size_t LittleFS::_f_write (void* fhdl, uint8_t const *buf, size_t size)
|
||||
{
|
||||
lfs_ssize_t wrcount = lfs_file_write(&_lfs, (lfs_file_t*) fhdl, buf, size);
|
||||
VERIFY(wrcount > 0, 0);
|
||||
return wrcount;
|
||||
}
|
||||
|
||||
void LittleFS::_f_flush (void* fhdl)
|
||||
{
|
||||
VERIFY_LFS(lfs_file_sync(&_lfs, (lfs_file_t* ) fhdl),);
|
||||
}
|
||||
|
||||
int LittleFS::_f_read (void* fhdl, void *buf, uint16_t nbyte)
|
||||
{
|
||||
return lfs_file_read(&_lfs, (lfs_file_t*) fhdl, buf, nbyte);
|
||||
}
|
||||
|
||||
bool LittleFS::_f_seek (void* fhdl, uint32_t pos)
|
||||
{
|
||||
return lfs_file_seek(&_lfs, (lfs_file_t*) fhdl, pos, LFS_SEEK_SET) >= 0;
|
||||
}
|
||||
|
||||
uint32_t LittleFS::_f_position (void* fhdl)
|
||||
{
|
||||
return lfs_file_tell(&_lfs, (lfs_file_t*) fhdl);
|
||||
}
|
||||
|
||||
uint32_t LittleFS::_f_size (void* fhdl)
|
||||
{
|
||||
return lfs_file_size(&_lfs, (lfs_file_t*) fhdl);
|
||||
}
|
||||
|
||||
void LittleFS::_f_close (void* fhdl, bool is_dir)
|
||||
{
|
||||
if ( is_dir )
|
||||
{
|
||||
lfs_dir_close(&_lfs, (lfs_dir_t *) fhdl);
|
||||
}
|
||||
else
|
||||
{
|
||||
lfs_file_close(&_lfs, (lfs_file_t*) fhdl);
|
||||
}
|
||||
}
|
||||
|
||||
File LittleFS::_f_openNextFile (void* fhdl, char const* cwd, uint8_t mode)
|
||||
{
|
||||
BluefruitFS::File file(*this);
|
||||
struct lfs_info info;
|
||||
|
||||
int rc;
|
||||
|
||||
// lfs_dir_read return 0 when reaching end of directory, 1 if found an entry
|
||||
// skip "." and ".." entries
|
||||
do
|
||||
{
|
||||
rc = lfs_dir_read(&_lfs, (lfs_dir_t *) fhdl, &info);
|
||||
} while ( rc == 1 && (!strcmp(".", info.name) || !strcmp("..", info.name)) );
|
||||
|
||||
if ( rc == 1 )
|
||||
{
|
||||
// string cat name with current folder
|
||||
char filepath[strlen(cwd) + 1 + strlen(info.name) + 1];
|
||||
|
||||
strcpy(filepath, cwd);
|
||||
if ( !(cwd[0] == '/' && cwd[1] == 0) ) strcat(filepath, "/"); // only add '/' if cwd is not root
|
||||
strcat(filepath, info.name);
|
||||
|
||||
file = (info.type == LFS_TYPE_REG) ? _open_file(filepath, mode) : _open_dir(filepath);
|
||||
}
|
||||
else if ( rc < 0 )
|
||||
{
|
||||
PRINT_LFS_ERR(rc);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void LittleFS::_f_rewindDirectory (void* fhdl)
|
||||
{
|
||||
VERIFY_LFS(lfs_dir_rewind(&_lfs, (lfs_dir_t* ) fhdl),);
|
||||
}
|
||||
|
||||
|
||||
int LittleFS::_flash_read (lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
|
||||
{
|
||||
uint32_t addr = lba2addr(block) + off;
|
||||
flash_nrf5x_read(buffer, addr, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Program a region in a block. The block must have previously
|
||||
// been erased. Negative error codes are propogated to the user.
|
||||
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
||||
int LittleFS::_flash_prog (lfs_block_t block, lfs_off_t off, const void *buffer,
|
||||
lfs_size_t size)
|
||||
{
|
||||
uint32_t addr = lba2addr(block) + off;
|
||||
flash_nrf5x_write(addr, buffer, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Erase a block. A block must be erased before being programmed.
|
||||
// The state of an erased block is undefined. Negative error codes
|
||||
// are propogated to the user.
|
||||
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
||||
int LittleFS::_flash_erase (lfs_block_t block)
|
||||
{
|
||||
uint32_t addr = lba2addr(block);
|
||||
|
||||
// implement as write 0xff to whole block address
|
||||
for(int i=0; i <LFS_BLOCK_SIZE; i++)
|
||||
{
|
||||
flash_nrf5x_write8(addr + i, 0xFF);
|
||||
}
|
||||
|
||||
// flash_nrf5x_flush();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LittleFS::_flash_erase_all()
|
||||
{
|
||||
for ( uint32_t addr = LFS_FLASH_ADDR; addr < LFS_FLASH_ADDR + LFS_FLASH_TOTAL_SIZE; addr += FLASH_NRF52_PAGE_SIZE )
|
||||
{
|
||||
flash_nrf5x_erase(addr);
|
||||
}
|
||||
}
|
||||
|
||||
// Sync the state of the underlying block device. Negative error codes
|
||||
// are propogated to the user.
|
||||
int LittleFS::_flash_sync ()
|
||||
{
|
||||
flash_nrf5x_flush();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LittleFS::_iflash_read (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
|
||||
{
|
||||
return ((LittleFS *)c->context)->_flash_read(block, off, buffer, size);
|
||||
}
|
||||
|
||||
// Program a region in a block. The block must have previously
|
||||
// been erased. Negative error codes are propogated to the user.
|
||||
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
||||
int LittleFS::_iflash_prog (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer,
|
||||
lfs_size_t size)
|
||||
{
|
||||
return ((LittleFS *)c->context)->_flash_prog(block, off, buffer, size);
|
||||
}
|
||||
|
||||
// Erase a block. A block must be erased before being programmed.
|
||||
// The state of an erased block is undefined. Negative error codes
|
||||
// are propogated to the user.
|
||||
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
||||
int LittleFS::_iflash_erase (const struct lfs_config *c, lfs_block_t block)
|
||||
{
|
||||
return ((LittleFS *)c->context)->_flash_erase(block);
|
||||
}
|
||||
|
||||
// Sync the state of the underlying block device. Negative error codes
|
||||
// are propogated to the user.
|
||||
int LittleFS::_iflash_sync (const struct lfs_config *c)
|
||||
{
|
||||
return ((LittleFS *)c->context)->_flash_sync();
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef INTERNALFS_H_
|
||||
#define INTERNALFS_H_
|
||||
|
||||
#include "Bluefruit_FileIO.h"
|
||||
|
||||
// Internal Flash uses ARM Little FileSystem
|
||||
// https://github.com/ARMmbed/littlefs
|
||||
#include "littlefs/lfs.h"
|
||||
|
||||
class LittleFS: public BluefruitFS::FileSystemClass
|
||||
{
|
||||
public:
|
||||
LittleFS (void);
|
||||
virtual ~LittleFS ();
|
||||
|
||||
bool begin (void);
|
||||
BluefruitFS::File open (char const *filepath, uint8_t mode = FILE_READ);
|
||||
bool exists (char const *filepath);
|
||||
bool mkdir (char const *filepath);
|
||||
bool remove (char const *filepath);
|
||||
bool rmdir (char const *filepath);
|
||||
bool rmdir_r (char const *filepath);
|
||||
bool format (bool eraseall);
|
||||
|
||||
protected:
|
||||
bool _begun;
|
||||
bool _mounted;
|
||||
|
||||
LittleFS (lfs_size_t read_size, lfs_size_t prog_size, lfs_size_t block_size, lfs_size_t block_count, lfs_size_t lookahead);
|
||||
|
||||
// Internal API: shouldn't be used by Arduino sketch
|
||||
virtual size_t _f_write (void* fhdl, uint8_t const *buf, size_t size);
|
||||
virtual int _f_read (void* fhdl, void *buf, uint16_t nbyte);
|
||||
virtual void _f_flush (void* fhdl);
|
||||
virtual void _f_close (void* fhdl, bool is_dir);
|
||||
virtual bool _f_seek (void* fhdl, uint32_t pos);
|
||||
virtual uint32_t _f_position (void* fhdl);
|
||||
virtual uint32_t _f_size (void* fhdl);
|
||||
|
||||
// Raw flash opperations, override to use an external flash chip
|
||||
virtual int _flash_read (lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size);
|
||||
virtual int _flash_prog (lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size);
|
||||
virtual int _flash_erase (lfs_block_t block);
|
||||
virtual void _flash_erase_all();
|
||||
virtual int _flash_sync ();
|
||||
|
||||
virtual BluefruitFS::File _f_openNextFile (void* fhdl, char const* cwd, uint8_t mode);
|
||||
virtual void _f_rewindDirectory (void* fhdl);
|
||||
private:
|
||||
struct lfs_config _lfs_cfg;
|
||||
lfs_t _lfs;
|
||||
|
||||
BluefruitFS::File _open_file (char const *filepath, uint8_t mode);
|
||||
BluefruitFS::File _open_dir (char const *filepath);
|
||||
|
||||
static int _iflash_read (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size);
|
||||
static int _iflash_prog (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size);
|
||||
static int _iflash_erase (const struct lfs_config *c, lfs_block_t block);
|
||||
static int _iflash_sync (const struct lfs_config *c);
|
||||
};
|
||||
|
||||
extern LittleFS InternalFS;
|
||||
|
||||
#endif /* INTERNALFS_H_ */
|
||||
@@ -1,24 +0,0 @@
|
||||
FatFs License
|
||||
|
||||
FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that heading the source files.
|
||||
|
||||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - Generic FAT Filesystem Module Rx.xx /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 20xx, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
/ that the following condition is met:
|
||||
/
|
||||
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||
/ this condition and the following disclaimer.
|
||||
/
|
||||
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||
/ and any warranties related to this software are DISCLAIMED.
|
||||
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||
/ by use of this software.
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.
|
||||
@@ -1,330 +0,0 @@
|
||||
----------------------------------------------------------------------------
|
||||
Revision history of FatFs module
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
R0.00 (February 26, 2006)
|
||||
|
||||
Prototype.
|
||||
|
||||
|
||||
|
||||
R0.01 (April 29, 2006)
|
||||
|
||||
The first release.
|
||||
|
||||
|
||||
|
||||
R0.02 (June 01, 2006)
|
||||
|
||||
Added FAT12 support.
|
||||
Removed unbuffered mode.
|
||||
Fixed a problem on small (<32M) partition.
|
||||
|
||||
|
||||
|
||||
R0.02a (June 10, 2006)
|
||||
|
||||
Added a configuration option (_FS_MINIMUM).
|
||||
|
||||
|
||||
|
||||
R0.03 (September 22, 2006)
|
||||
|
||||
Added f_rename().
|
||||
Changed option _FS_MINIMUM to _FS_MINIMIZE.
|
||||
|
||||
|
||||
|
||||
R0.03a (December 11, 2006)
|
||||
|
||||
Improved cluster scan algorithm to write files fast.
|
||||
Fixed f_mkdir() creates incorrect directory on FAT32.
|
||||
|
||||
|
||||
|
||||
R0.04 (February 04, 2007)
|
||||
|
||||
Added f_mkfs().
|
||||
Supported multiple drive system.
|
||||
Changed some interfaces for multiple drive system.
|
||||
Changed f_mountdrv() to f_mount().
|
||||
|
||||
|
||||
|
||||
R0.04a (April 01, 2007)
|
||||
|
||||
Supported multiple partitions on a physical drive.
|
||||
Added a capability of extending file size to f_lseek().
|
||||
Added minimization level 3.
|
||||
Fixed an endian sensitive code in f_mkfs().
|
||||
|
||||
|
||||
|
||||
R0.04b (May 05, 2007)
|
||||
|
||||
Added a configuration option _USE_NTFLAG.
|
||||
Added FSINFO support.
|
||||
Fixed DBCS name can result FR_INVALID_NAME.
|
||||
Fixed short seek (<= csize) collapses the file object.
|
||||
|
||||
|
||||
|
||||
R0.05 (August 25, 2007)
|
||||
|
||||
Changed arguments of f_read(), f_write() and f_mkfs().
|
||||
Fixed f_mkfs() on FAT32 creates incorrect FSINFO.
|
||||
Fixed f_mkdir() on FAT32 creates incorrect directory.
|
||||
|
||||
|
||||
|
||||
R0.05a (February 03, 2008)
|
||||
|
||||
Added f_truncate() and f_utime().
|
||||
Fixed off by one error at FAT sub-type determination.
|
||||
Fixed btr in f_read() can be mistruncated.
|
||||
Fixed cached sector is not flushed when create and close without write.
|
||||
|
||||
|
||||
|
||||
R0.06 (April 01, 2008)
|
||||
|
||||
Added fputc(), fputs(), fprintf() and fgets().
|
||||
Improved performance of f_lseek() on moving to the same or following cluster.
|
||||
|
||||
|
||||
|
||||
R0.07 (April 01, 2009)
|
||||
|
||||
Merged Tiny-FatFs as a configuration option. (_FS_TINY)
|
||||
Added long file name feature. (_USE_LFN)
|
||||
Added multiple code page feature. (_CODE_PAGE)
|
||||
Added re-entrancy for multitask operation. (_FS_REENTRANT)
|
||||
Added auto cluster size selection to f_mkfs().
|
||||
Added rewind option to f_readdir().
|
||||
Changed result code of critical errors.
|
||||
Renamed string functions to avoid name collision.
|
||||
|
||||
|
||||
|
||||
R0.07a (April 14, 2009)
|
||||
|
||||
Septemberarated out OS dependent code on reentrant cfg.
|
||||
Added multiple sector size feature.
|
||||
|
||||
|
||||
|
||||
R0.07c (June 21, 2009)
|
||||
|
||||
Fixed f_unlink() can return FR_OK on error.
|
||||
Fixed wrong cache control in f_lseek().
|
||||
Added relative path feature.
|
||||
Added f_chdir() and f_chdrive().
|
||||
Added proper case conversion to extended character.
|
||||
|
||||
|
||||
|
||||
R0.07e (November 03, 2009)
|
||||
|
||||
Septemberarated out configuration options from ff.h to ffconf.h.
|
||||
Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH.
|
||||
Fixed name matching error on the 13 character boundary.
|
||||
Added a configuration option, _LFN_UNICODE.
|
||||
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
|
||||
|
||||
|
||||
|
||||
R0.08 (May 15, 2010)
|
||||
|
||||
Added a memory configuration option. (_USE_LFN = 3)
|
||||
Added file lock feature. (_FS_SHARE)
|
||||
Added fast seek feature. (_USE_FASTSEEK)
|
||||
Changed some types on the API, XCHAR->TCHAR.
|
||||
Changed .fname in the FILINFO structure on Unicode cfg.
|
||||
String functions support UTF-8 encoding files on Unicode cfg.
|
||||
|
||||
|
||||
|
||||
R0.08a (August 16, 2010)
|
||||
|
||||
Added f_getcwd(). (_FS_RPATH = 2)
|
||||
Added sector erase feature. (_USE_ERASE)
|
||||
Moved file lock semaphore table from fs object to the bss.
|
||||
Fixed f_mkfs() creates wrong FAT32 volume.
|
||||
|
||||
|
||||
|
||||
R0.08b (January 15, 2011)
|
||||
|
||||
Fast seek feature is also applied to f_read() and f_write().
|
||||
f_lseek() reports required table size on creating CLMP.
|
||||
Extended format syntax of f_printf().
|
||||
Ignores duplicated directory separators in given path name.
|
||||
|
||||
|
||||
|
||||
R0.09 (September 06, 2011)
|
||||
|
||||
f_mkfs() supports multiple partition to complete the multiple partition feature.
|
||||
Added f_fdisk().
|
||||
|
||||
|
||||
|
||||
R0.09a (August 27, 2012)
|
||||
|
||||
Changed f_open() and f_opendir() reject null object pointer to avoid crash.
|
||||
Changed option name _FS_SHARE to _FS_LOCK.
|
||||
Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
|
||||
|
||||
|
||||
|
||||
R0.09b (January 24, 2013)
|
||||
|
||||
Added f_setlabel() and f_getlabel().
|
||||
|
||||
|
||||
|
||||
R0.10 (October 02, 2013)
|
||||
|
||||
Added selection of character encoding on the file. (_STRF_ENCODE)
|
||||
Added f_closedir().
|
||||
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
|
||||
Added forced mount feature with changes of f_mount().
|
||||
Improved behavior of volume auto detection.
|
||||
Improved write throughput of f_puts() and f_printf().
|
||||
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
|
||||
Fixed f_write() can be truncated when the file size is close to 4GB.
|
||||
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect value on error.
|
||||
|
||||
|
||||
|
||||
R0.10a (January 15, 2014)
|
||||
|
||||
Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
|
||||
Added a configuration option of minimum sector size. (_MIN_SS)
|
||||
2nd argument of f_rename() can have a drive number and it will be ignored.
|
||||
Fixed f_mount() with forced mount fails when drive number is >= 1. (appeared at R0.10)
|
||||
Fixed f_close() invalidates the file object without volume lock.
|
||||
Fixed f_closedir() returns but the volume lock is left acquired. (appeared at R0.10)
|
||||
Fixed creation of an entry with LFN fails on too many SFN collisions. (appeared at R0.07)
|
||||
|
||||
|
||||
|
||||
R0.10b (May 19, 2014)
|
||||
|
||||
Fixed a hard error in the disk I/O layer can collapse the directory entry.
|
||||
Fixed LFN entry is not deleted when delete/rename an object with lossy converted SFN. (appeared at R0.07)
|
||||
|
||||
|
||||
|
||||
R0.10c (November 09, 2014)
|
||||
|
||||
Added a configuration option for the platforms without RTC. (_FS_NORTC)
|
||||
Changed option name _USE_ERASE to _USE_TRIM.
|
||||
Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel(). (appeared at R0.09b)
|
||||
Fixed a potential problem of FAT access that can appear on disk error.
|
||||
Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)
|
||||
|
||||
|
||||
|
||||
R0.11 (February 09, 2015)
|
||||
|
||||
Added f_findfirst(), f_findnext() and f_findclose(). (_USE_FIND)
|
||||
Fixed f_unlink() does not remove cluster chain of the file. (appeared at R0.10c)
|
||||
Fixed _FS_NORTC option does not work properly. (appeared at R0.10c)
|
||||
|
||||
|
||||
|
||||
R0.11a (September 05, 2015)
|
||||
|
||||
Fixed wrong media change can lead a deadlock at thread-safe configuration.
|
||||
Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE)
|
||||
Removed some code pages actually not exist on the standard systems. (_CODE_PAGE)
|
||||
Fixed errors in the case conversion teble of code page 437 and 850 (ff.c).
|
||||
Fixed errors in the case conversion teble of Unicode (cc*.c).
|
||||
|
||||
|
||||
|
||||
R0.12 (April 12, 2016)
|
||||
|
||||
Added support for exFAT file system. (_FS_EXFAT)
|
||||
Added f_expand(). (_USE_EXPAND)
|
||||
Changed some members in FINFO structure and behavior of f_readdir().
|
||||
Added an option _USE_CHMOD.
|
||||
Removed an option _WORD_ACCESS.
|
||||
Fixed errors in the case conversion table of Unicode (cc*.c).
|
||||
|
||||
|
||||
|
||||
R0.12a (July 10, 2016)
|
||||
|
||||
Added support for creating exFAT volume with some changes of f_mkfs().
|
||||
Added a file open method FA_OPEN_APPEND. An f_lseek() following f_open() is no longer needed.
|
||||
f_forward() is available regardless of _FS_TINY.
|
||||
Fixed f_mkfs() creates wrong volume. (appeared at R0.12)
|
||||
Fixed wrong memory read in create_name(). (appeared at R0.12)
|
||||
Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD.
|
||||
|
||||
|
||||
|
||||
R0.12b (September 04, 2016)
|
||||
|
||||
Made f_rename() be able to rename objects with the same name but case.
|
||||
Fixed an error in the case conversion teble of code page 866. (ff.c)
|
||||
Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12)
|
||||
Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12)
|
||||
Fixed f_mkfs() creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12)
|
||||
Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12)
|
||||
Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12)
|
||||
Fixed some internal errors in f_expand() and f_lseek(). (appeared at R0.12)
|
||||
|
||||
|
||||
|
||||
R0.12c (March 04, 2017)
|
||||
|
||||
Improved write throughput at the fragmented file on the exFAT volume.
|
||||
Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN.
|
||||
Fixed successive f_getfree() can return wrong count on the FAT12/16 volume. (appeared at R0.12)
|
||||
Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c)
|
||||
|
||||
|
||||
|
||||
R0.13 (May 21, 2017)
|
||||
|
||||
Changed heading character of configuration keywords "_" to "FF_".
|
||||
Removed ASCII-only configuration, FF_CODE_PAGE = 1. Use FF_CODE_PAGE = 437 instead.
|
||||
Added f_setcp(), run-time code page configuration. (FF_CODE_PAGE = 0)
|
||||
Improved cluster allocation time on stretch a deep buried cluster chain.
|
||||
Improved processing time of f_mkdir() with large cluster size by using FF_USE_LFN = 3.
|
||||
Improved NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous.
|
||||
Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)
|
||||
Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)
|
||||
Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)
|
||||
|
||||
|
||||
|
||||
R0.13a (October 14, 2017)
|
||||
|
||||
Added support for UTF-8 encoding on the API. (FF_LFN_UNICODE = 2)
|
||||
Added options for file name output buffer. (FF_LFN_BUF, FF_SFN_BUF).
|
||||
Added dynamic memory allocation option for working buffer of f_mkfs() and f_fdisk().
|
||||
Fixed f_fdisk() and f_mkfs() create the partition table with wrong CHS parameters. (appeared at R0.09)
|
||||
Fixed f_unlink() can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c)
|
||||
Fixed f_setlabel() rejects some valid characters for exFAT volume. (appeared at R0.12)
|
||||
|
||||
|
||||
|
||||
R0.13b (April 07, 2018)
|
||||
|
||||
Added support for UTF-32 encoding on the API. (FF_LFN_UNICODE = 3)
|
||||
Added support for Unix style volume ID. (FF_STR_VOLUME_ID = 2)
|
||||
Fixed accesing any object on the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c)
|
||||
Fixed f_setlabel() does not reject some invalid characters. (appeared at R0.09b)
|
||||
|
||||
|
||||
|
||||
R0.13c (October 14, 2018)
|
||||
Supported stdint.h for C99 and later. (integer.h was included in ff.h)
|
||||
Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
|
||||
Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
|
||||
Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
FatFs Module Source Files R0.13c
|
||||
|
||||
|
||||
FILES
|
||||
|
||||
00readme.txt This file.
|
||||
00history.txt Revision history.
|
||||
ff.c FatFs module.
|
||||
ffconf.h Configuration file of FatFs module.
|
||||
ff.h Common include file for FatFs and application module.
|
||||
diskio.h Common include file for FatFs and disk I/O module.
|
||||
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
|
||||
ffunicode.c Optional Unicode utility functions.
|
||||
ffsystem.c An example of optional O/S related functions.
|
||||
|
||||
|
||||
Low level disk I/O module is not included in this archive because the FatFs
|
||||
module is only a generic file system layer and it does not depend on any specific
|
||||
storage device. You need to provide a low level disk I/O module written to
|
||||
control the storage device that attached to the target system.
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* If a working storage control module is available, it should be */
|
||||
/* attached to the FatFs via a glue function rather than modifying it. */
|
||||
/* This is an example of glue functions to attach various exsisting */
|
||||
/* storage control modules to the FatFs module with a defined API. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
|
||||
#include "ff.h" /* Obtains integer types */
|
||||
#include "diskio.h" /* Declarations of disk functions */
|
||||
|
||||
#include "flash/flash_qspi.h"
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get Drive Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
(void) pdrv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Inidialize a Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
(void) pdrv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
(void) pdrv;
|
||||
|
||||
uint32_t const len = count * FF_MIN_SS;
|
||||
return (len == flash_qspi_read(buff, sector * FF_MIN_SS, len)) ? RES_OK : RES_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#if FF_FS_READONLY == 0
|
||||
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
(void) pdrv;
|
||||
|
||||
uint32_t const len = count * FF_MIN_SS;
|
||||
return (len == flash_qspi_write(sector * FF_MIN_SS, buff, len)) ? RES_OK : RES_ERROR;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
(void) pdrv;
|
||||
|
||||
switch ( cmd )
|
||||
{
|
||||
case GET_SECTOR_COUNT:
|
||||
*((DWORD*) buff) = (flash_qspi_size() / FF_MIN_SS);
|
||||
break;
|
||||
|
||||
case GET_SECTOR_SIZE:
|
||||
*((WORD*) buff) = FF_MIN_SS;
|
||||
break;
|
||||
|
||||
case GET_BLOCK_SIZE:
|
||||
*((DWORD*) buff) = (FLASH_QSPI_PAGE_SIZE / FF_MIN_SS);
|
||||
break;
|
||||
|
||||
case CTRL_SYNC:
|
||||
flash_qspi_flush();
|
||||
break;
|
||||
|
||||
case CTRL_TRIM:
|
||||
// not support trim
|
||||
break;
|
||||
|
||||
default:
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/*-----------------------------------------------------------------------/
|
||||
/ Low level disk interface modlue include file (C)ChaN, 2014 /
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO_DEFINED
|
||||
#define _DISKIO_DEFINED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
|
||||
DSTATUS disk_initialize (BYTE pdrv);
|
||||
DSTATUS disk_status (BYTE pdrv);
|
||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl fucntion */
|
||||
|
||||
/* Generic command (Used by FatFs) */
|
||||
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
|
||||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
|
||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
|
||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
|
||||
|
||||
/* Generic command (Not used by FatFs) */
|
||||
#define CTRL_POWER 5 /* Get/Set power status */
|
||||
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
|
||||
#define CTRL_EJECT 7 /* Eject media */
|
||||
#define CTRL_FORMAT 8 /* Create physical format on the media */
|
||||
|
||||
/* MMC/SDC specific ioctl command */
|
||||
#define MMC_GET_TYPE 10 /* Get card type */
|
||||
#define MMC_GET_CSD 11 /* Get CSD */
|
||||
#define MMC_GET_CID 12 /* Get CID */
|
||||
#define MMC_GET_OCR 13 /* Get OCR */
|
||||
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
|
||||
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
|
||||
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
|
||||
|
||||
/* ATA/CF specific ioctl command */
|
||||
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||
#define ATA_GET_MODEL 21 /* Get model name */
|
||||
#define ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,405 +0,0 @@
|
||||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - Generic FAT Filesystem module R0.13c /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 2018, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
/ that the following condition is met:
|
||||
|
||||
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||
/ this condition and the following disclaimer.
|
||||
/
|
||||
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||
/ and any warranties related to this software are DISCLAIMED.
|
||||
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||
/ by use of this software.
|
||||
/
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef FF_DEFINED
|
||||
#define FF_DEFINED 86604 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
|
||||
#if FF_DEFINED != FFCONF_DEF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
#endif
|
||||
|
||||
|
||||
/* Integer types used for FatFs API */
|
||||
|
||||
#if defined(_WIN32) /* Main development platform */
|
||||
#define FF_INTDEF 2
|
||||
#include <windows.h>
|
||||
typedef unsigned __int64 QWORD;
|
||||
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
||||
#define FF_INTDEF 2
|
||||
#include <stdint.h>
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef uint16_t WORD; /* 16-bit unsigned integer */
|
||||
typedef uint16_t WCHAR; /* 16-bit unsigned integer */
|
||||
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
||||
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||
#else /* Earlier than C99 */
|
||||
#define FF_INTDEF 1
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef unsigned short WORD; /* 16-bit unsigned integer */
|
||||
typedef unsigned short WCHAR; /* 16-bit unsigned integer */
|
||||
typedef unsigned long DWORD; /* 32-bit unsigned integer */
|
||||
#endif
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
||||
#endif
|
||||
|
||||
#if FF_STR_VOLUME_ID
|
||||
#ifndef FF_VOLUME_STRS
|
||||
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of path name strings on FatFs API */
|
||||
|
||||
#ifndef _INC_TCHAR
|
||||
#define _INC_TCHAR
|
||||
|
||||
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
||||
typedef WCHAR TCHAR;
|
||||
#define _T(x) L ## x
|
||||
#define _TEXT(x) L ## x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) u8 ## x
|
||||
#define _TEXT(x) u8 ## x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */
|
||||
typedef DWORD TCHAR;
|
||||
#define _T(x) U ## x
|
||||
#define _TEXT(x) U ## x
|
||||
#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
|
||||
#error Wrong FF_LFN_UNICODE setting
|
||||
#else /* ANSI/OEM code in SBCS/DBCS */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of file size variables */
|
||||
|
||||
#if FF_FS_EXFAT
|
||||
#if FF_INTDEF != 2
|
||||
#error exFAT feature wants C99 or later
|
||||
#endif
|
||||
typedef QWORD FSIZE_t;
|
||||
#else
|
||||
typedef DWORD FSIZE_t;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Filesystem object structure (FATFS) */
|
||||
|
||||
typedef struct {
|
||||
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||
BYTE pdrv; /* Associated physical drive */
|
||||
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
WORD id; /* Volume mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
WORD csize; /* Cluster size [sectors] */
|
||||
#if FF_MAX_SS != FF_MIN_SS
|
||||
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if FF_USE_LFN
|
||||
WCHAR* lfnbuf; /* LFN working buffer */
|
||||
#endif
|
||||
#if FF_FS_EXFAT
|
||||
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
||||
#endif
|
||||
#if FF_FS_REENTRANT
|
||||
FF_SYNC_t sobj; /* Identifier of sync object */
|
||||
#endif
|
||||
#if !FF_FS_READONLY
|
||||
DWORD last_clst; /* Last allocated cluster */
|
||||
DWORD free_clst; /* Number of free clusters */
|
||||
#endif
|
||||
#if FF_FS_RPATH
|
||||
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
|
||||
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
|
||||
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
|
||||
#endif
|
||||
#endif
|
||||
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
||||
DWORD fsize; /* Size of an FAT [sectors] */
|
||||
DWORD volbase; /* Volume base sector */
|
||||
DWORD fatbase; /* FAT base sector */
|
||||
DWORD dirbase; /* Root directory base sector/cluster */
|
||||
DWORD database; /* Data base sector */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD bitbase; /* Allocation bitmap base sector */
|
||||
#endif
|
||||
DWORD winsect; /* Current sector appearing in the win[] */
|
||||
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
} FATFS;
|
||||
|
||||
|
||||
|
||||
/* Object ID and allocation information (FFOBJID) */
|
||||
|
||||
typedef struct {
|
||||
FATFS* fs; /* Pointer to the hosting volume of this object */
|
||||
WORD id; /* Hosting volume mount ID */
|
||||
BYTE attr; /* Object attribute */
|
||||
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
||||
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
||||
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */
|
||||
DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */
|
||||
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
|
||||
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
|
||||
DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */
|
||||
#endif
|
||||
#if FF_FS_LOCK
|
||||
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
} FFOBJID;
|
||||
|
||||
|
||||
|
||||
/* File object structure (FIL) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */
|
||||
BYTE flag; /* File status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
||||
DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !FF_FS_READONLY
|
||||
DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
||||
#endif
|
||||
#if FF_USE_FASTSEEK
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
|
||||
#endif
|
||||
#if !FF_FS_TINY
|
||||
BYTE buf[FF_MAX_SS]; /* File private data read/write window */
|
||||
#endif
|
||||
} FIL;
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (DIR) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier */
|
||||
DWORD dptr; /* Current read/write offset */
|
||||
DWORD clust; /* Current cluster */
|
||||
DWORD sect; /* Current sector (0:Read operation has terminated) */
|
||||
BYTE* dir; /* Pointer to the directory item in the win[] */
|
||||
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||
#if FF_USE_LFN
|
||||
DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
|
||||
#endif
|
||||
#if FF_USE_FIND
|
||||
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||
#endif
|
||||
} DIR;
|
||||
|
||||
|
||||
|
||||
/* File information structure (FILINFO) */
|
||||
|
||||
typedef struct {
|
||||
FSIZE_t fsize; /* File size */
|
||||
WORD fdate; /* Modified date */
|
||||
WORD ftime; /* Modified time */
|
||||
BYTE fattrib; /* File attribute */
|
||||
#if FF_USE_LFN
|
||||
TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
|
||||
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
||||
#else
|
||||
TCHAR fname[12 + 1]; /* File name */
|
||||
#endif
|
||||
} FILINFO;
|
||||
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
typedef enum {
|
||||
FR_OK = 0, /* (0) Succeeded */
|
||||
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||
FR_NO_FILE, /* (4) Could not find the file */
|
||||
FR_NO_PATH, /* (5) Could not find the path */
|
||||
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
|
||||
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||
} FRESULT;
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* FatFs module application interface */
|
||||
|
||||
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
|
||||
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate the file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||
FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */
|
||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */
|
||||
FRESULT f_setcp (WORD cp); /* Set current code page */
|
||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||
|
||||
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
||||
#define f_error(fp) ((fp)->err)
|
||||
#define f_tell(fp) ((fp)->fptr)
|
||||
#define f_size(fp) ((fp)->obj.objsize)
|
||||
#define f_rewind(fp) f_lseek((fp), 0)
|
||||
#define f_rewinddir(dp) f_readdir((dp), 0)
|
||||
#define f_rmdir(path) f_unlink(path)
|
||||
#define f_unmount(path) f_mount(0, path, 0)
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Additional user defined functions */
|
||||
|
||||
/* RTC function */
|
||||
#if !FF_FS_READONLY && !FF_FS_NORTC
|
||||
DWORD get_fattime (void);
|
||||
#endif
|
||||
|
||||
/* LFN support functions */
|
||||
#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
|
||||
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
|
||||
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
||||
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
||||
#endif
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||
void ff_memfree (void* mblock); /* Free memory block */
|
||||
#endif
|
||||
|
||||
/* Sync functions */
|
||||
#if FF_FS_REENTRANT
|
||||
int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Flags and offset address */
|
||||
|
||||
|
||||
/* File access mode and open method flags (3rd argument of f_open) */
|
||||
#define FA_READ 0x01
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define FA_OPEN_APPEND 0x30
|
||||
|
||||
/* Fast seek controls (2nd argument of f_lseek) */
|
||||
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
|
||||
|
||||
/* Format options (2nd argument of f_mkfs) */
|
||||
#define FM_FAT 0x01
|
||||
#define FM_FAT32 0x02
|
||||
#define FM_EXFAT 0x04
|
||||
#define FM_ANY 0x07
|
||||
#define FM_SFD 0x08
|
||||
|
||||
/* Filesystem type (FATFS.fs_type) */
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
#define FS_EXFAT 4
|
||||
|
||||
/* File attribute bits for directory entry (FILINFO.fattrib) */
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FF_DEFINED */
|
||||
@@ -1,288 +0,0 @@
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs Functional Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FFCONF_DEF 86604 /* Revision ID */
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Function Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_FS_READONLY 0
|
||||
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
|
||||
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
|
||||
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
|
||||
/ and optional writing functions as well. */
|
||||
|
||||
|
||||
#define FF_FS_MINIMIZE 0
|
||||
/* This option defines minimization level to remove some basic API functions.
|
||||
/
|
||||
/ 0: Basic functions are fully enabled.
|
||||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
|
||||
/ are removed.
|
||||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
||||
/ 3: f_lseek() function is removed in addition to 2. */
|
||||
|
||||
|
||||
#define FF_USE_STRFUNC 0
|
||||
/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
|
||||
/
|
||||
/ 0: Disable string functions.
|
||||
/ 1: Enable without LF-CRLF conversion.
|
||||
/ 2: Enable with LF-CRLF conversion. */
|
||||
|
||||
|
||||
#define FF_USE_FIND 0
|
||||
/* This option switches filtered directory read functions, f_findfirst() and
|
||||
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
|
||||
|
||||
|
||||
#define FF_USE_MKFS 1
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_FASTSEEK 0
|
||||
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_EXPAND 0
|
||||
/* This option switches f_expand function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_CHMOD 0
|
||||
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
|
||||
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
|
||||
|
||||
|
||||
#define FF_USE_LABEL 1
|
||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||
/ (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_FORWARD 0
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_CODE_PAGE 437
|
||||
/* This option specifies the OEM code page to be used on the target system.
|
||||
/ Incorrect code page setting can cause a file open failure.
|
||||
/
|
||||
/ 437 - U.S.
|
||||
/ 720 - Arabic
|
||||
/ 737 - Greek
|
||||
/ 771 - KBL
|
||||
/ 775 - Baltic
|
||||
/ 850 - Latin 1
|
||||
/ 852 - Latin 2
|
||||
/ 855 - Cyrillic
|
||||
/ 857 - Turkish
|
||||
/ 860 - Portuguese
|
||||
/ 861 - Icelandic
|
||||
/ 862 - Hebrew
|
||||
/ 863 - Canadian French
|
||||
/ 864 - Arabic
|
||||
/ 865 - Nordic
|
||||
/ 866 - Russian
|
||||
/ 869 - Greek 2
|
||||
/ 932 - Japanese (DBCS)
|
||||
/ 936 - Simplified Chinese (DBCS)
|
||||
/ 949 - Korean (DBCS)
|
||||
/ 950 - Traditional Chinese (DBCS)
|
||||
/ 0 - Include all code pages above and configured by f_setcp()
|
||||
*/
|
||||
|
||||
|
||||
#define FF_USE_LFN 1
|
||||
#define FF_MAX_LFN 255
|
||||
/* The FF_USE_LFN switches the support for LFN (long file name).
|
||||
/
|
||||
/ 0: Disable LFN. FF_MAX_LFN has no effect.
|
||||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
||||
/
|
||||
/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
|
||||
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
|
||||
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
|
||||
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
|
||||
/ be in range of 12 to 255. It is recommended to be set 255 to fully support LFN
|
||||
/ specification.
|
||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||
/ ff_memfree() in ffsystem.c, need to be added to the project. */
|
||||
|
||||
|
||||
#define FF_LFN_UNICODE 0
|
||||
/* This option switches the character encoding on the API when LFN is enabled.
|
||||
/
|
||||
/ 0: ANSI/OEM in current CP (TCHAR = char)
|
||||
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
|
||||
/ 2: Unicode in UTF-8 (TCHAR = char)
|
||||
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
|
||||
/
|
||||
/ Also behavior of string I/O functions will be affected by this option.
|
||||
/ When LFN is not enabled, this option has no effect. */
|
||||
|
||||
|
||||
#define FF_LFN_BUF 255
|
||||
#define FF_SFN_BUF 12
|
||||
/* This set of options defines size of file name members in the FILINFO structure
|
||||
/ which is used to read out directory items. These values should be suffcient for
|
||||
/ the file names to read. The maximum possible length of the read file name depends
|
||||
/ on character encoding. When LFN is not enabled, these options have no effect. */
|
||||
|
||||
|
||||
#define FF_STRF_ENCODE 3
|
||||
/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(),
|
||||
/ f_putc(), f_puts and f_printf() convert the character encoding in it.
|
||||
/ This option selects assumption of character encoding ON THE FILE to be
|
||||
/ read/written via those functions.
|
||||
/
|
||||
/ 0: ANSI/OEM in current CP
|
||||
/ 1: Unicode in UTF-16LE
|
||||
/ 2: Unicode in UTF-16BE
|
||||
/ 3: Unicode in UTF-8
|
||||
*/
|
||||
|
||||
|
||||
#define FF_FS_RPATH 0
|
||||
/* This option configures support for relative path.
|
||||
/
|
||||
/ 0: Disable relative path and remove related functions.
|
||||
/ 1: Enable relative path. f_chdir() and f_chdrive() are available.
|
||||
/ 2: f_getcwd() function is available in addition to 1.
|
||||
*/
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Drive/Volume Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_VOLUMES 1
|
||||
/* Number of volumes (logical drives) to be used. (1-10) */
|
||||
|
||||
|
||||
#define FF_STR_VOLUME_ID 0
|
||||
#define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3"
|
||||
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
|
||||
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
|
||||
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
|
||||
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid
|
||||
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
|
||||
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
|
||||
/ not defined, a user defined volume string table needs to be defined as:
|
||||
/
|
||||
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
|
||||
*/
|
||||
|
||||
|
||||
#define FF_MULTI_PARTITION 0
|
||||
/* This option switches support for multiple volumes on the physical drive.
|
||||
/ By default (0), each logical drive number is bound to the same physical drive
|
||||
/ number and only an FAT volume found on the physical drive will be mounted.
|
||||
/ When this function is enabled (1), each logical drive number can be bound to
|
||||
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
|
||||
/ funciton will be available. */
|
||||
|
||||
|
||||
#define FF_MIN_SS 512
|
||||
#define FF_MAX_SS 512
|
||||
/* This set of options configures the range of sector size to be supported. (512,
|
||||
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
|
||||
/ harddisk. But a larger value may be required for on-board flash memory and some
|
||||
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
|
||||
/ for variable sector size mode and disk_ioctl() function needs to implement
|
||||
/ GET_SECTOR_SIZE command. */
|
||||
|
||||
|
||||
#define FF_USE_TRIM 0
|
||||
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
|
||||
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
|
||||
#define FF_FS_NOFSINFO 0
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||
/ option, and f_getfree() function at first time after volume mount will force
|
||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_FS_TINY 0
|
||||
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
|
||||
/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
|
||||
/ Instead of private sector buffer eliminated from the file object, common sector
|
||||
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
|
||||
|
||||
|
||||
#define FF_FS_EXFAT 0
|
||||
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
|
||||
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
|
||||
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
||||
|
||||
|
||||
#define FF_FS_NORTC 1
|
||||
#define FF_NORTC_MON 1
|
||||
#define FF_NORTC_MDAY 1
|
||||
#define FF_NORTC_YEAR 2018
|
||||
/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
|
||||
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
|
||||
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
|
||||
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
|
||||
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
|
||||
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
|
||||
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
|
||||
/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */
|
||||
|
||||
|
||||
#define FF_FS_LOCK 0
|
||||
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
|
||||
/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
|
||||
/ is 1.
|
||||
/
|
||||
/ 0: Disable file lock function. To avoid volume corruption, application program
|
||||
/ should avoid illegal open, remove and rename to the open objects.
|
||||
/ >0: Enable file lock function. The value defines how many files/sub-directories
|
||||
/ can be opened simultaneously under file lock control. Note that the file
|
||||
/ lock control is independent of re-entrancy. */
|
||||
|
||||
|
||||
/* #include <somertos.h> // O/S definitions */
|
||||
#define FF_FS_REENTRANT 0
|
||||
#define FF_FS_TIMEOUT 1000
|
||||
#define FF_SYNC_t HANDLE
|
||||
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
|
||||
/ module itself. Note that regardless of this option, file access to different
|
||||
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
|
||||
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
|
||||
/ to the same volume is under control of this function.
|
||||
/
|
||||
/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
|
||||
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
|
||||
/ function, must be added to the project. Samples are available in
|
||||
/ option/syscall.c.
|
||||
/
|
||||
/ The FF_FS_TIMEOUT defines timeout period in unit of time tick.
|
||||
/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
|
||||
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
|
||||
/ included somewhere in the scope of ff.h. */
|
||||
|
||||
|
||||
|
||||
/*--- End of configuration options ---*/
|
||||
@@ -1,171 +0,0 @@
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Sample Code of OS Dependent Functions for FatFs */
|
||||
/* (C)ChaN, 2018 */
|
||||
/*------------------------------------------------------------------------*/
|
||||
#ifdef NRF52840_XXAA
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Allocate a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
|
||||
UINT msize /* Number of bytes to allocate */
|
||||
)
|
||||
{
|
||||
return malloc(msize); /* Allocate a new memory block with POSIX API */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Free a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void ff_memfree (
|
||||
void* mblock /* Pointer to the memory block to free (nothing to do if null) */
|
||||
)
|
||||
{
|
||||
free(mblock); /* Free the memory block with POSIX API */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if FF_FS_REENTRANT /* Mutal exclusion */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Create a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to create a new
|
||||
/ synchronization object for the volume, such as semaphore and mutex.
|
||||
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
//const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */
|
||||
|
||||
|
||||
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
|
||||
BYTE vol, /* Corresponding volume (logical drive number) */
|
||||
FF_SYNC_t* sobj /* Pointer to return the created sync object */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
*sobj = CreateMutex(NULL, FALSE, NULL);
|
||||
return (int)(*sobj != INVALID_HANDLE_VALUE);
|
||||
|
||||
/* uITRON */
|
||||
// T_CSEM csem = {TA_TPRI,1,1};
|
||||
// *sobj = acre_sem(&csem);
|
||||
// return (int)(*sobj > 0);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// *sobj = OSMutexCreate(0, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// *sobj = xSemaphoreCreateMutex();
|
||||
// return (int)(*sobj != NULL);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// *sobj = osMutexCreate(&Mutex[vol]);
|
||||
// return (int)(*sobj != NULL);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Delete a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to delete a synchronization
|
||||
/ object that created with ff_cre_syncobj() function. When a 0 is returned,
|
||||
/ the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
|
||||
FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
return (int)CloseHandle(sobj);
|
||||
|
||||
/* uITRON */
|
||||
// return (int)(del_sem(sobj) == E_OK);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// vSemaphoreDelete(sobj);
|
||||
// return 1;
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexDelete(sobj) == osOK);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Request Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on entering file functions to lock the volume.
|
||||
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
|
||||
*/
|
||||
|
||||
int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
|
||||
FF_SYNC_t sobj /* Sync object to wait */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
|
||||
|
||||
/* uITRON */
|
||||
// return (int)(wai_sem(sobj) == E_OK);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Release Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on leaving file functions to unlock the volume.
|
||||
*/
|
||||
|
||||
void ff_rel_grant (
|
||||
FF_SYNC_t sobj /* Sync object to be signaled */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
ReleaseMutex(sobj);
|
||||
|
||||
/* uITRON */
|
||||
// sig_sem(sobj);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OSMutexPost(sobj);
|
||||
|
||||
/* FreeRTOS */
|
||||
// xSemaphoreGive(sobj);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// osMutexRelease(sobj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,69 +0,0 @@
|
||||
TARGET = lfs.a
|
||||
ifneq ($(wildcard test.c main.c),)
|
||||
override TARGET = lfs
|
||||
endif
|
||||
|
||||
CC ?= gcc
|
||||
AR ?= ar
|
||||
SIZE ?= size
|
||||
|
||||
SRC += $(wildcard *.c emubd/*.c)
|
||||
OBJ := $(SRC:.c=.o)
|
||||
DEP := $(SRC:.c=.d)
|
||||
ASM := $(SRC:.c=.s)
|
||||
|
||||
TEST := $(patsubst tests/%.sh,%,$(wildcard tests/test_*))
|
||||
|
||||
SHELL = /bin/bash -o pipefail
|
||||
|
||||
ifdef DEBUG
|
||||
override CFLAGS += -O0 -g3
|
||||
else
|
||||
override CFLAGS += -Os
|
||||
endif
|
||||
ifdef WORD
|
||||
override CFLAGS += -m$(WORD)
|
||||
endif
|
||||
override CFLAGS += -I.
|
||||
override CFLAGS += -std=c99 -Wall -pedantic
|
||||
override CFLAGS += -Wshadow -Wunused-parameter -Wjump-misses-init -Wsign-compare
|
||||
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
asm: $(ASM)
|
||||
|
||||
size: $(OBJ)
|
||||
$(SIZE) -t $^
|
||||
|
||||
.SUFFIXES:
|
||||
test: test_format test_dirs test_files test_seek test_truncate \
|
||||
test_interspersed test_alloc test_paths test_orphan test_move test_corrupt
|
||||
@rm test.c
|
||||
test_%: tests/test_%.sh
|
||||
|
||||
ifdef QUIET
|
||||
@./$< | sed -n '/^[-=]/p'
|
||||
else
|
||||
./$<
|
||||
endif
|
||||
|
||||
-include $(DEP)
|
||||
|
||||
lfs: $(OBJ)
|
||||
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
|
||||
|
||||
%.a: $(OBJ)
|
||||
$(AR) rcs $@ $^
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -c -MMD $(CFLAGS) $< -o $@
|
||||
|
||||
%.s: %.c
|
||||
$(CC) -S $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
rm -f $(OBJ)
|
||||
rm -f $(DEP)
|
||||
rm -f $(ASM)
|
||||
@@ -1,370 +0,0 @@
|
||||
## The little filesystem technical specification
|
||||
|
||||
This is the technical specification of the little filesystem. This document
|
||||
covers the technical details of how the littlefs is stored on disk for
|
||||
introspection and tooling development. This document assumes you are
|
||||
familiar with the design of the littlefs, for more info on how littlefs
|
||||
works check out [DESIGN.md](DESIGN.md).
|
||||
|
||||
```
|
||||
| | | .---._____
|
||||
.-----. | |
|
||||
--|o |---| littlefs |
|
||||
--| |---| |
|
||||
'-----' '----------'
|
||||
| | |
|
||||
```
|
||||
|
||||
## Some important details
|
||||
|
||||
- The littlefs is a block-based filesystem. This is, the disk is divided into
|
||||
an array of evenly sized blocks that are used as the logical unit of storage
|
||||
in littlefs. Block pointers are stored in 32 bits.
|
||||
|
||||
- There is no explicit free-list stored on disk, the littlefs only knows what
|
||||
is in use in the filesystem.
|
||||
|
||||
- The littlefs uses the value of 0xffffffff to represent a null block-pointer.
|
||||
|
||||
- All values in littlefs are stored in little-endian byte order.
|
||||
|
||||
## Directories / Metadata pairs
|
||||
|
||||
Metadata pairs form the backbone of the littlefs and provide a system for
|
||||
atomic updates. Even the superblock is stored in a metadata pair.
|
||||
|
||||
As their name suggests, a metadata pair is stored in two blocks, with one block
|
||||
acting as a redundant backup in case the other is corrupted. These two blocks
|
||||
could be anywhere in the disk and may not be next to each other, so any
|
||||
pointers to directory pairs need to be stored as two block pointers.
|
||||
|
||||
Here's the layout of metadata blocks on disk:
|
||||
|
||||
| offset | size | description |
|
||||
|--------|---------------|----------------|
|
||||
| 0x00 | 32 bits | revision count |
|
||||
| 0x04 | 32 bits | dir size |
|
||||
| 0x08 | 64 bits | tail pointer |
|
||||
| 0x10 | size-16 bytes | dir entries |
|
||||
| 0x00+s | 32 bits | CRC |
|
||||
|
||||
**Revision count** - Incremented every update, only the uncorrupted
|
||||
metadata-block with the most recent revision count contains the valid metadata.
|
||||
Comparison between revision counts must use sequence comparison since the
|
||||
revision counts may overflow.
|
||||
|
||||
**Dir size** - Size in bytes of the contents in the current metadata block,
|
||||
including the metadata-pair metadata. Additionally, the highest bit of the
|
||||
dir size may be set to indicate that the directory's contents continue on the
|
||||
next metadata-pair pointed to by the tail pointer.
|
||||
|
||||
**Tail pointer** - Pointer to the next metadata-pair in the filesystem.
|
||||
A null pair-pointer (0xffffffff, 0xffffffff) indicates the end of the list.
|
||||
If the highest bit in the dir size is set, this points to the next
|
||||
metadata-pair in the current directory, otherwise it points to an arbitrary
|
||||
metadata-pair. Starting with the superblock, the tail-pointers form a
|
||||
linked-list containing all metadata-pairs in the filesystem.
|
||||
|
||||
**CRC** - 32 bit CRC used to detect corruption from power-lost, from block
|
||||
end-of-life, or just from noise on the storage bus. The CRC is appended to
|
||||
the end of each metadata-block. The littlefs uses the standard CRC-32, which
|
||||
uses a polynomial of 0x04c11db7, initialized with 0xffffffff.
|
||||
|
||||
Here's an example of a simple directory stored on disk:
|
||||
```
|
||||
(32 bits) revision count = 10 (0x0000000a)
|
||||
(32 bits) dir size = 154 bytes, end of dir (0x0000009a)
|
||||
(64 bits) tail pointer = 37, 36 (0x00000025, 0x00000024)
|
||||
(32 bits) CRC = 0xc86e3106
|
||||
|
||||
00000000: 0a 00 00 00 9a 00 00 00 25 00 00 00 24 00 00 00 ........%...$...
|
||||
00000010: 22 08 00 03 05 00 00 00 04 00 00 00 74 65 61 22 "...........tea"
|
||||
00000020: 08 00 06 07 00 00 00 06 00 00 00 63 6f 66 66 65 ...........coffe
|
||||
00000030: 65 22 08 00 04 09 00 00 00 08 00 00 00 73 6f 64 e"...........sod
|
||||
00000040: 61 22 08 00 05 1d 00 00 00 1c 00 00 00 6d 69 6c a"...........mil
|
||||
00000050: 6b 31 22 08 00 05 1f 00 00 00 1e 00 00 00 6d 69 k1"...........mi
|
||||
00000060: 6c 6b 32 22 08 00 05 21 00 00 00 20 00 00 00 6d lk2"...!... ...m
|
||||
00000070: 69 6c 6b 33 22 08 00 05 23 00 00 00 22 00 00 00 ilk3"...#..."...
|
||||
00000080: 6d 69 6c 6b 34 22 08 00 05 25 00 00 00 24 00 00 milk4"...%...$..
|
||||
00000090: 00 6d 69 6c 6b 35 06 31 6e c8 .milk5.1n.
|
||||
```
|
||||
|
||||
A note about the tail pointer linked-list: Normally, this linked-list is
|
||||
threaded through the entire filesystem. However, after power-loss this
|
||||
linked-list may become out of sync with the rest of the filesystem.
|
||||
- The linked-list may contain a directory that has actually been removed
|
||||
- The linked-list may contain a metadata pair that has not been updated after
|
||||
a block in the pair has gone bad.
|
||||
|
||||
The threaded linked-list must be checked for these errors before it can be
|
||||
used reliably. Fortunately, the threaded linked-list can simply be ignored
|
||||
if littlefs is mounted read-only.
|
||||
|
||||
## Entries
|
||||
|
||||
Each metadata block contains a series of entries that follow a standard
|
||||
layout. An entry contains the type of the entry, along with a section for
|
||||
entry-specific data, attributes, and a name.
|
||||
|
||||
Here's the layout of entries on disk:
|
||||
|
||||
| offset | size | description |
|
||||
|---------|------------------------|----------------------------|
|
||||
| 0x0 | 8 bits | entry type |
|
||||
| 0x1 | 8 bits | entry length |
|
||||
| 0x2 | 8 bits | attribute length |
|
||||
| 0x3 | 8 bits | name length |
|
||||
| 0x4 | entry length bytes | entry-specific data |
|
||||
| 0x4+e | attribute length bytes | system-specific attributes |
|
||||
| 0x4+e+a | name length bytes | entry name |
|
||||
|
||||
**Entry type** - Type of the entry, currently this is limited to the following:
|
||||
- 0x11 - file entry
|
||||
- 0x22 - directory entry
|
||||
- 0x2e - superblock entry
|
||||
|
||||
Additionally, the type is broken into two 4 bit nibbles, with the upper nibble
|
||||
specifying the type's data structure used when scanning the filesystem. The
|
||||
lower nibble clarifies the type further when multiple entries share the same
|
||||
data structure.
|
||||
|
||||
The highest bit is reserved for marking the entry as "moved". If an entry
|
||||
is marked as "moved", the entry may also exist somewhere else in the
|
||||
filesystem. If the entry exists elsewhere, this entry must be treated as
|
||||
though it does not exist.
|
||||
|
||||
**Entry length** - Length in bytes of the entry-specific data. This does
|
||||
not include the entry type size, attributes, or name. The full size in bytes
|
||||
of the entry is 4 + entry length + attribute length + name length.
|
||||
|
||||
**Attribute length** - Length of system-specific attributes in bytes. Since
|
||||
attributes are system specific, there is not much guarantee on the values in
|
||||
this section, and systems are expected to work even when it is empty. See the
|
||||
[attributes](#entry-attributes) section for more details.
|
||||
|
||||
**Name length** - Length of the entry name. Entry names are stored as UTF8,
|
||||
although most systems will probably only support ASCII. Entry names can not
|
||||
contain '/' and can not be '.' or '..' as these are a part of the syntax of
|
||||
filesystem paths.
|
||||
|
||||
Here's an example of a simple entry stored on disk:
|
||||
```
|
||||
(8 bits) entry type = file (0x11)
|
||||
(8 bits) entry length = 8 bytes (0x08)
|
||||
(8 bits) attribute length = 0 bytes (0x00)
|
||||
(8 bits) name length = 12 bytes (0x0c)
|
||||
(8 bytes) entry data = 05 00 00 00 20 00 00 00
|
||||
(12 bytes) entry name = smallavacado
|
||||
|
||||
00000000: 11 08 00 0c 05 00 00 00 20 00 00 00 73 6d 61 6c ........ ...smal
|
||||
00000010: 6c 61 76 61 63 61 64 6f lavacado
|
||||
```
|
||||
|
||||
## Superblock
|
||||
|
||||
The superblock is the anchor for the littlefs. The superblock is stored as
|
||||
a metadata pair containing a single superblock entry. It is through the
|
||||
superblock that littlefs can access the rest of the filesystem.
|
||||
|
||||
The superblock can always be found in blocks 0 and 1, however fetching the
|
||||
superblock requires knowing the block size. The block size can be guessed by
|
||||
searching the beginning of disk for the string "littlefs", although currently
|
||||
the filesystems relies on the user providing the correct block size.
|
||||
|
||||
The superblock is the most valuable block in the filesystem. It is updated
|
||||
very rarely, only during format or when the root directory must be moved. It
|
||||
is encouraged to always write out both superblock pairs even though it is not
|
||||
required.
|
||||
|
||||
Here's the layout of the superblock entry:
|
||||
|
||||
| offset | size | description |
|
||||
|--------|------------------------|----------------------------------------|
|
||||
| 0x00 | 8 bits | entry type (0x2e for superblock entry) |
|
||||
| 0x01 | 8 bits | entry length (20 bytes) |
|
||||
| 0x02 | 8 bits | attribute length |
|
||||
| 0x03 | 8 bits | name length (8 bytes) |
|
||||
| 0x04 | 64 bits | root directory |
|
||||
| 0x0c | 32 bits | block size |
|
||||
| 0x10 | 32 bits | block count |
|
||||
| 0x14 | 32 bits | version |
|
||||
| 0x18 | attribute length bytes | system-specific attributes |
|
||||
| 0x18+a | 8 bytes | magic string ("littlefs") |
|
||||
|
||||
**Root directory** - Pointer to the root directory's metadata pair.
|
||||
|
||||
**Block size** - Size of the logical block size used by the filesystem.
|
||||
|
||||
**Block count** - Number of blocks in the filesystem.
|
||||
|
||||
**Version** - The littlefs version encoded as a 32 bit value. The upper 16 bits
|
||||
encodes the major version, which is incremented when a breaking-change is
|
||||
introduced in the filesystem specification. The lower 16 bits encodes the
|
||||
minor version, which is incremented when a backwards-compatible change is
|
||||
introduced. Non-standard Attribute changes do not change the version. This
|
||||
specification describes version 1.1 (0x00010001), which is the first version
|
||||
of littlefs.
|
||||
|
||||
**Magic string** - The magic string "littlefs" takes the place of an entry
|
||||
name.
|
||||
|
||||
Here's an example of a complete superblock:
|
||||
```
|
||||
(32 bits) revision count = 3 (0x00000003)
|
||||
(32 bits) dir size = 52 bytes, end of dir (0x00000034)
|
||||
(64 bits) tail pointer = 3, 2 (0x00000003, 0x00000002)
|
||||
(8 bits) entry type = superblock (0x2e)
|
||||
(8 bits) entry length = 20 bytes (0x14)
|
||||
(8 bits) attribute length = 0 bytes (0x00)
|
||||
(8 bits) name length = 8 bytes (0x08)
|
||||
(64 bits) root directory = 3, 2 (0x00000003, 0x00000002)
|
||||
(32 bits) block size = 512 bytes (0x00000200)
|
||||
(32 bits) block count = 1024 blocks (0x00000400)
|
||||
(32 bits) version = 1.1 (0x00010001)
|
||||
(8 bytes) magic string = littlefs
|
||||
(32 bits) CRC = 0xc50b74fa
|
||||
|
||||
00000000: 03 00 00 00 34 00 00 00 03 00 00 00 02 00 00 00 ....4...........
|
||||
00000010: 2e 14 00 08 03 00 00 00 02 00 00 00 00 02 00 00 ................
|
||||
00000020: 00 04 00 00 01 00 01 00 6c 69 74 74 6c 65 66 73 ........littlefs
|
||||
00000030: fa 74 0b c5 .t..
|
||||
```
|
||||
|
||||
## Directory entries
|
||||
|
||||
Directories are stored in entries with a pointer to the first metadata pair
|
||||
in the directory. Keep in mind that a directory may be composed of multiple
|
||||
metadata pairs connected by the tail pointer when the highest bit in the dir
|
||||
size is set.
|
||||
|
||||
Here's the layout of a directory entry:
|
||||
|
||||
| offset | size | description |
|
||||
|--------|------------------------|-----------------------------------------|
|
||||
| 0x0 | 8 bits | entry type (0x22 for directory entries) |
|
||||
| 0x1 | 8 bits | entry length (8 bytes) |
|
||||
| 0x2 | 8 bits | attribute length |
|
||||
| 0x3 | 8 bits | name length |
|
||||
| 0x4 | 64 bits | directory pointer |
|
||||
| 0xc | attribute length bytes | system-specific attributes |
|
||||
| 0xc+a | name length bytes | directory name |
|
||||
|
||||
**Directory pointer** - Pointer to the first metadata pair in the directory.
|
||||
|
||||
Here's an example of a directory entry:
|
||||
```
|
||||
(8 bits) entry type = directory (0x22)
|
||||
(8 bits) entry length = 8 bytes (0x08)
|
||||
(8 bits) attribute length = 0 bytes (0x00)
|
||||
(8 bits) name length = 3 bytes (0x03)
|
||||
(64 bits) directory pointer = 5, 4 (0x00000005, 0x00000004)
|
||||
(3 bytes) name = tea
|
||||
|
||||
00000000: 22 08 00 03 05 00 00 00 04 00 00 00 74 65 61 "...........tea
|
||||
```
|
||||
|
||||
## File entries
|
||||
|
||||
Files are stored in entries with a pointer to the head of the file and the
|
||||
size of the file. This is enough information to determine the state of the
|
||||
CTZ skip-list that is being referenced.
|
||||
|
||||
How files are actually stored on disk is a bit complicated. The full
|
||||
explanation of CTZ skip-lists can be found in [DESIGN.md](DESIGN.md#ctz-skip-lists).
|
||||
|
||||
A terribly quick summary: For every nth block where n is divisible by 2^x,
|
||||
the block contains a pointer to block n-2^x. These pointers are stored in
|
||||
increasing order of x in each block of the file preceding the data in the
|
||||
block.
|
||||
|
||||
The maximum number of pointers in a block is bounded by the maximum file size
|
||||
divided by the block size. With 32 bits for file size, this results in a
|
||||
minimum block size of 104 bytes.
|
||||
|
||||
Here's the layout of a file entry:
|
||||
|
||||
| offset | size | description |
|
||||
|--------|------------------------|------------------------------------|
|
||||
| 0x0 | 8 bits | entry type (0x11 for file entries) |
|
||||
| 0x1 | 8 bits | entry length (8 bytes) |
|
||||
| 0x2 | 8 bits | attribute length |
|
||||
| 0x3 | 8 bits | name length |
|
||||
| 0x4 | 32 bits | file head |
|
||||
| 0x8 | 32 bits | file size |
|
||||
| 0xc | attribute length bytes | system-specific attributes |
|
||||
| 0xc+a | name length bytes | directory name |
|
||||
|
||||
**File head** - Pointer to the block that is the head of the file's CTZ
|
||||
skip-list.
|
||||
|
||||
**File size** - Size of file in bytes.
|
||||
|
||||
Here's an example of a file entry:
|
||||
```
|
||||
(8 bits) entry type = file (0x11)
|
||||
(8 bits) entry length = 8 bytes (0x08)
|
||||
(8 bits) attribute length = 0 bytes (0x00)
|
||||
(8 bits) name length = 12 bytes (0x03)
|
||||
(32 bits) file head = 543 (0x0000021f)
|
||||
(32 bits) file size = 256 KB (0x00040000)
|
||||
(12 bytes) name = largeavacado
|
||||
|
||||
00000000: 11 08 00 0c 1f 02 00 00 00 00 04 00 6c 61 72 67 ............larg
|
||||
00000010: 65 61 76 61 63 61 64 6f eavacado
|
||||
```
|
||||
|
||||
## Entry attributes
|
||||
|
||||
Each dir entry can have up to 256 bytes of system-specific attributes. Since
|
||||
these attributes are system-specific, they may not be portable between
|
||||
different systems. For this reason, all attributes must be optional. A minimal
|
||||
littlefs driver must be able to get away with supporting no attributes at all.
|
||||
|
||||
For some level of portability, littlefs has a simple scheme for attributes.
|
||||
Each attribute is prefixes with an 8-bit type that indicates what the attribute
|
||||
is. The length of attributes may also be determined from this type. Attributes
|
||||
in an entry should be sorted based on portability, since attribute parsing
|
||||
will end when it hits the first attribute it does not understand.
|
||||
|
||||
Each system should choose a 4-bit value to prefix all attribute types with to
|
||||
avoid conflicts with other systems. Additionally, littlefs drivers that support
|
||||
attributes should provide a "ignore attributes" flag to users in case attribute
|
||||
conflicts do occur.
|
||||
|
||||
Attribute types prefixes with 0x0 and 0xf are currently reserved for future
|
||||
standard attributes. Standard attributes will be added to this document in
|
||||
that case.
|
||||
|
||||
Here's an example of non-standard time attribute:
|
||||
```
|
||||
(8 bits) attribute type = time (0xc1)
|
||||
(72 bits) time in seconds = 1506286115 (0x0059c81a23)
|
||||
|
||||
00000000: c1 23 1a c8 59 00 .#..Y.
|
||||
```
|
||||
|
||||
Here's an example of non-standard permissions attribute:
|
||||
```
|
||||
(8 bits) attribute type = permissions (0xc2)
|
||||
(16 bits) permission bits = rw-rw-r-- (0x01b4)
|
||||
|
||||
00000000: c2 b4 01 ...
|
||||
```
|
||||
|
||||
Here's what a dir entry may look like with these attributes:
|
||||
```
|
||||
(8 bits) entry type = file (0x11)
|
||||
(8 bits) entry length = 8 bytes (0x08)
|
||||
(8 bits) attribute length = 9 bytes (0x09)
|
||||
(8 bits) name length = 12 bytes (0x0c)
|
||||
(8 bytes) entry data = 05 00 00 00 20 00 00 00
|
||||
(8 bits) attribute type = time (0xc1)
|
||||
(72 bits) time in seconds = 1506286115 (0x0059c81a23)
|
||||
(8 bits) attribute type = permissions (0xc2)
|
||||
(16 bits) permission bits = rw-rw-r-- (0x01b4)
|
||||
(12 bytes) entry name = smallavacado
|
||||
|
||||
00000000: 11 08 09 0c 05 00 00 00 20 00 00 00 c1 23 1a c8 ........ ....#..
|
||||
00000010: 59 00 c2 b4 01 73 6d 61 6c 6c 61 76 61 63 61 64 Y....smallavacad
|
||||
00000020: 6f o
|
||||
```
|
||||
+9
-6
@@ -12,7 +12,10 @@
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <Bluefruit_FileIO.h>
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup()
|
||||
@@ -33,11 +36,11 @@ void setup()
|
||||
// Initialize Internal File System
|
||||
InternalFS.begin();
|
||||
|
||||
Serial.print("Formating ...");
|
||||
|
||||
// Format without erase
|
||||
// Pass true for full external flash erasing (take time)
|
||||
InternalFS.format(true);
|
||||
Serial.print("Formating ... ");
|
||||
delay(1); // for message appear on monitor
|
||||
|
||||
// Format
|
||||
InternalFS.format();
|
||||
|
||||
Serial.println("Done");
|
||||
}
|
||||
+15
-8
@@ -12,8 +12,10 @@
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <bluefruit.h>
|
||||
#include <Bluefruit_FileIO.h>
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
/* This example print out Internal Flash contents up to
|
||||
* MAX_LEVEL level of directories (including root)
|
||||
@@ -38,7 +40,7 @@ void setup()
|
||||
|
||||
// Print prompt
|
||||
Serial.println();
|
||||
Serial.println("Enter anything to print directory tree (again):");
|
||||
Serial.println("Enter anything to print directory tree:");
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
@@ -53,7 +55,7 @@ void loop()
|
||||
|
||||
// Print prompt
|
||||
Serial.println();
|
||||
Serial.println("Enter anything to print directory tree (again):");
|
||||
Serial.println("Enter anything to print directory tree:");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +70,7 @@ void loop()
|
||||
void printTreeDir(const char* cwd, uint8_t level)
|
||||
{
|
||||
// Open the input folder
|
||||
File dir(cwd, FILE_READ, InternalFS);
|
||||
File dir(cwd, FILE_O_READ, InternalFS);
|
||||
|
||||
// Print root
|
||||
if (level == 0) Serial.println("root");
|
||||
@@ -76,8 +78,8 @@ void printTreeDir(const char* cwd, uint8_t level)
|
||||
// File within folder
|
||||
File item(InternalFS);
|
||||
|
||||
// Loop through the directory
|
||||
while( (item = dir.openNextFile(FILE_READ)) )
|
||||
// Loop through the directory
|
||||
while( (item = dir.openNextFile(FILE_O_READ)) )
|
||||
{
|
||||
// Indentation according to dir level
|
||||
for(int i=0; i<level; i++) Serial.print("| ");
|
||||
@@ -93,7 +95,12 @@ void printTreeDir(const char* cwd, uint8_t level)
|
||||
// High number of MAX_LEVEL can cause memory overflow
|
||||
if ( level < MAX_LEVEL )
|
||||
{
|
||||
printTreeDir( item.path(), level+1 );
|
||||
char dpath[strlen(cwd) + strlen(item.name()) + 2 ];
|
||||
strcpy(dpath, cwd);
|
||||
strcat(dpath, "/");
|
||||
strcat(dpath, item.name());
|
||||
|
||||
printTreeDir( dpath, level+1 );
|
||||
}
|
||||
}else
|
||||
{
|
||||
+9
-7
@@ -12,11 +12,13 @@
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <Bluefruit_FileIO.h>
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
#define FILENAME "/adafruit.txt"
|
||||
|
||||
#define CONTENTS "Bluefruit Feather52's file contents"
|
||||
#define CONTENTS "Adafruit Little File System test file contents"
|
||||
|
||||
File file(InternalFS);
|
||||
|
||||
@@ -42,7 +44,7 @@ void setup()
|
||||
// Initialize Internal File System
|
||||
InternalFS.begin();
|
||||
|
||||
file.open(FILENAME, FILE_READ);
|
||||
file.open(FILENAME, FILE_O_READ);
|
||||
|
||||
// file existed
|
||||
if ( file )
|
||||
@@ -60,7 +62,7 @@ void setup()
|
||||
{
|
||||
Serial.print("Open " FILENAME " file to write ... ");
|
||||
|
||||
if( file.open(FILENAME, FILE_WRITE) )
|
||||
if( file.open(FILENAME, FILE_O_WRITE) )
|
||||
{
|
||||
Serial.println("OK");
|
||||
file.write(CONTENTS, strlen(CONTENTS));
|
||||
@@ -70,11 +72,11 @@ void setup()
|
||||
Serial.println("Failed!");
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("Done");
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop()
|
||||
{
|
||||
digitalToggle(LED_RED);
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
name=Adafruit Internal File System on Bluefruit nRF52
|
||||
version=0.11.0
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Adafruit Internal File System on Bluefruit nRF52
|
||||
paragraph=Adafruit Internal File System on Bluefruit nRF52
|
||||
category=Data Storage
|
||||
url=https://github.com/adafruit/Adafruit_nRF52_Arduino
|
||||
architectures=*
|
||||
includes=InternalFileSystem.h
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 hathach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "InternalFileSystem.h"
|
||||
#include "flash/flash_nrf5x.h"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
#define LFS_FLASH_ADDR 0xED000
|
||||
#else
|
||||
#define LFS_FLASH_ADDR 0x6D000
|
||||
#endif
|
||||
|
||||
#define LFS_FLASH_TOTAL_SIZE (7*FLASH_NRF52_PAGE_SIZE)
|
||||
#define LFS_BLOCK_SIZE 128
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// LFS Disk IO
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static inline uint32_t lba2addr(uint32_t block)
|
||||
{
|
||||
return ((uint32_t) LFS_FLASH_ADDR) + block * LFS_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
static int _internal_flash_read (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
|
||||
{
|
||||
(void) c;
|
||||
|
||||
uint32_t addr = lba2addr(block) + off;
|
||||
flash_nrf5x_read(buffer, addr, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Program a region in a block. The block must have previously
|
||||
// been erased. Negative error codes are propogated to the user.
|
||||
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
||||
static int _internal_flash_prog (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer,
|
||||
lfs_size_t size)
|
||||
{
|
||||
(void) c;
|
||||
|
||||
uint32_t addr = lba2addr(block) + off;
|
||||
flash_nrf5x_write(addr, buffer, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Erase a block. A block must be erased before being programmed.
|
||||
// The state of an erased block is undefined. Negative error codes
|
||||
// are propogated to the user.
|
||||
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
||||
static int _internal_flash_erase (const struct lfs_config *c, lfs_block_t block)
|
||||
{
|
||||
(void) c;
|
||||
|
||||
uint32_t addr = lba2addr(block);
|
||||
|
||||
// implement as write 0xff to whole block address
|
||||
for(int i=0; i <LFS_BLOCK_SIZE; i++)
|
||||
{
|
||||
flash_nrf5x_write8(addr + i, 0xFF);
|
||||
}
|
||||
|
||||
// flash_nrf5x_flush();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Sync the state of the underlying block device. Negative error codes
|
||||
// are propogated to the user.
|
||||
static int _internal_flash_sync (const struct lfs_config *c)
|
||||
{
|
||||
(void) c;
|
||||
flash_nrf5x_flush();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static struct lfs_config _InternalFSConfig =
|
||||
{
|
||||
.context = NULL,
|
||||
|
||||
.read = _internal_flash_read,
|
||||
.prog = _internal_flash_prog,
|
||||
.erase = _internal_flash_erase,
|
||||
.sync = _internal_flash_sync,
|
||||
|
||||
.read_size = LFS_BLOCK_SIZE,
|
||||
.prog_size = LFS_BLOCK_SIZE,
|
||||
.block_size = LFS_BLOCK_SIZE,
|
||||
.block_count = LFS_FLASH_TOTAL_SIZE / LFS_BLOCK_SIZE,
|
||||
.lookahead = 128,
|
||||
|
||||
.read_buffer = NULL,
|
||||
.prog_buffer = NULL,
|
||||
.lookahead_buffer = NULL,
|
||||
.file_buffer = NULL
|
||||
};
|
||||
|
||||
InternalFileSystem InternalFS;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
InternalFileSystem::InternalFileSystem(void)
|
||||
: Adafruit_LittleFS(&_InternalFSConfig)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool InternalFileSystem::begin(void)
|
||||
{
|
||||
// failed to mount, erase all sector then format and mount again
|
||||
if ( !Adafruit_LittleFS::begin() )
|
||||
{
|
||||
// Erase all sectors of internal flash region for Filesystem.
|
||||
for ( uint32_t addr = LFS_FLASH_ADDR; addr < LFS_FLASH_ADDR + LFS_FLASH_TOTAL_SIZE; addr += FLASH_NRF52_PAGE_SIZE )
|
||||
{
|
||||
VERIFY( flash_nrf5x_erase(addr) );
|
||||
}
|
||||
|
||||
// lfs format
|
||||
this->format();
|
||||
|
||||
// mount again if still failed, give up
|
||||
if ( !Adafruit_LittleFS::begin() ) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 hathach for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef INTERNALFILESYSTEM_H_
|
||||
#define INTERNALFILESYSTEM_H_
|
||||
|
||||
#include "Adafruit_LittleFS.h"
|
||||
|
||||
class InternalFileSystem : public Adafruit_LittleFS
|
||||
{
|
||||
public:
|
||||
InternalFileSystem(void);
|
||||
|
||||
// overwrite to also perform low level format (sector erase of whole flash region)
|
||||
bool begin(void);
|
||||
};
|
||||
|
||||
extern InternalFileSystem InternalFS;
|
||||
|
||||
#endif /* INTERNALFILESYSTEM_H_ */
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-2
@@ -17,7 +17,7 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
name=Adafruit nRF52 Boards
|
||||
version=0.10.5
|
||||
version=0.11.0
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
@@ -59,7 +59,7 @@ nordic.path={build.core.path}/nordic
|
||||
# ARDUINO_FEATHER52 is defined for backward compatiable with other lib only
|
||||
# should be replaced by ARDUINO_NRF52_ADAFRUIT in the future
|
||||
|
||||
build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_FEATHER52 -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -Os {build.debug_flags} "-I{build.core.path}/cmsis/include" "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{build.core.path}/Adafruit_TinyUSB_Core" "-I{build.core.path}/Adafruit_TinyUSB_Core/tinyusb/src"
|
||||
build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_FEATHER52 -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -DLFS_NAME_MAX=64 -Os {build.debug_flags} "-I{build.core.path}/cmsis/include" "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{build.core.path}/Adafruit_TinyUSB_Core" "-I{build.core.path}/Adafruit_TinyUSB_Core/tinyusb/src"
|
||||
|
||||
# usb flags
|
||||
build.flags.usb= -DUSBCON -DUSE_TINYUSB -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "wiring_constants.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "nrf.h"
|
||||
#include "flash/flash_qspi.h"
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] =
|
||||
{
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "wiring_constants.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "nrf.h"
|
||||
#include "flash/flash_qspi.h"
|
||||
|
||||
#define _PINNUM(port, pin) ((port)*32 + (pin))
|
||||
|
||||
@@ -88,10 +87,5 @@ void initVariant()
|
||||
|
||||
pinMode(PIN_LED2, OUTPUT);
|
||||
ledOff(PIN_LED2);
|
||||
|
||||
#if 0 // disable QSPI flash for now
|
||||
// Init External Flash
|
||||
flash_qspi_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "wiring_constants.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "nrf.h"
|
||||
#include "flash/flash_qspi.h"
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] =
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user