Skip to content

Commit 54140dc

Browse files
committed
Fix Arduino PIN counts
1 parent 9f8b433 commit 54140dc

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

cores/esp32/esp32-hal-gpio.c

-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@
2828
#include "esp32/rom/ets_sys.h"
2929
#include "esp32/rom/gpio.h"
3030
#include "esp_intr_alloc.h"
31-
#define NUM_OUPUT_PINS 34
3231
#define GPIO_FUNC 2
3332
#elif CONFIG_IDF_TARGET_ESP32S2
3433
#include "esp32s2/rom/ets_sys.h"
3534
#include "esp32s2/rom/gpio.h"
3635
#include "esp_intr_alloc.h"
3736
#include "soc/periph_defs.h"
38-
#define NUM_OUPUT_PINS 45
3937
#define GPIO_FUNC 1
4038
#else
4139
#error Target CONFIG_IDF_TARGET is not supported

cores/esp32/esp32-hal-gpio.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ extern "C" {
2727
#include "esp32-hal.h"
2828
#include "soc/gpio_caps.h"
2929

30+
#if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3)
31+
#define NUM_OUPUT_PINS 45
32+
#define PIN_DAC1 17
33+
#define PIN_DAC2 18
34+
#else
35+
#define NUM_OUPUT_PINS 34
36+
#define PIN_DAC1 25
37+
#define PIN_DAC2 26
38+
#endif
39+
3040
#define LOW 0x0
3141
#define HIGH 0x1
3242

@@ -68,12 +78,12 @@ typedef struct {
6878
extern const esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT];
6979
extern const int8_t esp32_adc2gpio[20];
7080

71-
#define digitalPinIsValid(pin) ((pin) < 40 && esp32_gpioMux[(pin)].reg)
72-
#define digitalPinCanOutput(pin) ((pin) < 34 && esp32_gpioMux[(pin)].reg)
73-
#define digitalPinToRtcPin(pin) (((pin) < 40)?esp32_gpioMux[(pin)].rtc:-1)
74-
#define digitalPinToAnalogChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].adc:-1)
75-
#define digitalPinToTouchChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].touch:-1)
76-
#define digitalPinToDacChannel(pin) (((pin) == 25)?0:((pin) == 26)?1:-1)
81+
#define digitalPinIsValid(pin) ((pin) < GPIO_PIN_COUNT && esp32_gpioMux[(pin)].reg)
82+
#define digitalPinCanOutput(pin) ((pin) < NUM_OUPUT_PINS && esp32_gpioMux[(pin)].reg)
83+
#define digitalPinToRtcPin(pin) (((pin) < GPIO_PIN_COUNT)?esp32_gpioMux[(pin)].rtc:-1)
84+
#define digitalPinToAnalogChannel(pin) (((pin) < GPIO_PIN_COUNT)?esp32_gpioMux[(pin)].adc:-1)
85+
#define digitalPinToTouchChannel(pin) (((pin) < GPIO_PIN_COUNT)?esp32_gpioMux[(pin)].touch:-1)
86+
#define digitalPinToDacChannel(pin) (((pin) == PIN_DAC1)?0:((pin) == PIN_DAC2)?1:-1)
7787

7888
void pinMode(uint8_t pin, uint8_t mode);
7989
void digitalWrite(uint8_t pin, uint8_t val);

0 commit comments

Comments
 (0)