nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions
nrfcxx::periph::UART Class Reference

Wrapper around the nRF51 UART peripheral. More...

#include <nrfcxx/periph.hpp>

Data Structures

struct  statistics_type
 Statistics on the UART operation. More...
 

Public Types

using fifo_type = pabigot::container::rr_adaptor< uint8_t >
 The type used for transmission and reception buffers.
 
using size_type = unsigned int
 The type used for transfer sizes (unsigned)
 
using ssize_type = int
 The type used for transfer sizes or errors (signed)
 

Public Member Functions

void enable (uint32_t cfg_baudrate=UART_BAUDRATE_BAUDRATE_Baud115200, bool hwfc=false)
 Enable the UART. More...
 
void disable ()
 Disable the UART.
 
bool enabled (bool live=false) const
 Indicate whether UART is enabled. More...
 
bool autoenable (int on)
 Query or control whether the UART self-enables for output. More...
 
ssize_type write (const uint8_t *sp, size_type count)
 Write data to the UART. More...
 
ssize_type read (uint8_t *dp, size_type count)
 Read data from the UART. More...
 
statistics_type statistics () const
 Get a snapshot of the UART statistics.
 
event_setevents ()
 Reference the UART events. More...
 
void irq_handler ()
 Implementation for UART#_IRQHandler required by this module. More...
 
const nrf5::UART_Typeperipheral () const
 Reference the nRF5 UART peripheral instance used by the abstraction.
 

Static Public Member Functions

static UARTinstance ()
 Reference the abstraction instance for UART0.
 

Static Public Attributes

static constexpr event_set::event_type EVT_RXAVAIL = 0x01
 Event set in events() when data is received.
 
static constexpr event_set::event_type EVT_TXAVAIL = 0x02
 Event set in events() when there is space in the transmit buffer.
 
static constexpr event_set::event_type EVT_TXDONE = 0x04
 Event set in events() when transmission completes. More...
 
static constexpr event_set::event_type EVT_ERROR = 0x04
 Event set in events() when an error is detected. More...
 
static UART UART0
 A reference to a board-specific standard UART instance.
 

Protected Member Functions

 UART (const nrf5::UART_Type &uart, fifo_type &rxb, fifo_type &txb, int rxd_pin, int txd_pin, int cts_pin=-1, int rts_pin=-1)
 

Detailed Description

Wrapper around the nRF51 UART peripheral.

This provides interrupt-driven (only) transmission and reception.

Note
This module does not configure the RTS and CTS GPIOs. If hardware flow control is enabled RTS should be configured through GPIO logic high to notify connected devices that there is no listener during periods when the UART is disabled. When the UART is enabled RTS will be controlled by it, based on whether there is space in the peripheral receive buffer.

Member Function Documentation

◆ autoenable()

bool nrfcxx::periph::UART::autoenable ( int  on)

Query or control whether the UART self-enables for output.

By default the UART is entirely controlled by enable(). If auto-enable is requested the UART will be disabled internally except when there is material pending transmission.

An explicit use invocation of enable() or disable() turns off auto-enable.

Parameters
onpositive to turn on auto-enable; zero to turn off auto-enable; negative to return the current state without changing it.
Returns
true if auto-enable is turned on, otherwise false.

◆ enable()

void nrfcxx::periph::UART::enable ( uint32_t  cfg_baudrate = UART_BAUDRATE_BAUDRATE_Baud115200,
bool  hwfc = false 
)

Enable the UART.

Note
Use of autoenable() may cause the device to be disabled during periods when there is no transmission pending.
Parameters
cfg_baudratethe NRF51 BAUDRATE.BAUDRATE field value from the Nordic headers. Note that the value is not numerically equivalent to the baud rate. An explicit zero value selects the default baud rate.
hwfctrue iff hardware flow control should be enabled. The value is ignored if either RTS or CTS pins are undefined.

◆ enabled()

bool nrfcxx::periph::UART::enabled ( bool  live = false) const

Indicate whether UART is enabled.

Parameters
liveif true this returns the actual state of the peripheral. If false this disregards a disable due to autoenable().

◆ events()

event_set& nrfcxx::periph::UART::events ( )

Reference the UART events.

See also
EVT_RXAVAIL
EVT_TXAVAIL
EVT_TXDONE
EVT_ERROR

◆ irq_handler()

void nrfcxx::periph::UART::irq_handler ( )

Implementation for UART#_IRQHandler required by this module.

This class requires that the UART#_IRQHandler process events to fulfill its obligations. At this time the handler is implicitly installed for UART0.

◆ read()

ssize_type nrfcxx::periph::UART::read ( uint8_t *  dp,
size_type  count 
)

Read data from the UART.

Parameters
dppointer to where received octets should be written
countthe maximum number of octets to be read
Returns
the number of octets actually read. This may be less than count if the receive buffer does not have the requested amount of data.

◆ write()

ssize_type nrfcxx::periph::UART::write ( const uint8_t *  sp,
size_type  count 
)

Write data to the UART.

Parameters
sppointer to the source of the data
countthe number of octets to be written
Returns
the number of octets actually written. This may be less than count if the transmit buffer lacks space.

Field Documentation

◆ EVT_ERROR

constexpr event_set::event_type nrfcxx::periph::UART::EVT_ERROR = 0x04
staticconstexpr

Event set in events() when an error is detected.

Specifically a hardware error; dropped received data is not detected through this event.

◆ EVT_TXDONE

constexpr event_set::event_type nrfcxx::periph::UART::EVT_TXDONE = 0x04
staticconstexpr

Event set in events() when transmission completes.

This event does not occur when the transmit buffer is emptied, but only when it remains empty after the UART has transmitted the last byte.


The documentation for this class was generated from the following file: