AFE_NXP_Arduino 2.0.5 Analog Front-End (AFE) device operation sample code for Arduino

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
AFE_base Class Referenceabstract

`#include <AFE_NXP.h>`

Inheritance diagram for AFE_base:

## Public Types
enum | LV_mux_sel : uint8_t { REF2_REF2 = 0 , GPIO0_GPIO1 , REFCOARSE_REF2 , VADD_REF2 , VHDD_REF2 , REF2_VHSS , HV_MUX }
using | raw_t = int32_t
using | volt_t = double
typedef void(* | callback_fp_t) (void)

## Public Member Functions
| AFE_base (bool spi_addr, bool highspeed_variant, int nINT, int DRDY, int SYN, int nRESET, int DRDY_input, int SYNCDAC)
virtual | ~AFE_base ()
virtual void | begin (void)
virtual void | boot (void)=0
virtual void | reset (bool hardware_reset=false)=0
virtual void | set_DRDY_callback (callback_fp_t fnc)
virtual void | open_logical_channel (int ch, uint16_t cc0, uint16_t cc1, uint16_t cc2, uint16_t cc3)=0
virtual void | open_logical_channel (int ch, const uint16_t(&cc)[4])=0
virtual void | close_logical_channel (int ch)=0
virtual void | close_logical_channel (void)=0
virtual void | enable_logical_channel (int ch)=0
virtual void | start (int ch)=0
virtual void | start (void)=0
virtual void | start_continuous_conversion (void)=0
virtual void | DRDY_by_sequencer_done (bool flag=true)=0
virtual raw_t | read (int ch)=0
virtual void | read (raw_t *data_ptr)=0
virtual void | read (volt_t *data_ptr)=0
virtual raw_t | start_and_read (int ch)
template<typename T>
void | start_and_read (T data)
double | raw2uv (int ch, raw_t value)
double | raw2mv (int ch, raw_t value)
virtual double | raw2v (int ch, raw_t value)=0
double | drdy_delay (int ch)
double | drdy_delay (void)
int | enabled_logical_channels (void)
void | use_DRDY_trigger (bool use=true)
Public Member Functions inherited from SPI_for_AFE
virtual void | txrx (uint8_t *data, int size)
virtual void | write_r16 (uint16_t reg)
virtual void | write_r16 (uint16_t reg, uint16_t val)
virtual uint16_t | read_r16 (uint16_t reg)
virtual void | write_r24 (uint16_t reg, uint32_t val)
virtual int32_t | read_r24 (uint16_t reg)
virtual void | burst (uint32_t *data, int length, int width=3)
virtual void | spi_frequency (uint32_t frequency=1000000)

## Static Public Attributes
static AFE_base * | instance = nullptr

## Protected Member Functions
int | bit_count (uint32_t value)
void | default_drdy_cb ()
virtual void | init (void)
int | wait_conversion_complete (double delay=-1.0)
Protected Member Functions inherited from SPI_for_AFE
void | init (void)

## Static Protected Member Functions
static void | static_default_drdy_cb ()
static void | DRDY_cb ()

## Protected Attributes
bool | dev_add
bool | highspeed_variant
int | pin_nINT
int | pin_DRDY
int | pin_SYN
int | pin_nRESET
int | pin_DRDY_input
int | pin_SYNCDAC
int | enabled_channels
uint8_t | sequence_order [16]
double | coeff_V [16]
int | mux_setting [16]
double | ch_delay [16]
double | total_delay
uint32_t | drdy_count
volatile bool | drdy_flag
Protected Attributes inherited from SPI_for_AFE
uint32_t | frequency

## Static Protected Attributes
static double | delay_accuracy = 1.1
static constexpr uint32_t | timeout_limit = 10000000
static callback_fp_t | cbf_DRDY = nullptr

## Detailed Description

NXP Analog Front End class library for Arduino

Copyright: 2023 - 2026 Tedd OKANO Released under the MIT license

A simple class library for NXP Analog Front End: NAFE13388, NAFE33352 evaluation boards

Definition at line 17 of file AFE_NXP.h.

## Member Typedef Documentation

## ◆ callback_fp_t

typedef void(* AFE_base::callback_fp_t) (void)

Callback function type called when DRDY asserts

Definition at line 46 of file AFE_NXP.h.

## ◆ raw_t

using AFE_base::raw_t = int32_t

ADC readout types

Definition at line 22 of file AFE_NXP.h.

## ◆ volt_t

using AFE_base::volt_t = double

Definition at line 23 of file AFE_NXP.h.

## Member Enumeration Documentation

## ◆ LV_mux_sel

enum AFE_base::LV_mux_sel : uint8_t

Low-voltage MUX input selection for internal diagnostic measurements

Enumerator
REF2_REF2 |
GPIO0_GPIO1 |
REFCOARSE_REF2 |
VADD_REF2 |
VHDD_REF2 |
REF2_VHSS |
HV_MUX |

Definition at line 157 of file AFE_NXP.h.

## Constructor & Destructor Documentation

## ◆ AFE_base()

AFE_base::AFE_base | ( | bool | spi_addr,
|  | bool | highspeed_variant,
|  | int | nINT,
|  | int | DRDY,
|  | int | SYN,
|  | int | nRESET,
|  | int | DRDY_input,
|  | int | SYNCDAC )

Constructor to create an AFE_base instance

Definition at line 70 of file AFE_NXP.cpp.

Referenced by NAFE13388_Base::NAFE13388_Base(), and NAFE33352_Base::NAFE33352_Base().

## ◆ ~AFE_base()

AFE_base::~AFE_base | ( |  | ) |
| virtual

Destructor

Definition at line 84 of file AFE_NXP.cpp.

## Member Function Documentation

## ◆ begin()

void AFE_base::begin | ( | void |  | ) |
| virtual

Begin the device operation

NAFE13388 initialization. It does following steps (1) Call reset() (2) Call boot()

Definition at line 98 of file AFE_NXP.cpp.

## ◆ bit_count()

int AFE_base::bit_count | ( | uint32_t | value | ) |
| protected

Count number of set bits in a value

Parameters

  value | input value

Returns
  number of set bits

Definition at line 155 of file AFE_NXP.cpp.

## ◆ boot()

virtual void AFE_base::boot | ( | void |  | ) |
| pure virtual

Set system-level config registers

Implemented in NAFE13388_Base, and NAFE33352_Base.

Referenced by begin().

## ◆ close_logical_channel() [1/2]

virtual void AFE_base::close_logical_channel | ( | int | ch | ) |
| pure virtual

Logical channel disable

Parameters

  ch | logical channel number (0 ~ 15)

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ close_logical_channel() [2/2]

virtual void AFE_base::close_logical_channel | ( | void |  | ) |
| pure virtual

All logical channel disable

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ default_drdy_cb()

void AFE_base::default_drdy_cb | ( | void |  | ) |
| protected

Definition at line 126 of file AFE_NXP.cpp.

## ◆ DRDY_by_sequencer_done()

virtual void AFE_base::DRDY_by_sequencer_done | ( | bool | flag = true | ) |
| pure virtual

DRDY event select

Parameters

  flag | true for DRDY by sequencer is done

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ DRDY_cb()

void AFE_base::DRDY_cb | ( | void |  | ) |
| static protected

Definition at line 114 of file AFE_NXP.cpp.

Referenced by init().

## ◆ drdy_delay() [1/2]

double AFE_base::drdy_delay | ( | int | ch | ) |
| inline

Calculated delay from logical channel setting (for single channel)

Parameters

  ch | logical channel number

Definition at line 198 of file AFE_NXP.h.

## ◆ drdy_delay() [2/2]

double AFE_base::drdy_delay | ( | void |  | ) |
| inline

Calculated delay from logical channel setting (for all channels)

Definition at line 205 of file AFE_NXP.h.

## ◆ enable_logical_channel()

virtual void AFE_base::enable_logical_channel | ( | int | ch | ) |
| pure virtual

Logical channel enable

Parameters

  ch | logical channel number (0 ~ 15)

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ enabled_logical_channels()

int AFE_base::enabled_logical_channels | ( | void |  | ) |
| inline

Number of enabled logical channels

Definition at line 211 of file AFE_NXP.h.

## ◆ init()

void AFE_base::init | ( | void |  | ) |
| protected virtual

Initialize AFE device and SPI peripheral

Definition at line 88 of file AFE_NXP.cpp.

Referenced by begin().

## ◆ open_logical_channel() [1/2]

virtual void AFE_base::open_logical_channel | ( | int | ch,
|  | const uint16_t(&) | cc[4] )
| pure virtual

Configure logical channel

Parameters

  ch | logical channel number (0 ~ 15)
  cc | array for CH_CONFIG0, CH_CONFIG1, CH_CONFIG2 and CH_CONFIG3 values

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ open_logical_channel() [2/2]

virtual void AFE_base::open_logical_channel | ( | int | ch,
|  | uint16_t | cc0,
|  | uint16_t | cc1,
|  | uint16_t | cc2,
|  | uint16_t | cc3 )
| pure virtual

Configure logical channel

Parameters

  ch | logical channel number (0 ~ 15)
  cc0 | 16bit value to be set CH_CONFIG0 register (0x20)
  cc1 | 16bit value to be set CH_CONFIG1 register (0x21)
  cc2 | 16bit value to be set CH_CONFIG2 register (0x22)
  cc3 | 16bit value to be set CH_CONFIG3 register (0x23)

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ raw2mv()

double AFE_base::raw2mv | ( | int | ch,
|  | raw_t | value )
| inline

Convert raw output to milli-volt

Parameters

  ch | logical channel number to select its gain coefficient
  value | ADC read value

Definition at line 182 of file AFE_NXP.h.

Referenced by NAFE13388_Base::self_calibrate().

## ◆ raw2uv()

double AFE_base::raw2uv | ( | int | ch,
|  | raw_t | value )
| inline

Convert raw output to micro-volt

Parameters

  ch | logical channel number to select its gain coefficient
  value | ADC read value

Definition at line 172 of file AFE_NXP.h.

Referenced by NAFE33352_Base::read().

## ◆ raw2v()

virtual double AFE_base::raw2v | ( | int | ch,
|  | raw_t | value )
| pure virtual

Convert raw output to volt

Parameters

  ch | logical channel number to select its gain coefficient
  value | ADC read value

Implemented in NAFE13388_Base, and NAFE33352_Base.

Referenced by raw2mv(), and raw2uv().

## ◆ read() [1/3]

virtual raw_t AFE_base::read | ( | int | ch | ) |
| pure virtual

Read ADC for single channel

Parameters

  ch | logical channel number (0 ~ 15)

Implemented in NAFE13388_Base, and NAFE33352_Base.

Referenced by LogicalChannel_Base::operator AFE_base::raw_t(), LogicalChannel_Base::operator AFE_base::volt_t(), start_and_read(), and start_and_read().

## ◆ read() [2/3]

virtual void AFE_base::read | ( | raw_t * | data_ptr | ) |
| pure virtual

Read ADC for all channel

Parameters

  data_ptr | pointer to array to store ADC data

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ read() [3/3]

virtual void AFE_base::read | ( | volt_t * | data_ptr | ) |
| pure virtual

Read ADC for all channel

Parameters

  data_ptr | pointer to array to store ADC data

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ reset()

virtual void AFE_base::reset | ( | bool | hardware_reset = false | ) |
| pure virtual

Issue RESET command

Implemented in NAFE13388_Base, and NAFE33352_Base.

Referenced by begin().

## ◆ set_DRDY_callback()

void AFE_base::set_DRDY_callback | ( | callback_fp_t | fnc | ) |
| virtual

Set callback function invoked when DRDY asserts

Parameters

  fnc | pointer to the callback function

Definition at line 109 of file AFE_NXP.cpp.

Referenced by init(), and use_DRDY_trigger().

## ◆ start() [1/2]

virtual void AFE_base::start | ( | int | ch | ) |
| pure virtual

Start ADC

Parameters

  ch | logical channel number (0 ~ 15)

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ start() [2/2]

virtual void AFE_base::start | ( | void |  | ) |
| pure virtual

Start ADC on all logical channel

Implemented in NAFE13388_Base, and NAFE33352_Base.

Referenced by start_and_read(), and start_and_read().

## ◆ start_and_read() [1/2]

int32_t AFE_base::start_and_read | ( | int | ch | ) |
| virtual

Start and read ADC for single channel

Parameters

  ch | logical channel number (0 ~ 15)

Definition at line 132 of file AFE_NXP.cpp.

Referenced by NAFE13388_Base::self_calibrate().

## ◆ start_and_read() [2/2]

template<typename T>

void AFE_base::start_and_read | ( | T | data | ) |
| inline

Start ADC and read results for all enabled channels

Parameters

  data | pointer to array to store ADC data (raw_t* or volt_t*)

Definition at line 145 of file AFE_NXP.h.

## ◆ start_continuous_conversion()

virtual void AFE_base::start_continuous_conversion | ( | void |  | ) |
| pure virtual

Start continuous AD conversion

Implemented in NAFE13388_Base, and NAFE33352_Base.

## ◆ static_default_drdy_cb()

void AFE_base::static_default_drdy_cb | ( | void |  | ) |
| static protected

Definition at line 120 of file AFE_NXP.cpp.

Referenced by init(), and use_DRDY_trigger().

## ◆ use_DRDY_trigger()

void AFE_base::use_DRDY_trigger | ( | bool | use = true | ) |

Switch to use DRDY to start ADC result reading

Parameters

  use | true (default) to use DRDY. if false, calculated delay is used to start reading.

Definition at line 194 of file AFE_NXP.cpp.

Referenced by init().

## ◆ wait_conversion_complete()

int AFE_base::wait_conversion_complete | ( | double | delay = -1.0 | ) |
| protected

Wait until ADC conversion completes

Parameters

  delay | wait time in seconds; negative value uses DRDY interrupt

Returns
  0 on success, negative on timeout

Definition at line 168 of file AFE_NXP.cpp.

Referenced by start_and_read(), and start_and_read().

## Member Data Documentation

## ◆ cbf_DRDY

AFE_base::callback_fp_t AFE_base::cbf_DRDY = nullptr
| static protected

Definition at line 263 of file AFE_NXP.h.

Referenced by DRDY_cb(), set_DRDY_callback(), start_and_read(), and start_and_read().

## ◆ ch_delay

double AFE_base::ch_delay[16]
| protected

Channel delay

Definition at line 253 of file AFE_NXP.h.

Referenced by NAFE13388_Base::calc_delay(), NAFE33352_Base::calc_delay(), NAFE13388_Base::channel_info_update(), NAFE33352_Base::channel_info_update(), drdy_delay(), NAFE13388_Base::open_logical_channel(), NAFE33352_Base::open_logical_channel(), and start_and_read().

## ◆ coeff_V

double AFE_base::coeff_V[16]
| protected

Coefficient to convert from ADC read value to micro-volt

Definition at line 247 of file AFE_NXP.h.

Referenced by NAFE13388_Base::open_logical_channel(), NAFE33352_Base::open_logical_channel(), NAFE13388_Base::raw2v(), and NAFE33352_Base::raw2v().

## ◆ delay_accuracy

double AFE_base::delay_accuracy = 1.1
| static protected

NXP Analog Front End class library for Arduino

Author
  Tedd OKANO

Copyright: 2023 - 2026 Tedd OKANO Released under the MIT license

Definition at line 255 of file AFE_NXP.h.

Referenced by start_and_read(), start_and_read(), and wait_conversion_complete().

## ◆ dev_add

bool AFE_base::dev_add
| protected

Definition at line 223 of file AFE_NXP.h.

Referenced by AFE_base().

## ◆ drdy_count

uint32_t AFE_base::drdy_count
| protected

Definition at line 261 of file AFE_NXP.h.

Referenced by default_drdy_cb().

## ◆ drdy_flag

volatile bool AFE_base::drdy_flag
| protected

Definition at line 262 of file AFE_NXP.h.

Referenced by default_drdy_cb(), init(), and wait_conversion_complete().

## ◆ enabled_channels

int AFE_base::enabled_channels
| protected

Number of enabled logical channels

Definition at line 241 of file AFE_NXP.h.

Referenced by AFE_base(), NAFE13388_Base::channel_info_update(), NAFE33352_Base::channel_info_update(), enabled_logical_channels(), NAFE13388_Base::read(), NAFE13388_Base::read(), NAFE33352_Base::read(), and NAFE33352_Base::read().

## ◆ highspeed_variant

bool AFE_base::highspeed_variant
| protected

Definition at line 224 of file AFE_NXP.h.

Referenced by AFE_base(), NAFE13388_Base::calc_delay(), and NAFE33352_Base::calc_delay().

## ◆ instance

AFE_base * AFE_base::instance = nullptr
| static

Definition at line 277 of file AFE_NXP.h.

Referenced by begin(), and static_default_drdy_cb().

## ◆ mux_setting

int AFE_base::mux_setting[16]
| protected

Multiplexer setting

Definition at line 250 of file AFE_NXP.h.

Referenced by NAFE13388_Base::open_logical_channel(), NAFE33352_Base::open_logical_channel(), NAFE13388_Base::raw2v(), and NAFE33352_Base::raw2v().

## ◆ pin_DRDY

int AFE_base::pin_DRDY
| protected

Definition at line 226 of file AFE_NXP.h.

Referenced by AFE_base().

## ◆ pin_DRDY_input

int AFE_base::pin_DRDY_input
| protected

Definition at line 229 of file AFE_NXP.h.

Referenced by AFE_base(), and init().

## ◆ pin_nINT

int AFE_base::pin_nINT
| protected

Definition at line 225 of file AFE_NXP.h.

Referenced by AFE_base().

## ◆ pin_nRESET

int AFE_base::pin_nRESET
| protected

Definition at line 228 of file AFE_NXP.h.

Referenced by AFE_base(), and NAFE13388_Base::reset().

## ◆ pin_SYN

int AFE_base::pin_SYN
| protected

Definition at line 227 of file AFE_NXP.h.

Referenced by AFE_base().

## ◆ pin_SYNCDAC

int AFE_base::pin_SYNCDAC
| protected

Definition at line 230 of file AFE_NXP.h.

Referenced by AFE_base().

## ◆ sequence_order

uint8_t AFE_base::sequence_order[16]
| protected

Number of enabled logical channels

Definition at line 244 of file AFE_NXP.h.

Referenced by NAFE13388_Base::channel_info_update(), NAFE33352_Base::channel_info_update(), NAFE13388_Base::read(), and NAFE33352_Base::read().

## ◆ timeout_limit

uint32_t AFE_base::timeout_limit = 10000000
| static constexpr protected

Definition at line 257 of file AFE_NXP.h.

Referenced by wait_conversion_complete().

## ◆ total_delay

double AFE_base::total_delay
| protected

Definition at line 254 of file AFE_NXP.h.

Referenced by NAFE13388_Base::channel_info_update(), NAFE33352_Base::channel_info_update(), drdy_delay(), and start_and_read().

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

- AFE_NXP.h
- AFE_NXP.cpp