Skip to content

Commit bbac68e

Browse files
authored
Merge pull request #3232 from hierophect/esp32-neopixel
ESP32-S2: Add Neopixel support
2 parents bccfb8b + 4613b58 commit bbac68e

File tree

16 files changed

+258
-34
lines changed

16 files changed

+258
-34
lines changed

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ bool run_code_py(safe_mode_t safe_mode) {
282282
}
283283
}
284284

285-
// Wait for connection or character.
285+
// Display a different completion message if the user has no USB attached (cannot save files)
286286
if (!serial_connected_at_start) {
287287
serial_write_compressed(translate("\nCode done running. Waiting for reload.\n"));
288288
}

ports/esp32s2/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ SRC_C += \
171171
lib/utils/stdout_helpers.c \
172172
lib/utils/sys_stdio_mphal.c \
173173
peripherals/pins.c \
174+
peripherals/rmt.c \
174175
supervisor/shared/memory.c
175176

176177
ifneq ($(USB),FALSE)

ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@
2929
#define MICROPY_HW_BOARD_NAME "Saola 1 w/Wroom"
3030
#define MICROPY_HW_MCU_NAME "ESP32S2"
3131

32+
#define MICROPY_HW_NEOPIXEL (&pin_GPIO18)
33+
3234
#define AUTORESET_DELAY_MS 500

ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ LONGINT_IMPL = MPZ
1010
# so increase it to 32.
1111
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
1212

13-
CIRCUITPY_NEOPIXEL_WRITE = 0
14-
1513
CIRCUITPY_ESP_FLASH_MODE=dio
1614
CIRCUITPY_ESP_FLASH_FREQ=40m
1715
CIRCUITPY_ESP_FLASH_SIZE=4MB

ports/esp32s2/boards/espressif_saola_1_wrover/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@
2929
#define MICROPY_HW_BOARD_NAME "Saola 1 w/Wrover"
3030
#define MICROPY_HW_MCU_NAME "ESP32S2"
3131

32+
#define MICROPY_HW_NEOPIXEL (&pin_GPIO18)
33+
3234
#define AUTORESET_DELAY_MS 500

ports/esp32s2/boards/espressif_saola_1_wrover/mpconfigboard.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ LONGINT_IMPL = MPZ
1010
# so increase it to 32.
1111
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
1212

13-
CIRCUITPY_NEOPIXEL_WRITE = 0
14-
1513
CIRCUITPY_ESP_FLASH_MODE=dio
1614
CIRCUITPY_ESP_FLASH_FREQ=40m
1715
CIRCUITPY_ESP_FLASH_SIZE=4MB

ports/esp32s2/boards/espressif_saola_1_wrover/pins.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
4242
{ MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) },
4343
{ MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) },
4444
{ MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) },
45+
46+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO18) },
4547
};
4648
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ USB_PRODUCT = "FeatherS2"
44
USB_MANUFACTURER = "UnexpectedMaker"
55
USB_DEVICES = "CDC,MSC,HID"
66

7-
87
INTERNAL_FLASH_FILESYSTEM = 1
98
LONGINT_IMPL = MPZ
109

1110
# The default queue depth of 16 overflows on release builds,
1211
# so increase it to 32.
1312
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
1413

15-
CIRCUITPY_NEOPIXEL_WRITE = 0
16-
1714
CIRCUITPY_ESP_FLASH_MODE=qio
1815
CIRCUITPY_ESP_FLASH_FREQ=40m
1916
CIRCUITPY_ESP_FLASH_SIZE=16MB

ports/esp32s2/common-hal/microcontroller/Pin.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@
2626
*/
2727

2828
#include "shared-bindings/microcontroller/Pin.h"
29+
#include "shared-bindings/digitalio/DigitalInOut.h"
30+
#include "supervisor/shared/rgb_led_status.h"
2931

3032
#include "py/mphal.h"
3133

3234
#include "esp-idf/components/driver/include/driver/gpio.h"
3335
#include "esp-idf/components/soc/include/hal/gpio_hal.h"
3436

37+
#ifdef MICROPY_HW_NEOPIXEL
38+
bool neopixel_in_use;
39+
#endif
40+
3541
STATIC uint32_t never_reset_pins[2];
3642
STATIC uint32_t in_use[2];
3743

@@ -50,6 +56,14 @@ void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
5056
void reset_pin_number(gpio_num_t pin_number) {
5157
never_reset_pins[pin_number / 32] &= ~(1 << pin_number % 32);
5258
in_use[pin_number / 32] &= ~(1 << pin_number % 32);
59+
60+
#ifdef MICROPY_HW_NEOPIXEL
61+
if (pin_number == MICROPY_HW_NEOPIXEL->number) {
62+
neopixel_in_use = false;
63+
rgb_led_status_init();
64+
return;
65+
}
66+
#endif
5367
}
5468

5569
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
@@ -69,13 +83,32 @@ void reset_all_pins(void) {
6983
}
7084
in_use[0] = 0;
7185
in_use[1] = 0;
86+
87+
#ifdef MICROPY_HW_NEOPIXEL
88+
neopixel_in_use = false;
89+
#endif
7290
}
7391

7492
void claim_pin(const mcu_pin_obj_t* pin) {
7593
in_use[pin->number / 32] |= (1 << pin->number % 32);
94+
#ifdef MICROPY_HW_NEOPIXEL
95+
if (pin == MICROPY_HW_NEOPIXEL) {
96+
neopixel_in_use = true;
97+
}
98+
#endif
99+
}
100+
101+
void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
102+
claim_pin(pin);
76103
}
77104

78105
bool pin_number_is_free(gpio_num_t pin_number) {
106+
#ifdef MICROPY_HW_NEOPIXEL
107+
if (pin_number == MICROPY_HW_NEOPIXEL->number) {
108+
return !neopixel_in_use;
109+
}
110+
#endif
111+
79112
uint8_t offset = pin_number / 32;
80113
uint8_t mask = 1 << pin_number % 32;
81114
return (never_reset_pins[offset] & mask) == 0 && (in_use[offset] & mask) == 0;

ports/esp32s2/common-hal/microcontroller/Pin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
extern bool apa102_mosi_in_use;
3535
extern bool apa102_sck_in_use;
3636

37+
#ifdef MICROPY_HW_NEOPIXEL
38+
extern bool neopixel_in_use;
39+
#endif
40+
3741
void reset_all_pins(void);
3842
// reset_pin_number takes the pin number instead of the pointer so that objects don't
3943
// need to store a full pointer.

0 commit comments

Comments
 (0)