Skip to content

Commit cd31356

Browse files
committed
Moved constants to pins_arduino.h
1 parent 6967d8f commit cd31356

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

Diff for: cores/esp32/esp32-hal-gpio.c

+27-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "esp32-hal-gpio.h"
1616
#include "hal/gpio_hal.h"
1717
#include "soc/soc_caps.h"
18+
#include "pins_arduino.h"
1819

1920
// It fixes lack of pin definition for S3 and for any future SoC
2021
// this function works for ESP32, ESP32-S2 and ESP32-S3 - including the C3, it will return -1 for any pin
@@ -91,6 +92,17 @@ static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = {0,};
9192

9293
extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
9394
{
95+
log_d("pin %d", pin);
96+
#ifdef BOARD_HAS_NEOPIXEL
97+
log_d("BOARD_HAS_NEOPIXEL");
98+
if (pin == LED_BUILTIN){
99+
log_d("pin == LED_BUILTIN; call __pinMode(%d)", NEOPIXEL_PIN);
100+
__pinMode(NEOPIXEL_PIN, mode);
101+
return;
102+
}
103+
#endif
104+
105+
log_d("Normal operation");
94106
if (!GPIO_IS_VALID_GPIO(pin)) {
95107
log_e("Invalid pin selected");
96108
return;
@@ -126,18 +138,25 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
126138
}
127139

128140
void RGBLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){
129-
static bool initialized = false;
130141
rmt_data_t led_data[24];
131142
static rmt_obj_t* rmt_send = NULL;
143+
static bool initialized = false;
144+
145+
uint8_t _pin;
146+
if(pin == LED_BUILTIN){
147+
_pin = NEOPIXEL_PIN;
148+
}else{
149+
_pin = pin;
150+
}
132151

133152
if(!initialized){
134-
if ((rmt_send = rmtInit(pin, RMT_TX_MODE, RMT_MEM_64)) == NULL){
153+
if((rmt_send = rmtInit(_pin, RMT_TX_MODE, RMT_MEM_64)) == NULL){
135154
log_e("RGB LED driver initialization failed!");
136155
rmt_send = NULL;
137156
return;
138-
}
139-
rmtSetTick(rmt_send, 100);
140-
initialized = true;
157+
}
158+
rmtSetTick(rmt_send, 100);
159+
initialized = true;
141160
}
142161

143162
int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE
@@ -165,11 +184,11 @@ void RGBLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_v
165184

166185
extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
167186
{
168-
#ifdef BOARD_HAS_RGB_LED
187+
#ifdef BOARD_HAS_NEOPIXEL
169188
if(pin == LED_BUILTIN){
170189
//use RMT to set all channels on/off
171-
const uint8_t comm_val = val != 0 ? 255 : 0;
172-
RGBLedWrite(pin, comm_val, comm_val, comm_val);
190+
const uint8_t comm_val = val != 0 ? LED_BRIGHTNESS : 0;
191+
RGBLedWrite(LED_BUILTIN, comm_val, comm_val, comm_val);
173192
return;
174193
}
175194
#endif

Diff for: cores/esp32/esp32-hal-gpio.h

-16
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,6 @@ extern "C" {
6363
#define ONLOW_WE 0x0C
6464
#define ONHIGH_WE 0x0D
6565

66-
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
67-
#define BOARD_HAS_RGB_LED
68-
#endif
69-
70-
#if CONFIG_IDF_TARGET_ESP32S2
71-
#define LED_BUILTIN 18 // Saola-1 & DevKitM-1
72-
//#define LED_BUILTIN 45 // Kaluga
73-
#elif CONFIG_IDF_TARGET_ESP32S3
74-
// Some boards have too low voltage on this pin (board design bug)
75-
// Use different pin with 3V and connect with 48
76-
#define LED_BUILTIN 48
77-
#elif CONFIG_IDF_TARGET_ESP32C3
78-
#define LED_BUILTIN 8
79-
#else
80-
#define LED_BUILTIN 21 // ESP32 has no builtin RGB LED
81-
#endif
8266

8367
#define digitalPinIsValid(pin) GPIO_IS_VALID_GPIO(pin)
8468
#define digitalPinCanOutput(pin) GPIO_IS_VALID_OUTPUT_GPIO(pin)

Diff for: variants/esp32c3/pins_arduino.h

+8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
#define Pins_Arduino_h
33

44
#include <stdint.h>
5+
#include "soc/soc_caps.h"
56

67
#define EXTERNAL_NUM_INTERRUPTS 22
78
#define NUM_DIGITAL_PINS 22
89
#define NUM_ANALOG_INPUTS 6
910

11+
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+1; // non-existing pin
12+
#define BUILTIN_LED LED_BUILTIN // backward compatibility
13+
#define LED_BUILTIN LED_BUILTIN
14+
#define BOARD_HAS_NEOPIXEL
15+
#define NEOPIXEL_PIN 8 // Actual NeoPixel GPIO pin
16+
#define LED_BRIGHTNESS 64
17+
1018
#define analogInputToDigitalPin(p) (((p)<NUM_ANALOG_INPUTS)?(analogChannelToDigitalPin(p)):-1)
1119
#define digitalPinToInterrupt(p) (((p)<NUM_DIGITAL_PINS)?(p):-1)
1220
#define digitalPinHasPWM(p) (p < EXTERNAL_NUM_INTERRUPTS)

Diff for: variants/esp32s2/pins_arduino.h

+9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
#define Pins_Arduino_h
33

44
#include <stdint.h>
5+
#include "soc/soc_caps.h"
56

67
#define EXTERNAL_NUM_INTERRUPTS 46
78
#define NUM_DIGITAL_PINS 48
89
#define NUM_ANALOG_INPUTS 20
910

11+
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+1; // non-existing pin
12+
#define BUILTIN_LED LED_BUILTIN // backward compatibility
13+
#define LED_BUILTIN LED_BUILTIN
14+
#define BOARD_HAS_NEOPIXEL
15+
#define NEOPIXEL_PIN 18 // Actual NeoPixel GPIO pin for Saola-1 & DevKitM-1
16+
//#define NEOPIXEL_PIN 45 // Actual NeoPixel GPIO pin for Kaluga
17+
#define LED_BRIGHTNESS 64
18+
1019
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
1120
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
1221
#define digitalPinHasPWM(p) (p < 46)

Diff for: variants/esp32s3/pins_arduino.h

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define Pins_Arduino_h
33

44
#include <stdint.h>
5+
#include "soc/soc_caps.h"
56

67
#define USB_VID 0x303a
78
#define USB_PID 0x1001
@@ -10,6 +11,15 @@
1011
#define NUM_DIGITAL_PINS 48
1112
#define NUM_ANALOG_INPUTS 20
1213

14+
// Some boards have too low voltage on this pin (board design bug)
15+
// Use different pin with 3V and connect with 48
16+
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+1; // non-existing pin
17+
#define BUILTIN_LED LED_BUILTIN // backward compatibility
18+
#define LED_BUILTIN LED_BUILTIN
19+
#define BOARD_HAS_NEOPIXEL
20+
#define NEOPIXEL_PIN 48 // Actual NeoPixel GPIO pin
21+
#define LED_BRIGHTNESS 64
22+
1323
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
1424
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
1525
#define digitalPinHasPWM(p) (p < 46)

0 commit comments

Comments
 (0)