mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-18 16:53:45 +00:00
fc043da9c6
* FuriHal: UART refactoring * ApiSymbols: add furi_record_destroy * FuriHal: cleanup serial API, add logging configuration in RTC * FuriHal: hide private part in _i header. Toolbox: cleanup value index. SystemSettings: logging device and baudrate. * FuriHal: RTC logging method documentation * Synchronize API Symbols * Furi: mark HEAP_PRINT_DEBUG as broken * FuriHal: furi_hal_serial, add custom IRQ func * Fix PR review issues * FuriHal: UART add reception DMA (#3220) * FuriHal: add DMA serial rx mode * usb_uart_bridge: switch to working with DMA * Sync api symbol versions * FuriHal: update serial docs and api * FuriHal: Selial added similar API for simple reception mode as with DMA * FuriHal: Update API target H18 * API: ver API H7 * FuriHal: Serial error processing * FuriHal: fix furi_hal_serial set baudrate * Sync api symbols * FuriHal: cleanup serial isr and various flag handling procedures * FuriHal: cleanup and simplify serial API * Debug: update UART Echo serial related flags * FuriHal: update serial API symbols naming * FuriHalSerial: various improvements and PR review fixes * FuriHal: proper ISR function signatures --------- Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com> Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: SkorP <skorpionm@yandex.ru> Co-authored-by: Skorpionm <85568270+Skorpionm@users.noreply.github.com>
189 lines
5.1 KiB
C
189 lines
5.1 KiB
C
/**
|
|
* @file furi_hal_serial.h
|
|
*
|
|
* Serial HAL API
|
|
*/
|
|
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include "furi_hal_serial_types.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/** Initialize Serial
|
|
*
|
|
* Configures GPIO, configures and enables transceiver.
|
|
*
|
|
* @param handle Serial handle
|
|
* @param baud baud rate
|
|
*/
|
|
void furi_hal_serial_init(FuriHalSerialHandle* handle, uint32_t baud);
|
|
|
|
/** De-initialize Serial
|
|
*
|
|
* Configures GPIO to analog, clears callback and callback context, disables
|
|
* hardware
|
|
*
|
|
* @param handle Serial handle
|
|
*/
|
|
void furi_hal_serial_deinit(FuriHalSerialHandle* handle);
|
|
|
|
/** Suspend operation
|
|
*
|
|
* Suspend hardware, settings and callbacks are preserved
|
|
*
|
|
* @param handle Serial handle
|
|
*/
|
|
void furi_hal_serial_suspend(FuriHalSerialHandle* handle);
|
|
|
|
/** Resume operation
|
|
*
|
|
* Resumes hardware from suspended state
|
|
*
|
|
* @param handle Serial handle
|
|
*/
|
|
void furi_hal_serial_resume(FuriHalSerialHandle* handle);
|
|
|
|
/** Changes baud rate
|
|
*
|
|
* @param handle Serial handle
|
|
* @param baud baud rate
|
|
*/
|
|
void furi_hal_serial_set_br(FuriHalSerialHandle* handle, uint32_t baud);
|
|
|
|
/** Transmits data in semi-blocking mode
|
|
*
|
|
* Fills transmission pipe with data, returns as soon as all bytes from buffer
|
|
* are in the pipe.
|
|
*
|
|
* Real transmission will be completed later. Use
|
|
* `furi_hal_serial_tx_wait_complete` to wait for completion if you need it.
|
|
*
|
|
* @param handle Serial handle
|
|
* @param buffer data
|
|
* @param buffer_size data size (in bytes)
|
|
*/
|
|
void furi_hal_serial_tx(FuriHalSerialHandle* handle, const uint8_t* buffer, size_t buffer_size);
|
|
|
|
/** Wait until transmission is completed
|
|
*
|
|
* Ensures that all data has been sent.
|
|
*
|
|
* @param handle Serial handle
|
|
*/
|
|
void furi_hal_serial_tx_wait_complete(FuriHalSerialHandle* handle);
|
|
|
|
/** Serial RX events */
|
|
typedef enum {
|
|
FuriHalSerialRxEventData = (1 << 0), /**< Data: new data available */
|
|
FuriHalSerialRxEventIdle = (1 << 1), /**< Idle: bus idle detected */
|
|
FuriHalSerialRxEventFrameError = (1 << 2), /**< Framing Error: incorrect frame detected */
|
|
FuriHalSerialRxEventNoiseError = (1 << 3), /**< Noise Error: noise on the line detected */
|
|
FuriHalSerialRxEventOverrunError = (1 << 4), /**< Overrun Error: no space for received data */
|
|
} FuriHalSerialRxEvent;
|
|
|
|
/** Receive callback
|
|
*
|
|
* @warning Callback will be called in interrupt context, ensure thread
|
|
* safety on your side.
|
|
* @param handle Serial handle
|
|
* @param event FuriHalSerialRxEvent
|
|
* @param context Callback context provided earlier
|
|
*/
|
|
typedef void (*FuriHalSerialAsyncRxCallback)(
|
|
FuriHalSerialHandle* handle,
|
|
FuriHalSerialRxEvent event,
|
|
void* context);
|
|
|
|
/** Start and sets Serial Receive callback
|
|
*
|
|
* @warning Callback will be called in interrupt context, ensure thread
|
|
* safety on your side
|
|
*
|
|
* @param handle Serial handle
|
|
* @param callback callback pointer
|
|
* @param context callback context
|
|
* @param[in] report_errors report RX error
|
|
*/
|
|
void furi_hal_serial_async_rx_start(
|
|
FuriHalSerialHandle* handle,
|
|
FuriHalSerialAsyncRxCallback callback,
|
|
void* context,
|
|
bool report_errors);
|
|
|
|
/** Stop Serial Receive
|
|
*
|
|
* @param handle Serial handle
|
|
*/
|
|
void furi_hal_serial_async_rx_stop(FuriHalSerialHandle* handle);
|
|
|
|
/** Get data Serial receive
|
|
*
|
|
* @warning This function must be called only from the callback
|
|
* FuriHalSerialAsyncRxCallback
|
|
*
|
|
* @param handle Serial handle
|
|
*
|
|
* @return data
|
|
*/
|
|
uint8_t furi_hal_serial_async_rx(FuriHalSerialHandle* handle);
|
|
|
|
/* DMA based Serial API */
|
|
|
|
#define FURI_HAL_SERIAL_DMA_BUFFER_SIZE (256u)
|
|
|
|
/** Receive DMA callback
|
|
*
|
|
* @warning DMA Callback will be called in interrupt context, ensure thread
|
|
* safety on your side.
|
|
*
|
|
* @param handle Serial handle
|
|
* @param event FuriHalSerialDmaRxEvent
|
|
* @param data_len Received data
|
|
* @param context Callback context provided earlier
|
|
*/
|
|
typedef void (*FuriHalSerialDmaRxCallback)(
|
|
FuriHalSerialHandle* handle,
|
|
FuriHalSerialRxEvent event,
|
|
size_t data_len,
|
|
void* context);
|
|
|
|
/** Start and sets Serial event callback receive DMA
|
|
*
|
|
* @param handle Serial handle
|
|
* @param callback callback pointer
|
|
* @param context callback context
|
|
* @param[in] report_errors report RX error
|
|
*/
|
|
void furi_hal_serial_dma_rx_start(
|
|
FuriHalSerialHandle* handle,
|
|
FuriHalSerialDmaRxCallback callback,
|
|
void* context,
|
|
bool report_errors);
|
|
|
|
/** Stop Serial receive DMA
|
|
*
|
|
* @param handle Serial handle
|
|
*/
|
|
void furi_hal_serial_dma_rx_stop(FuriHalSerialHandle* handle);
|
|
|
|
/** Get data Serial receive DMA
|
|
*
|
|
* @warning This function must be called only from the callback
|
|
* FuriHalSerialDmaRxCallback
|
|
*
|
|
* @param handle Serial handle
|
|
* @param data pointer to data buffer
|
|
* @param len get data size (in bytes)
|
|
*
|
|
* @return size actual data receive (in bytes)
|
|
*/
|
|
size_t furi_hal_serial_dma_rx(FuriHalSerialHandle* handle, uint8_t* data, size_t len);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|