api-hal-vcp.h 1008 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /**
  9. * Init VCP HAL
  10. * Allocates ring buffer and initializes state
  11. */
  12. void api_hal_vcp_init();
  13. /**
  14. * Recieve data from VCP
  15. * Waits till some data arrives, never returns 0
  16. * @param buffer - pointer to buffer
  17. * @param size - buffer size
  18. * @return items copied in buffer, 0 if channel closed
  19. */
  20. size_t api_hal_vcp_rx(uint8_t* buffer, size_t size);
  21. /**
  22. * Recieve data from VCP with timeout
  23. * Waits till some data arrives during timeout
  24. * @param buffer - pointer to buffer
  25. * @param size - buffer size
  26. * @param timeout - rx timeout in ms
  27. * @return items copied in buffer, 0 if channel closed or timeout occurs
  28. */
  29. size_t api_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeout);
  30. /**
  31. * Transmit data to VCP
  32. * @param buffer - pointer to buffer
  33. * @param size - buffer size
  34. */
  35. void api_hal_vcp_tx(const uint8_t* buffer, size_t size);
  36. #ifdef __cplusplus
  37. }
  38. #endif