serial.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef STM32SPROG_SERIAL_H
  2. #define STM32SPROG_SERIAL_H
  3. /** \file serial.h
  4. *
  5. * Provides a serial communication interface.
  6. */
  7. #include <stdbool.h>
  8. #include <stddef.h>
  9. #include <stdint.h>
  10. #include "usart.h"
  11. #define USARTn USER_USART
  12. #define MAX_READ_RETRIES 50000000
  13. /** Serial device handle. */
  14. typedef struct SSerialDev SerialDev;
  15. /** \brief Read data from a serial device.
  16. *
  17. * Blocks until all data has been read or an error has occurred.
  18. *
  19. * \param dev An open serial device.
  20. * \param buffer The data buffer to fill.
  21. * \param n The number of bytes to read.
  22. *
  23. * \return \c true on success, \c false if any error occurred.
  24. */
  25. bool serialRead(SerialDev *dev, uint8_t *buffer, size_t n);
  26. /** \brief Write data to a serial device.
  27. *
  28. * Blocks until all data has been written or an error has occurred.
  29. *
  30. * \param dev An open serial device.
  31. * \param buffer The data to write.
  32. * \param n The number of bytes to write.
  33. *
  34. * \return \c true on success, \c false if any error occurred.
  35. */
  36. bool serialWrite(SerialDev *dev, const uint8_t *buffer, size_t n);
  37. #endif /* STM32SPROG_SERIAL_H */