BSB Developer Docs
Loading...
Searching...
No Matches
furi_hal_serial.h File Reference

Serial HAL API. More...

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

Go to the source code of this file.

Typedefs

typedef void(* FuriHalSerialTxCallback) (FuriHalSerialHandle *handle, FuriHalSerialTxEvent event, void *context)
 Receive callback function type.
 
typedef void(* FuriHalSerialRxCallback) (FuriHalSerialHandle *handle, FuriHalSerialRxEvent event, void *context)
 Transmit callback function type.
 

Enumerations

enum  FuriHalSerialHwFlowControl { FuriHalSerialHwFlowControlNone , FuriHalSerialHwFlowControlRtsCts }
 Serial hardware flow control modes. More...
 
enum  FuriHalSerialRxEvent {
  FuriHalSerialRxEventData = (1 << 0) , FuriHalSerialRxEventIdle = (1 << 1) , FuriHalSerialRxEventBreak = (1 << 2) , FuriHalSerialRxEventFrameError = (1 << 3) ,
  FuriHalSerialRxEventNoiseError = (1 << 4) , FuriHalSerialRxEventOverrunError = (1 << 5)
}
 Serial RX events. More...
 
enum  FuriHalSerialTxEvent { FuriHalSerialTxEventComplete = (1 << 0) }
 Serial TX events. More...
 

Functions

void furi_hal_serial_init (FuriHalSerialHandle *handle, uint32_t baud_rate)
 Initialize the serial interface.
 
void furi_hal_serial_deinit (FuriHalSerialHandle *handle)
 Deinitialize the serial interface.
 
void furi_hal_serial_suspend (FuriHalSerialHandle *handle)
 Suspend the serial interface.
 
void furi_hal_serial_resume (FuriHalSerialHandle *handle)
 Resume the serial interface.
 
bool furi_hal_serial_is_baud_rate_supported (FuriHalSerialHandle *handle, uint32_t baud_rate)
 Determine whether a certain baud rate is supported.
 
void furi_hal_serial_set_baud_rate (FuriHalSerialHandle *handle, uint32_t baud_rate)
 Set the baud rate for the serial interface.
 
void furi_hal_serial_set_hw_flow_control (FuriHalSerialHandle *handle, FuriHalSerialHwFlowControl flow_control)
 Set the hardware flow control mode for the serial interface.
 
void furi_hal_serial_set_tx_callback (FuriHalSerialHandle *handle, FuriHalSerialTxCallback callback, void *context)
 Set the transmit callback function for the serial interface.
 
void furi_hal_serial_set_rx_callback (FuriHalSerialHandle *handle, FuriHalSerialRxCallback callback, void *context)
 Set the receive callback function for the serial interface.
 
size_t furi_hal_serial_tx (FuriHalSerialHandle *handle, const uint8_t *buffer, size_t buffer_size, uint32_t timeout)
 Put data into the UART transmit FIFO buffer.
 
bool furi_hal_serial_tx_wait_complete (FuriHalSerialHandle *handle, uint32_t timeout)
 Wait for the UART transmit FIFO buffer to empty, meaning all bytes have been transmitted.
 
bool furi_hal_serial_rx_available (FuriHalSerialHandle *handle)
 Determine whether there is received data ready for reading.
 
uint8_t furi_hal_serial_rx (FuriHalSerialHandle *handle)
 Read the next received data character.
 
void furi_hal_serial_async_rx_start (FuriHalSerialHandle *handle, bool report_errors)
 Start receiving in interrupt-driven mode.
 
void furi_hal_serial_async_rx_stop (FuriHalSerialHandle *handle)
 Stop receiving in interrupt-driven mode.
 
void furi_hal_serial_dma_init (FuriHalSerialHandle *handle)
 Enable DMA-related functions for the serial instance.
 
void furi_hal_serial_dma_deinit (FuriHalSerialHandle *handle)
 Disable DMA-related functions for the serial instance.
 
void furi_hal_serial_dma_tx (FuriHalSerialHandle *handle, const uint8_t *buffer, size_t buffer_size)
 Transmit data over the serial interface using DMA.
 
void furi_hal_serial_dma_rx_start (FuriHalSerialHandle *handle, uint8_t *buffer, size_t buffer_size)
 Start receiving in DMA mode.
 
void furi_hal_serial_dma_rx_stop (FuriHalSerialHandle *handle)
 Stop receiving in DMA mode.
 
void furi_hal_serial_clear (FuriHalSerialHandle *handle, FuriHalSerialDirection direction)
 Clear pending characters in (a) specified direction(s).
 
bool furi_hal_serial_get_pin_state (FuriHalSerialHandle *handle, FuriHalSerialPin pin)
 Get the state of a designated pin associated with the serial.
 

Detailed Description

Serial HAL API.

Typedef Documentation

◆ FuriHalSerialRxCallback

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

Transmit callback function type.

Parameters
handlePointer to the serial handle.
eventBitmask of occurred events.
contextPointer to the context object.

◆ FuriHalSerialTxCallback

typedef void(* FuriHalSerialTxCallback) (FuriHalSerialHandle *handle, FuriHalSerialTxEvent event, void *context)

Receive callback function type.

Parameters
handlePointer to the serial handle.
eventBitmask of occurred events.
contextPointer to the context object.

Enumeration Type Documentation

◆ FuriHalSerialHwFlowControl

Serial hardware flow control modes.

Enumerator
FuriHalSerialHwFlowControlNone 

Do not use any hardware flow control.

FuriHalSerialHwFlowControlRtsCts 

Use both RTS and CTS signals.

◆ FuriHalSerialRxEvent

Serial RX events.

Enumerator
FuriHalSerialRxEventData 

Data: new data available.

FuriHalSerialRxEventIdle 

Idle: bus idle detected.

FuriHalSerialRxEventBreak 

Break: break condition detected.

FuriHalSerialRxEventFrameError 

Framing Error: incorrect frame detected.

FuriHalSerialRxEventNoiseError 

Noise Error: noise on the line detected.

FuriHalSerialRxEventOverrunError 

Overrun Error: no space for received data.

◆ FuriHalSerialTxEvent

Serial TX events.

Enumerator
FuriHalSerialTxEventComplete 

Transmission complete.

Function Documentation

◆ furi_hal_serial_async_rx_start()

void furi_hal_serial_async_rx_start ( FuriHalSerialHandle * handle,
bool report_errors )

Start receiving in interrupt-driven mode.

Parameters
handlePointer to the serial handle.
report_errorsEnable error events if set to true, do not enable otherwise.

◆ furi_hal_serial_async_rx_stop()

void furi_hal_serial_async_rx_stop ( FuriHalSerialHandle * handle)

Stop receiving in interrupt-driven mode.

Parameters
handlePointer to the serial handle.

◆ furi_hal_serial_clear()

void furi_hal_serial_clear ( FuriHalSerialHandle * handle,
FuriHalSerialDirection direction )

Clear pending characters in (a) specified direction(s).

Parameters
handlePointer to the serial handle.
directionDirection (transmit, receive or both) to clear.

◆ furi_hal_serial_deinit()

void furi_hal_serial_deinit ( FuriHalSerialHandle * handle)

Deinitialize the serial interface.

Parameters
handlePointer to the serial handle.

◆ furi_hal_serial_dma_deinit()

void furi_hal_serial_dma_deinit ( FuriHalSerialHandle * handle)

Disable DMA-related functions for the serial instance.

Precondition
furi_hal_serial_dma_init

◆ furi_hal_serial_dma_init()

void furi_hal_serial_dma_init ( FuriHalSerialHandle * handle)

Enable DMA-related functions for the serial instance.

Parameters
handlePointer to the serial handle.

◆ furi_hal_serial_dma_rx_start()

void furi_hal_serial_dma_rx_start ( FuriHalSerialHandle * handle,
uint8_t * buffer,
size_t buffer_size )

Start receiving in DMA mode.

Precondition
furi_hal_serial_dma_init
Note
In this mode, the receive event will only be generated once the whole buffer has been filled.
Parameters
handlePointer to the serial handle.
bufferPointer to the receive buffer (must be allocated and of appropriate size).
buffer_sizeSize of the receive buffer.

◆ furi_hal_serial_dma_rx_stop()

void furi_hal_serial_dma_rx_stop ( FuriHalSerialHandle * handle)

Stop receiving in DMA mode.

Precondition
furi_hal_serial_dma_init
Parameters
handlePointer to the serial handle.

◆ furi_hal_serial_dma_tx()

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

Transmit data over the serial interface using DMA.

Precondition
furi_hal_serial_dma_init
Parameters
handlePointer to the serial handle.
bufferPointer to the data buffer.
buffer_sizeSize of the data buffer.

◆ furi_hal_serial_get_pin_state()

bool furi_hal_serial_get_pin_state ( FuriHalSerialHandle * handle,
FuriHalSerialPin pin )

Get the state of a designated pin associated with the serial.

Parameters
handlePointer to the serial handle.
pinPin identifier from FuriHalSerialPin enum.

◆ furi_hal_serial_init()

void furi_hal_serial_init ( FuriHalSerialHandle * handle,
uint32_t baud_rate )

Initialize the serial interface.

Parameters
handlePointer to the serial handle.
baud_rateBaud rate.

◆ furi_hal_serial_is_baud_rate_supported()

bool furi_hal_serial_is_baud_rate_supported ( FuriHalSerialHandle * handle,
uint32_t baud_rate )

Determine whether a certain baud rate is supported.

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

◆ furi_hal_serial_resume()

void furi_hal_serial_resume ( FuriHalSerialHandle * handle)
inline

Resume the serial interface.

Parameters
handlePointer to the serial handle.

◆ furi_hal_serial_rx()

uint8_t furi_hal_serial_rx ( FuriHalSerialHandle * handle)

Read the next received data character.

Parameters
handlePointer to the serial handle.
Returns
the value of the first available received character.

◆ furi_hal_serial_rx_available()

bool furi_hal_serial_rx_available ( FuriHalSerialHandle * handle)

Determine whether there is received data ready for reading.

Parameters
handlePointer to the serial handle.
Returns
true if there is data ready to be read, false otherwise.

◆ furi_hal_serial_set_baud_rate()

void furi_hal_serial_set_baud_rate ( FuriHalSerialHandle * handle,
uint32_t baud_rate )

Set the baud rate for the serial interface.

Parameters
handlePointer to the serial handle.
baud_rateBaud rate.

◆ furi_hal_serial_set_hw_flow_control()

void furi_hal_serial_set_hw_flow_control ( FuriHalSerialHandle * handle,
FuriHalSerialHwFlowControl flow_control )

Set the hardware flow control mode for the serial interface.

Parameters
handlePointer to the serial handle.
flow_controlFlow control mode.

◆ furi_hal_serial_set_rx_callback()

void furi_hal_serial_set_rx_callback ( FuriHalSerialHandle * handle,
FuriHalSerialRxCallback callback,
void * context )

Set the receive callback function for the serial interface.

Parameters
handlePointer to the serial handle.
callbackPointer to the receive callback function.
contextPointer to the context object.

◆ furi_hal_serial_set_tx_callback()

void furi_hal_serial_set_tx_callback ( FuriHalSerialHandle * handle,
FuriHalSerialTxCallback callback,
void * context )

Set the transmit callback function for the serial interface.

Parameters
handlePointer to the serial handle.
callbackPointer to the transmit callback function.
contextPointer to the context object.

◆ furi_hal_serial_suspend()

void furi_hal_serial_suspend ( FuriHalSerialHandle * handle)
inline

Suspend the serial interface.

Parameters
handlePointer to the serial handle.

◆ furi_hal_serial_tx()

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

Put data into the UART transmit FIFO buffer.

Parameters
handlePointer to the serial handle.
bufferPointer to the data buffer.
buffer_sizeSize of the data buffer.
timeoutTimeout in milliseconds, or FuriWaitForever.
Returns
Number of bytes put into the buffer within the specified timeout

◆ furi_hal_serial_tx_wait_complete()

bool furi_hal_serial_tx_wait_complete ( FuriHalSerialHandle * handle,
uint32_t timeout )

Wait for the UART transmit FIFO buffer to empty, meaning all bytes have been transmitted.

Parameters
handlePointer to the serial handle.
timeoutTimeout in milliseconds.
Returns
true if the transmission was complete within the timeout, false otherwise