nrfcxx
0.1.0
C++-17 Framework for Nordic nRF5 Devices
|
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_set & | events () |
Reference the UART events. More... | |
void | irq_handler () |
Implementation for UART#_IRQHandler required by this module. More... | |
const nrf5::UART_Type & | peripheral () const |
Reference the nRF5 UART peripheral instance used by the abstraction. | |
Static Public Member Functions | |
static UART & | instance () |
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) | |
Wrapper around the nRF51 UART peripheral.
This provides interrupt-driven (only) transmission and reception.
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.
on | positive to turn on auto-enable; zero to turn off auto-enable; negative to return the current state without changing it. |
true
if auto-enable is turned on, otherwise false
. void nrfcxx::periph::UART::enable | ( | uint32_t | cfg_baudrate = UART_BAUDRATE_BAUDRATE_Baud115200 , |
bool | hwfc = false |
||
) |
Enable the UART.
cfg_baudrate | the 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. |
hwfc | true iff hardware flow control should be enabled. The value is ignored if either RTS or CTS pins are undefined. |
bool nrfcxx::periph::UART::enabled | ( | bool | live = false | ) | const |
Indicate whether UART is enabled.
live | if true this returns the actual state of the peripheral. If false this disregards a disable due to autoenable(). |
event_set& nrfcxx::periph::UART::events | ( | ) |
Reference the UART events.
void nrfcxx::periph::UART::irq_handler | ( | ) |
ssize_type nrfcxx::periph::UART::read | ( | uint8_t * | dp, |
size_type | count | ||
) |
Read data from the UART.
dp | pointer to where received octets should be written |
count | the maximum number of octets to be read |
count
if the receive buffer does not have the requested amount of data. ssize_type nrfcxx::periph::UART::write | ( | const uint8_t * | sp, |
size_type | count | ||
) |
Write data to the UART.
sp | pointer to the source of the data |
count | the number of octets to be written |
count
if the transmit buffer lacks space.
|
staticconstexpr |
Event set in events() when an error is detected.
Specifically a hardware error; dropped received data is not detected through this event.
|
staticconstexpr |