forked from marko-pi/MCP4728
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MCP4728.h
82 lines (57 loc) · 1.91 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
/*
Marko Pinteric 2020
GPIO communication based on Tiny GPIO Access on http://abyz.me.uk/rpi/pigpio/examples.html
Header for MCP4728.c
*/
#define UNDEFINED 0xFFFF
/* TINY GPIO VARIABLES */
#define GPSET0 7
#define GPSET1 8
#define GPCLR0 10
#define GPCLR1 11
#define GPLEV0 13
#define GPLEV1 14
#define GPPUD 37
#define GPPUDCLK0 38
#define GPPUDCLK1 39
#define PI_BANK (gpio>>5)
#define PI_BIT (1<<(gpio&0x1F))
/* gpio modes */
#define PI_INPUT 0
#define PI_OUTPUT 1
#define PI_ALT0 4
#define PI_ALT1 5
#define PI_ALT2 6
#define PI_ALT3 7
#define PI_ALT4 3
#define PI_ALT5 2
/* values for pull-ups/downs off, pull-down && pull-up */
#define PI_PUD_OFF 0
#define PI_PUD_DOWN 1
#define PI_PUD_UP 2
/* chip data */
struct chip
{
unsigned sda;
unsigned scl;
unsigned ldac;
unsigned address;
unsigned bus;
};
/* ---------------- public functions ----------------------- */
/* initialises communications */
struct chip *mcp4728_initialize(int sda, int scl, int ldac, int address);
/* deinitialise communications */
int mcp4728_deinitialize(struct chip *tempchip);
/* gets the DAC address */
int mcp4728_getaddress(struct chip *tempchip);
/* sets the DAC address */
int mcp4728_setaddress(struct chip *tempchip, unsigned addr);
/* writes single value to the selected DAC channel using internal reference - channels 1 to 4 */
int mcp4728_singleinternal(struct chip *tempchip, int channel, float volt, bool eeprom);
/* writes single value to the selected DAC channel using external reference - channels 1 to 4 */
int mcp4728_singleexternal(struct chip *tempchip, int channel, float rel, bool eeprom);
/* writes four values to the DAC channels using internal reference */
int mcp4728_multipleinternal(struct chip *tempchip, float volts[], bool eeprom);
/* writes four values to DAC channels using external reference */
int mcp4728_multipleexternal(struct chip *tempchip, float rels[], bool eeprom);