Experimental direct register access

This commit is contained in:
Jan Käberich 2021-05-26 20:38:27 +02:00
parent 95a715233e
commit 9f33d47da0
26 changed files with 1761 additions and 8 deletions

View file

@ -0,0 +1,24 @@
#include <RegisterDevice.hpp>
#include <cstring>
uint8_t RegisterDevice::cnt = 0;
std::array<RegisterDevice*, RegisterDevice::maxDevices> RegisterDevice::devices;
Protocol::DirectRegisterInfo RegisterDevice::getInfo() {
Protocol::DirectRegisterInfo i;
i.num = num;
strncpy(i.name, name, sizeof(i.name));
i.name[sizeof(i.name) - 1] = '\0';
strncpy(i.type, type, sizeof(i.type));
i.type[sizeof(i.type) - 1] = '\0';
return i;
}
RegisterDevice* RegisterDevice::getDevice(uint8_t num) {
if(num < cnt) {
return devices[num];
} else {
return nullptr;
}
}

View file

@ -0,0 +1,41 @@
#pragma once
#include <cstdint>
#include <array>
#include "Protocol.hpp"
extern int global;
class RegisterDevice {
public:
constexpr RegisterDevice(const char *type, const char *name) :
type(type),
name(name),
num(0)
{
num = cnt;
if(cnt < maxDevices) {
devices[cnt] = this;
cnt++;
} else {
// not enough room in array. A debug message would be useful here
// but the constructor is called before any hardware initialization
// so we can do nothing here
}
}
virtual void writeRegister(uint32_t address, uint64_t data) = 0;
virtual uint64_t readRegister(uint32_t address) = 0;
Protocol::DirectRegisterInfo getInfo();
static uint8_t getNumDevices() { return cnt;};
static RegisterDevice *getDevice(uint8_t num);
private:
static constexpr uint8_t maxDevices = 10;
static std::array<RegisterDevice*,maxDevices> devices;
static uint8_t cnt;
const char *type;
const char *name;
uint8_t num;
};

View file

@ -417,3 +417,18 @@ uint8_t MAX2871::GetTemp() {
// convert to celsius and return
return 95 - 1.14f * ADC_raw;
}
void MAX2871::writeRegister(uint32_t address, uint64_t data) {
if(address <= 5) {
regs[address] = (uint32_t) data;
Update();
}
}
uint64_t MAX2871::readRegister(uint32_t address) {
if(address <= 5) {
return regs[address];
} else {
return 0;
}
}

View file

@ -1,15 +1,17 @@
#pragma once
#include "stm.hpp"
#include "RegisterDevice.hpp"
class MAX2871 {
class MAX2871 : public RegisterDevice {
public:
constexpr MAX2871(SPI_HandleTypeDef *hspi, GPIO_TypeDef *LE = nullptr,
constexpr MAX2871(const char *name, SPI_HandleTypeDef *hspi, GPIO_TypeDef *LE = nullptr,
uint16_t LEpin = 0, GPIO_TypeDef *RF_EN = nullptr,
uint16_t RF_ENpin = 0, GPIO_TypeDef *LD = nullptr, uint16_t LDpin = 0,
GPIO_TypeDef *CE = nullptr, uint16_t CEpin = 0,
GPIO_TypeDef *MUX = nullptr, uint16_t MUXpin = 0) :
regs(), f_PFD(0),
RegisterDevice("MAX2871", name),
regs(), f_PFD(0),
hspi(hspi),
CE(CE), CEpin(CEpin),
LE(LE), LEpin(LEpin),
@ -60,6 +62,9 @@ public:
uint64_t GetActualFrequency() {
return outputFrequency;
}
void writeRegister(uint32_t address, uint64_t data) override;
uint64_t readRegister(uint32_t address) override;
private:
static constexpr uint64_t MaxFreq = 6100000000; // 6GHz according to datasheet, but slight overclocking is possible