Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tusb_msc): Add device mount/unmount callback #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

peter-marcisovsky
Copy link
Collaborator

Description

This MR adds a possibility to define a user callback for device mount/unmount events.

Right now, the tusb_msc_storage.c automatically calls:

  • tinyusb_msc_storage_mount() at tud_umount_cb()
  • tinyusb_msc_storage_unmount() at tud_mount_cb()

User has no flexibility to do anything else upon the device mount/unmount.

This MR adds a flexibility to the user, to for example control an owership of the storage (eg, not to automatically unmount a storage when a USB device is plugged in)

Also cleaned conceptions between device mount/unmount and storage mount/unmount, not to confuse anyone when the code refers to device mount/unmount and when to storage mount/unmount.

Related

Related to #78

Testing


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@peter-marcisovsky peter-marcisovsky self-assigned this Jan 20, 2025
@peter-marcisovsky peter-marcisovsky force-pushed the feat/tusb_msc_add_device_mount_umount_cb branch from 5815978 to 4230c66 Compare January 20, 2025 18:38
@peter-marcisovsky
Copy link
Collaborator Author

I added a user callback which gets called at tud_umount_cb() or tud_mount_cb().

There is a new event TINYUSB_MSC_EVENT_DEVICE_MOUNT_CHANGED registered to the callback looking like this:

typedef enum {
    TINYUSB_MSC_EVENT_MOUNT_CHANGED,                /*!< Event type AFTER storage mount/unmount operation is successfully finished */
    TINYUSB_MSC_EVENT_PREMOUNT_CHANGED,             /*!< Event type BEFORE storage mount/unmount operation is started */
    TINYUSB_MSC_EVENT_DEVICE_MOUNT_CHANGED,         /*!< Event type at device mounted/unmounted event */
} tinyusb_msc_event_type_t;

There are 3 events now, EVENT_MOUNT, EVENT_PREMOUNT and EVENT_DEVICE_MOUNT.
It might make sense to rename:

  • EVENT_MOUNT to EVENT_STORAGE_MOUNT
  • EVENT_PREMOUNT to EVENT_STORAGE_PREMOUNT

Just to make sure, which event is registered to storage mount and which to device mount. So we will have something like this:

typedef enum {
    TINYUSB_MSC_EVENT_STORAGE_MOUNT_CHANGED,                /*!< Event type AFTER storage mount/unmount operation is successfully finished */
    TINYUSB_MSC_EVENT_STORAGE_PREMOUNT_CHANGED,             /*!< Event type BEFORE storage mount/unmount operation is started */
    TINYUSB_MSC_EVENT_DEVICE_MOUNT_CHANGED,         /*!< Event type at device mounted/unmounted event */
} tinyusb_msc_event_type_t;

But those event enums are used in tusb_msc example So we will be changing some publicly accessible enums. Also esp-idf examples build CI Job won't pass.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant