-
Notifications
You must be signed in to change notification settings - Fork 1
/
PCA9535.cpp
108 lines (90 loc) · 2.24 KB
/
PCA9535.cpp
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
#include "Arduino.h"
#include "PCA9535.h"
PCA9535::PCA9535(uint8_t PCAaddress, bool beginWire)
{
PCA9535Address = PCAaddress;
if (beginWire)
Wire.begin();
}
void PCA9535::writeI2c(uint8_t address, uint8_t data)
{
Wire.beginTransmission(address);
Wire.write(data);
Wire.endTransmission();
}
void PCA9535::writeI2c(uint8_t address, uint8_t data, uint8_t data2)
{
Wire.beginTransmission(address);
Wire.write(data);
Wire.write(data2);
Wire.endTransmission();
}
uint8_t PCA9535::readI2c(uint8_t address)
{
Wire.requestFrom(address, returnDataSize);
return Wire.read();
}
uint8_t PCA9535::readInputGpioGroup0()
{
writeI2c(PCA9535Address, inputP0);
return readI2c(PCA9535Address);
}
uint8_t PCA9535::readInputGpioGroup1()
{
writeI2c(PCA9535Address, inputP1);
return readI2c(PCA9535Address);
}
uint8_t PCA9535::readOutputGpioGroup0()
{
writeI2c(PCA9535Address, outputP0);
return readI2c(PCA9535Address);
}
uint8_t PCA9535::readOutputGpioGroup1()
{
writeI2c(PCA9535Address, outputP1);
return readI2c(PCA9535Address);
}
void PCA9535::writeGpioGroup0(uint8_t groupValue)
{
writeI2c(PCA9535Address, outputP0, groupValue);
}
void PCA9535::writeGpioGroup1(uint8_t groupValue)
{
writeI2c(PCA9535Address, outputP1, groupValue);
}
uint8_t PCA9535::readInputPolarityGroup0()
{
writeI2c(PCA9535Address, polarityInversionP0);
return readI2c(PCA9535Address);
}
uint8_t PCA9535::readInputPolarityGroup1()
{
writeI2c(PCA9535Address, polarityInversionP1);
return readI2c(PCA9535Address);
}
void PCA9535::setPolarityInversionGroup0(uint8_t groupValue)
{
writeI2c(PCA9535Address, polarityInversionP0, groupValue);
}
void PCA9535::setPolarityInversionGroup1(uint8_t groupValue)
{
writeI2c(PCA9535Address, polarityInversionP1, groupValue);
}
uint8_t PCA9535::readConfigurationGroup0()
{
writeI2c(PCA9535Address, configurationP0);
return readI2c(PCA9535Address);
}
uint8_t PCA9535::readConfigurationGroup1()
{
writeI2c(PCA9535Address, configurationP1);
return readI2c(PCA9535Address);
}
void PCA9535::setConfigurationGroup0(uint8_t configuration)
{
writeI2c(PCA9535Address, configurationP0, configuration);
}
void PCA9535::setConfigurationGroup1(uint8_t configuration)
{
writeI2c(PCA9535Address, configurationP1, configuration);
}