furi_hal_uart.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @file furi_hal_uart.h
  3. * @version 1.0
  4. * @date 2021-11-19
  5. *
  6. * UART HAL api interface
  7. */
  8. #pragma once
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /**
  15. * UART channels
  16. */
  17. typedef enum {
  18. FuriHalUartIdUSART1,
  19. FuriHalUartIdLPUART1,
  20. } FuriHalUartId;
  21. /**
  22. * UART events
  23. */
  24. typedef enum {
  25. UartIrqEventRXNE,
  26. } UartIrqEvent;
  27. /**
  28. * Init UART
  29. * Configures GPIO to UART function, сonfigures UART hardware, enables UART hardware
  30. * @param channel UART channel
  31. * @param baud baudrate
  32. */
  33. void furi_hal_uart_init(FuriHalUartId channel, uint32_t baud);
  34. /**
  35. * Deinit UART
  36. * Configures GPIO to analog, clears callback and callback context, disables UART hardware
  37. * @param channel UART channel
  38. */
  39. void furi_hal_uart_deinit(FuriHalUartId channel);
  40. /**
  41. * Suspend UART operation
  42. * Disables UART hardware, settings and callbacks are preserved
  43. * @param channel UART channel
  44. */
  45. void furi_hal_uart_suspend(FuriHalUartId channel);
  46. /**
  47. * Resume UART operation
  48. * Resumes UART hardware from suspended state
  49. * @param channel UART channel
  50. */
  51. void furi_hal_uart_resume(FuriHalUartId channel);
  52. /**
  53. * Changes UART baudrate
  54. * @param channel UART channel
  55. * @param baud baudrate
  56. */
  57. void furi_hal_uart_set_br(FuriHalUartId channel, uint32_t baud);
  58. /**
  59. * Transmits data
  60. * @param channel UART channel
  61. * @param buffer data
  62. * @param buffer_size data size (in bytes)
  63. */
  64. void furi_hal_uart_tx(FuriHalUartId channel, uint8_t* buffer, size_t buffer_size);
  65. /**
  66. * Sets UART event callback
  67. * @param channel UART channel
  68. * @param callback callback pointer
  69. * @param context callback context
  70. */
  71. void furi_hal_uart_set_irq_cb(
  72. FuriHalUartId channel,
  73. void (*callback)(UartIrqEvent event, uint8_t data, void* context),
  74. void* context);
  75. #ifdef __cplusplus
  76. }
  77. #endif