ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
cdc.c File Reference
#include <stdint.h>
#include "esp_check.h"
#include "esp_err.h"
#include "esp_log.h"
#include "tusb.h"
#include "cdc.h"
Include dependency graph for cdc.c:

Go to the source code of this file.

Macros

#define CDC_INTF_NUM   CFG_TUD_CDC

Functions

esp_tusb_cdc_ttinyusb_cdc_get_intf (int itf_num)
 Return interface of a CDC device.
static esp_err_t cdc_obj_check (int itf, bool expected_inited, tusb_class_code_t expected_type)
static esp_err_t tusb_cdc_comm_init (int itf)
static esp_err_t tusb_cdc_deinit_comm (int itf)
static esp_err_t tusb_cdc_data_init (int itf)
static esp_err_t tusb_cdc_deinit_data (int itf)
esp_err_t tinyusb_cdc_init (int itf, const tinyusb_config_cdc_t *cfg)
 Initializing CDC basic object.
esp_err_t tinyusb_cdc_deinit (int itf)
 De-initializing CDC. Clean its objects.

Variables

static esp_tusb_cdc_tcdc_obj [CFG_TUD_CDC] = {}
static const char * TAG = "tusb_cdc"

Macro Definition Documentation

◆ CDC_INTF_NUM

#define CDC_INTF_NUM   CFG_TUD_CDC

Definition at line 14 of file cdc.c.

Referenced by tinyusb_cdc_get_intf().

Function Documentation

◆ cdc_obj_check()

esp_err_t cdc_obj_check ( int itf,
bool expected_inited,
tusb_class_code_t expected_type )
static

Definition at line 26 of file cdc.c.

27{
28 esp_tusb_cdc_t *this_itf = tinyusb_cdc_get_intf(itf);
29
30 bool inited = (this_itf != NULL);
31 ESP_RETURN_ON_FALSE(expected_inited == inited, ESP_ERR_INVALID_STATE, TAG, "Wrong state of the interface. Expected state: %s", expected_inited ? "initialized" : "not initialized");
32 ESP_RETURN_ON_FALSE(!(inited && (expected_type != -1) && !(this_itf->type == expected_type)), ESP_ERR_INVALID_STATE, TAG, "Wrong type of the interface. Should be : 0x%x (tusb_class_code_t)", expected_type);
33 return ESP_OK;
34}
esp_tusb_cdc_t * tinyusb_cdc_get_intf(int itf_num)
Return interface of a CDC device.
Definition cdc.c:18
#define ESP_OK
Definition esp_err.h:23
static const char * TAG
Definition main/main.c:31
tusb_class_code_t type
Definition cdc.h:42

References ESP_OK, TAG, tinyusb_cdc_get_intf(), and esp_tusb_cdc_t::type.

Referenced by tinyusb_cdc_deinit(), tinyusb_cdc_init(), tusb_cdc_comm_init(), tusb_cdc_data_init(), tusb_cdc_deinit_comm(), and tusb_cdc_deinit_data().

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

◆ tinyusb_cdc_deinit()

esp_err_t tinyusb_cdc_deinit ( int itf)

De-initializing CDC. Clean its objects.

Parameters
itf- number of a CDC object
Returns
esp_err_t ESP_OK, ESP_ERR_INVALID_ARG, ESP_ERR_INVALID_STATE

Definition at line 96 of file cdc.c.

97{
98 ESP_RETURN_ON_ERROR(cdc_obj_check(itf, true, -1), TAG, "cdc_obj_check failed");
99
100 ESP_LOGD(TAG, "Deinit CDC %d", itf);
101 if (cdc_obj[itf]->type == TUSB_CLASS_CDC) {
102 ESP_RETURN_ON_ERROR(tusb_cdc_deinit_comm(itf), TAG, "tusb_cdc_deinit_comm failed");
103 } else if (cdc_obj[itf]->type == TUSB_CLASS_CDC_DATA) {
104 ESP_RETURN_ON_ERROR(tusb_cdc_deinit_data(itf), TAG, "tusb_cdc_deinit_data failed");
105 } else {
106 return ESP_ERR_INVALID_ARG;
107 }
108 return ESP_OK;
109}
#define ESP_RETURN_ON_ERROR(x, log_tag, format,...)
static esp_err_t tusb_cdc_deinit_comm(int itf)
Definition cdc.c:50
static esp_err_t cdc_obj_check(int itf, bool expected_inited, tusb_class_code_t expected_type)
Definition cdc.c:26
static esp_err_t tusb_cdc_deinit_data(int itf)
Definition cdc.c:72
static esp_tusb_cdc_t * cdc_obj[CFG_TUD_CDC]
Definition cdc.c:15
#define ESP_LOGD
Definition esp_log.h:22

References cdc_obj, cdc_obj_check(), ESP_LOGD, ESP_OK, ESP_RETURN_ON_ERROR, TAG, tusb_cdc_deinit_comm(), and tusb_cdc_deinit_data().

Referenced by tusb_cdc_acm_init().

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

◆ tinyusb_cdc_get_intf()

esp_tusb_cdc_t * tinyusb_cdc_get_intf ( int itf_num)

Return interface of a CDC device.

Parameters
itf_num
Returns
esp_tusb_cdc_t* pointer to the interface or (NULL) on error

Definition at line 18 of file cdc.c.

19{
20 if (itf_num >= CDC_INTF_NUM || itf_num < 0) {
21 return NULL;
22 }
23 return cdc_obj[itf_num];
24}
#define CDC_INTF_NUM
Definition cdc.c:14

References CDC_INTF_NUM, and cdc_obj.

Referenced by alloc_obj(), cdc_obj_check(), free_obj(), and get_acm().

Here is the caller graph for this function:

◆ tinyusb_cdc_init()

esp_err_t tinyusb_cdc_init ( int itf,
const tinyusb_config_cdc_t * cfg )

Initializing CDC basic object.

Parameters
itf- number of a CDC object
cfg- CDC configuration structure
Returns
esp_err_t ESP_OK or ESP_FAIL

Definition at line 80 of file cdc.c.

81{
82 ESP_RETURN_ON_ERROR(cdc_obj_check(itf, false, -1), TAG, "cdc_obj_check failed");
83
84 ESP_LOGD(TAG, "Init CDC %d", itf);
85 if (cfg->cdc_class == TUSB_CLASS_CDC) {
86 ESP_RETURN_ON_ERROR(tusb_cdc_comm_init(itf), TAG, "tusb_cdc_comm_init failed");
87 cdc_obj[itf]->cdc_subclass.comm_subclass = cfg->cdc_subclass.comm_subclass;
88 } else {
89 ESP_RETURN_ON_ERROR(tusb_cdc_data_init(itf), TAG, "tusb_cdc_data_init failed");
90 cdc_obj[itf]->cdc_subclass.data_subclass = cfg->cdc_subclass.data_subclass;
91 }
92 cdc_obj[itf]->usb_dev = cfg->usb_dev;
93 return ESP_OK;
94}
static esp_err_t tusb_cdc_comm_init(int itf)
Definition cdc.c:36
static esp_err_t tusb_cdc_data_init(int itf)
Definition cdc.c:58
tinyusb_usbdev_t usb_dev
Definition cdc.h:32
cdc_comm_sublcass_type_t comm_subclass
Definition cdc.h:35
union tinyusb_config_cdc_t::@312104222326077254040135322351363045356166043242 cdc_subclass
cdc_data_sublcass_type_t data_subclass
Definition cdc.h:36
tusb_class_code_t cdc_class
Definition cdc.h:33

References tinyusb_config_cdc_t::cdc_class, cdc_obj, cdc_obj_check(), tinyusb_config_cdc_t::cdc_subclass, tinyusb_config_cdc_t::comm_subclass, tinyusb_config_cdc_t::data_subclass, ESP_LOGD, ESP_OK, ESP_RETURN_ON_ERROR, TAG, tusb_cdc_comm_init(), tusb_cdc_data_init(), and tinyusb_config_cdc_t::usb_dev.

Referenced by tusb_cdc_acm_init().

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

◆ tusb_cdc_comm_init()

esp_err_t tusb_cdc_comm_init ( int itf)
static

Definition at line 36 of file cdc.c.

37{
38 ESP_RETURN_ON_ERROR(cdc_obj_check(itf, false, -1), TAG, "cdc_obj_check failed");
39 cdc_obj[itf] = calloc(1, sizeof(esp_tusb_cdc_t));
40 if (cdc_obj[itf] != NULL) {
41 cdc_obj[itf]->type = TUSB_CLASS_CDC;
42 ESP_LOGD(TAG, "CDC Comm class initialized");
43 return ESP_OK;
44 } else {
45 ESP_LOGE(TAG, "CDC Comm initialization error");
46 return ESP_FAIL;
47 }
48}

References cdc_obj, cdc_obj_check(), ESP_LOGD, ESP_OK, ESP_RETURN_ON_ERROR, and TAG.

Referenced by tinyusb_cdc_init().

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

◆ tusb_cdc_data_init()

esp_err_t tusb_cdc_data_init ( int itf)
static

Definition at line 58 of file cdc.c.

59{
60 ESP_RETURN_ON_ERROR(cdc_obj_check(itf, false, TUSB_CLASS_CDC_DATA), TAG, "cdc_obj_check failed");
61 cdc_obj[itf] = calloc(1, sizeof(esp_tusb_cdc_t));
62 if (cdc_obj[itf] != NULL) {
63 cdc_obj[itf]->type = TUSB_CLASS_CDC_DATA;
64 ESP_LOGD(TAG, "CDC Data class initialized");
65 return ESP_OK;
66 } else {
67 ESP_LOGE(TAG, "CDC Data initialization error");
68 return ESP_FAIL;
69 }
70}

References cdc_obj, cdc_obj_check(), ESP_LOGD, ESP_OK, ESP_RETURN_ON_ERROR, and TAG.

Referenced by tinyusb_cdc_init().

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

◆ tusb_cdc_deinit_comm()

esp_err_t tusb_cdc_deinit_comm ( int itf)
static

Definition at line 50 of file cdc.c.

51{
52 ESP_RETURN_ON_ERROR(cdc_obj_check(itf, true, TUSB_CLASS_CDC), TAG, "cdc_obj_check failed");
53 free(cdc_obj[itf]);
54 cdc_obj[itf] = NULL;
55 return ESP_OK;
56}

References cdc_obj, cdc_obj_check(), ESP_OK, ESP_RETURN_ON_ERROR, and TAG.

Referenced by tinyusb_cdc_deinit().

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

◆ tusb_cdc_deinit_data()

esp_err_t tusb_cdc_deinit_data ( int itf)
static

Definition at line 72 of file cdc.c.

73{
74 ESP_RETURN_ON_ERROR(cdc_obj_check(itf, true, TUSB_CLASS_CDC_DATA), TAG, "cdc_obj_check failed");
75 free(cdc_obj[itf]);
76 cdc_obj[itf] = NULL;
77 return ESP_OK;
78}

References cdc_obj, cdc_obj_check(), ESP_OK, ESP_RETURN_ON_ERROR, and TAG.

Referenced by tinyusb_cdc_deinit().

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

Variable Documentation

◆ cdc_obj

◆ TAG

const char* TAG = "tusb_cdc"
static

Definition at line 16 of file cdc.c.