AFE_NXP_Arduino 2.0.5 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
12#ifndef ARDUINO_SPI_FOR_AFE_H
13#define ARDUINO_SPI_FOR_AFE_H
14
15#include <Arduino.h>
16#include <stdint.h>
17
18#include <SPI.h>
19
20 class SPI_for_AFE
21{
22 public:
28 virtual void txrx( uint8_t *data, int size );
29
34 virtual void write_r16( uint16_t reg );
35
41 virtual void write_r16( uint16_t reg, uint16_t val );
42
48 virtual uint16_t read_r16( uint16_t reg );
49
55 virtual void write_r24( uint16_t reg, uint32_t val );
56
62 virtual int32_t read_r24( uint16_t reg );
63
70 virtual void burst( uint32_t *data, int length, int width = 3 );
71
76 virtual void spi_frequency( uint32_t frequency = 1000000 );
77
78 protected:
80 void init( void );
81 uint32_t frequency;
82
83 private:
84 // functions to access AFE multibyte data access independent from endianess
85 inline int32_t get_data16( uint8_t *vp )
86 {
87 return ((uint16_t)(*(vp + 0)) << 8) | *(vp + 1);
88 }
89
90 inline int32_t get_data24( uint8_t *vp )
91 {
92 int32_t r0 = *(vp + 0);
93 int32_t r1 = *(vp + 1);
94 int32_t r2 = *(vp + 2);
95 int32_t r = ( (r0 << 24) | (r1 << 16) | (r2 << 8) );
96
97 return r >> 8;
98 }
99
100 static constexpr int command_length = 2;
101// const bool dev_ad;
102};
103
104#endif // ARDUINO_SPI_FOR_AFE_H
SPI_for_AFE
Definition SPI_for_AFE.h:21
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:100
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:81
SPI_for_AFE::get_data24
int32_t get_data24(uint8_t *vp)
Definition SPI_for_AFE.h:90
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:85
SPI_for_AFE::spi_frequency
virtual void spi_frequency(uint32_t frequency=1000000)
Definition SPI_for_AFE.cpp:73