|
@@ -23,9 +23,12 @@
|
23
|
23
|
#include "config.h"
|
24
|
24
|
#include "config_pins.h"
|
25
|
25
|
|
26
|
|
-#ifdef PLATFORM_ESP
|
|
26
|
+#ifdef TWI_GPIO
|
27
|
27
|
#include <PCF8574.h>
|
28
|
28
|
#include <Wire.h>
|
|
29
|
+#endif
|
|
30
|
+
|
|
31
|
+#ifdef PLATFORM_ESP
|
29
|
32
|
#include "WifiStuff.h"
|
30
|
33
|
#endif // PLATFORM_ESP
|
31
|
34
|
|
|
@@ -33,13 +36,13 @@
|
33
|
36
|
|
34
|
37
|
// ----------------------------------------------------------------------------
|
35
|
38
|
|
36
|
|
-#if (I2C_GPIO_EXPANDER_COUNT > 0)
|
|
39
|
+#if defined(TWI_GPIO) && (I2C_GPIO_EXPANDER_COUNT > 0)
|
37
|
40
|
static uint8_t expand_addr[I2C_GPIO_EXPANDER_COUNT] = { I2C_GPIO_EXPANDER_ADDR };
|
38
|
41
|
static PCF8574 expand[I2C_GPIO_EXPANDER_COUNT];
|
39
|
42
|
#endif
|
40
|
43
|
|
41
|
44
|
void gpio_i2c_init(void) {
|
42
|
|
-#if (I2C_GPIO_EXPANDER_COUNT > 0)
|
|
45
|
+#if defined(TWI_GPIO) && (I2C_GPIO_EXPANDER_COUNT > 0)
|
43
|
46
|
for (int i = 0; i < I2C_GPIO_EXPANDER_COUNT; i++) {
|
44
|
47
|
expand[i].setAddress(expand_addr[i]);
|
45
|
48
|
expand[i].begin(0xFF);
|
|
@@ -53,6 +56,7 @@ static void gpio_pinMode(int pin, int value) {
|
53
|
56
|
} else if (pin < 0) {
|
54
|
57
|
// ignore negative pin numbers
|
55
|
58
|
} else {
|
|
59
|
+#if defined(TWI_GPIO) && (I2C_GPIO_EXPANDER_COUNT > 0)
|
56
|
60
|
pin -= 100;
|
57
|
61
|
int ex = pin / 8;
|
58
|
62
|
pin = pin % 8;
|
|
@@ -65,6 +69,7 @@ static void gpio_pinMode(int pin, int value) {
|
65
|
69
|
}
|
66
|
70
|
expand[ex].setButtonMask(mask);
|
67
|
71
|
}
|
|
72
|
+#endif
|
68
|
73
|
}
|
69
|
74
|
}
|
70
|
75
|
|
|
@@ -74,12 +79,14 @@ static void gpio_digitalWrite(int pin, int value) {
|
74
|
79
|
} else if (pin < 0) {
|
75
|
80
|
// ignore negative pin numbers
|
76
|
81
|
} else {
|
|
82
|
+#if defined(TWI_GPIO) && (I2C_GPIO_EXPANDER_COUNT > 0)
|
77
|
83
|
pin -= 100;
|
78
|
84
|
int ex = pin / 8;
|
79
|
85
|
pin = pin % 8;
|
80
|
86
|
if (ex < I2C_GPIO_EXPANDER_COUNT) {
|
81
|
87
|
expand[ex].write(pin, value);
|
82
|
88
|
}
|
|
89
|
+#endif
|
83
|
90
|
}
|
84
|
91
|
}
|
85
|
92
|
|
|
@@ -90,6 +97,7 @@ static int gpio_digitalRead(int pin) {
|
90
|
97
|
// ignore negative pin numbers
|
91
|
98
|
return 0;
|
92
|
99
|
} else {
|
|
100
|
+#if defined(TWI_GPIO) && (I2C_GPIO_EXPANDER_COUNT > 0)
|
93
|
101
|
pin -= 100;
|
94
|
102
|
int ex = pin / 8;
|
95
|
103
|
pin = pin % 8;
|
|
@@ -98,6 +106,9 @@ static int gpio_digitalRead(int pin) {
|
98
|
106
|
} else {
|
99
|
107
|
return 0;
|
100
|
108
|
}
|
|
109
|
+#else
|
|
110
|
+ return 0;
|
|
111
|
+#endif
|
101
|
112
|
}
|
102
|
113
|
}
|
103
|
114
|
|