forked from espressif/arduino-esp32
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathio_pin_remap.cpp
55 lines (48 loc) · 1.24 KB
/
io_pin_remap.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
#ifndef BOARD_USES_HW_GPIO_NUMBERS
#include "Arduino.h"
static const int8_t TO_GPIO_NUMBER[NUM_DIGITAL_PINS] = {
[D0] = 44, // RX
[D1] = 43, // TX
[D2] = 5,
[D3] = 6, // CTS
[D4] = 7, // DSR
[D5] = 8,
[D6] = 9,
[D7] = 10,
[D8] = 17,
[D9] = 18,
[D10] = 21, // SS
[D11] = 38, // MOSI
[D12] = 47, // MISO
[D13] = 48, // SCK, LED_BUILTIN
[LED_RED] = 46,
[LED_GREEN] = 0,
[LED_BLUE] = 45, // RTS
[A0] = 1, // DTR
[A1] = 2,
[A2] = 3,
[A3] = 4,
[A4] = 11, // SDA
[A5] = 12, // SCL
[A6] = 13,
[A7] = 14,
};
int8_t digitalPinToGPIONumber(int8_t digitalPin)
{
if ((digitalPin < 0) || (digitalPin >= NUM_DIGITAL_PINS))
return -1;
return TO_GPIO_NUMBER[digitalPin];
}
int8_t gpioNumberToDigitalPin(int8_t gpioNumber)
{
if (gpioNumber < 0)
return -1;
// slow linear table lookup
for (int8_t digitalPin = 0; digitalPin < NUM_DIGITAL_PINS; ++digitalPin) {
if (TO_GPIO_NUMBER[digitalPin] == gpioNumber)
return digitalPin;
}
// not found
return -1;
}
#endif