|
1 |
| -/* |
2 |
| - esp8266_waveform - General purpose waveform generation and control, |
3 |
| - supporting outputs on all pins in parallel. |
4 |
| -
|
5 |
| - Copyright (c) 2018 Earle F. Philhower, III. All rights reserved. |
6 |
| -
|
7 |
| - The core idea is to have a programmable waveform generator with a unique |
8 |
| - high and low period (defined in microseconds or CPU clock cycles). TIMER1 is |
9 |
| - set to 1-shot mode and is always loaded with the time until the next edge |
10 |
| - of any live waveforms. |
11 |
| -
|
12 |
| - Up to one waveform generator per pin supported. |
13 |
| -
|
14 |
| - Each waveform generator is synchronized to the ESP clock cycle counter, not the |
15 |
| - timer. This allows for removing interrupt jitter and delay as the counter |
16 |
| - always increments once per 80MHz clock. Changes to a waveform are |
17 |
| - contiguous and only take effect on the next waveform transition, |
18 |
| - allowing for smooth transitions. |
19 |
| -
|
20 |
| - This replaces older tone(), analogWrite(), and the Servo classes. |
21 |
| -
|
22 |
| - Everywhere in the code where "cycles" is used, it means ESP.getCycleCount() |
23 |
| - clock cycle count, or an interval measured in CPU clock cycles, but not TIMER1 |
24 |
| - cycles (which may be 2 CPU clock cycles @ 160MHz). |
25 |
| -
|
26 |
| - This library is free software; you can redistribute it and/or |
27 |
| - modify it under the terms of the GNU Lesser General Public |
28 |
| - License as published by the Free Software Foundation; either |
29 |
| - version 2.1 of the License, or (at your option) any later version. |
30 |
| -
|
31 |
| - This library is distributed in the hope that it will be useful, |
32 |
| - but WITHOUT ANY WARRANTY; without even the implied warranty of |
33 |
| - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
34 |
| - Lesser General Public License for more details. |
35 |
| -
|
36 |
| - You should have received a copy of the GNU Lesser General Public |
37 |
| - License along with this library; if not, write to the Free Software |
38 |
| - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
39 |
| -*/ |
40 |
| - |
41 |
| -#include <Arduino.h> |
42 |
| - |
43 |
| -#ifndef __ESP8266_WAVEFORM_H |
44 |
| -#define __ESP8266_WAVEFORM_H |
45 |
| - |
46 |
| -#ifdef __cplusplus |
47 |
| -extern "C" { |
48 |
| -#endif |
49 |
| - |
50 |
| -// Start or change a waveform of the specified high and low times on specific pin. |
51 |
| -// If runtimeUS > 0 then automatically stop it after that many usecs. |
52 |
| -// Returns true or false on success or failure. |
53 |
| -int startWaveform(uint8_t pin, uint32_t timeHighUS, uint32_t timeLowUS, uint32_t runTimeUS); |
54 |
| -// Start or change a waveform of the specified high and low CPU clock cycles on specific pin. |
55 |
| -// If runtimeCycles > 0 then automatically stop it after that many CPU clock cycles. |
56 |
| -// Returns true or false on success or failure. |
57 |
| -int startWaveformClockCycles(uint8_t pin, uint32_t timeHighCycles, uint32_t timeLowCycles, uint32_t runTimeCycles); |
58 |
| -// Stop a waveform, if any, on the specified pin. |
59 |
| -// Returns true or false on success or failure. |
60 |
| -int stopWaveform(uint8_t pin); |
61 |
| - |
62 |
| -// Add a callback function to be called on *EVERY* timer1 trigger. The |
63 |
| -// callback returns the number of microseconds until the next desired call. |
64 |
| -// However, since it is called every timer1 interrupt, it may be called |
65 |
| -// again before this period. It should therefore use the ESP Cycle Counter |
66 |
| -// to determine whether or not to perform an operation. |
67 |
| -// Pass in NULL to disable the callback and, if no other waveforms being |
68 |
| -// generated, stop the timer as well. |
69 |
| -// Make sure the CB function has the ICACHE_RAM_ATTR decorator. |
70 |
| -void setTimer1Callback(uint32_t (*fn)()); |
71 |
| - |
72 |
| - |
73 |
| - |
74 |
| -// Internal-only calls, not for applications |
75 |
| -extern void _setPWMFreq(uint32_t freq); |
76 |
| -extern bool _stopPWM(int pin); |
77 |
| -extern bool _setPWM(int pin, uint32_t val, uint32_t range); |
78 |
| - |
79 |
| -#ifdef __cplusplus |
80 |
| -} |
81 |
| -#endif |
| 1 | +// Wrapper to include both versions of the waveform generator |
82 | 2 |
|
| 3 | +#ifdef WAVEFORM_LOCKED_PHASE |
| 4 | + #include "core_esp8266_waveform_phase.h" |
| 5 | +#else |
| 6 | + #include "core_esp8266_waveform_pwm.h" |
83 | 7 | #endif
|
0 commit comments