Skip to content

Commit e6d5d96

Browse files
authored
Update fade_s2.py
made the default LED pin 4, with the option for the user to change led_pin.
1 parent 277067c commit e6d5d96

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

examples/fade_s2.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# SPDX-License-Identifier: MIT
77

88
"""
9-
Example for: ESP32-S2 Wemos mini development board V1.0.0 with led on pin 15
9+
Example for: ESP32-S2
1010
1111
This example creates a PWM-like dimming effect using self-modifying ULP code.
1212
The ULP program rewrites the `WAIT` instructions to control on/off LED durations,
@@ -23,32 +23,34 @@
2323
from time import sleep
2424

2525
source = """\
26+
# Pin with LED: (0 to 21)
27+
.set led_pin, 4
28+
2629
# constants from:
2730
# https://github.com/espressif/esp-idf/blob/v5.0.2/components/soc/esp32s2/include/soc/reg_base.h
2831
#define DR_REG_RTCIO_BASE 0x3f408400
2932
33+
# constants from:
34+
# Espressif Technical Reference Manual (TRM) Chapter 5.15 Register 5.63:
35+
#define RTCIO_TOUCH_PADn_REG (DR_REG_RTCIO_BASE + 0x84 + 4 * led_pin)
36+
#define RTCIO_TOUCH_PADn_MUX_SEL_M (BIT(19))
37+
3038
# constants from:
3139
# https://github.com/espressif/esp-idf/blob/v5.0.2/components/soc/esp32s2/include/soc/rtc_io_reg.h
32-
#define RTC_IO_XTAL_32P_PAD_REG (DR_REG_RTCIO_BASE + 0xC0)
33-
#define RTC_IO_X32P_MUX_SEL_M (BIT(19))
3440
#define RTC_GPIO_OUT_REG (DR_REG_RTCIO_BASE + 0x0)
3541
#define RTC_GPIO_ENABLE_REG (DR_REG_RTCIO_BASE + 0xc)
3642
#define RTC_GPIO_ENABLE_S 10
3743
#define RTC_GPIO_OUT_DATA_S 10
3844
39-
# constants from:
40-
# https://github.com/espressif/esp-idf/blob/v5.0.2/components/soc/esp32s2/include/soc/rtc_io_channel.h
41-
#define RTCIO_GPIO15_CHANNEL 15
42-
4345
.global entry
4446
program_init:
45-
# connect GPIO to ULP (0: GPIO connected to digital GPIO module, 1: GPIO connected to analog RTC module)
46-
WRITE_RTC_REG(RTC_IO_XTAL_32P_PAD_REG, RTC_IO_X32P_MUX_SEL_M, 1, 1);
47+
# connect GPIO to ULP (0: GPIO connected to digital GPIO module, 1: GPIO connected to analog RTC module)
48+
WRITE_RTC_REG(RTCIO_TOUCH_PADn_REG, RTCIO_TOUCH_PADn_MUX_SEL_M, 1, 1);
4749
48-
# enable GPIO as output, not input (this also enables a pull-down by default)
49-
WRITE_RTC_REG(RTC_GPIO_ENABLE_REG, RTC_GPIO_ENABLE_S + RTCIO_GPIO15_CHANNEL, 1, 1)
50+
# enable GPIO as output, not input (this also enables a pull-down by default)
51+
WRITE_RTC_REG(RTC_GPIO_ENABLE_REG, RTC_GPIO_ENABLE_S + led_pin, 1, 1)
5052
51-
set_waits: add r0, r0, 0xFF # Increase r0 (delay time)
53+
set_waits: add r0, r0, 200 # Increase r0 (delay time)
5254
move r3, wait_off
5355
st r0, r3, 0 # Overwrite wait_off with new delay value
5456
@@ -57,9 +59,9 @@
5759
move r3, wait_on
5860
st r1, r3, 0 # Overwrite wait_on with new value
5961
60-
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + RTCIO_GPIO15_CHANNEL, 1, 0) # turn off led
62+
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + led_pin, 1, 0) # turn off led (clear GPIO)
6163
wait_off: wait 0 # Placeholder; value overwritten dynamically
62-
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + RTCIO_GPIO15_CHANNEL, 1, 1) # turn on led
64+
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + led_pin, 1, 1) # turn on led (set GPIO)
6365
wait_on: wait 0 # Placeholder; value overwritten dynamically
6466
6567
jump set_waits # Loop program

0 commit comments

Comments
 (0)