|
8 | 8 | """ |
9 | 9 | Example for: ESP32 |
10 | 10 |
|
11 | | -Simple example showing how to control a GPIO pin from the ULPcoprocessor. |
| 11 | +Simple example showing how to control a GPIO pin from the ULPco-processor. |
12 | 12 |
|
13 | 13 | The GPIO port is configured to be attached to the RTC module, and then set |
14 | | -to OUTPUT mode. To avoid re-initializing the GPIO on everywakeup, a magic |
| 14 | +to OUTPUT mode. To avoid re-initializing the GPIO on everywake-up, a magic |
15 | 15 | token gets set in memory. |
16 | 16 |
|
17 | 17 | After every change of state, the ULP is put back to sleep again until the |
18 | | -nextwakeup. The ULP wakes up every500ms to change the state of the GPIO |
19 | | -pin. An LED attached to the GPIO pin would toggle on and off every500ms. |
| 18 | +nextwake-up. The ULP wakes up every500 ms to change the state of the GPIO |
| 19 | +pin. An LED attached to the GPIO pin would toggle on and off every500 ms. |
20 | 20 |
|
21 | | -The end of thepython script has a loop to show the value of the magic token |
| 21 | +The end of thePython script has a loop to show the value of the magic token |
22 | 22 | and the current state, so you can confirm the magic token gets set and watch |
23 | 23 | the state value changing. If the loop is stopped (Ctrl-C), the LED attached |
24 | | -to the GPIO pin continues to blink, because the ULP runs independentlyfrom |
| 24 | +to the GPIO pin continues to blink, because the ULP runs independentlyof |
25 | 25 | the main processor. |
26 | 26 | """ |
27 | 27 |
|
|
61 | 61 | move r0, magic |
62 | 62 | ld r1, r0, 0 |
63 | 63 |
|
64 | | - # test if we haveinitialised already |
| 64 | + # test if we haveinitialized already |
65 | 65 | sub r1, r1, token |
66 | 66 | jump after_init, eq # jump if magic == token (note: "eq" means the last instruction (sub) resulted in 0) |
67 | 67 |
|
|
72 | 72 | # GPIO shall be output, not input (this also enables a pull-down by default) |
73 | 73 | WRITE_RTC_REG(RTC_GPIO_ENABLE_REG, RTC_GPIO_ENABLE_S + gpio, 1, 1) |
74 | 74 |
|
75 | | - # store that we're done withinitialisation |
| 75 | + # store that we're done withinitialization |
76 | 76 | move r0, magic |
77 | 77 | move r1, token |
78 | 78 | st r1, r0, 0 |
|
89 | 89 | jump off # else jump to 'off' |
90 | 90 |
|
91 | 91 | on: |
92 | | - # turn onled (set GPIO) |
| 92 | + # turn onLED (set GPIO) |
93 | 93 | WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + gpio, 1, 1) |
94 | 94 | jump exit |
95 | 95 |
|
96 | 96 | off: |
97 | | - # turn offled (clear GPIO) |
| 97 | + # turn offLED (clear GPIO) |
98 | 98 | WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + gpio, 1, 0) |
99 | 99 | jump exit |
100 | 100 |
|
101 | 101 | exit: |
102 | | - halt # go back to sleep until nextwakeup period |
| 102 | + halt # go back to sleep untilthenextwake-up period |
103 | 103 | """ |
104 | 104 |
|
105 | 105 | binary=src_to_binary(source,cpu="esp32")# cpu is esp32 or esp32s2 |
|
110 | 110 | ULP_DATA_MASK=0xffff# ULP data is only in lower 16 bits |
111 | 111 |
|
112 | 112 | ulp=ULP() |
113 | | -ulp.set_wakeup_period(0,500000)# use timer0, wakeupafter500000usec(0.5s) |
| 113 | +ulp.set_wakeup_period(0,500000)# use timer0; wake upafter500000 usec(0.5 s) |
114 | 114 | ulp.load_binary(load_addr,binary) |
115 | 115 |
|
116 | 116 | ulp.run(entry_addr) |
|