19#include "esp_vfs_dev.h"
25const static char *
TAG =
"tusb_vfs";
30#define FD_CHECK(fd, ret_val) do { \
39#if CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF
40# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_CRLF
41#elif CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR
42# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_CR
44# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_LF
47#if CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF
48# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_CRLF
49#elif CONFIG_NEWLIB_STDIN_LINE_ENDING_CR
50# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_CR
52# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_LF
71 size_t path_len = strlen(path) + 1;
74 return ESP_ERR_INVALID_ARG;
82 ESP_LOGV(
TAG,
"Path is set to `%s`",
s_vfstusb.vfs_path);
111static int tusb_open(
const char *path,
int flags,
int mode)
122 size_t written_sz = 0;
123 const char *data_c = (
const char *)
data;
125 for (
size_t i = 0; i < size; i++) {
128 if (c ==
'\n' &&
s_vfstusb.tx_mode != ESP_LINE_ENDINGS_LF) {
134 if (
s_vfstusb.tx_mode == ESP_LINE_ENDINGS_CR) {
146 tud_cdc_n_write_flush(
s_vfstusb.cdc_intf);
160 char *data_c = (
char *)
data;
166 while (received < size) {
168 int c = tud_cdc_n_read_char(0);
169 if (
s_vfstusb.rx_mode == ESP_LINE_ENDINGS_CR) {
173 }
else if (
s_vfstusb.rx_mode == ESP_LINE_ENDINGS_CR) {
174 if ((c ==
'\n') & (cm1 ==
'\r')) {
182 data_c[received] = (char) c;
200 memset(st, 0,
sizeof(*st));
201 st->st_mode = S_IFCHR;
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);
243 res = esp_vfs_unregister(
s_vfstusb.vfs_path);
245 ESP_LOGE(
TAG,
"Can't unregister TinyUSB driver from '%s' (err: 0x%x)",
s_vfstusb.vfs_path, res);
261 ESP_LOGE(
TAG,
"TinyUSB CDC#%d is not initialized", cdc_intf);
262 return ESP_ERR_INVALID_STATE;
271 .flags = ESP_VFS_FLAG_DEFAULT,
280 res = esp_vfs_register(
s_vfstusb.vfs_path, &vfs, NULL);
282 ESP_LOGE(
TAG,
"Can't register TinyUSB driver (err: %x)", res);
esp_line_endings_t rx_mode
esp_line_endings_t tx_mode
char vfs_path[VFS_TUSB_MAX_PATH]
static float data[128 *2]
bool tusb_cdc_acm_initialized(tinyusb_cdcacm_itf_t itf)
Check if the ACM initialized.
size_t tinyusb_cdcacm_write_queue_char(tinyusb_cdcacm_itf_t itf, char ch)
Sent one character to a write buffer.
static int tusb_close(int fd)
esp_err_t esp_vfs_tusb_cdc_unregister(char const *path)
Unregister TinyUSB CDC from VFS.
static esp_err_t apply_path(char const *path)
static vfs_tinyusb_t s_vfstusb
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.
static void vfstusb_deinit(void)
Clear s_vfstusb to default values.
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)
esp_err_t esp_vfs_tusb_cdc_register(int cdc_intf, char const *path)
Register TinyUSB CDC at VFS with path.
#define FD_CHECK(fd, ret_val)
#define VFS_TUSB_PATH_DEFAULT
#define VFS_TUSB_MAX_PATH