Skip to content
Snippets Groups Projects
Commit 63a0df6c authored by Karol Krizka's avatar Karol Krizka
Browse files

Pass target std::vector by reference to DeviceCom read_block functions....

Pass target std::vector by reference to DeviceCom read_block functions. I2CDevCom read/write reg functions are now MSG first. Add PCA9548ACom for multiplexed I2CCom.
parent 2bda58f3
Branches
Tags v0.1
No related merge requests found
Showing
with 671 additions and 41 deletions
image: centos:7
before_script:
- curl -o /etc/yum.repos.d/picoscope.repo https://labs.picotech.com/rpm/picoscope.repo
- rpmkeys --import https://labs.picotech.com/rpm/repodata/repomd.xml.key
- yum -y install epel-release
- yum -y install make gcc gcc-c++ autoconf
- yum -y install git
- yum -y install cmake
- yum -y install json-devel
build-bare:
script:
- echo "Hello World"
- mkdir build
- cd build
- cmake ..
- make
build:
script:
- echo "Hello World"
- curl -o /etc/yum.repos.d/picoscope.repo https://labs.picotech.com/rpm/picoscope.repo
- rpmkeys --import https://labs.picotech.com/rpm/repodata/repomd.xml.key
- yum -y install libftdi-devel libftdi-c++-devel
- yum -y install opencv-devel
- yum -y install autoconf git swig
- yum -y install picoscope
- yum -y install autoconf automake git swig
- pushd $(mktemp -d)
- git clone https://github.com/l29ah/libmpsse.git
- cd libmpsse/src
- autoconf
- git checkout -b v1.3.2 v1.3.2
- autoreconf
- ./configure CFLAGS="-std=c99" --disable-python
- make
- make install
- popd
build:
script:
- echo "Hello World"
- ls
- mkdir build
- cd build
- cmake ..
......
-D__STDC_CONSTANT_MACROS
-D__STDC_LIMIT_MACROS
-std=c++11
-Isrc/libDevCom
-Isrc/libGalil/include
-Isrc/libGPIB/include
-Isrc/libImageRec/include
-Isrc/libScope/include
-Isrc/libWaferProb/include
-Isrc/libZaber/include
-Isrc/pbv3
-Isrc/pbv2active
......@@ -6,10 +6,10 @@
# LIBLIBFTDI_DEFINITIONS - Compiler switches required for using libftdi1
FIND_PATH(LIBFTDI_INCLUDE_DIR ftdi.h
HINTS /usr/include/libftdi1 )
HINTS /usr/include/libftdi1 /usr/local/include/libftdi1 )
FIND_LIBRARY(LIBFTDI_LIBRARY NAMES ftdi1 libftdi1
HINTS /usr/lib64 )
FIND_LIBRARY(LIBFTDI_LIBRARY NAMES ftdi1 libftdi1 libftdi
HINTS /usr/lib64 /usr/local/lib /usr/lib/x86_64-linux-gnu )
INCLUDE(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBFTDI_FOUND to TRUE
......
# - Try to find libmpsse
# Once done this will define
# LIBMPSSE_FOUND - System has libmpsse
# LIBMPSSE_INCLUDE_DIRS - The libmpsse include directories
# LIBMPSSE_INCLUDE_DIR - The libmpsse include directories
# LIBMPSSE_LIBRARIES - The libraries needed to use libmpsse
# LIBMPSSE_DEFINITIONS - Compiler switches required for using libmpsse
......
......@@ -22,13 +22,14 @@ add_compile_options(-Wno-deprecated)
add_compile_options(-std=c++11)
add_compile_options(-Wall)
add_compile_options(-fPIC)
add_compile_options(-pthread)
add_compile_options(-m64)
add_compile_options(-I/usr/include/root)
#
# Check dependencies
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
#
# FTDI
# Find libFTDI1
find_package ( LibFTDI1 )
......@@ -44,19 +45,10 @@ else()
message(" libmpsse = ${LIBMPSSE_FOUND}")
endif()
#
# Find libpico
find_package(Pico)
if ( ${LIBPICO_FOUND} )
set(ENABLE_SCOPE 1)
else()
message("Disabling libScope due to missing libpico")
endif()
#
# Add libraries
add_subdirectory(libGPIB)
add_subdirectory(libDevCom)
add_subdirectory(libGalil)
add_subdirectory(libImageRec)
add_subdirectory(libZaber)
......@@ -67,5 +59,6 @@ add_subdirectory(libScope)
# Add binaries
add_subdirectory(prober)
add_subdirectory(pbv2)
add_subdirectory(pbv3)
add_subdirectory(varload)
add_subdirectory(examples)
# add global dependencies
include_directories( ../libGPIB/include )
include_directories( ../libDevCom )
link_directories( ${CMAKE_BINARY_DIR}/lib )
if( ${ENABLE_FTDI} )
......@@ -21,11 +22,13 @@ foreach(target ${tools})
get_filename_component(srcfile ${target} NAME)
add_executable(${execname} ${srcfile})
target_link_libraries(${execname} -lGPIB)
add_dependencies(${execname} GPIB)
target_link_libraries(${execname} -lGPIB -lDevCom)
add_dependencies(${execname} GPIB DevCom)
if( ${ENABLE_SCOPE} )
add_dependencies(${execname} Scope)
target_link_libraries(${execname} -lScope)
add_dependencies(${execname} Scope)
endif()
endforeach()
......@@ -17,7 +17,7 @@ int main(int argc, char*argv[]) {
meter.turnOn();
for (unsigned i=0; i<10; i++) {
log(logINFO) << meter.sense(KeithleyMode::VOLTAGE);
logger(logINFO) << meter.sense(KeithleyMode::VOLTAGE);
sleep(1);
}
......
......@@ -19,7 +19,7 @@ int main(int argc, char* argv[])
}
#ifndef SCOPE
log(logERROR) << "Missing libScope";
logger(logERROR) << "Missing libScope";
#else // SCOPE
PicoScope *pico=new PS6000();
......
......@@ -15,7 +15,7 @@ loglevel_e loglevel = logINFO;
int main()
{
#ifndef SCOPE
log(logERROR) << "Missing libScope";
logger(logERROR) << "Missing libScope";
#else // SCOPE
PicoScope *pico=new PS6000();
......
#include "AD799X.h"
#include "LinearCalibration.h"
#include "NotSupportedException.h"
const std::map<AD799X::Model, AD799XModelInfo> AD799X::ModelInfo =
{
{AD799X::Model::AD7993, AD799XModelInfo({.NumChannels=4, .MaxValue=0x3FF}) },
{AD799X::Model::AD7994, AD799XModelInfo({.NumChannels=4, .MaxValue=0xFFF}) },
{AD799X::Model::AD7997, AD799XModelInfo({.NumChannels=8, .MaxValue=0x3FF}) },
{AD799X::Model::AD7998, AD799XModelInfo({.NumChannels=8, .MaxValue=0xFFF}) }
};
AD799X::AD799X(double reference, Model model, std::shared_ptr<I2CCom> com)
: ADCDevice(std::make_shared<LinearCalibration>(reference, ModelInfo.at(model).MaxValue)),
m_model(model), m_numChannels(ModelInfo.at(model).NumChannels), m_com(com)
{ }
AD799X::~AD799X()
{ }
uint32_t AD799X::readCount()
{
std::vector<uint8_t> data(2);
m_com->read_block(0x0, data);
uint16_t chresult=(data[0]<<8)|(data[1]<<0);
// TODO: Check if returned channel is the correct one
//uint8_t ch =((chresult>>12)&0x007);
uint32_t chcounts=(m_model==AD7993 || m_model==AD7997)?((chresult>> 2)&0x3FF):(chresult&0xFFF);
return chcounts;
}
uint32_t AD799X::readCount(uint8_t ch)
{
uint8_t chmask=0;
switch(m_model)
{
case AD7993:
case AD7994:
chmask=(1<<ch);
break;
case AD7997:
case AD7998:
chmask=0x8|ch;
break;
default:
throw NotSupportedException("Model not supported by AD799X");
break;
};
std::vector<uint8_t> data(2);
m_com->read_block((chmask<<4)&0xFF, data);
uint16_t chresult=(data[0]<<8)|(data[1]<<0);
// TODO: Check if returned channel is the correct one
//uint8_t ch =((chresult>>12)&0x007);
uint32_t chcounts=(m_model==AD7993 || m_model==AD7997)?((chresult>> 2)&0x3FF):(chresult&0xFFF);
return chcounts;
}
void AD799X::readCount(const std::vector<uint8_t>& chs, std::vector<uint32_t>& counts)
{
uint8_t chmask=0;
for(uint8_t ch : chs)
chmask|=(1<<ch);
std::vector<uint8_t> data(2*chs.size());
switch(m_model)
{
case AD7993:
case AD7994:
m_com->read_block((chmask<<4)&0xFF, data);
break;
case AD7997:
case AD7998:
m_com->write_reg16(0x2, (chmask<<4)|8);
m_com->read_block(0x70, data);
break;
default:
throw NotSupportedException("Model not supported by AD799X");
break;
};
counts.clear();
for(uint8_t chi=0;chi<chs.size();chi++)
{
uint16_t chresult=(data[2*chi+0]<<8)|(data[2*chi+1]<<0);
// TODO: Check if returned channel is the correct one
//uint8_t ch =((chresult>>12)&0x007);
uint32_t chcounts=(m_model==AD7993 || m_model==AD7997)?((chresult>> 2)&0x3FF):(chresult&0xFFF);
counts.push_back(chcounts);
}
}
#ifndef AD799X_H
#define AD799X_H
#include <stdint.h>
#include <memory>
#include <map>
#include "I2CCom.h"
#include "ADCDevice.h"
struct AD799XModelInfo
{
int32_t NumChannels;
int32_t MaxValue;
};
class AD799X : public ADCDevice
{
public:
enum Model {AD7993, AD7994, AD7997, AD7998};
AD799X(double reference, Model model, std::shared_ptr<I2CCom> com);
virtual ~AD799X();
virtual uint32_t readCount();
virtual uint32_t readCount(uint8_t ch);
virtual void readCount(const std::vector<uint8_t>& chs, std::vector<uint32_t>& data);
private:
// Model information
static const std::map<Model, AD799XModelInfo> ModelInfo;
// Properties of device
Model m_model;
uint32_t m_numChannels = 0;
std::shared_ptr<I2CCom> m_com;
};
#endif // AD799X_H
#include "ADCDevice.h"
#include <iostream>
ADCDevice::ADCDevice(std::shared_ptr<DeviceCalibration> calibration)
: m_calibration(calibration)
{ }
ADCDevice::~ADCDevice()
{ }
void ADCDevice::setCalibration(std::shared_ptr<DeviceCalibration> calibration)
{ m_calibration=calibration; }
void ADCDevice::setCalibration(uint8_t ch, std::shared_ptr<DeviceCalibration> calibration)
{ m_channelCalibration[ch]=calibration; }
std::shared_ptr<DeviceCalibration> ADCDevice::findCalibration(uint8_t ch) const
{
return (m_channelCalibration.find(ch)==m_channelCalibration.end())?m_calibration:m_channelCalibration.at(ch);
}
double ADCDevice::read()
{ return m_calibration->calibrate(readCount()); }
double ADCDevice::read(uint8_t ch)
{ return findCalibration(ch)->calibrate(readCount(ch)); }
void ADCDevice::read(const std::vector<uint8_t>& chs, std::vector<double>& data)
{
std::vector<uint32_t> counts(chs.size());
readCount(chs, counts);
data.clear();
for(uint i=0; i<chs.size(); i++)
data.push_back(findCalibration(chs[i])->calibrate(counts[i]));
}
#ifndef ADCDEVICE_H
#define ADCDEVICE_H
#include <cstdint>
#include <vector>
#include <memory>
#include <map>
#include "DeviceCalibration.h"
#include "DummyCalibration.h"
class ADCDevice
{
public:
ADCDevice(std::shared_ptr<DeviceCalibration> calibration=std::make_shared<DummyCalibration>());
virtual ~ADCDevice();
void setCalibration(std::shared_ptr<DeviceCalibration> calibration);
void setCalibration(uint8_t ch, std::shared_ptr<DeviceCalibration> calibration);
double read();
double read(uint8_t ch);
void read(const std::vector<uint8_t>& chs, std::vector<double>& data);
virtual uint32_t readCount() =0;
virtual uint32_t readCount(uint8_t ch) =0;
virtual void readCount(const std::vector<uint8_t>& chs, std::vector<uint32_t>& data) =0;
private:
std::shared_ptr<DeviceCalibration> findCalibration(uint8_t ch) const;
std::shared_ptr<DeviceCalibration> m_calibration;
std::map<uint8_t, std::shared_ptr<DeviceCalibration>> m_channelCalibration;
};
#endif // ADCDEVICE_H
#include "AMAC.h"
AMAC::AMAC(std::shared_ptr<I2CCom> i2c)
: m_i2c(i2c)
{ }
AMAC::~AMAC()
{ }
void AMAC::init()
{
write(AMACreg::LV_ENABLE, 0x0); // ensure output is disabled
write(AMACreg::BANDGAP_CONTROL, 10); //1.2V LDO output
write(AMACreg::RT_CH3_GAIN_SEL, 0); // no attenuation
write(AMACreg::LT_CH3_GAIN_SEL, 0); // no attentuation
write(AMACreg::RT_CH0_SEL, 1); //a
write(AMACreg::LT_CH0_SEL, 1); //a
write(AMACreg::LEFT_RAMP_GAIN, 3); // best range
write(AMACreg::RIGHT_RAMP_GAIN, 3); // best range
write(AMACreg::OPAMP_GAIN_RIGHT, 0); // highest gain
write(AMACreg::OPAMP_GAIN_LEFT, 0); // highest gain
write(AMACreg::HV_FREQ, 0x1);
}
//Reads the according bits from the according AMAC register
int AMAC::read(AMACreg reg, unsigned &val)
{
switch(reg)
{
case AMACreg::STATUS_HV_ILOCK: return this->readBits(0,1,0, val);
case AMACreg::STATUS_LV_ILOCK: return this->readBits(0,1,1, val);
case AMACreg::STATUS_HV_WARN: return this->readBits(0,1,2, val);
case AMACreg::STATUS_LV_WARN: return this->readBits(0,1,3, val);
case AMACreg::STATUS_ID: return this->readBits(0,4,4, val);
case AMACreg::VALUE_LEFT_CH0: return this->readBits(20,10,0, val);
case AMACreg::VALUE_LEFT_CH1: return this->readBits(21,10,2, val);
case AMACreg::VALUE_LEFT_CH2: return this->readBits(22,10,4, val);
case AMACreg::VALUE_LEFT_CH3: return this->readBits(23,10,6, val);
case AMACreg::VALUE_LEFT_CH4: return this->readBits(25,10,0, val);
case AMACreg::VALUE_LEFT_CH5: return this->readBits(26,10,2, val);
case AMACreg::VALUE_LEFT_CH6: return this->readBits(27,10,4, val);
case AMACreg::VALUE_RIGHT_CH0: return this->readBits(29,10,0, val);
case AMACreg::VALUE_RIGHT_CH1: return this->readBits(30,10,2, val);
case AMACreg::VALUE_RIGHT_CH2: return this->readBits(31,10,4, val);
case AMACreg::VALUE_RIGHT_CH3: return this->readBits(32,10,6, val);
case AMACreg::VALUE_RIGHT_CH4: return this->readBits(34,10,0, val);
case AMACreg::VALUE_RIGHT_CH5: return this->readBits(35,10,2, val);
case AMACreg::VALUE_RIGHT_CH6: return this->readBits(36,10,4, val);
case AMACreg::LEFT_RAMP_GAIN: return this->readBits(45,2,0, val);
case AMACreg::RIGHT_RAMP_GAIN: return this->readBits(45,2,4, val);
case AMACreg::OPAMP_GAIN_RIGHT: return this->readBits(42,4,4, val);
case AMACreg::OPAMP_GAIN_LEFT: return this->readBits(42,4,0, val);
case AMACreg::BANDGAP_CONTROL: return this->readBits(40,5,0, val);
case AMACreg::RT_CH3_GAIN_SEL: return this->readBits(45,1,7, val);
case AMACreg::LT_CH3_GAIN_SEL: return this->readBits(45,1,3, val);
case AMACreg::HV_ENABLE: return this->readBits(43,1,0, val);
case AMACreg::LV_ENABLE: return this->readBits(44,1,0, val);
case AMACreg::HV_FREQ: return this->readBits(43,2,1, val);
case AMACreg::ILOCK_FLAG_HV_LEFT_HI: return this->readBits(1,7,0,val);
case AMACreg::ILOCK_FLAG_HV_LEFT_LO: return this->readBits(2,7,0,val);
case AMACreg::ILOCK_FLAG_HV_RIGHT_HI: return this->readBits(3,7,0,val);
case AMACreg::ILOCK_FLAG_HV_RIGHT_LO: return this->readBits(4,7,0,val);
case AMACreg::ILOCK_FLAG_LV_LEFT_HI: return this->readBits(5,7,0,val);
case AMACreg::ILOCK_FLAG_LV_LEFT_LO: return this->readBits(6,7,0,val);
case AMACreg::ILOCK_FLAG_LV_RIGHT_HI: return this->readBits(7,7,0,val);
case AMACreg::ILOCK_FLAG_LV_RIGHT_LO: return this->readBits(8,7,0,val);
case AMACreg::WARN_FLAG_HV_LEFT_HI: return this->readBits(9,7,0,val);
case AMACreg::WARN_FLAG_HV_LEFT_LO: return this->readBits(10,7,0,val);
case AMACreg::WARN_FLAG_HV_RIGHT_HI: return this->readBits(11,7,0,val);
case AMACreg::WARN_FLAG_HV_RIGHT_LO: return this->readBits(12,7,0,val);
case AMACreg::WARN_FLAG_LV_LEFT_HI: return this->readBits(13,7,0,val);
case AMACreg::WARN_FLAG_LV_LEFT_LO: return this->readBits(14,7,0,val);
case AMACreg::WARN_FLAG_LV_RIGHT_HI: return this->readBits(15,7,0,val);
case AMACreg::WARN_FLAG_LV_RIGHT_LO: return this->readBits(16,7,0,val);
case AMACreg::ILOCK_EN_HV_LEFT_HI: return this->readBits(50,7,0,val);
case AMACreg::ILOCK_EN_HV_LEFT_LO: return this->readBits(51,7,0,val);
case AMACreg::ILOCK_EN_HV_RIGHT_HI: return this->readBits(52,7,0,val);
case AMACreg::ILOCK_EN_HV_RIGHT_LO: return this->readBits(53,7,0,val);
case AMACreg::ILOCK_EN_LV_LEFT_HI: return this->readBits(54,7,0,val);
case AMACreg::ILOCK_EN_LV_LEFT_LO: return this->readBits(55,7,0,val);
case AMACreg::ILOCK_EN_LV_RIGHT_HI: return this->readBits(56,7,0,val);
case AMACreg::ILOCK_EN_LV_RIGHT_LO: return this->readBits(57,7,0,val);
case AMACreg::WARN_EN_HV_LEFT_HI: return this->readBits(58,7,0,val);
case AMACreg::WARN_EN_HV_LEFT_LO: return this->readBits(59,7,0,val);
case AMACreg::WARN_EN_HV_RIGHT_HI: return this->readBits(60,7,0,val);
case AMACreg::WARN_EN_HV_RIGHT_LO: return this->readBits(61,7,0,val);
case AMACreg::WARN_EN_LV_LEFT_HI: return this->readBits(62,7,0,val);
case AMACreg::WARN_EN_LV_LEFT_LO: return this->readBits(63,7,0,val);
case AMACreg::WARN_EN_LV_RIGHT_HI: return this->readBits(64,7,0,val);
case AMACreg::WARN_EN_LV_RIGHT_LO: return this->readBits(65,7,0,val);
case AMACreg::ILOCK_HV_THRESH_HI_L_CH0: return this->readBits(66,10,0,val);
default:
return -2; break;
}
}
//Writes the according bits in the according AMAC register
int AMAC::write(AMACreg reg, unsigned val)
{
switch(reg)
{
case AMACreg::LEFT_RAMP_GAIN: return this->writeBits(45,2,0,val);
case AMACreg::RIGHT_RAMP_GAIN: return this->writeBits(45,2,4,val);
case AMACreg::OPAMP_GAIN_RIGHT: return this->writeBits(42,4,4,val);
case AMACreg::OPAMP_GAIN_LEFT: return this->writeBits(42,4,0,val);
case AMACreg::BANDGAP_CONTROL: return this->writeBits(40,5,0,val);
case AMACreg::RT_CH3_GAIN_SEL: return this->writeBits(45,1,7,val);
case AMACreg::LT_CH3_GAIN_SEL: return this->writeBits(45,1,3,val);
case AMACreg::RT_CH0_SEL: return this->writeBits(45,1,6,val);
case AMACreg::LT_CH0_SEL: return this->writeBits(45,1,2,val);
case AMACreg::CLK_OUT_ENABLE : return this->writeBits(41,1,0,val);
case AMACreg::CLK_SELECT: return this->writeBits(49,1,0,val);
case AMACreg::HV_FREQ: return this->writeBits(43,2,1,val);
case AMACreg::HV_ENABLE: return this->writeBits(43,1,0,val);
case AMACreg::LV_ENABLE: return this->writeBits(44,1,0,val);
case AMACreg::HV_ILOCK: return this->writeBits(43,1,7,val);
case AMACreg::HV_ILOCK_LAM: return this->writeBits(43,1,5,val);
case AMACreg::LV_ILOCK: return this->writeBits(44,1,7,val);
case AMACreg::LV_ILOCK_LAM: return this->writeBits(44,1,5,val);
case AMACreg::RESET_HV_ILOCK: return this->writeBits(48,1,0,val);
case AMACreg::RESET_HV_WARN: return this->writeBits(48,1,1,val);
case AMACreg::RESET_LV_ILOCK: return this->writeBits(48,1,2,val);
case AMACreg::RESET_LV_WARN: return this->writeBits(48,1,3,val);
case AMACreg::ILOCK_EN_HV_LEFT_HI: return this->writeBits(50,7,0,val);
case AMACreg::ILOCK_EN_HV_LEFT_LO: return this->writeBits(51,7,0,val);
case AMACreg::ILOCK_EN_HV_RIGHT_HI: return this->writeBits(52,7,0,val);
case AMACreg::ILOCK_EN_HV_RIGHT_LO: return this->writeBits(53,7,0,val);
case AMACreg::ILOCK_EN_LV_LEFT_HI: return this->writeBits(54,7,0,val);
case AMACreg::ILOCK_EN_LV_LEFT_LO: return this->writeBits(55,7,0,val);
case AMACreg::ILOCK_EN_LV_RIGHT_HI: return this->writeBits(56,7,0,val);
case AMACreg::ILOCK_EN_LV_RIGHT_LO: return this->writeBits(57,7,0,val);
case AMACreg::WARN_EN_HV_LEFT_HI: return this->writeBits(58,7,0,val);
case AMACreg::WARN_EN_HV_LEFT_LO: return this->writeBits(59,7,0,val);
case AMACreg::WARN_EN_HV_RIGHT_HI: return this->writeBits(60,7,0,val);
case AMACreg::WARN_EN_HV_RIGHT_LO: return this->writeBits(61,7,0,val);
case AMACreg::WARN_EN_LV_LEFT_HI: return this->writeBits(62,7,0,val);
case AMACreg::WARN_EN_LV_LEFT_LO: return this->writeBits(63,7,0,val);
case AMACreg::WARN_EN_LV_RIGHT_HI: return this->writeBits(64,7,0,val);
case AMACreg::WARN_EN_LV_RIGHT_LO: return this->writeBits(65,7,0,val);
case AMACreg::ILOCK_HV_THRESH_HI_L_CH0: return this->writeBits(66,10,0,val);
case AMACreg::ILOCK_HV_THRESH_HI_L_CH1: return this->writeBits(67,10,2,val);
case AMACreg::ILOCK_HV_THRESH_HI_L_CH2: return this->writeBits(68,10,4,val);
case AMACreg::ILOCK_HV_THRESH_HI_L_CH3: return this->writeBits(69,10,6,val);
case AMACreg::ILOCK_HV_THRESH_HI_L_CH4: return this->writeBits(71,10,0,val);
case AMACreg::ILOCK_HV_THRESH_HI_L_CH5: return this->writeBits(72,10,2,val);
case AMACreg::ILOCK_HV_THRESH_HI_L_CH6: return this->writeBits(73,10,4,val);
case AMACreg::ILOCK_HV_THRESH_LO_L_CH0: return this->writeBits(75,10,0,val);
case AMACreg::ILOCK_HV_THRESH_LO_L_CH1: return this->writeBits(76,10,2,val);
case AMACreg::ILOCK_HV_THRESH_LO_L_CH2: return this->writeBits(77,10,4,val);
case AMACreg::ILOCK_HV_THRESH_LO_L_CH3: return this->writeBits(78,10,6,val);
case AMACreg::ILOCK_HV_THRESH_LO_L_CH4: return this->writeBits(80,10,0,val);
case AMACreg::ILOCK_HV_THRESH_LO_L_CH5: return this->writeBits(81,10,2,val);
case AMACreg::ILOCK_HV_THRESH_LO_L_CH6: return this->writeBits(82,10,4,val);
case AMACreg::ILOCK_HV_THRESH_HI_R_CH0: return this->writeBits(84,10,0,val);
case AMACreg::ILOCK_HV_THRESH_HI_R_CH1: return this->writeBits(85,10,2,val);
case AMACreg::ILOCK_HV_THRESH_HI_R_CH2: return this->writeBits(86,10,4,val);
case AMACreg::ILOCK_HV_THRESH_HI_R_CH3: return this->writeBits(87,10,6,val);
case AMACreg::ILOCK_HV_THRESH_HI_R_CH4: return this->writeBits(89,10,0,val);
case AMACreg::ILOCK_HV_THRESH_HI_R_CH5: return this->writeBits(90,10,2,val);
case AMACreg::ILOCK_HV_THRESH_HI_R_CH6: return this->writeBits(91,10,4,val);
case AMACreg::ILOCK_HV_THRESH_LO_R_CH0: return this->writeBits(93,10,0,val);
case AMACreg::ILOCK_HV_THRESH_LO_R_CH1: return this->writeBits(94,10,2,val);
case AMACreg::ILOCK_HV_THRESH_LO_R_CH2: return this->writeBits(95,10,4,val);
case AMACreg::ILOCK_HV_THRESH_LO_R_CH3: return this->writeBits(96,10,6,val);
case AMACreg::ILOCK_HV_THRESH_LO_R_CH4: return this->writeBits(98,10,0,val);
case AMACreg::ILOCK_HV_THRESH_LO_R_CH5: return this->writeBits(99,10,2,val);
case AMACreg::ILOCK_HV_THRESH_LO_R_CH6: return this->writeBits(100,10,4,val);
case AMACreg::ILOCK_LV_THRESH_HI_L_CH0: return this->writeBits(102,10,0,val);
case AMACreg::ILOCK_LV_THRESH_HI_L_CH1: return this->writeBits(103,10,2,val);
case AMACreg::ILOCK_LV_THRESH_HI_L_CH2: return this->writeBits(104,10,4,val);
case AMACreg::ILOCK_LV_THRESH_HI_L_CH3: return this->writeBits(105,10,6,val);
case AMACreg::ILOCK_LV_THRESH_HI_L_CH4: return this->writeBits(107,10,0,val);
case AMACreg::ILOCK_LV_THRESH_HI_L_CH5: return this->writeBits(108,10,2,val);
case AMACreg::ILOCK_LV_THRESH_HI_L_CH6: return this->writeBits(109,10,4,val);
case AMACreg::ILOCK_LV_THRESH_LO_L_CH0: return this->writeBits(111,10,0,val);
case AMACreg::ILOCK_LV_THRESH_LO_L_CH1: return this->writeBits(112,10,2,val);
case AMACreg::ILOCK_LV_THRESH_LO_L_CH2: return this->writeBits(113,10,4,val);
case AMACreg::ILOCK_LV_THRESH_LO_L_CH3: return this->writeBits(114,10,6,val);
case AMACreg::ILOCK_LV_THRESH_LO_L_CH4: return this->writeBits(116,10,0,val);
case AMACreg::ILOCK_LV_THRESH_LO_L_CH5: return this->writeBits(117,10,2,val);
case AMACreg::ILOCK_LV_THRESH_LO_L_CH6: return this->writeBits(118,10,4,val);
case AMACreg::ILOCK_LV_THRESH_HI_R_CH0: return this->writeBits(120,10,0,val);
case AMACreg::ILOCK_LV_THRESH_HI_R_CH1: return this->writeBits(121,10,2,val);
case AMACreg::ILOCK_LV_THRESH_HI_R_CH2: return this->writeBits(122,10,4,val);
case AMACreg::ILOCK_LV_THRESH_HI_R_CH3: return this->writeBits(123,10,6,val);
case AMACreg::ILOCK_LV_THRESH_HI_R_CH4: return this->writeBits(125,10,0,val);
case AMACreg::ILOCK_LV_THRESH_HI_R_CH5: return this->writeBits(126,10,2,val);
case AMACreg::ILOCK_LV_THRESH_HI_R_CH6: return this->writeBits(127,10,4,val);
case AMACreg::ILOCK_LV_THRESH_LO_R_CH0: return this->writeBits(129,10,0,val);
case AMACreg::ILOCK_LV_THRESH_LO_R_CH1: return this->writeBits(130,10,2,val);
case AMACreg::ILOCK_LV_THRESH_LO_R_CH2: return this->writeBits(131,10,4,val);
case AMACreg::ILOCK_LV_THRESH_LO_R_CH3: return this->writeBits(132,10,6,val);
case AMACreg::ILOCK_LV_THRESH_LO_R_CH4: return this->writeBits(134,10,0,val);
case AMACreg::ILOCK_LV_THRESH_LO_R_CH5: return this->writeBits(135,10,2,val);
case AMACreg::ILOCK_LV_THRESH_LO_R_CH6: return this->writeBits(136,10,4,val);
case AMACreg::WARN_HV_THRESH_HI_L_CH0: return this->writeBits(138,10,0,val);
case AMACreg::WARN_HV_THRESH_HI_L_CH1: return this->writeBits(139,10,2,val);
case AMACreg::WARN_HV_THRESH_HI_L_CH2: return this->writeBits(140,10,4,val);
case AMACreg::WARN_HV_THRESH_HI_L_CH3: return this->writeBits(141,10,6,val);
case AMACreg::WARN_HV_THRESH_HI_L_CH4: return this->writeBits(143,10,0,val);
case AMACreg::WARN_HV_THRESH_HI_L_CH5: return this->writeBits(144,10,2,val);
case AMACreg::WARN_HV_THRESH_HI_L_CH6: return this->writeBits(145,10,4,val);
case AMACreg::WARN_HV_THRESH_LO_L_CH0: return this->writeBits(147,10,0,val);
case AMACreg::WARN_HV_THRESH_LO_L_CH1: return this->writeBits(148,10,2,val);
case AMACreg::WARN_HV_THRESH_LO_L_CH2: return this->writeBits(149,10,4,val);
case AMACreg::WARN_HV_THRESH_LO_L_CH3: return this->writeBits(150,10,6,val);
case AMACreg::WARN_HV_THRESH_LO_L_CH4: return this->writeBits(152,10,0,val);
case AMACreg::WARN_HV_THRESH_LO_L_CH5: return this->writeBits(153,10,2,val);
case AMACreg::WARN_HV_THRESH_LO_L_CH6: return this->writeBits(154,10,4,val);
case AMACreg::WARN_HV_THRESH_HI_R_CH0: return this->writeBits(156,10,0,val);
case AMACreg::WARN_HV_THRESH_HI_R_CH1: return this->writeBits(157,10,2,val);
case AMACreg::WARN_HV_THRESH_HI_R_CH2: return this->writeBits(158,10,4,val);
case AMACreg::WARN_HV_THRESH_HI_R_CH3: return this->writeBits(159,10,6,val);
case AMACreg::WARN_HV_THRESH_HI_R_CH4: return this->writeBits(161,10,0,val);
case AMACreg::WARN_HV_THRESH_HI_R_CH5: return this->writeBits(162,10,2,val);
case AMACreg::WARN_HV_THRESH_HI_R_CH6: return this->writeBits(163,10,4,val);
case AMACreg::WARN_HV_THRESH_LO_R_CH0: return this->writeBits(165,10,0,val);
case AMACreg::WARN_HV_THRESH_LO_R_CH1: return this->writeBits(166,10,2,val);
case AMACreg::WARN_HV_THRESH_LO_R_CH2: return this->writeBits(167,10,4,val);
case AMACreg::WARN_HV_THRESH_LO_R_CH3: return this->writeBits(168,10,6,val);
case AMACreg::WARN_HV_THRESH_LO_R_CH4: return this->writeBits(170,10,0,val);
case AMACreg::WARN_HV_THRESH_LO_R_CH5: return this->writeBits(171,10,2,val);
case AMACreg::WARN_HV_THRESH_LO_R_CH6: return this->writeBits(172,10,4,val);
case AMACreg::WARN_LV_THRESH_HI_L_CH0: return this->writeBits(174,10,0,val);
case AMACreg::WARN_LV_THRESH_HI_L_CH1: return this->writeBits(175,10,2,val);
case AMACreg::WARN_LV_THRESH_HI_L_CH2: return this->writeBits(176,10,4,val);
case AMACreg::WARN_LV_THRESH_HI_L_CH3: return this->writeBits(177,10,6,val);
case AMACreg::WARN_LV_THRESH_HI_L_CH4: return this->writeBits(179,10,0,val);
case AMACreg::WARN_LV_THRESH_HI_L_CH5: return this->writeBits(180,10,2,val);
case AMACreg::WARN_LV_THRESH_HI_L_CH6: return this->writeBits(181,10,4,val);
case AMACreg::WARN_LV_THRESH_LO_L_CH0: return this->writeBits(183,10,0,val);
case AMACreg::WARN_LV_THRESH_LO_L_CH1: return this->writeBits(184,10,2,val);
case AMACreg::WARN_LV_THRESH_LO_L_CH2: return this->writeBits(185,10,4,val);
case AMACreg::WARN_LV_THRESH_LO_L_CH3: return this->writeBits(186,10,6,val);
case AMACreg::WARN_LV_THRESH_LO_L_CH4: return this->writeBits(188,10,0,val);
case AMACreg::WARN_LV_THRESH_LO_L_CH5: return this->writeBits(189,10,2,val);
case AMACreg::WARN_LV_THRESH_LO_L_CH6: return this->writeBits(190,10,4,val);
case AMACreg::WARN_LV_THRESH_HI_R_CH0: return this->writeBits(192,10,0,val);
case AMACreg::WARN_LV_THRESH_HI_R_CH1: return this->writeBits(193,10,2,val);
case AMACreg::WARN_LV_THRESH_HI_R_CH2: return this->writeBits(194,10,4,val);
case AMACreg::WARN_LV_THRESH_HI_R_CH3: return this->writeBits(195,10,6,val);
case AMACreg::WARN_LV_THRESH_HI_R_CH4: return this->writeBits(197,10,0,val);
case AMACreg::WARN_LV_THRESH_HI_R_CH5: return this->writeBits(198,10,2,val);
case AMACreg::WARN_LV_THRESH_HI_R_CH6: return this->writeBits(199,10,4,val);
case AMACreg::WARN_LV_THRESH_LO_R_CH0: return this->writeBits(201,10,0,val);
case AMACreg::WARN_LV_THRESH_LO_R_CH1: return this->writeBits(202,10,2,val);
case AMACreg::WARN_LV_THRESH_LO_R_CH2: return this->writeBits(203,10,4,val);
case AMACreg::WARN_LV_THRESH_LO_R_CH3: return this->writeBits(204,10,6,val);
case AMACreg::WARN_LV_THRESH_LO_R_CH4: return this->writeBits(206,10,0,val);
case AMACreg::WARN_LV_THRESH_LO_R_CH5: return this->writeBits(207,10,2,val);
case AMACreg::WARN_LV_THRESH_LO_R_CH6: return this->writeBits(208,10,4,val);
default:
return -2; break;
}
}
//Works until up to 4 bytes
int AMAC::readBits(unsigned startreg, unsigned num_bits, unsigned offset, unsigned &value)
{
int num_bytes = ((num_bits + offset -1) / 8) + 1;
std::vector<uint8_t> buf(num_bytes);
m_i2c->read_block(startreg, buf);
uint temp = 0;
for(int i = num_bytes - 1; i >= 0; i--)
{
temp <<= 8;
temp += (buf[i] & 0xFF);
}
value = (temp >> offset) & ((1 << num_bits) -1);
return 0;
}
//Works until up to 4 bytes
//Read register, modify bits, write register
int AMAC::writeBits(unsigned startreg, unsigned num_bits, unsigned offset, unsigned value)
{
int num_bytes = ((num_bits + offset -1) / 8) + 1;
std::vector<uint8_t> buf(num_bytes);
// Read existing value
int temp;
int mask = ((1 << num_bits) -1) << offset;
m_i2c->read_block(startreg, buf);
temp = 0;
for(int i = num_bytes - 1; i >= 0; i--)
{
temp <<= 8;
temp += (buf[i] & 0xFF);
}
// Modify the required bits
temp &= ~mask;
temp |= ((value << offset) & mask);
for(int i = 0; i < num_bytes; i++, temp >>= 8)
buf[i] = temp & 0xFF;
// Write back
m_i2c->write_block(startreg, buf);
return 0;
}
......@@ -10,7 +10,7 @@ enum class AMACreg;
class AMAC {
public:
AMAC(unsigned id, std::shared_ptr<I2CCom> i2c);
AMAC(std::shared_ptr<I2CCom> i2c);
~AMAC();
void init();
......@@ -19,7 +19,6 @@ public:
int write(AMACreg reg, unsigned val);
private:
unsigned m_id;
std::shared_ptr<I2CCom> m_i2c;
int readBits(unsigned startreg, unsigned num_bits, unsigned offset, unsigned &value);
......
# Commented files are from amacv2_tester version of the library. They still need to be
# ported to labRemote.
set(SrcFiles DeviceCom.cpp
#UIOCom.cpp
#SPICom.cpp
I2CCom.cpp
I2CDevCom.cpp
PCA9548ACom.cpp
SPICom.cpp
ComIOException.cpp
NotSupportedException.cpp
ClimateSensor.cpp
#BME280.cpp
HIH6130.cpp
DACDevice.cpp
DAC5574.cpp
MCP4801.cpp
#LTC2666.cpp
ADCDevice.cpp
AD799X.cpp
MAX11619.cpp
#LTC2333.cpp
#AD5160.cpp
AMAC.cpp
DeviceCalibration.cpp
DummyCalibration.cpp
LinearCalibration.cpp
FileCalibration.cpp
)
if ( ${ENABLE_FTDI} )
set(SrcFiles ${SrcFiles}
I2CFTDICom.cpp)
include_directories ( ${LIBFTDI_INCLUDE_DIR} ${LIBMPSSE_INCLUDE_DIR} )
else()
message("skipping FTDICom due to missing libftdi1 or libmpsse")
message(" libftdi1 = ${LIBFTDI_FOUND}")
message(" libmpsse = ${LIBMPSSE_FOUND}")
endif()
add_library(DevCom SHARED ${SrcFiles})
if ( ${ENABLE_FTDI} )
target_link_libraries(DevCom ${LIBMPSSE_LIBRARIES} ${LIBFTDI_LIBRARIES})
endif()
add_compile_options(-std=c++11)
add_subdirectory(examples)
#include "ClimateSensor.h"
ClimateSensor::ClimateSensor()
{ }
ClimateSensor::~ClimateSensor()
{ }
#ifndef CLIMATESENSOR_H
#define CLIMATESENSOR_H
class ClimateSensor
{
public:
ClimateSensor();
virtual ~ClimateSensor();
virtual void init() =0;
virtual void reset() =0;
virtual void read() =0;
virtual float temperature() const =0;
virtual float humidity() const =0;
virtual float pressure() const =0;
};
#endif // CLIMATESENSOR_H
#ifndef COMEXCEPTION_H
#define COMEXCEPTION_H
#include <exception>
class ComException : public std::exception
{ };
#endif // COMEXCEPTION_H
#include "ComIOException.h"
ComIOException::ComIOException(const std::string& msg)
: m_msg("ComIOException: "+msg)
{ }
const char* ComIOException::what() const throw()
{ return m_msg.c_str(); }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment