ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
vfs_tinyusb.h File Reference
#include "esp_err.h"
Include dependency graph for vfs_tinyusb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VFS_TUSB_MAX_PATH   16
#define VFS_TUSB_PATH_DEFAULT   "/dev/tusb_cdc"

Functions

esp_err_t esp_vfs_tusb_cdc_register (int cdc_intf, char const *path)
 Register TinyUSB CDC at VFS with path.
esp_err_t esp_vfs_tusb_cdc_unregister (char const *path)
 Unregister TinyUSB CDC from VFS.

Macro Definition Documentation

◆ VFS_TUSB_MAX_PATH

#define VFS_TUSB_MAX_PATH   16

Definition at line 15 of file vfs_tinyusb.h.

Referenced by apply_path().

◆ VFS_TUSB_PATH_DEFAULT

#define VFS_TUSB_PATH_DEFAULT   "/dev/tusb_cdc"

Definition at line 16 of file vfs_tinyusb.h.

Referenced by apply_path(), esp_tusb_init_console(), and esp_vfs_tusb_cdc_unregister().

Function Documentation

◆ esp_vfs_tusb_cdc_register()

esp_err_t esp_vfs_tusb_cdc_register ( int cdc_intf,
char const * path )

Register TinyUSB CDC at VFS with path.

Parameters
cdc_intf- interface number of TinyUSB's CDC
path- path where the CDC will be registered, /dev/tusb_cdc will be used if left NULL.
Returns
esp_err_t ESP_OK or ESP_FAIL

Definition at line 256 of file vfs_tinyusb.c.

257{
258 ESP_LOGD(TAG, "Registering TinyUSB CDC driver");
259 int res;
260 if (!tusb_cdc_acm_initialized(cdc_intf)) {
261 ESP_LOGE(TAG, "TinyUSB CDC#%d is not initialized", cdc_intf);
262 return ESP_ERR_INVALID_STATE;
263 }
264
265 res = vfstusb_init(cdc_intf, path);
266 if (res != ESP_OK) {
267 return res;
268 }
269
270 esp_vfs_t vfs = {
271 .flags = ESP_VFS_FLAG_DEFAULT,
272 .close = &tusb_close,
273 .fcntl = &tusb_fcntl,
274 .fstat = &tusb_fstat,
275 .open = &tusb_open,
276 .read = &tusb_read,
277 .write = &tusb_write,
278 };
279
280 res = esp_vfs_register(s_vfstusb.vfs_path, &vfs, NULL);
281 if (res != ESP_OK) {
282 ESP_LOGE(TAG, "Can't register TinyUSB driver (err: %x)", res);
283 } else {
284 ESP_LOGD(TAG, "TinyUSB CDC registered (%s)", s_vfstusb.vfs_path);
285 }
286 return res;
287}
#define ESP_OK
Definition esp_err.h:23
#define ESP_LOGD
Definition esp_log.h:22
static const char * TAG
Definition main/main.c:31
bool tusb_cdc_acm_initialized(tinyusb_cdcacm_itf_t itf)
Check if the ACM initialized.
static int tusb_close(int fd)
static vfs_tinyusb_t s_vfstusb
Definition vfs_tinyusb.c:65
static int tusb_open(const char *path, int flags, int mode)
static esp_err_t vfstusb_init(int cdc_intf, char const *path)
Fill s_vfstusb.
Definition vfs_tinyusb.c:93
static int tusb_fcntl(int fd, int cmd, int arg)
static int tusb_fstat(int fd, struct stat *st)
static ssize_t tusb_read(int fd, void *data, size_t size)
static ssize_t tusb_write(int fd, const void *data, size_t size)

References ESP_LOGD, ESP_OK, s_vfstusb, TAG, tusb_cdc_acm_initialized(), tusb_close(), tusb_fcntl(), tusb_fstat(), tusb_open(), tusb_read(), tusb_write(), and vfstusb_init().

Referenced by esp_tusb_init_console().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ esp_vfs_tusb_cdc_unregister()

esp_err_t esp_vfs_tusb_cdc_unregister ( char const * path)

Unregister TinyUSB CDC from VFS.

Parameters
path- path where the CDC will be unregistered if NULL will be used /dev/tusb_cdc
Returns
esp_err_t ESP_OK or ESP_FAIL

Definition at line 224 of file vfs_tinyusb.c.

225{
226 ESP_LOGD(TAG, "Unregistering TinyUSB driver");
227 int res;
228
229 if (path == NULL) { // NULL means using the default path for unregistering: VFS_TUSB_PATH_DEFAULT
230 res = strcmp(s_vfstusb.vfs_path, VFS_TUSB_PATH_DEFAULT);
231 } else {
232 res = strcmp(s_vfstusb.vfs_path, path);
233 }
234
235 if (res) {
236 res = ESP_ERR_INVALID_ARG;
237 ESP_LOGE(TAG, "There is no TinyUSB driver registerred to the path '%s' (err: 0x%x)", s_vfstusb.vfs_path, res);
238 return res;
239 }
240
241
242
243 res = esp_vfs_unregister(s_vfstusb.vfs_path);
244 if (res != ESP_OK) {
245 ESP_LOGE(TAG, "Can't unregister TinyUSB driver from '%s' (err: 0x%x)", s_vfstusb.vfs_path, res);
246 } else {
247 ESP_LOGD(TAG, "Unregistered TinyUSB driver");
249 }
250 return res;
251}
static void vfstusb_deinit(void)
Clear s_vfstusb to default values.
#define VFS_TUSB_PATH_DEFAULT
Definition vfs_tinyusb.h:16

References ESP_LOGD, ESP_OK, s_vfstusb, TAG, VFS_TUSB_PATH_DEFAULT, and vfstusb_deinit().

Referenced by esp_tusb_deinit_console().

Here is the call graph for this function:
Here is the caller graph for this function: