1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Allow specifying waveform generator in source code (#7800)

* Allow specifying waveform generator in source code

Allows code to explicitly specify which waveform generator it wants,
without needing to use one of the 100 IDE menus or adding a `-D`
compile-time define.

Uses weakrefs to allow for apps to call `enablePhaseLockedWaveform();`
within their `setup()` (or anywhere, really) and have the phase locked
versions override the default waveform generators automatically.

For example:

````
void setup() {
  // Uncomment following line to use phase-locked waveform generator
  // enablePhaseLockedWaveform();
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  analogWriteRange(1000);
}
void loop() {
  analogWrite(LED_BUILTIN, 100);
  delay(1000);                      // Wait for a second
  analogWrite(LED_BUILTIN, 900);
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}
````

Also adds an example showing it's use.

Address @dok-net's comments and also remove the _weak/_bound version of
startWaveform() since it's invariant of the actual waveform generator.
This commit is contained in:
Earle F. Philhower, III
2021-01-17 15:57:26 -08:00
committed by GitHub
parent a4b6003c2e
commit f5fd5912fe
14 changed files with 283 additions and 413 deletions

View File

@ -1488,18 +1488,6 @@ def led (name, default, ledList):
]))
return { name: led }
################################################################
# Waveform flavour
def waveform ():
return { 'waveform': collections.OrderedDict([
('.menu.waveform.pwm', 'Locked PWM'),
('.menu.waveform.pwm.build.waveform', ''),
('.menu.waveform.phase', 'Locked Phase'),
('.menu.waveform.phase.build.waveform', '-DWAVEFORM_LOCKED_PHASE'),
])
}
################################################################
# sdk selection
@ -1551,7 +1539,6 @@ 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('#')
@ -1596,7 +1583,6 @@ def all_boards ():
print('menu.wipe=Erase Flash')
print('menu.sdk=Espressif FW')
print('menu.ssl=SSL Support')
print('menu.waveform=Waveform Flavour')
print('menu.mmu=MMU')
print('menu.non32xfer=Non-32-Bit Access')
print('')
@ -1619,7 +1605,7 @@ def all_boards ():
print(id + optname + '=' + board['opts'][optname])
# macros
macrolist = [ 'defaults', 'cpufreq_menu', 'vtable_menu', 'exception_menu', 'stacksmash_menu', 'ssl_cipher_menu', 'waveform', 'mmu_menu', 'non32xfer_menu' ]
macrolist = [ 'defaults', 'cpufreq_menu', 'vtable_menu', 'exception_menu', 'stacksmash_menu', 'ssl_cipher_menu', 'mmu_menu', 'non32xfer_menu' ]
if 'macro' in board:
macrolist += board['macro']
macrolist += [ 'lwip', 'debug_menu', 'flash_erase_menu' ]