try to fix submodule
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
|
||||
#include "./A1334.h"
|
||||
|
||||
|
||||
|
||||
A1334::A1334(SPISettings settings, int nCS) : settings(settings), nCS(nCS) {
|
||||
// nix
|
||||
};
|
||||
|
||||
|
||||
|
||||
A1334::~A1334() {
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void A1334::init(SPIClass* _spi) {
|
||||
spi = _spi;
|
||||
if (nCS>=0)
|
||||
pinMode(nCS, OUTPUT);
|
||||
digitalWrite(nCS, HIGH);
|
||||
//SPI has an internal SPI-device counter, it is possible to call "begin()" from different devices
|
||||
spi->begin();
|
||||
readRawAngle(); // read an angle
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
A1334Angle A1334::readRawAngle() {
|
||||
uint16_t command = A1334_REG_ANG;
|
||||
uint16_t cmdResult = spi_transfer16(command); // TODO fast mode
|
||||
cmdResult = spi_transfer16(command);
|
||||
A1334Angle result = { .reg = cmdResult };
|
||||
// TODO check parity
|
||||
// errorflag = result.ef;
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
uint16_t A1334::spi_transfer16(uint16_t outdata) {
|
||||
if (nCS>=0)
|
||||
digitalWrite(nCS, 0);
|
||||
spi->beginTransaction(settings);
|
||||
uint16_t result = spi->transfer16(outdata);
|
||||
spi->endTransaction();
|
||||
if (nCS>=0)
|
||||
digitalWrite(nCS, 1);
|
||||
return result;
|
||||
};
|
||||
|
||||
51
firmware/lib/Arduino-FOC-drivers/src/encoders/a1334/A1334.h
Normal file
51
firmware/lib/Arduino-FOC-drivers/src/encoders/a1334/A1334.h
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
|
||||
#ifndef __A1334_H__
|
||||
#define __A1334_H__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
|
||||
|
||||
#define A1334_CPR 4096
|
||||
#define A1334_BITORDER MSBFIRST
|
||||
|
||||
static SPISettings A1334SPISettings(8000000, A1334_BITORDER, SPI_MODE3); // @suppress("Invalid arguments")
|
||||
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint16_t angle:12;
|
||||
uint16_t p:1;
|
||||
uint16_t nf:1;
|
||||
uint16_t ef:1;
|
||||
uint16_t ridc:1;
|
||||
};
|
||||
uint16_t reg;
|
||||
} A1334Angle;
|
||||
|
||||
|
||||
#define A1334_REG_ANG 0x2000
|
||||
|
||||
|
||||
|
||||
|
||||
class A1334 {
|
||||
public:
|
||||
A1334(SPISettings settings = A1334SPISettings, int nCS = -1);
|
||||
virtual ~A1334();
|
||||
|
||||
virtual void init(SPIClass* _spi = &SPI);
|
||||
A1334Angle readRawAngle(); // 10 or 12 bit angle value
|
||||
protected:
|
||||
uint16_t spi_transfer16(uint16_t outdata);
|
||||
SPIClass* spi;
|
||||
SPISettings settings;
|
||||
int nCS = -1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
#include "./MagneticSensorA1334.h"
|
||||
#include "common/foc_utils.h"
|
||||
#include "common/time_utils.h"
|
||||
|
||||
MagneticSensorA1334::MagneticSensorA1334(int nCS, SPISettings settings) : A1334(settings, nCS) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
MagneticSensorA1334::~MagneticSensorA1334(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MagneticSensorA1334::init(SPIClass* _spi) {
|
||||
this->A1334::init(_spi);
|
||||
this->Sensor::init();
|
||||
}
|
||||
|
||||
|
||||
float MagneticSensorA1334::getSensorAngle() {
|
||||
A1334Angle angle_data = readRawAngle();
|
||||
float result = ( angle_data.angle / (float)A1334_CPR) * _2PI;
|
||||
// return the shaft angle
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
#ifndef __MAGNETIC_SENSOR_A1334_H__
|
||||
#define __MAGNETIC_SENSOR_A1334_H__
|
||||
|
||||
#include "common/base_classes/Sensor.h"
|
||||
#include "./A1334.h"
|
||||
|
||||
|
||||
|
||||
class MagneticSensorA1334 : public Sensor, public A1334 {
|
||||
public:
|
||||
MagneticSensorA1334(int nCS = -1, SPISettings settings = A1334SPISettings);
|
||||
virtual ~MagneticSensorA1334();
|
||||
|
||||
virtual float getSensorAngle() override;
|
||||
|
||||
virtual void init(SPIClass* _spi = &SPI);
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user