work on dac

master
edwin 4 years ago
parent ff66e63fa6
commit 1ee2eb4024

@ -4,6 +4,7 @@ cpp_src += $(wildcard ./communication/i2c/*.cpp)
cpp_src += $(wildcard ./management/*.cpp)
cpp_src += $(wildcard ./drivers/bh1750/*.cpp)
cpp_src += $(wildcard ./drivers/pca9685/*.cpp)
cpp_src += $(wildcard ./drivers/mcp4725/*.cpp)
cpp_src += $(wildcard ./systems/*.cpp)
c_src += $(wildcard ./algorithms/*.c)
@ -12,7 +13,7 @@ c_src += $(wildcard ./drivers/pf8574/*.c)
cpp_obj = $(cpp_src:.cpp=.o)
c_obj = $(c_src:.c=.o)
CC = g++
CFLAGS = -Wall -pedantic -li2c
CFLAGS = -Wall -pedantic -li2c
LDFLAGS =
EXEC = runtest

@ -1,11 +1,16 @@
#include "mcp4725.hpp"
#if 0
MCP4725::MCP4725(pwrd_md power_down_mode,
i2c_addr address,
i2c_write_n_t i2c_write) :
I2C* i2c) :
power_down_mode(power_down_mode),
address(address),
i2c_write(i2c_write)
i2c(i2c),
dac_value(0),
eeprom_value(0)
{
uint8_t temp[6];
@ -16,14 +21,17 @@ MCP4725::MCP4725(pwrd_md power_down_mode,
temp[4] = temp[1];
temp[5] = temp[2];
i2c_write(address, temp,6);
//i2c_write(address, temp,6);
}
MCP4725::MCP4725(i2c_addr address,
i2c_write_n_t i2c_write)
power_down_mode(MCP4725::normal),
I2C* i2c) :
power_down_mode(pwrd_md::normal),
address(address),
i2c_write(i2c_write)
i2c(i2c),
dac_value(0),
eeprom_value(0)
{
uint8_t temp[6];
@ -34,26 +42,57 @@ MCP4725::MCP4725(i2c_addr address,
temp[4] = temp[1];
temp[5] = temp[2];
i2c_write(address, temp, 6);
//i2c_write(address, temp, 6);
}
#endif
MCP4725::~MCP4725()
MCP4725::MCP4725()
{
}
MCP4725::MCP4725(I2C* i2c) :
//power_down_mode(pwrd_md::normal),
//address(i2c_addr::addr_0x6),
i2c(i2c),
dac_value(0),
eeprom_value(0)
{
uint8_t temp[6];
temp[0] = cmd_write_dac_and_eeprom | (power_down_mode << 1);
temp[1] = static_cast<uint8_t>(dac_value >> 4);
temp[2] = static_cast<uint8_t>(dac_value << 4);
temp[3] = temp[0];
temp[4] = temp[1];
temp[5] = temp[2];
//i2c_write(address, temp, 6);
}
//MCP4725::~MCP4725()
//{
//}
void MCP4725::operator=(uint16_t dac_value)
{
uint8_t temp[3];
this.dac_value = dac_value;
this->dac_value = dac_value;
temp[0] = cmd_write_dac | (power_down_mode << 1);
temp[1] = static_cast<uint8_t>(dac_value >> 4);
temp[2] = static_cast<uint8_t>(dac_value << 4);
i2c_write(address, temp, 3);
i2c->writeBuffer(address, temp, 3);
//i2c_write(address, temp, 3);
}
#if 0
void MCP4725::operator==(uint16_t dac_and_eeprom_value)
{
uint8_t temp[6];
@ -61,6 +100,14 @@ void MCP4725::operator==(uint16_t dac_and_eeprom_value)
eeprom_value = dac_value;
temp[0] = cmd_write_dac_and_eeprom | (power_down_mode << 1);
temp[1] = static_cast<uint8_t>(dac_and_eeprom_value >> 4);
temp[2] = static_cast<uint8_t>(dac_and_eeprom_value << 4);
temp[3] = temp[0];
temp[4] = temp[1];
temp[5] = temp[2];
//i2c_write(address, temp, 6);
}
void MCP4725::write_dac(uint16_t dac_value)
@ -73,4 +120,4 @@ void MCP4725::write_dac_and_eeprom(uint16_t dac_and_eeprom_value)
&this == dac_and_eeprom_value;
}
#endif

@ -2,12 +2,19 @@
#define _MCP4725_HPP_
#include <stdint.h>
#include <unistd.h>
#include <functional>
#include "../../communication/i2c/i2c.hpp"
class MCP4725
{
public:
typedef std::function<void(uint8_t,uint8_t*,uint8_t)> i2c_write_n_t;
//typedef std::function<void(uint8_t,uint8_t*,uint8_t)> i2c_write_n_t;
//typedef std::function<void(const uint8_t&,const uint8_t*,const uint8_t&)> i2c_write_n_t;
//typedef void(*i2c_write_n_t)(const uint8_t&, const uint8_t*, const uint8_t&);
//typedef std::function<void(int)>i2c_write_n_t;
// address list
enum i2c_addr
{
@ -41,17 +48,24 @@ class MCP4725
* @param address i2c_addr i2c address of the dac
* @param i2c_write i2c_write_n_t callback for i2c writ
*/
#if 0
MCP4725(pwrd_md power_down_mode,
i2c_addr address,
i2c_write_n_t i2c_write);
I2C* i2c);
MCP4725(i2c_addr address,
i2c_write_n_t i2c_write);
I2C* i2c);
#endif
MCP4725();
MCP4725(I2C* i2c);
// ~MCP4725();
~MCP4725();
void operator=(uint16_t dac_value);
#if 0
void operator==(uint16_t dac_and_eeprom_value);
void write_dac_and_eeprom(uint16_t value);
@ -59,7 +73,7 @@ class MCP4725
void set_powerdown_impedance(pwrd_md mode);
i2c_addr get_i2c_addr();
#endif
//void set_power
@ -72,9 +86,11 @@ class MCP4725
cmd_write_dac_and_eeprom = 0x60
};
I2C* i2c;
i2c_addr address;
pwrd_md power_down_mode;
i2c_write_n_t i2c_write;
//i2c_write_n_t i2c_write;
uint16_t dac_value;
uint16_t eeprom_value;

@ -11,6 +11,7 @@
#include <stdint.h>
#include <unistd.h>
#include <bitset>
#include <functional>
#include "./management/errorHandling.h"
#include "./management/commandManager.h"
@ -32,7 +33,6 @@
#include "./pimpl/interface.hpp"
ErrorHandler errorHandle;
CommandManager commander;
@ -117,16 +117,42 @@ void pca9685_motor()
}
void i_test(const uint8_t& a, const uint8_t* b, const uint8_t& c)
{
std::cout << "i_test called" << std::endl;
}
void foo(int baa)
{
std::cout << "foo called" << std::endl;
}
void mcp4725_test()
{
std::cout << "mcp4725 dac test" << std::endl;
MCP4725 dac(&i2c);
dac = 0x0000;
/*
auto cb = std::bind()
MCP4725 dac(//MCP4725::pwrd_md::normal,
MCP4725::i2c_addr::addr_0x6,
std::bind(&foo, std::placeholders::_1));
*/
MCP4725 dac(MCP4725::normal,
MCP4725::addr_0x6,
)
*/
//MCP4725::pwrd_md g = MCP4725::pwrd_md::normal;
/*
MCP4725 dac(MCP4725::i2c_addr::addr_0x6,
std::bind(&I2C::writeBuffer,
&i2c,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3));
*/
}
void dummy()

Binary file not shown.
Loading…
Cancel
Save