|
@@ -27,6 +27,10 @@
|
27
|
27
|
* Utility functions
|
28
|
28
|
*/
|
29
|
29
|
|
|
30
|
+// I2S expander pin mapping.
|
|
31
|
+#define IS_I2S_EXPANDER_PIN(IO) TEST(IO, 7)
|
|
32
|
+#define I2S_EXPANDER_PIN_INDEX(IO) (IO & 0x7F)
|
|
33
|
+
|
30
|
34
|
// Set pin as input
|
31
|
35
|
#define _SET_INPUT(IO) pinMode(IO, INPUT)
|
32
|
36
|
|
|
@@ -37,10 +41,10 @@
|
37
|
41
|
#define _PULLUP(IO, v) pinMode(IO, v ? INPUT_PULLUP : INPUT)
|
38
|
42
|
|
39
|
43
|
// Read a pin wrapper
|
40
|
|
-#define READ(IO) (TEST(IO, 7) ? i2s_state(IO & 0x7F) : digitalRead(IO))
|
|
44
|
+#define READ(IO) (IS_I2S_EXPANDER_PIN(IO) ? i2s_state(I2S_EXPANDER_PIN_INDEX(IO)) : digitalRead(IO))
|
41
|
45
|
|
42
|
46
|
// Write to a pin wrapper
|
43
|
|
-#define WRITE(IO, v) (TEST(IO, 7) ? i2s_write(IO & 0x7F, v) : digitalWrite(IO, v))
|
|
47
|
+#define WRITE(IO, v) (IS_I2S_EXPANDER_PIN(IO) ? i2s_write(I2S_EXPANDER_PIN_INDEX(IO), v) : digitalWrite(IO, v))
|
44
|
48
|
|
45
|
49
|
// Set pin as input wrapper
|
46
|
50
|
#define SET_INPUT(IO) _SET_INPUT(IO)
|
|
@@ -61,8 +65,9 @@
|
61
|
65
|
#define extDigitalRead(IO) digitalRead(IO)
|
62
|
66
|
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|
63
|
67
|
|
64
|
|
-#define PWM_PIN(P) true
|
65
|
|
-#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
|
|
68
|
+// PWM outputs
|
|
69
|
+#define PWM_PIN(P) (P < 34) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
|
|
70
|
+#define USEABLE_HARDWARE_PWM(P) (!IS_I2S_EXPANDER_PIN(P) && PWM_PIN(P))
|
66
|
71
|
|
67
|
72
|
// Toggle pin value
|
68
|
73
|
#define TOGGLE(IO) WRITE(IO, !READ(IO))
|