-
Notifications
You must be signed in to change notification settings - Fork 1
/
Max517Dac.h
135 lines (121 loc) · 3.73 KB
/
Max517Dac.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Max517Dac.h
*
* MAX517 8-bit DAC library definition.
*
* Copyright (c) 2012 Jordan Goulder. All rights reserved.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not see <http://www.gnu.org/licenses/>.
*/
/**
* @file Max517Dac.h
*
* MAX517 8-bit DAC library definition
*
* @author Jordan Goulder
*/
#ifndef MAX517DAC_H
#define MAX517DAC_H
#include <stdint.h>
/**
* MAX517 8-bit DAC Device Class.
* This class provides a simple interface to the MAX517 8-bit DAC.
*/
class Max517Dac
{
public:
/**
* Default I2C address of the DAC.
*
* @note This assumes that AD0 and AD1 of the DAC are tied to ground.
*/
static const uint8_t DEFAULT_ADDRESS = 0x2C;
/**
* Create a new MAX517 device.
*
* @param deviceAddress The I2C address of the device.
*/
Max517Dac(uint8_t deviceAddress = DEFAULT_ADDRESS);
/**
* Reset the DAC output back to 0.
*
* @param powerDownMode Put the device in power down mode after the
* command is exectued.
*
* @return I2C write status.<br><br>
* true: I2C write successful.<br>
* false: I2C write failed.<br>
*
* @note The output of the device is left floating while in the
* power down mode.
*/
bool resetOutput(bool powerDownMode = false) const;
/**
* Change the value of the DAC.
*
* @param value Value used to set the DAC.
* @param powerDownMode Put the device in power down mode after the
* command is exectued.
*
* @return I2C write status.<br><br>
* true: I2C write successful.<br>
* false: I2C write failed.<br>
*
* @note The output of the device is left floating while in the
* power down mode.
*/
bool setOutput(uint8_t value, bool powerDownMode = false) const;
/**
* Power down the device.
*
* @return I2C write status.<br><br>
* true: I2C write successful.<br>
* false: I2C write failed.<br>
*
* @note The output of the device is left floating while in the
* power down mode.
*/
bool powerDown() const;
/**
* Power up the device.
*
* @return I2C write status.<br><br>
* true: I2C write successful.<br>
* false: I2C write failed.<br>
*
* @note The output is restored to the last output value written
* to the device.
*/
bool powerUp() const;
private:
/**
* I2C address of the device
*/
uint8_t mDeviceAddress;
/**
* Performs the actual I2C write to the device
*
* @param command Command used to control the device.
* @param output Value to send as the output byte of the message.
* @param sendOuput Set this to true to indicate that the output should be sent.
*
* @return I2C write status.<br><br>
* true: I2C write successful.<br>
* false: I2C write failed.<br>
*/
bool mSendCommand(uint8_t command,
uint8_t output = 0,
bool sendOutput = false) const;
};
#endif