Skip to content

Commit eec4dc4

Browse files
authored
install a new waveform-flavouring Arduino IDE menu and a new PIO #define (esp8266#7712)
1 parent 0e735e3 commit eec4dc4

File tree

8 files changed

+204
-17
lines changed

8 files changed

+204
-17
lines changed

boards.txt

+137
Large diffs are not rendered by default.

cores/esp8266/core_esp8266_waveform.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4040
*/
4141

42+
#ifdef WAVEFORM_LOCKED_PHASE
43+
4244
#include "core_esp8266_waveform.h"
4345
#include <Arduino.h>
4446
#include "ets_sys.h"
@@ -434,3 +436,5 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
434436
// Register access is fast and edge IRQ was configured before.
435437
T1L = nextEventCcys;
436438
}
439+
440+
#endif // WAVEFORM_LOCKED_PHASE

cores/esp8266/core_esp8266_waveform.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4040
*/
4141

42+
#ifdef WAVEFORM_LOCKED_PHASE
43+
4244
#include <Arduino.h>
4345

4446
#ifndef __ESP8266_WAVEFORM_H
@@ -86,4 +88,6 @@ void setTimer1Callback(uint32_t (*fn)());
8688
}
8789
#endif
8890

89-
#endif
91+
#endif // __ESP8266_WAVEFORM_H
92+
93+
#endif // WAVEFORM_LOCKED_PHASE

cores/esp8266/core_esp8266_wiring_pwm.cpp

+21-12
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,12 @@
2626

2727
extern "C" {
2828

29-
static uint32_t analogMap = 0;
3029
static int32_t analogScale = 255; // Match upstream default, breaking change from 2.x.x
31-
static uint16_t analogFreq = 1000;
3230

33-
extern void __analogWriteRange(uint32_t range) {
34-
if ((range >= 15) && (range <= 65535)) {
35-
analogScale = range;
36-
}
37-
}
31+
#ifdef WAVEFORM_LOCKED_PHASE
3832

39-
extern void __analogWriteResolution(int res) {
40-
if ((res >= 4) && (res <= 16)) {
41-
analogScale = (1 << res) - 1;
42-
}
43-
}
33+
static uint32_t analogMap = 0;
34+
static uint16_t analogFreq = 1000;
4435

4536
extern void __analogWriteFreq(uint32_t freq) {
4637
if (freq < 100) {
@@ -82,6 +73,24 @@ extern void __analogWrite(uint8_t pin, int val) {
8273
}
8374
}
8475

76+
#endif // WAVEFORM_LOCKED_PHASE
77+
78+
#ifdef WAVEFORM_LOCKED_PWM
79+
80+
#endif // WAVEFORM_LOCKED_PWM
81+
82+
extern void __analogWriteRange(uint32_t range) {
83+
if ((range >= 15) && (range <= 65535)) {
84+
analogScale = range;
85+
}
86+
}
87+
88+
extern void __analogWriteResolution(int res) {
89+
if ((res >= 4) && (res <= 16)) {
90+
analogScale = (1 << res) - 1;
91+
}
92+
}
93+
8594
extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite")));
8695
extern void analogWriteFreq(uint32_t freq) __attribute__((weak, alias("__analogWriteFreq")));
8796
extern void analogWriteRange(uint32_t range) __attribute__((weak, alias("__analogWriteRange")));

libraries/Servo/src/Servo.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
6969
uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs, int value)
7070
{
7171
if (!_attached) {
72+
#ifdef WAVEFORM_LOCKED_PHASE
7273
pinMode(pin, OUTPUT);
7374
digitalWrite(pin, LOW);
75+
#else
76+
digitalWrite(pin, LOW);
77+
pinMode(pin, OUTPUT);
78+
#endif
7479
_pin = pin;
7580
_attached = true;
7681
}
@@ -115,9 +120,14 @@ void Servo::writeMicroseconds(int value)
115120
_valueUs = value;
116121
if (_attached) {
117122
_servoMap &= ~(1 << _pin);
123+
#ifdef WAVEFORM_LOCKED_PHASE
118124
// Find the first GPIO being generated by checking GCC's find-first-set (returns 1 + the bit of the first 1 in an int32_t)
119125
int phaseReference = __builtin_ffs(_servoMap) - 1;
120-
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0, phaseReference)) {
126+
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0, phaseReference))
127+
#else
128+
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0))
129+
#endif
130+
{
121131
_servoMap |= (1 << _pin);
122132
}
123133
}

platform.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
5555
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"
5656

5757
compiler.c.cmd=xtensa-lx106-elf-gcc
58-
compiler.c.flags=-c {compiler.warning_flags} -std=gnu17 {build.stacksmash_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags}
58+
compiler.c.flags=-c {compiler.warning_flags} -std=gnu17 {build.stacksmash_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.waveform}
5959

6060
compiler.S.cmd=xtensa-lx106-elf-gcc
6161
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
@@ -66,7 +66,7 @@ compiler.c.elf.cmd=xtensa-lx106-elf-gcc
6666
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc
6767

6868
compiler.cpp.cmd=xtensa-lx106-elf-g++
69-
compiler.cpp.flags=-c {compiler.warning_flags} {build.stacksmash_flags} -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags}
69+
compiler.cpp.flags=-c {compiler.warning_flags} {build.stacksmash_flags} -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.waveform}
7070

7171
compiler.as.cmd=xtensa-lx106-elf-as
7272

tools/boards.txt.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,18 @@ def led (name, default, ledList):
14661466
]))
14671467
return { name: led }
14681468

1469+
################################################################
1470+
# Waveform flavour
1471+
1472+
def waveform ():
1473+
return { 'waveform': collections.OrderedDict([
1474+
('.menu.waveform.phase', 'Locked Phase'),
1475+
('.menu.waveform.phase.build.waveform', '-DWAVEFORM_LOCKED_PHASE'),
1476+
('.menu.waveform.pwm', 'Locked PWM'),
1477+
('.menu.waveform.pwm.build.waveform', '-DWAVEFORM_LOCKED_PWM'),
1478+
])
1479+
}
1480+
14691481
################################################################
14701482
# sdk selection
14711483

@@ -1517,6 +1529,7 @@ def all_boards ():
15171529
macros.update(led('led', led_default, range(0,led_max+1)))
15181530
macros.update(led('led216', 2, { 16 }))
15191531
macros.update(sdk())
1532+
macros.update(waveform())
15201533

15211534
if boardfilteropt or excludeboards:
15221535
print('#')
@@ -1561,6 +1574,7 @@ def all_boards ():
15611574
print('menu.wipe=Erase Flash')
15621575
print('menu.sdk=Espressif FW')
15631576
print('menu.ssl=SSL Support')
1577+
print('menu.waveform=Waveform Flavour')
15641578
print('')
15651579

15661580
missingboards = []
@@ -1581,7 +1595,7 @@ def all_boards ():
15811595
print(id + optname + '=' + board['opts'][optname])
15821596

15831597
# macros
1584-
macrolist = [ 'defaults', 'cpufreq_menu', 'vtable_menu', 'exception_menu', 'stacksmash_menu', 'ssl_cipher_menu' ]
1598+
macrolist = [ 'defaults', 'cpufreq_menu', 'vtable_menu', 'exception_menu', 'stacksmash_menu', 'ssl_cipher_menu', 'waveform' ]
15851599
if 'macro' in board:
15861600
macrolist += board['macro']
15871601
macrolist += [ 'lwip', 'debug_menu', 'flash_erase_menu' ]

tools/platformio-build.py

+9
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ def scons_patched_match_splitext(path, suffixes=None):
237237
LIBS=["lwip2-536-feat"]
238238
)
239239

240+
#
241+
# Waveform
242+
#
243+
if "PIO_FRAMEWORK_ARDUINO_WAVEFORM_LOCKED_PWM" in flatten_cppdefines:
244+
env.Append(CPPDEFINES=[("WAVEFORM_LOCKED_PWM", 1)])
245+
# PIO_FRAMEWORK_ARDUINO_WAVEFORM_LOCKED_PHASE (defaults)
246+
else:
247+
env.Append(CPPDEFINES=[("WAVEFORM_LOCKED_PHASE", 1)])
248+
240249
#
241250
# VTables
242251
#

0 commit comments

Comments
 (0)