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

Loading...
Searching...
No Matches
SPI_for_AFE.h
Go to the documentation of this file.
1
13
14#ifndef ARDUINO_SPI_FOR_AFE_H
15#define ARDUINO_SPI_FOR_AFE_H
16
17#include <Arduino.h>
18#include <stdint.h>
19
20#include <SPI.h>
21
22 class SPI_for_AFE
23{
24 public:
30 virtual void txrx( uint8_t *data, int size );
31
36 virtual void write_r16( uint16_t reg );
37
43 virtual void write_r16( uint16_t reg, uint16_t val );
44
50 virtual uint16_t read_r16( uint16_t reg );
51
57 virtual void write_r24( uint16_t reg, uint32_t val );
58
64 virtual int32_t read_r24( uint16_t reg );
65
72 virtual void burst( uint32_t *data, int length, int width = 3 );
73
78 virtual void spi_frequency( uint32_t frequency = 1'000'000 );
79
80 protected:
82 void init( void );
83 uint32_t frequency;
84
85 private:
86 // functions to access AFE multibyte data access independent from endianess
87 inline int32_t get_data16( uint8_t *vp )
88 {
89 return ((uint16_t)(*(vp + 0)) << 8) | *(vp + 1);
90 }
91
92 inline int32_t get_data24( uint8_t *vp )
93 {
94 int32_t r0 = *(vp + 0);
95 int32_t r1 = *(vp + 1);
96 int32_t r2 = *(vp + 2);
97 int32_t r = ( (r0 << 24) | (r1 << 16) | (r2 << 8) );
98
99 return r >> 8;
100 }
101
102 static constexpr int command_length = 2;
103// const bool dev_ad;
104};
105
106#endif // ARDUINO_SPI_FOR_AFE_H
SPI_for_AFE
Definition SPI_for_AFE.h:23
SPI_for_AFE::read_r24
virtual int32_t read_r24(uint16_t reg)
Definition SPI_for_AFE.cpp:48
SPI_for_AFE::txrx
virtual void txrx(uint8_t *data, int size)
Definition SPI_for_AFE.cpp:3
SPI_for_AFE::init
void init(void)
Definition SPI_for_AFE.cpp:78
SPI_for_AFE::write_r24
virtual void write_r24(uint16_t reg, uint32_t val)
Definition SPI_for_AFE.cpp:40
SPI_for_AFE::read_r16
virtual uint16_t read_r16(uint16_t reg)
Definition SPI_for_AFE.cpp:29
SPI_for_AFE::command_length
static constexpr int command_length
Definition SPI_for_AFE.h:102
SPI_for_AFE::burst
virtual void burst(uint32_t *data, int length, int width=3)
Definition SPI_for_AFE.cpp:59
SPI_for_AFE::frequency
uint32_t frequency
Definition SPI_for_AFE.h:83
SPI_for_AFE::get_data24
int32_t get_data24(uint8_t *vp)
Definition SPI_for_AFE.h:92
SPI_for_AFE::write_r16
virtual void write_r16(uint16_t reg)
Definition SPI_for_AFE.cpp:13
SPI_for_AFE::get_data16
int32_t get_data16(uint8_t *vp)
Definition SPI_for_AFE.h:87
SPI_for_AFE::spi_frequency
virtual void spi_frequency(uint32_t frequency=1 '000 '000)
Definition SPI_for_AFE.cpp:73