2021-11-19 22:19:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* @file furi-hal-uart.h
|
|
|
|
|
* @version 1.0
|
|
|
|
|
* @date 2021-11-19
|
|
|
|
|
*
|
|
|
|
|
* UART HAL api interface
|
|
|
|
|
*/
|
2021-10-26 18:41:56 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-11-19 22:19:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* UART channels
|
|
|
|
|
*/
|
2021-10-26 18:41:56 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
FuriHalUartIdUSART1,
|
|
|
|
|
FuriHalUartIdLPUART1,
|
|
|
|
|
} FuriHalUartId;
|
|
|
|
|
|
2021-11-19 22:19:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* UART events
|
|
|
|
|
*/
|
2021-11-04 19:33:28 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
UartIrqEventRXNE,
|
|
|
|
|
UartIrqEventIDLE,
|
|
|
|
|
//TODO: more events
|
|
|
|
|
} UartIrqEvent;
|
2021-10-26 18:41:56 +00:00
|
|
|
|
|
2021-11-19 22:19:31 +00: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 18:41:56 +00:00
|
|
|
|
|
2021-11-19 22:19:31 +00: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 18:41:56 +00:00
|
|
|
|
|
2021-11-19 22:19:31 +00: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 18:41:56 +00:00
|
|
|
|
|
2021-11-19 22:19:31 +00: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 18:41:56 +00:00
|
|
|
|
|
2021-11-19 22:19:31 +00: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 18:41:56 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
2021-11-19 22:19:31 +00:00
|
|
|
|
#endif
|