usb_console.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #pragma once
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include <stdint.h>
  18. #include "esp_err.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @file usb_console.h
  24. * This file contains definitions of low-level USB console functions.
  25. * These functions are not considered to be a public interface and
  26. * should not be called by applications directly.
  27. * Application interface to the USB console is provided either by
  28. * "cdcacm" VFS driver, or by the USB CDC driver in TinyUSB.
  29. */
  30. /**
  31. * RX/TX callback function type
  32. * @param arg callback-specific context pointer
  33. */
  34. typedef void (*esp_usb_console_cb_t)(void* arg);
  35. /**
  36. * Initialize USB console output using ROM USB CDC driver.
  37. * This function is called by the early startup code if USB CDC is
  38. * selected as the console output option.
  39. * @return
  40. * - ESP_OK on success
  41. * - ESP_ERR_NO_MEM
  42. * - other error codes from the interrupt allocator
  43. */
  44. esp_err_t esp_usb_console_init(void);
  45. /**
  46. * Write a buffer to USB CDC
  47. * @param buf data to write
  48. * @param size size of the data, in bytes
  49. * @return -1 on error, otherwise the number of bytes
  50. */
  51. ssize_t esp_usb_console_write_buf(const char* buf, size_t size);
  52. ssize_t esp_usb_console_flush(void);
  53. ssize_t esp_usb_console_read_buf(char* buf, size_t buf_size);
  54. bool esp_usb_console_read_available(void);
  55. bool esp_usb_console_write_available(void);
  56. esp_err_t esp_usb_console_set_cb(esp_usb_console_cb_t rx_cb, esp_usb_console_cb_t tx_cb, void* arg);
  57. #ifdef __cplusplus
  58. }
  59. #endif