nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Public Types | Static Public Member Functions | Static Public Attributes
nrfcxx::periph::details::comm_error_support Class Reference

Abstracted support for error returns. More...

#include <nrfcxx/periph.hpp>

Inheritance diagram for nrfcxx::periph::details::comm_error_support:
nrfcxx::periph::SPI nrfcxx::periph::TWI

Public Types

using size_type = unsigned int
 The type used for transfer sizes (unsigned)
 
using ssize_type = int
 The type used for transfer sizes (non-negative) or errors (negative). More...
 
using error_type = unsigned int
 The type used to encode TWI peripheral errors. More...
 

Static Public Member Functions

constexpr static error_type error_decoded (ssize_type rc)
 Extract an encoded error value from an API return value. More...
 
constexpr static ssize_type error_encoded (error_type ec)
 Pack an error value into a negative return value. More...
 

Static Public Attributes

constexpr static unsigned int ERR_OVERRUN = 0x001
 NRF_TWI_Type::ERRORSRC bit indicating incomplete reception at start.
 
constexpr static unsigned int ERR_ANACK = 0x002
 NRF_TWI_Type::ERRORSRC bit indicating NACK received during address transmission.
 
constexpr static unsigned int ERR_DNACK = 0x004
 NRF_TWI_Type::ERRORSRC bit indicating NACK received during data transmission.
 
constexpr static unsigned int ERR_TIMEOUT = 0x100
 Bit set in an error code when the TWI bus transaction timed out.
 
constexpr static unsigned int ERR_CLEAR = 0x200
 Bit set in an error code when the TWI bus could not be cleared.
 
constexpr static unsigned int ERR_INVALID = 0x400
 Bit set in an error code to indicate that the bus was not properly configured or a parameter was invalid.
 
constexpr static unsigned int ERR_CHECKSUM = 0x800
 Bit set in an error code to indicate a checksum error. More...
 
constexpr static unsigned int ERR_UNKNOWN = 0x1000
 Bit set in an error code to indicate an undescribable error.
 

Detailed Description

Abstracted support for error returns.

This is designed around the needs of #TWI but applies to SPI as well for a couple operations that can fail with ERR_INVALID.

Member Typedef Documentation

◆ error_type

The type used to encode TWI peripheral errors.

TWI errors are indicated returned as negative ssize_type values from read() and write(). Details of the error are obtained by converting this value to an error_type value using error_decoded().

The resulting code comprises bits from the TWI ERRORSRC register along with ERR_TIMEOUT, ERR_CLEAR, ERR_INVALID, and ERR_UNKNOWN.

See also
error_decoded

◆ ssize_type

The type used for transfer sizes (non-negative) or errors (negative).

See also
error_type

Member Function Documentation

◆ error_decoded()

constexpr static error_type nrfcxx::periph::details::comm_error_support::error_decoded ( ssize_type  rc)
inlinestaticconstexpr

Extract an encoded error value from an API return value.

Parameters
rca result code, which is negative if it represents an error.
Returns
Zero if rc does not represent an error, otherwise the corresponding error_type value.

◆ error_encoded()

constexpr static ssize_type nrfcxx::periph::details::comm_error_support::error_encoded ( error_type  ec)
inlinestaticconstexpr

Pack an error value into a negative return value.

Returns
Zero if ec is zero, otherwise the encoded error value.

Field Documentation

◆ ERR_CHECKSUM

constexpr static unsigned int nrfcxx::periph::details::comm_error_support::ERR_CHECKSUM = 0x800
staticconstexpr

Bit set in an error code to indicate a checksum error.

Generally this error will appear only in results from methods supporting higher-level operations on devices that can detect data errors.


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