forked from BenoitSchillings/mcp4728
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcp4728.h
86 lines (79 loc) · 2.35 KB
/
mcp4728.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
Arduino library for MicroChip MCP4728 I2C D/A converter.
*/
#ifndef mcp4728_h
#define mcp4728_h
#include "Arduino.h"
#include <Wire.h>
#define defaultVDD 5000
#define BASE_ADDR 0x60
#define RESET 0B00000110
#define WAKE 0B00001001
#define UPDATE 0B00001000
#define MULTIWRITE 0B01000000
#define SINGLEWRITE 0B01011000
#define SEQWRITE 0B01010000
#define VREFWRITE 0B10000000
#define GAINWRITE 0B11000000
#define POWERDOWNWRITE 0B10100000
#define GENERALCALL 0B0000000
#define GAINWRITE 0B11000000
class mcp4728
{
public:
mcp4728(uint8_t);
void vdd(uint16_t);
void begin();
uint8_t reset();
uint8_t wake();
uint8_t update();
uint8_t analogWrite(uint16_t, uint16_t, uint16_t, uint16_t);
uint8_t analogWrite(uint8_t, uint16_t);
uint8_t eepromWrite(uint16_t, uint16_t, uint16_t, uint16_t);
uint8_t eepromWrite(uint8_t, uint16_t);
uint8_t eepromWrite();
uint8_t eepromReset();
void print();
uint8_t setVref(uint8_t, uint8_t, uint8_t, uint8_t);
uint8_t setVref(uint8_t, uint8_t);
uint8_t setGain(uint8_t, uint8_t, uint8_t, uint8_t);
uint8_t setGain(uint8_t, uint8_t);
uint8_t setPowerDown(uint8_t, uint8_t, uint8_t, uint8_t);
uint8_t setPowerDown(uint8_t, uint8_t);
uint8_t getId();
uint8_t getVref(uint8_t);
uint8_t getGain(uint8_t);
uint8_t getPowerDown(uint8_t);
uint16_t getValue(uint8_t);
uint8_t getVrefEp(uint8_t);
uint8_t getGainEp(uint8_t);
uint8_t getPowerDownEp(uint8_t);
uint16_t getValueEp(uint8_t);
uint16_t getVout(uint8_t);
void voutWrite(uint8_t, uint16_t);
void voutWrite(uint16_t, uint16_t, uint16_t, uint16_t);
public:
void getStatus();
uint8_t fastWrite();
uint8_t multiWrite();
uint8_t singleWrite(uint8_t);
uint8_t seqWrite();
uint8_t writeVref();
uint8_t writeGain();
uint8_t writePowerDown();
void writeVout();
uint8_t _dev_address;
uint8_t _deviceID;
uint8_t _intVref[4];
uint8_t _gain[4];
uint8_t _powerDown[4];
uint16_t _values[4];
uint16_t _valuesEp[4];
uint8_t _intVrefEp[4];
uint8_t _gainEp[4];
uint8_t _powerDownEp[4];
uint16_t _vOut[4];
uint16_t _vdd;
uint8_t _simpleCommand(byte);
};
#endif