|
15 | 15 | #include "esp32-hal-gpio.h" |
16 | 16 | #include "hal/gpio_hal.h" |
17 | 17 | #include "soc/soc_caps.h" |
| 18 | +#include "pins_arduino.h" |
18 | 19 |
|
19 | 20 | // It fixes lack of pin definition for S3 and for any future SoC |
20 | 21 | // 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,}; |
91 | 92 |
|
92 | 93 | extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) |
93 | 94 | { |
| 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"); |
94 | 106 | if (!GPIO_IS_VALID_GPIO(pin)) { |
95 | 107 | log_e("Invalid pin selected"); |
96 | 108 | return; |
@@ -126,18 +138,25 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) |
126 | 138 | } |
127 | 139 |
|
128 | 140 | void RGBLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){ |
129 | | - static bool initialized = false; |
130 | 141 | rmt_data_t led_data[24]; |
131 | 142 | 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 | + } |
132 | 151 |
|
133 | 152 | 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){ |
135 | 154 | log_e("RGB LED driver initialization failed!"); |
136 | 155 | rmt_send = NULL; |
137 | 156 | return; |
138 | | - } |
139 | | - rmtSetTick(rmt_send, 100); |
140 | | - initialized = true; |
| 157 | + } |
| 158 | + rmtSetTick(rmt_send, 100); |
| 159 | + initialized = true; |
141 | 160 | } |
142 | 161 |
|
143 | 162 | 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 |
165 | 184 |
|
166 | 185 | extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) |
167 | 186 | { |
168 | | - #ifdef BOARD_HAS_RGB_LED |
| 187 | + #ifdef BOARD_HAS_NEOPIXEL |
169 | 188 | if(pin == LED_BUILTIN){ |
170 | 189 | //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); |
173 | 192 | return; |
174 | 193 | } |
175 | 194 | #endif |
|
0 commit comments