SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
MagneticSensorI2C.h
Go to the documentation of this file.
1#ifndef MAGNETICSENSORI2C_LIB_H
2#define MAGNETICSENSORI2C_LIB_H
3
4#include "Arduino.h"
5#include <Wire.h>
6#include "../common/base_classes/Sensor.h"
7#include "../common/foc_utils.h"
8#include "../common/time_utils.h"
9
11 uint8_t chip_address;
14 uint8_t msb_mask;
15 uint8_t msb_shift;
16 uint8_t lsb_mask;
17 uint8_t lsb_shift;
18};
19
20// some predefined structures
22
23#if defined(TARGET_RP2040)
24#define SDA I2C_SDA
25#define SCL I2C_SCL
26#endif
27
28
30 public:
31 /**
32 * MagneticSensorI2C class constructor
33 * @param chip_address I2C chip address
34 * @param bits number of bits of the sensor resolution
35 * @param angle_register_msb angle read register msb
36 * @param _bits_used_msb number of used bits in msb
37 */
38 MagneticSensorI2C(uint8_t _chip_address, int _bit_resolution, uint8_t _angle_register_msb, int _msb_bits_used, bool lsb_right_aligned = true);
39
40 /**
41 * MagneticSensorI2C class constructor
42 * @param config I2C config
43 */
45
47
48 /** sensor initialise pins */
49 void init(TwoWire* _wire = &Wire);
50
51 // implementation of abstract functions of the Sensor class
52 /** get current angle (rad) */
53 float getSensorAngle() override;
54
55 /** experimental function to check and fix SDA locked LOW issues */
56 int checkBus(byte sda_pin , byte scl_pin );
57
58 /** current error code from Wire endTransmission() call **/
59 uint8_t currWireError = 0;
60
61 private:
62 float cpr; //!< Maximum range of the magnetic sensor
64
65 // I2C functions
66 /** Read one I2C register value */
67 int read(uint8_t angle_register_msb);
68
69 /**
70 * Function getting current angle register value
71 * it uses angle_register variable
72 */
73 int getRawCount();
74
75 /* the two wire instance for this sensor */
76 TwoWire* wire;
77};
78
79
80#endif
MagneticSensorI2CConfig_s AS5048_I2C
MagneticSensorI2CConfig_s MT6701_I2C
MagneticSensorI2CConfig_s AS5600_I2C
float getSensorAngle() override
static MagneticSensorI2C AS5600()
int checkBus(byte sda_pin, byte scl_pin)
virtual void init()
Definition Sensor.cpp:59