Skip to content

Commit

Permalink
install a new waveform-flavouring Arduino IDE menu and a new PIO #def…
Browse files Browse the repository at this point in the history
…ine (#7712)
  • Loading branch information
d-a-v authored Nov 19, 2020
1 parent 0e735e3 commit eec4dc4
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 17 deletions.
137 changes: 137 additions & 0 deletions boards.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions cores/esp8266/core_esp8266_waveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef WAVEFORM_LOCKED_PHASE

#include "core_esp8266_waveform.h"
#include <Arduino.h>
#include "ets_sys.h"
Expand Down Expand Up @@ -434,3 +436,5 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
// Register access is fast and edge IRQ was configured before.
T1L = nextEventCcys;
}

#endif // WAVEFORM_LOCKED_PHASE
6 changes: 5 additions & 1 deletion cores/esp8266/core_esp8266_waveform.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef WAVEFORM_LOCKED_PHASE

#include <Arduino.h>

#ifndef __ESP8266_WAVEFORM_H
Expand Down Expand Up @@ -86,4 +88,6 @@ void setTimer1Callback(uint32_t (*fn)());
}
#endif

#endif
#endif // __ESP8266_WAVEFORM_H

#endif // WAVEFORM_LOCKED_PHASE
33 changes: 21 additions & 12 deletions cores/esp8266/core_esp8266_wiring_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,12 @@

extern "C" {

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

extern void __analogWriteRange(uint32_t range) {
if ((range >= 15) && (range <= 65535)) {
analogScale = range;
}
}
#ifdef WAVEFORM_LOCKED_PHASE

extern void __analogWriteResolution(int res) {
if ((res >= 4) && (res <= 16)) {
analogScale = (1 << res) - 1;
}
}
static uint32_t analogMap = 0;
static uint16_t analogFreq = 1000;

extern void __analogWriteFreq(uint32_t freq) {
if (freq < 100) {
Expand Down Expand Up @@ -82,6 +73,24 @@ extern void __analogWrite(uint8_t pin, int val) {
}
}

#endif // WAVEFORM_LOCKED_PHASE

#ifdef WAVEFORM_LOCKED_PWM

#endif // WAVEFORM_LOCKED_PWM

extern void __analogWriteRange(uint32_t range) {
if ((range >= 15) && (range <= 65535)) {
analogScale = range;
}
}

extern void __analogWriteResolution(int res) {
if ((res >= 4) && (res <= 16)) {
analogScale = (1 << res) - 1;
}
}

extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite")));
extern void analogWriteFreq(uint32_t freq) __attribute__((weak, alias("__analogWriteFreq")));
extern void analogWriteRange(uint32_t range) __attribute__((weak, alias("__analogWriteRange")));
Expand Down
12 changes: 11 additions & 1 deletion libraries/Servo/src/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs, int value)
{
if (!_attached) {
#ifdef WAVEFORM_LOCKED_PHASE
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
#else
digitalWrite(pin, LOW);
pinMode(pin, OUTPUT);
#endif
_pin = pin;
_attached = true;
}
Expand Down Expand Up @@ -115,9 +120,14 @@ void Servo::writeMicroseconds(int value)
_valueUs = value;
if (_attached) {
_servoMap &= ~(1 << _pin);
#ifdef WAVEFORM_LOCKED_PHASE
// 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)
int phaseReference = __builtin_ffs(_servoMap) - 1;
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0, phaseReference)) {
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0, phaseReference))
#else
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0))
#endif
{
_servoMap |= (1 << _pin);
}
}
Expand Down
4 changes: 2 additions & 2 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
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"

compiler.c.cmd=xtensa-lx106-elf-gcc
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}
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}

compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
Expand All @@ -66,7 +66,7 @@ compiler.c.elf.cmd=xtensa-lx106-elf-gcc
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

compiler.cpp.cmd=xtensa-lx106-elf-g++
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}
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}

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

Expand Down
16 changes: 15 additions & 1 deletion tools/boards.txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,18 @@ def led (name, default, ledList):
]))
return { name: led }

################################################################
# Waveform flavour

def waveform ():
return { 'waveform': collections.OrderedDict([
('.menu.waveform.phase', 'Locked Phase'),
('.menu.waveform.phase.build.waveform', '-DWAVEFORM_LOCKED_PHASE'),
('.menu.waveform.pwm', 'Locked PWM'),
('.menu.waveform.pwm.build.waveform', '-DWAVEFORM_LOCKED_PWM'),
])
}

################################################################
# sdk selection

Expand Down Expand Up @@ -1517,6 +1529,7 @@ def all_boards ():
macros.update(led('led', led_default, range(0,led_max+1)))
macros.update(led('led216', 2, { 16 }))
macros.update(sdk())
macros.update(waveform())

if boardfilteropt or excludeboards:
print('#')
Expand Down Expand Up @@ -1561,6 +1574,7 @@ def all_boards ():
print('menu.wipe=Erase Flash')
print('menu.sdk=Espressif FW')
print('menu.ssl=SSL Support')
print('menu.waveform=Waveform Flavour')
print('')

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

# macros
macrolist = [ 'defaults', 'cpufreq_menu', 'vtable_menu', 'exception_menu', 'stacksmash_menu', 'ssl_cipher_menu' ]
macrolist = [ 'defaults', 'cpufreq_menu', 'vtable_menu', 'exception_menu', 'stacksmash_menu', 'ssl_cipher_menu', 'waveform' ]
if 'macro' in board:
macrolist += board['macro']
macrolist += [ 'lwip', 'debug_menu', 'flash_erase_menu' ]
Expand Down
9 changes: 9 additions & 0 deletions tools/platformio-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ def scons_patched_match_splitext(path, suffixes=None):
LIBS=["lwip2-536-feat"]
)

#
# Waveform
#
if "PIO_FRAMEWORK_ARDUINO_WAVEFORM_LOCKED_PWM" in flatten_cppdefines:
env.Append(CPPDEFINES=[("WAVEFORM_LOCKED_PWM", 1)])
# PIO_FRAMEWORK_ARDUINO_WAVEFORM_LOCKED_PHASE (defaults)
else:
env.Append(CPPDEFINES=[("WAVEFORM_LOCKED_PHASE", 1)])

#
# VTables
#
Expand Down

0 comments on commit eec4dc4

Please sign in to comment.