You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.9 KiB
101 lines
1.9 KiB
#ifndef _MCP4725_HPP_
|
|
#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(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
|
|
{
|
|
addr_0x60 = 0b01100000,
|
|
addr_0x61 = addr_0x60 + 1,
|
|
addr_0x62 = addr_0x60 + 2,
|
|
addr_0x63 = addr_0x60 + 3,
|
|
addr_0x64 = addr_0x60 + 4,
|
|
addr_0x65 = addr_0x60 + 5,
|
|
addr_0x66 = addr_0x60 + 6,
|
|
addr_0x67 = addr_0x60 + 7
|
|
};
|
|
|
|
// power down impedance modes
|
|
enum pwrd_md
|
|
{
|
|
normal = 0x04,
|
|
ohm_1k = 0x01,
|
|
ohm_100k = 0x02,
|
|
ohm_500k = 0x03
|
|
};
|
|
|
|
//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)>;
|
|
|
|
/**
|
|
* @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
|
|
*/
|
|
#if 0
|
|
MCP4725(pwrd_md power_down_mode,
|
|
i2c_addr address,
|
|
I2C* i2c);
|
|
|
|
MCP4725(i2c_addr address,
|
|
I2C* i2c);
|
|
#endif
|
|
|
|
MCP4725();
|
|
MCP4725(I2C* i2c);
|
|
|
|
// ~MCP4725();
|
|
|
|
|
|
|
|
void operator=(uint16_t dac_value);
|
|
|
|
void operator==(uint16_t dac_and_eeprom_value);
|
|
|
|
#if 0
|
|
void write_dac_and_eeprom(uint16_t value);
|
|
|
|
void set_powerdown_impedance(pwrd_md mode);
|
|
|
|
i2c_addr get_i2c_addr();
|
|
#endif
|
|
//void set_power
|
|
|
|
|
|
private:
|
|
|
|
enum commands_t
|
|
{
|
|
cmd_fast_mode = 0x00,
|
|
cmd_write_dac = 0x40,
|
|
cmd_write_dac_and_eeprom = 0x60
|
|
};
|
|
|
|
I2C* i2c;
|
|
|
|
i2c_addr address;
|
|
pwrd_md power_down_mode;
|
|
//i2c_write_n_t i2c_write;
|
|
uint16_t dac_value;
|
|
uint16_t eeprom_value;
|
|
|
|
};
|
|
|
|
#endif // _MCP4725_HPP_
|