• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019-2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <stdbool.h>
18 #include <stddef.h>
19 #include <stdint.h>
20 #include "esp_err.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * @file usb_console.h
28  * This file contains definitions of low-level USB console functions.
29  * These functions are not considered to be a public interface and
30  * should not be called by applications directly.
31  * Application interface to the USB console is provided either by
32  * "cdcacm" VFS driver, or by the USB CDC driver in TinyUSB.
33  */
34 
35 
36 /**
37  * RX/TX callback function type
38  * @param arg  callback-specific context pointer
39  */
40 typedef void (*esp_usb_console_cb_t)(void* arg);
41 
42 /**
43  * Initialize USB console output using ROM USB CDC driver.
44  * This function is called by the early startup code if USB CDC is
45  * selected as the console output option.
46  * @return
47  *  - ESP_OK on success
48  *  - ESP_ERR_NO_MEM
49  *  - other error codes from the interrupt allocator
50  */
51 esp_err_t esp_usb_console_init(void);
52 
53 /**
54  * Write a buffer to USB CDC
55  * @param buf  data to write
56  * @param size  size of the data, in bytes
57  * @return -1 on error, otherwise the number of bytes
58  */
59 ssize_t esp_usb_console_write_buf(const char* buf, size_t size);
60 
61 ssize_t esp_usb_console_flush(void);
62 
63 ssize_t esp_usb_console_read_buf(char* buf, size_t buf_size);
64 
65 bool esp_usb_console_read_available(void);
66 
67 bool esp_usb_console_write_available(void);
68 
69 esp_err_t esp_usb_console_set_cb(esp_usb_console_cb_t rx_cb, esp_usb_console_cb_t tx_cb, void* arg);
70 
71 #ifdef __cplusplus
72 }
73 #endif
74