A USB mass storage device supports one or more logical units, each of which is a physical storage device. More...

#include <HostDevice.h>

Inheritance diagram for USB::MSC::HostDevice:
Collaboration diagram for USB::MSC::HostDevice:

Public Types

using EnumCallback = Delegate< bool(LogicalUnit &unit, const Inquiry &inquiry)>
 Callback passed to enumerate() method. More...
 

Public Member Functions

bool begin (const Instance &inst)
 
void end ()
 Called when device is disconnected. Override as required. More...
 
bool enumerate (EnumCallback callback)
 Enumerate all logical units managed by this device. More...
 
LogicalUnitoperator[] (unsigned lun) const
 Access a specific logical unit by number. More...
 
size_t getSectorSize (uint8_t lun) const
 Get the declared block/sector size for a unit. More...
 
storage_size_t getSectorCount (uint8_t lun) const
 Get the number of blocks/sectors for a unit. More...
 
bool read_sectors (uint8_t lun, uint32_t lba, void *dst, size_t size)
 Read data from a unit. More...
 
bool write_sectors (uint8_t lun, uint32_t lba, const void *src, size_t size)
 Write data to a unit. More...
 
bool wait ()
 Wait for all outstanding operations to complete. More...
 
- Public Member Functions inherited from USB::HostInterface
void begin (const Instance &inst)
 Descendant classes should override this method to peform initialisation. More...
 
const char * getName () const
 
uint8_t getAddress () const
 
bool operator== (const HostInterface &other) const
 
bool operator== (const Instance &other) const
 

Public Attributes

std::unique_ptr< LogicalUnitunits [MAX_LUN] {}
 

Static Public Attributes

static constexpr size_t MAX_LUN {CFG_TUH_MSC_MAXLUN}
 

Additional Inherited Members

- Protected Attributes inherited from USB::HostInterface
Instance inst
 

Detailed Description

A USB mass storage device supports one or more logical units, each of which is a physical storage device.

Member Typedef Documentation

◆ EnumCallback

using USB::MSC::HostDevice::EnumCallback = Delegate<bool(LogicalUnit& unit, const Inquiry& inquiry)>

Callback passed to enumerate() method.

Parameters
unitThe logical unit attached to a device
inquiryDetailed information
Return values
booltrue to continue enumeration, false to stop

Member Function Documentation

◆ begin()

bool USB::MSC::HostDevice::begin ( const Instance inst)

◆ end()

void USB::MSC::HostDevice::end ( )
virtual

Called when device is disconnected. Override as required.

Reimplemented from USB::HostInterface.

◆ enumerate()

bool USB::MSC::HostDevice::enumerate ( EnumCallback  callback)

Enumerate all logical units managed by this device.

Parameters
callbackInvoked for each discovered Logical Unit

◆ getSectorCount()

storage_size_t USB::MSC::HostDevice::getSectorCount ( uint8_t  lun) const
inline

Get the number of blocks/sectors for a unit.

Parameters
lunThe logical Unit Number
Return values
size_tNumber of blocks, 0 if invalid

◆ getSectorSize()

size_t USB::MSC::HostDevice::getSectorSize ( uint8_t  lun) const
inline

Get the declared block/sector size for a unit.

Parameters
lunThe logical Unit Number
Return values
size_tBlock size in bytes, or 0 if invalid

◆ operator[]()

LogicalUnit* USB::MSC::HostDevice::operator[] ( unsigned  lun) const
inline

Access a specific logical unit by number.

Parameters
lunThe logical Unit Number
Return values
LogicalUnit*The corresponding LU, or nullptr if invalid

◆ read_sectors()

bool USB::MSC::HostDevice::read_sectors ( uint8_t  lun,
uint32_t  lba,
void *  dst,
size_t  size 
)

Read data from a unit.

Parameters
lunThe logical Unit Number
lbaStarting Logical Block Address
dstBuffer to store data
sizeNumber of sectors to read
Return values
booltrue on success

◆ wait()

bool USB::MSC::HostDevice::wait ( )

Wait for all outstanding operations to complete.

Parameters
lunThe logical Unit Number
Return values
boolfalse on error (e.g. device forceably disconnected)

Write operations are asynchronous so calling this method ensures that the operation has completed.

◆ write_sectors()

bool USB::MSC::HostDevice::write_sectors ( uint8_t  lun,
uint32_t  lba,
const void *  src,
size_t  size 
)

Write data to a unit.

Parameters
lunThe logical Unit Number
lbaStarting Logical Block Address
srcData to write
sizeNumber of sectors to write
Return values
booltrue on success

Member Data Documentation

◆ MAX_LUN

constexpr size_t USB::MSC::HostDevice::MAX_LUN {CFG_TUH_MSC_MAXLUN}
staticconstexpr

◆ units

std::unique_ptr<LogicalUnit> USB::MSC::HostDevice::units[MAX_LUN] {}

The documentation for this class was generated from the following file: