58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
#pragma once
|
|
|
|
|
|
#include <cstdint>
|
|
#include <cfloat>
|
|
#include <algorithm>
|
|
#include <memory>
|
|
#include "device/Device.h"
|
|
#include "registers/MGMT.h"
|
|
#include "Constants.h"
|
|
|
|
#define FM10K_GET_REGISTER(i, t) i.getType<t>(t ## __Address)
|
|
#define FM10K_MAP_REGISTER(i, t) i.mapType<t>(t ## __Address)
|
|
#define FM10K_SET_REGISTER(i, t, v) i.setType<t>(t ## __Address, v)
|
|
#define FM10K_SET_REGISTER_FIELD(i, t, f, v) \
|
|
auto __f = FM10K_MAP_REGISTER(i, t); \
|
|
__f->fields. f = v
|
|
|
|
namespace FM10K{
|
|
|
|
class FM10K {
|
|
public:
|
|
|
|
explicit FM10K(std::unique_ptr<Device> device) : m_device(std::move(device)) {
|
|
|
|
}
|
|
|
|
template<typename T> volatile T* mapType(uint32_t address) const {
|
|
return reinterpret_cast<volatile T*>(m_device->map32(address));
|
|
}
|
|
|
|
template<typename T> T getType(uint32_t address) const {
|
|
T t;
|
|
t.value = m_device->get32(address);
|
|
return std::move(t);
|
|
}
|
|
|
|
template<typename T> void setType(uint32_t address, const T& t) const {
|
|
t.value = m_device->set32(address, t.value);
|
|
return std::move(t);
|
|
}
|
|
|
|
template<typename T> void setTypeMask(uint32_t address, uint32_t mask, const T& t) const {
|
|
t.value = m_device->set32(address, t.value & mask);
|
|
return std::move(t);
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
std::unique_ptr<Device> m_device;
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|