SimpleFOClibrary
2.4.0
Loading...
Searching...
No Matches
MagneticSensorSPI.h
Go to the documentation of this file.
1
#ifndef MAGNETICSENSORSPI_LIB_H
2
#define MAGNETICSENSORSPI_LIB_H
3
4
5
#include "Arduino.h"
6
#include <SPI.h>
7
#include "../common/base_classes/Sensor.h"
8
#include "../common/foc_utils.h"
9
#include "../common/time_utils.h"
10
11
#define DEF_ANGLE_REGISTER 0x3FFF
12
13
struct
MagneticSensorSPIConfig_s
{
14
int
spi_mode
;
15
long
clock_speed
;
16
int
bit_resolution
;
17
int
angle_register
;
18
int
data_start_bit
;
19
int
command_rw_bit
;
20
int
command_parity_bit
;
21
};
22
// typical configuration structures
23
extern
MagneticSensorSPIConfig_s
AS5147_SPI
,
AS5048_SPI
,
AS5047_SPI
,
MA730_SPI
;
24
25
class
MagneticSensorSPI
:
public
Sensor
{
26
public
:
27
/**
28
* MagneticSensorSPI class constructor
29
* @param cs SPI chip select pin
30
* @param bit_resolution sensor resolution bit number
31
* @param angle_register (optional) angle read register - default 0x3FFF
32
* @param clock_speed (optional) SPI clock speed
33
*/
34
MagneticSensorSPI
(
int
cs,
int
bit_resolution,
int
angle_register = 0,
long
clock_speed
=
NOT_SET
);
35
36
/**
37
* MagneticSensorSPI class constructor
38
/**
39
* MagneticSensorSPI class constructor
40
* @param config SPI config
41
* @param cs SPI chip select pin
42
* @param clock_speed (optional) SPI clock speed
43
*/
44
MagneticSensorSPI
(
MagneticSensorSPIConfig_s
config,
int
cs,
long
clock_speed
=
NOT_SET
);
45
46
/** sensor initialise pins */
47
void
init
(SPIClass* _spi = &SPI);
48
49
// implementation of abstract functions of the Sensor class
50
/** get current angle (rad) */
51
float
getSensorAngle
()
override
;
52
53
// returns the spi mode (phase/polarity of read/writes) i.e one of SPI_MODE0 | SPI_MODE1 | SPI_MODE2 | SPI_MODE3
54
int
spi_mode
;
55
56
/* returns the speed of the SPI clock signal */
57
long
clock_speed
;
58
59
60
private
:
61
float
cpr;
//!< Maximum range of the magnetic sensor
62
// spi variables
63
int
angle_register;
//!< SPI angle register to read
64
int
chip_select_pin;
//!< SPI chip select pin
65
SPISettings settings;
//!< SPI settings variable
66
// spi functions
67
/** Stop SPI communication */
68
void
close();
69
/** Read one SPI register value */
70
word read(word angle_register);
71
/** Calculate parity value */
72
byte
spiCalcEvenParity(word value);
73
74
/**
75
* Function getting current angle register value
76
* it uses angle_register variable
77
*/
78
int
getRawCount();
79
80
int
bit_resolution;
//!< the number of bites of angle data
81
int
command_parity_bit;
//!< the bit where parity flag is stored in command
82
int
command_rw_bit;
//!< the bit where read/write flag is stored in command
83
int
data_start_bit;
//!< the the position of first bit
84
85
SPIClass* spi;
86
};
87
88
89
#endif
MA730_SPI
MagneticSensorSPIConfig_s MA730_SPI
Definition
MagneticSensorSPI.h:23
AS5047_SPI
MagneticSensorSPIConfig_s AS5047_SPI
Definition
MagneticSensorSPI.h:23
AS5048_SPI
MagneticSensorSPIConfig_s AS5048_SPI
Definition
MagneticSensorSPI.h:23
AS5147_SPI
MagneticSensorSPIConfig_s AS5147_SPI
Definition
MagneticSensorSPI.cpp:5
MagneticSensorSPI
Definition
MagneticSensorSPI.h:25
MagneticSensorSPI::spi_mode
int spi_mode
Definition
MagneticSensorSPI.h:54
MagneticSensorSPI::getSensorAngle
float getSensorAngle() override
Definition
MagneticSensorSPI.cpp:103
MagneticSensorSPI::clock_speed
long clock_speed
Definition
MagneticSensorSPI.h:57
Sensor
Definition
Sensor.h:44
Sensor::init
virtual void init()
Definition
Sensor.cpp:59
NOT_SET
#define NOT_SET
Definition
foc_utils.h:34
MagneticSensorSPIConfig_s
Definition
MagneticSensorSPI.h:13
MagneticSensorSPIConfig_s::bit_resolution
int bit_resolution
Definition
MagneticSensorSPI.h:16
MagneticSensorSPIConfig_s::data_start_bit
int data_start_bit
Definition
MagneticSensorSPI.h:18
MagneticSensorSPIConfig_s::command_parity_bit
int command_parity_bit
Definition
MagneticSensorSPI.h:20
MagneticSensorSPIConfig_s::angle_register
int angle_register
Definition
MagneticSensorSPI.h:17
MagneticSensorSPIConfig_s::spi_mode
int spi_mode
Definition
MagneticSensorSPI.h:14
MagneticSensorSPIConfig_s::command_rw_bit
int command_rw_bit
Definition
MagneticSensorSPI.h:19
MagneticSensorSPIConfig_s::clock_speed
long clock_speed
Definition
MagneticSensorSPI.h:15
src
sensors
MagneticSensorSPI.h
Generated by
1.9.8