1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include <stdint.h> 10 #include <sys/queue.h> 11 #include "esp_err.h" 12 #include "esp_check.h" 13 #include "diskio_usb.h" 14 #include "usb/usb_host.h" 15 #include "usb/usb_types_stack.h" 16 #include "freertos/semphr.h" 17 18 #ifdef __cplusplus 19 extern "C" 20 { 21 #endif 22 23 typedef enum { 24 MSC_EP_OUT, 25 MSC_EP_IN 26 } msc_endpoint_t; 27 28 typedef struct { 29 uint16_t bulk_in_mps; 30 uint8_t bulk_in_ep; 31 uint8_t bulk_out_ep; 32 uint8_t iface_num; 33 } msc_config_t; 34 35 typedef struct msc_host_device { 36 STAILQ_ENTRY(msc_host_device) tailq_entry; 37 usb_transfer_status_t transfer_status; 38 SemaphoreHandle_t transfer_done; 39 usb_device_handle_t handle; 40 usb_transfer_t *xfer; 41 msc_config_t config; 42 usb_disk_t disk; 43 } msc_device_t; 44 45 esp_err_t msc_bulk_transfer(msc_device_t *device_handle, uint8_t *data, size_t size, msc_endpoint_t ep); 46 47 esp_err_t msc_control_transfer(msc_device_t *device_handle, usb_transfer_t *xfer, size_t len); 48 49 #define MSC_GOTO_ON_ERROR(exp) ESP_GOTO_ON_ERROR(exp, fail, TAG, "") 50 51 #define MSC_GOTO_ON_FALSE(exp, err) ESP_GOTO_ON_FALSE( (exp), err, fail, TAG, "" ) 52 53 #define MSC_RETURN_ON_ERROR(exp) ESP_RETURN_ON_ERROR((exp), TAG, "") 54 55 #define MSC_RETURN_ON_FALSE(exp, err) ESP_RETURN_ON_FALSE( (exp), (err), TAG, "") 56 57 #define MSC_RETURN_ON_INVALID_ARG(exp) ESP_RETURN_ON_FALSE((exp) != NULL, ESP_ERR_INVALID_ARG, TAG, "") 58 59 #ifdef __cplusplus 60 } 61 #endif 62