usb: device_next: msc: Allow user to sort LUNs

Modify USBD_DEFINE_MSC_LUN() to take in separate id by which the LUNs
are sorted. Previously the disk name itself was implicitly used as a
sorting key. This is a breaking change to Experimental API.

Another advantage of splitting the sorting id from disk name is the
ability to use KConfig symbols as disk name. Currently the MMC disk
driver uses KConfig symbol CONFIG_MMC_VOLUME_NAME.

Mark LUN definitions as static const because the LUNs are ending up in
ITERABLE_SECTION_ROM().

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
This commit is contained in:
Tomasz Moń 2024-08-23 07:35:16 +02:00 committed by Anas Nashif
parent e4236be678
commit aa6319dcfd
2 changed files with 10 additions and 9 deletions

View File

@ -37,17 +37,18 @@ struct usbd_msc_lun {
* Up to `CONFIG_USBD_MSC_LUNS_PER_INSTANCE` disks can be registered on single
* USB MSC instance. Currently only one USB MSC instance is supported.
*
* @param id Identifier by which the linker sorts registered LUNs
* @param disk_name Disk name as used in @ref disk_access_interface
* @param t10_vendor T10 Vendor Indetification
* @param t10_product T10 Product Identification
* @param t10_revision T10 Product Revision Level
*/
#define USBD_DEFINE_MSC_LUN(disk_name, t10_vendor, t10_product, t10_revision) \
STRUCT_SECTION_ITERABLE(usbd_msc_lun, usbd_msc_lun_##disk_name) = { \
.disk = STRINGIFY(disk_name), \
.vendor = t10_vendor, \
.product = t10_product, \
.revision = t10_revision, \
#define USBD_DEFINE_MSC_LUN(id, disk_name, t10_vendor, t10_product, t10_revision) \
static const STRUCT_SECTION_ITERABLE(usbd_msc_lun, usbd_msc_lun_##id) = { \
.disk = disk_name, \
.vendor = t10_vendor, \
.product = t10_product, \
.revision = t10_revision, \
}
/**

View File

@ -45,15 +45,15 @@ static struct fs_mount_t fs_mnt;
static struct usbd_context *sample_usbd;
#if CONFIG_DISK_DRIVER_RAM
USBD_DEFINE_MSC_LUN(RAM, "Zephyr", "RAMDisk", "0.00");
USBD_DEFINE_MSC_LUN(ram, "RAM", "Zephyr", "RAMDisk", "0.00");
#endif
#if CONFIG_DISK_DRIVER_FLASH
USBD_DEFINE_MSC_LUN(NAND, "Zephyr", "FlashDisk", "0.00");
USBD_DEFINE_MSC_LUN(nand, "NAND", "Zephyr", "FlashDisk", "0.00");
#endif
#if CONFIG_DISK_DRIVER_SDMMC
USBD_DEFINE_MSC_LUN(SD, "Zephyr", "SD", "0.00");
USBD_DEFINE_MSC_LUN(sd, "SD", "Zephyr", "SD", "0.00");
#endif
static int enable_usb_device_next(void)