Loading...
Searching...
No Matches
furi_hal_serial.h File Reference

Serial HAL API. More...

#include <stddef.h>
#include <stdint.h>
#include "furi_hal_serial_types.h"

Go to the source code of this file.

Macros

#define FURI_HAL_SERIAL_DMA_BUFFER_SIZE   (256u)
 

Typedefs

typedef void(* FuriHalSerialAsyncRxCallback) (FuriHalSerialHandle *handle, FuriHalSerialRxEvent event, void *context)
 Receive callback.
 
typedef void(* FuriHalSerialDmaRxCallback) (FuriHalSerialHandle *handle, FuriHalSerialRxEvent event, size_t data_len, void *context)
 Receive DMA callback.
 

Enumerations

enum  FuriHalSerialRxEvent {
  FuriHalSerialRxEventData = (1 << 0) , FuriHalSerialRxEventIdle = (1 << 1) , FuriHalSerialRxEventFrameError = (1 << 2) , FuriHalSerialRxEventNoiseError = (1 << 3) ,
  FuriHalSerialRxEventOverrunError = (1 << 4)
}
 Serial RX events. More...
 

Functions

void furi_hal_serial_init (FuriHalSerialHandle *handle, uint32_t baud)
 Initialize Serial.
 
void furi_hal_serial_deinit (FuriHalSerialHandle *handle)
 De-initialize Serial.
 
void furi_hal_serial_suspend (FuriHalSerialHandle *handle)
 Suspend operation.
 
void furi_hal_serial_resume (FuriHalSerialHandle *handle)
 Resume operation.
 
bool furi_hal_serial_is_baud_rate_supported (FuriHalSerialHandle *handle, uint32_t baud)
 Determine whether a certain baud rate is supported.
 
void furi_hal_serial_set_br (FuriHalSerialHandle *handle, uint32_t baud)
 Changes baud rate.
 
void furi_hal_serial_tx (FuriHalSerialHandle *handle, const uint8_t *buffer, size_t buffer_size)
 Transmits data in semi-blocking mode.
 
void furi_hal_serial_tx_wait_complete (FuriHalSerialHandle *handle)
 Wait until transmission is completed.
 
void furi_hal_serial_async_rx_start (FuriHalSerialHandle *handle, FuriHalSerialAsyncRxCallback callback, void *context, bool report_errors)
 Start and sets Serial Receive callback.
 
void furi_hal_serial_async_rx_stop (FuriHalSerialHandle *handle)
 Stop Serial Receive.
 
bool furi_hal_serial_async_rx_available (FuriHalSerialHandle *handle)
 Check if there is data available for reading.
 
uint8_t furi_hal_serial_async_rx (FuriHalSerialHandle *handle)
 Get data Serial receive.
 
void furi_hal_serial_enable_direction (FuriHalSerialHandle *handle, FuriHalSerialDirection direction)
 Enable an input/output directon.
 
void furi_hal_serial_disable_direction (FuriHalSerialHandle *handle, FuriHalSerialDirection direction)
 Disable an input/output directon.
 
const GpioPinfuri_hal_serial_get_gpio_pin (FuriHalSerialHandle *handle, FuriHalSerialDirection direction)
 Get the GPIO pin associated with a serial.
 
void furi_hal_serial_dma_rx_start (FuriHalSerialHandle *handle, FuriHalSerialDmaRxCallback callback, void *context, bool report_errors)
 Start and sets Serial event callback receive DMA.
 
void furi_hal_serial_dma_rx_stop (FuriHalSerialHandle *handle)
 Stop Serial receive DMA.
 
size_t furi_hal_serial_dma_rx (FuriHalSerialHandle *handle, uint8_t *data, size_t len)
 Get data Serial receive DMA.
 

Detailed Description

Serial HAL API.

Typedef Documentation

◆ FuriHalSerialAsyncRxCallback

typedef void(* FuriHalSerialAsyncRxCallback) (FuriHalSerialHandle *handle, FuriHalSerialRxEvent event, void *context)

Receive callback.

Warning
Callback will be called in interrupt context, ensure thread safety on your side.
Parameters
handleSerial handle
eventFuriHalSerialRxEvent
contextCallback context provided earlier

◆ FuriHalSerialDmaRxCallback

typedef void(* FuriHalSerialDmaRxCallback) (FuriHalSerialHandle *handle, FuriHalSerialRxEvent event, size_t data_len, void *context)

Receive DMA callback.

Warning
DMA Callback will be called in interrupt context, ensure thread safety on your side.
Parameters
handleSerial handle
eventFuriHalSerialDmaRxEvent
data_lenReceived data
contextCallback context provided earlier

Enumeration Type Documentation

◆ FuriHalSerialRxEvent

Serial RX events.

Enumerator
FuriHalSerialRxEventData 

Data: new data available.

FuriHalSerialRxEventIdle 

Idle: bus idle detected.

FuriHalSerialRxEventFrameError 

Framing Error: incorrect frame detected.

FuriHalSerialRxEventNoiseError 

Noise Error: noise on the line detected.

FuriHalSerialRxEventOverrunError 

Overrun Error: no space for received data.

Function Documentation

◆ furi_hal_serial_async_rx()

uint8_t furi_hal_serial_async_rx ( FuriHalSerialHandle * handle)

Get data Serial receive.

Warning
This function must be called only from the callback FuriHalSerialAsyncRxCallback
Parameters
handleSerial handle
Returns
data

◆ furi_hal_serial_async_rx_available()

bool furi_hal_serial_async_rx_available ( FuriHalSerialHandle * handle)

Check if there is data available for reading.

Warning
This function must be called only from the callback FuriHalSerialAsyncRxCallback
Parameters
handleSerial handle
Returns
true if data is available for reading, false otherwise

◆ furi_hal_serial_async_rx_start()

void furi_hal_serial_async_rx_start ( FuriHalSerialHandle * handle,
FuriHalSerialAsyncRxCallback callback,
void * context,
bool report_errors )

Start and sets Serial Receive callback.

Warning
Callback will be called in interrupt context, ensure thread safety on your side
Parameters
handleSerial handle
callbackcallback pointer
contextcallback context
[in]report_errorsreport RX error

◆ furi_hal_serial_async_rx_stop()

void furi_hal_serial_async_rx_stop ( FuriHalSerialHandle * handle)

Stop Serial Receive.

Parameters
handleSerial handle

◆ furi_hal_serial_deinit()

void furi_hal_serial_deinit ( FuriHalSerialHandle * handle)

De-initialize Serial.

Configures GPIO to analog, clears callback and callback context, disables hardware

Parameters
handleSerial handle

◆ furi_hal_serial_disable_direction()

void furi_hal_serial_disable_direction ( FuriHalSerialHandle * handle,
FuriHalSerialDirection direction )

Disable an input/output directon.

Releases the respective pin by reconfiguring it to initial state, making possible its use for other purposes.

Parameters
handleSerial handle
directionDirection to disable

◆ furi_hal_serial_dma_rx()

size_t furi_hal_serial_dma_rx ( FuriHalSerialHandle * handle,
uint8_t * data,
size_t len )

Get data Serial receive DMA.

Warning
This function must be called only from the callback FuriHalSerialDmaRxCallback
Parameters
handleSerial handle
datapointer to data buffer
lenget data size (in bytes)
Returns
size actual data receive (in bytes)

◆ furi_hal_serial_dma_rx_start()

void furi_hal_serial_dma_rx_start ( FuriHalSerialHandle * handle,
FuriHalSerialDmaRxCallback callback,
void * context,
bool report_errors )

Start and sets Serial event callback receive DMA.

Parameters
handleSerial handle
callbackcallback pointer
contextcallback context
[in]report_errorsreport RX error

◆ furi_hal_serial_dma_rx_stop()

void furi_hal_serial_dma_rx_stop ( FuriHalSerialHandle * handle)

Stop Serial receive DMA.

Parameters
handleSerial handle

◆ furi_hal_serial_enable_direction()

void furi_hal_serial_enable_direction ( FuriHalSerialHandle * handle,
FuriHalSerialDirection direction )

Enable an input/output directon.

Takes over the respective pin by reconfiguring it to the appropriate alternative function.

Parameters
handleSerial handle
directionDirection to enable

◆ furi_hal_serial_get_gpio_pin()

const GpioPin * furi_hal_serial_get_gpio_pin ( FuriHalSerialHandle * handle,
FuriHalSerialDirection direction )

Get the GPIO pin associated with a serial.

Parameters
handleSerial handle
directionDirection to query
Returns
pointer to the respective pin instance

◆ furi_hal_serial_init()

void furi_hal_serial_init ( FuriHalSerialHandle * handle,
uint32_t baud )

Initialize Serial.

Configures GPIO, configures and enables transceiver.

Parameters
handleSerial handle
baudbaud rate

◆ furi_hal_serial_is_baud_rate_supported()

bool furi_hal_serial_is_baud_rate_supported ( FuriHalSerialHandle * handle,
uint32_t baud )

Determine whether a certain baud rate is supported.

Parameters
handleSerial handle
baudbaud rate to be checked
Returns
true if baud rate is supported, false otherwise.

◆ furi_hal_serial_resume()

void furi_hal_serial_resume ( FuriHalSerialHandle * handle)

Resume operation.

Resumes hardware from suspended state

Parameters
handleSerial handle

◆ furi_hal_serial_set_br()

void furi_hal_serial_set_br ( FuriHalSerialHandle * handle,
uint32_t baud )

Changes baud rate.

Parameters
handleSerial handle
baudbaud rate

◆ furi_hal_serial_suspend()

void furi_hal_serial_suspend ( FuriHalSerialHandle * handle)

Suspend operation.

Suspend hardware, settings and callbacks are preserved

Parameters
handleSerial handle

◆ furi_hal_serial_tx()

void furi_hal_serial_tx ( FuriHalSerialHandle * handle,
const uint8_t * buffer,
size_t buffer_size )

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.

Parameters
handleSerial handle
bufferdata
buffer_sizedata size (in bytes)

◆ furi_hal_serial_tx_wait_complete()

void furi_hal_serial_tx_wait_complete ( FuriHalSerialHandle * handle)

Wait until transmission is completed.

Ensures that all data has been sent.

Parameters
handleSerial handle