work on mcp4725 dac

master
edwin 4 years ago
parent b262a37964
commit a0c90a3f0f

@ -9,7 +9,7 @@ MCP4725::MCP4725(pwrd_md power_down_mode,
{
uint8_t temp[6];
temp[0] = write_dac_and_eeprom | (power_down_mode << 1);
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];
@ -27,7 +27,7 @@ MCP4725::MCP4725(i2c_addr address,
{
uint8_t temp[6];
temp[0] = write_dac_and_eeprom | (power_down_mode << 1);
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];
@ -47,7 +47,7 @@ void MCP4725::operator=(uint16_t dac_value)
uint8_t temp[3];
this.dac_value = dac_value;
temp[0] = write_dac | (power_down_mode << 1);
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);
@ -60,7 +60,7 @@ void MCP4725::operator==(uint16_t dac_and_eeprom_value)
dac_value = dac_and_eeprom_value;
eeprom_value = dac_value;
temp[0] = write_dac_and_eeprom | (power_down_mode << 1);
temp[0] = cmd_write_dac_and_eeprom | (power_down_mode << 1);
}
void MCP4725::write_dac(uint16_t dac_value)

@ -7,6 +7,7 @@
class MCP4725
{
public:
typedef std::function<void(uint8_t,uint8_t*,uint8_t)> i2c_write_n_t;
// address list
enum i2c_addr
{
@ -18,7 +19,7 @@ class MCP4725
addr_0x5 = addr_0x0 + 1,
addr_0x6 = addr_0x0 + 1,
addr_0x7 = addr_0x0 + 1
}
};
// power down impedance modes
enum pwrd_md
@ -31,8 +32,15 @@ class MCP4725
//using std::functional<uint8_t(uint8_t, uint8_t)> i2c_read_n_t;
using i2c_write_n_t = std::functional<void(uint8_t, uint8_t*,uint8_t)>;
//using i2c_write_n_t = std::functional<void(uint8_t, uint8_t*,uint8_t)>;
/**
* @brief Constructor of mcp4725 dac
*
* @param power_down_mode pwrd_md power down mode
* @param address i2c_addr i2c address of the dac
* @param i2c_write i2c_write_n_t callback for i2c writ
*/
MCP4725(pwrd_md power_down_mode,
i2c_addr address,
i2c_write_n_t i2c_write);
@ -52,16 +60,16 @@ class MCP4725
i2c_addr get_i2c_addr();
void set_power
//void set_power
private:
enum commands_t
{
fast_mode = 0x00,
write_dac = 0x40,
write_dac_and_eeprom = 0x60
cmd_fast_mode = 0x00,
cmd_write_dac = 0x40,
cmd_write_dac_and_eeprom = 0x60
};
i2c_addr address;

@ -11,14 +11,27 @@
#include <stdint.h>
#include <unistd.h>
#include <bitset>
#include "./management/errorHandling.h"
#include "./management/commandManager.h"
// hardwareinterfaces
#include "./communication/i2c/i2c.hpp"
// drivers
#include "./drivers/bh1750/bh1750.h"
#include "./drivers/pf8574/pf8574lcd.h"
#include "./drivers/pca9685/pca9685.h"
#include "./drivers/mcp4725/mcp4725.hpp"
#include "./algorithms/bitgestion.h"
#include "./pimpl/interface.hpp"
#include "./communication/i2c/i2c.hpp"
ErrorHandler errorHandle;
CommandManager commander;
@ -107,6 +120,13 @@ void pca9685_motor()
void mcp4725_test()
{
std::cout << "mcp4725 dac test" << std::endl;
/*
auto cb = std::bind()
MCP4725 dac(MCP4725::normal,
MCP4725::addr_0x6,
)
*/
}
void dummy()

Loading…
Cancel
Save