2021-11-20 01:19:31 +03:00
|
|
|
|
/**
|
2022-01-05 19:10:18 +03:00
|
|
|
|
* @file furi_hal_uart.h
|
2021-11-20 01:19:31 +03:00
|
|
|
|
* @version 1.0
|
|
|
|
|
* @date 2021-11-19
|
|
|
|
|
*
|
|
|
|
|
* UART HAL api interface
|
|
|
|
|
*/
|
2021-10-26 21:41:56 +03:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-11-20 01:19:31 +03:00
|
|
|
|
/**
|
|
|
|
|
* UART channels
|
|
|
|
|
*/
|
2021-10-26 21:41:56 +03:00
|
|
|
|
typedef enum {
|
|
|
|
|
FuriHalUartIdUSART1,
|
|
|
|
|
FuriHalUartIdLPUART1,
|
|
|
|
|
} FuriHalUartId;
|
|
|
|
|
|
2021-11-20 01:19:31 +03:00
|
|
|
|
/**
|
|
|
|
|
* UART events
|
|
|
|
|
*/
|
2021-11-04 22:33:28 +03:00
|
|
|
|
typedef enum {
|
|
|
|
|
UartIrqEventRXNE,
|
|
|
|
|
UartIrqEventIDLE,
|
|
|
|
|
//TODO: more events
|
|
|
|
|
} UartIrqEvent;
|
2021-10-26 21:41:56 +03:00
|
|
|
|
|
2021-11-20 01:19:31 +03:00
|
|
|
|
/**
|
|
|
|
|
* Init UART
|
|
|
|
|
* Configures GPIO to UART function, сonfigures UART hardware, enables UART hardware
|
|
|
|
|
* @param channel UART channel
|
|
|
|
|
* @param baud baudrate
|
|
|
|
|
*/
|
|
|
|
|
void furi_hal_uart_init(FuriHalUartId channel, uint32_t baud);
|
2021-10-26 21:41:56 +03:00
|
|
|
|
|
2021-11-20 01:19:31 +03:00
|
|
|
|
/**
|
|
|
|
|
* Deinit UART
|
|
|
|
|
* Configures GPIO to analog, clears callback and callback context, disables UART hardware
|
|
|
|
|
* @param channel UART channel
|
|
|
|
|
*/
|
|
|
|
|
void furi_hal_uart_deinit(FuriHalUartId channel);
|
2021-10-26 21:41:56 +03:00
|
|
|
|
|
2021-11-20 01:19:31 +03:00
|
|
|
|
/**
|
|
|
|
|
* Changes UART baudrate
|
|
|
|
|
* @param channel UART channel
|
|
|
|
|
* @param baud baudrate
|
|
|
|
|
*/
|
|
|
|
|
void furi_hal_uart_set_br(FuriHalUartId channel, uint32_t baud);
|
2021-10-26 21:41:56 +03:00
|
|
|
|
|
2021-11-20 01:19:31 +03:00
|
|
|
|
/**
|
|
|
|
|
* Transmits data
|
|
|
|
|
* @param channel UART channel
|
|
|
|
|
* @param buffer data
|
|
|
|
|
* @param buffer_size data size (in bytes)
|
|
|
|
|
*/
|
|
|
|
|
void furi_hal_uart_tx(FuriHalUartId channel, uint8_t* buffer, size_t buffer_size);
|
2021-10-26 21:41:56 +03:00
|
|
|
|
|
2021-11-20 01:19:31 +03:00
|
|
|
|
/**
|
|
|
|
|
* Sets UART event callback
|
|
|
|
|
* @param channel UART channel
|
|
|
|
|
* @param callback callback pointer
|
|
|
|
|
* @param context callback context
|
|
|
|
|
*/
|
|
|
|
|
void furi_hal_uart_set_irq_cb(
|
|
|
|
|
FuriHalUartId channel,
|
|
|
|
|
void (*callback)(UartIrqEvent event, uint8_t data, void* context),
|
|
|
|
|
void* context);
|
2021-10-26 21:41:56 +03:00
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
2021-12-09 07:58:07 +03:00
|
|
|
|
#endif
|